Skip to content

Commit

Permalink
Allow all source files to be modified in configure_make when using co…
Browse files Browse the repository at this point in the history
…nfigure_in_place = True (#856)
  • Loading branch information
jsharpe authored Jan 10, 2022
1 parent 2f99650 commit e24d9ce
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 1 deletion.
18 changes: 18 additions & 0 deletions examples/configure_modify_input_source/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
load("@rules_cc//cc:defs.bzl", "cc_test")
load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make")

configure_make(
name = "simple",
configure_in_place = True,
lib_source = "//configure_modify_input_source/simple_lib:simple_srcs",
targets = [
"simple",
"install",
],
)

cc_test(
name = "test",
srcs = ["testSimple.c"],
deps = [":simple"],
)
5 changes: 5 additions & 0 deletions examples/configure_modify_input_source/simple_lib/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
filegroup(
name = "simple_srcs",
srcs = glob(["**"]),
visibility = ["//visibility:public"],
)
11 changes: 11 additions & 0 deletions examples/configure_modify_input_source/simple_lib/Makefile.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
simple: $(OUTPUT)

$(OUTPUT): ./src/simple.c
$(CC) $(CPPFLAGS) -o $(OBJECT) -c ./src/simple.c -I./include -I.
$(AR) $(LDFLAGS)

install: $(OUTPUT)
mkdir -p simple
mkdir -p simple/lib
cp $(OUTPUT) ./simple/lib/$(OUTPUT)
cp -r ./include ./simple
28 changes: 28 additions & 0 deletions examples/configure_modify_input_source/simple_lib/configure
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

set -euo pipefail

# (Using perl here for replacement to avoid difference in in-place
# arguments on macOS sed)

perl -i -pe 's/42/0/' src/simple.c

echo "CC = $CC" > Makefile
echo "LDFLAGS = $LDFLAGS" >> Makefile
if [[ "$(uname)" == *"NT"* ]]; then
echo "AR = ${AR}" >> Makefile
echo "OBJECT = simple.obj" >> Makefile
echo "OUTPUT = simple.lib" >> Makefile

ESCAPED_CPPFLAGS="$(echo ${CFLAGS} | sed 's@\\@/@g')"
ESCAPED_LDFLAGS="$(echo ${LDFLAGS} | sed 's@\\@/@g')"
echo "CPPFLAGS = /c ${ESCAPED_CPPFLAGS}" >> Makefile
echo "LDFLAGS = \$(OBJECT) ${ESCAPED_LDFLAGS} /OUT:\$(OUTPUT)" >> Makefile
else
echo "AR = \"ar\"" >> Makefile
echo "OBJECT = simple.o" >> Makefile
echo "OUTPUT = simple.a" >> Makefile
echo "CPPFLAGS = ${CFLAGS}" >> Makefile
echo "LDFLAGS = rcs \$(OUTPUT) \$(OBJECT)" >> Makefile
fi
cat Makefile.in >> Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef SIMPLE_H_
#define SIMPLE_H_ (1)

int simpleFun(void);

#endif // SIMPLE_H_
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "simple.h"

int simpleFun(void) {
return 42;
}
5 changes: 5 additions & 0 deletions examples/configure_modify_input_source/testSimple.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "simple.h"

int main(int argc, char **argv) {
return simpleFun();
}
2 changes: 1 addition & 1 deletion foreign_cc/private/configure_script.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def create_configure_script(
root_path = "$$EXT_BUILD_ROOT$$/{}".format(root)
configure_path = "{}/{}".format(root_path, configure_command)
if configure_in_place:
script.append("##symlink_contents_to_dir## $$EXT_BUILD_ROOT$$/{} $$BUILD_TMPDIR$$".format(root))
script.append("##copy_dir_contents_to_dir## $$EXT_BUILD_ROOT$$/{} $$BUILD_TMPDIR$$".format(root))
root_path = "$$BUILD_TMPDIR$$"
configure_path = "{}/{}".format(root_path, configure_command)

Expand Down

0 comments on commit e24d9ce

Please sign in to comment.