Skip to content

Commit db73f12

Browse files
nbdd0121UebelAndre
andauthored
Propagate cc_library defines to clang (#3271)
Currently if `cc_library` uses `defines = [...]`, it won't be picked by bindgen. This is a 2-line fix to add the support (with tests). Co-authored-by: UebelAndre <[email protected]>
1 parent eec80a3 commit db73f12

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

extensions/bindgen/private/bindgen.bzl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,10 @@ def _rust_bindgen_impl(ctx):
307307
open_arg = True
308308
continue
309309

310+
# Propagated defines should be made visible to clang
311+
for define in ctx.attr.cc_lib[CcInfo].compilation_context.defines.to_list():
312+
args.add("-D" + define)
313+
310314
_, _, linker_env = get_linker_and_args(ctx, "bin", cc_toolchain, feature_configuration, None)
311315
env.update(**linker_env)
312316

extensions/bindgen/test/integration/simple/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ cc_library(
1111
name = "simple",
1212
srcs = ["simple.cc"],
1313
hdrs = ["simple.h"],
14+
defines = ["SIMPLE_DEFINE=1"],
1415
visibility = ["//test/integration:__pkg__"],
1516
)

extensions/bindgen/test/integration/simple/simple.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@
99

1010
#include <stdint.h>
1111

12+
#ifdef SIMPLE_DEFINE
13+
1214
static const int64_t SIMPLE_VALUE = 42;
1315

16+
#endif
17+
1418
EXTERN_C const int64_t simple_function();
1519

1620
static inline int64_t simple_static_function() { return 84; }

0 commit comments

Comments
 (0)