-
Notifications
You must be signed in to change notification settings - Fork 2
/
rules_foreign_cc.patch
133 lines (125 loc) · 5.2 KB
/
rules_foreign_cc.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
diff --git foreign_cc/boost_build.bzl foreign_cc/boost_build.bzl
index d8e489f..2462117 100644
--- foreign_cc/boost_build.bzl
+++ foreign_cc/boost_build.bzl
@@ -15,6 +15,7 @@ def _boost_build_impl(ctx):
ctx.attr,
configure_name = "BoostBuild",
create_configure_script = _create_configure_script,
+ tools_data = [],
)
return cc_external_rule_impl(ctx, attrs)
diff --git foreign_cc/configure.bzl foreign_cc/configure.bzl
index ddfc379..38eec7d 100644
--- foreign_cc/configure.bzl
+++ foreign_cc/configure.bzl
@@ -98,6 +98,7 @@ def _create_configure_script(configureParameters):
deps = ctx.attr.deps,
inputs = inputs,
env_vars = user_env,
+ env_vars_override = ctx.attr.env_override,
configure_in_place = ctx.attr.configure_in_place,
prefix_flag = ctx.attr.prefix_flag,
autoconf = ctx.attr.autoconf,
diff --git foreign_cc/make.bzl foreign_cc/make.bzl
index fcdd8a5..c7c6862 100644
--- foreign_cc/make.bzl
+++ foreign_cc/make.bzl
@@ -74,6 +74,7 @@ def _create_make_script(configureParameters):
deps = ctx.attr.deps,
inputs = inputs,
env_vars = user_env,
+ env_vars_override = ctx.attr.env_override,
make_commands = make_commands,
)
diff --git foreign_cc/private/configure_script.bzl foreign_cc/private/configure_script.bzl
index 06c516e..de4f470 100644
--- foreign_cc/private/configure_script.bzl
+++ foreign_cc/private/configure_script.bzl
@@ -14,6 +14,7 @@ def create_configure_script(
deps,
inputs,
env_vars,
+ env_vars_override,
configure_in_place,
prefix_flag,
autoconf,
@@ -70,7 +71,7 @@ def create_configure_script(
script.append("##mkdirs## $$BUILD_TMPDIR$$/$$INSTALL_PREFIX$$")
script.append("{env_vars} {prefix}\"{configure}\" {prefix_flag}$$BUILD_TMPDIR$$/$$INSTALL_PREFIX$$ {user_options}".format(
- env_vars = get_make_env_vars(workspace_name, tools, flags, env_vars, deps, inputs),
+ env_vars = get_make_env_vars(workspace_name, tools, flags, env_vars, env_vars_override, deps, inputs),
prefix = configure_prefix,
configure = configure_path,
prefix_flag = prefix_flag,
diff --git foreign_cc/private/framework.bzl foreign_cc/private/framework.bzl
index 9c263c0..56f1ae3 100644
--- foreign_cc/private/framework.bzl
+++ foreign_cc/private/framework.bzl
@@ -108,6 +108,13 @@ CC_EXTERNAL_RULE_ATTRIBUTES = {
"Variables containing `PATH` (e.g. `PATH`, `LD_LIBRARY_PATH`, `CPATH`) entries will be prepended to the existing variable."
),
),
+ "env_override": attr.string_list(
+ doc = (
+ "List of keys from the 'env' attribute that should override any values set by the underlying C toolchain."
+ ),
+ mandatory = False,
+ default = [],
+ ),
"includes": attr.string_list(
doc = (
"Optional list of include dirs to be passed to the dependencies of this library. " +
diff --git foreign_cc/private/make_env_vars.bzl foreign_cc/private/make_env_vars.bzl
index b5177c7..e70c974 100644
--- foreign_cc/private/make_env_vars.bzl
+++ foreign_cc/private/make_env_vars.bzl
@@ -9,9 +9,10 @@ def get_make_env_vars(
tools,
flags,
user_vars,
+ user_vars_override,
deps,
inputs):
- vars = _get_make_variables(workspace_name, tools, flags, user_vars)
+ vars = _get_make_variables(workspace_name, tools, flags, user_vars, user_vars_override)
deps_flags = _define_deps_flags(deps, inputs)
# For cross-compilation.
@@ -94,7 +95,7 @@ _MAKE_TOOLS = {
# missing: cxx_linker_executable
}
-def _get_make_variables(workspace_name, tools, flags, user_env_vars):
+def _get_make_variables(workspace_name, tools, flags, user_env_vars, user_vars_override):
vars = {}
for flag in _MAKE_FLAGS:
@@ -106,7 +107,10 @@ def _get_make_variables(workspace_name, tools, flags, user_env_vars):
for user_var in user_env_vars:
toolchain_val = vars.get(user_var)
if toolchain_val:
- vars[user_var] = toolchain_val + [user_env_vars[user_var]]
+ if user_var in user_vars_override:
+ vars[user_var] = [user_env_vars[user_var]]
+ else:
+ vars[user_var] = toolchain_val + [user_env_vars[user_var]]
tools_dict = {}
for tool in _MAKE_TOOLS:
diff --git foreign_cc/private/make_script.bzl foreign_cc/private/make_script.bzl
index d86ff60..039b0cf 100644
--- foreign_cc/private/make_script.bzl
+++ foreign_cc/private/make_script.bzl
@@ -9,6 +9,7 @@ def create_make_script(
flags,
root,
env_vars,
+ env_vars_override,
deps,
inputs,
make_commands):
@@ -19,7 +20,7 @@ def create_make_script(
script.append("##symlink_contents_to_dir## $$EXT_BUILD_ROOT$$/{} $$BUILD_TMPDIR$$ False".format(root))
script.append("##enable_tracing##")
- configure_vars = get_make_env_vars(workspace_name, tools, flags, env_vars, deps, inputs)
+ configure_vars = get_make_env_vars(workspace_name, tools, flags, env_vars, env_vars_override, deps, inputs)
script.extend(["{env_vars} {command}".format(
env_vars = configure_vars,
command = command,