Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow all source files to be modified in configure_make when using configure_in_place = True #856

Merged
merged 4 commits into from
Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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