Skip to content

Commit 8bc77be

Browse files
nbdd0121jwnrt
authored andcommitted
[bazel] patch bindgen to recognise cc_library defines
Signed-off-by: Gary Guo <[email protected]> Signed-off-by: Alex Jones <[email protected]>
1 parent ce11ad8 commit 8bc77be

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
commit 27500d1eaa0e8e0f8c53b8ff5a0b9772417cdb3b
2+
Author: Gary Guo <[email protected]>
3+
Date: Fri Feb 14 15:18:37 2025 +0000
4+
5+
Propagate cc_library defines to clang
6+
7+
diff --git a/extensions/bindgen/private/bindgen.bzl b/extensions/bindgen/private/bindgen.bzl
8+
index 6fa53571..1ebe104c 100644
9+
--- a/extensions/bindgen/private/bindgen.bzl
10+
+++ b/extensions/bindgen/private/bindgen.bzl
11+
@@ -307,6 +307,10 @@ def _rust_bindgen_impl(ctx):
12+
open_arg = True
13+
continue
14+
15+
+ # Propagated defines should be made visible to clang
16+
+ for define in ctx.attr.cc_lib[CcInfo].compilation_context.defines.to_list():
17+
+ args.add("-D" + define)
18+
+
19+
_, _, linker_env = get_linker_and_args(ctx, "bin", cc_toolchain, feature_configuration, None)
20+
env.update(**linker_env)
21+
22+
diff --git a/extensions/bindgen/test/integration/simple/BUILD.bazel b/extensions/bindgen/test/integration/simple/BUILD.bazel
23+
index 0a1162b1..c52e8272 100644
24+
--- a/extensions/bindgen/test/integration/simple/BUILD.bazel
25+
+++ b/extensions/bindgen/test/integration/simple/BUILD.bazel
26+
@@ -11,5 +11,6 @@ cc_library(
27+
name = "simple",
28+
srcs = ["simple.cc"],
29+
hdrs = ["simple.h"],
30+
+ defines = ["SIMPLE_DEFINE=1"],
31+
visibility = ["//test/integration:__pkg__"],
32+
)
33+
diff --git a/extensions/bindgen/test/integration/simple/simple.h b/extensions/bindgen/test/integration/simple/simple.h
34+
index a7ca3f43..d68c739a 100644
35+
--- a/extensions/bindgen/test/integration/simple/simple.h
36+
+++ b/extensions/bindgen/test/integration/simple/simple.h
37+
@@ -9,8 +9,12 @@
38+
39+
#include <stdint.h>
40+
41+
+#ifdef SIMPLE_DEFINE
42+
+
43+
static const int64_t SIMPLE_VALUE = 42;
44+
45+
+#endif
46+
+
47+
EXTERN_C const int64_t simple_function();
48+
49+
static inline int64_t simple_static_function() { return 84; }
50+

third_party/rust/rust.MODULE.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ single_version_override(
2121
module_name = "rules_rust_bindgen",
2222
patches = [
2323
"//third_party/rust/patches:rules_rust.bindgen_static_lib.patch",
24+
"//third_party/rust/patches:rules_rust.bindgen_defines.patch",
2425
],
2526
patch_strip = 3,
2627
version = "0.56.0",

0 commit comments

Comments
 (0)