Skip to content

Propagate cc_library defines to clang #3271

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

Merged
merged 3 commits into from
Feb 27, 2025
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
4 changes: 4 additions & 0 deletions extensions/bindgen/private/bindgen.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@ def _rust_bindgen_impl(ctx):
open_arg = True
continue

# Propagated defines should be made visible to clang
for define in ctx.attr.cc_lib[CcInfo].compilation_context.defines.to_list():
args.add("-D" + define)

_, _, linker_env = get_linker_and_args(ctx, "bin", cc_toolchain, feature_configuration, None)
env.update(**linker_env)

Expand Down
1 change: 1 addition & 0 deletions extensions/bindgen/test/integration/simple/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ cc_library(
name = "simple",
srcs = ["simple.cc"],
hdrs = ["simple.h"],
defines = ["SIMPLE_DEFINE=1"],
visibility = ["//test/integration:__pkg__"],
)
4 changes: 4 additions & 0 deletions extensions/bindgen/test/integration/simple/simple.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@

#include <stdint.h>

#ifdef SIMPLE_DEFINE

static const int64_t SIMPLE_VALUE = 42;

#endif

EXTERN_C const int64_t simple_function();

static inline int64_t simple_static_function() { return 84; }
Expand Down