Skip to content

Commit b1e52ae

Browse files
committed
Add cc_import.defines
Fixes #19753
1 parent 195c066 commit b1e52ae

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

src/main/starlark/builtins_bzl/common/cc/cc_import.bzl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ def _cc_import_impl(ctx):
165165
public_hdrs = ctx.files.hdrs,
166166
includes = ctx.attr.includes,
167167
name = ctx.label.name,
168+
defines = cc_helper.defines(ctx, {}),
168169
)
169170

170171
this_cc_info = CcInfo(compilation_context = compilation_context, linking_context = linking_context)
@@ -416,6 +417,16 @@ most build rules</a>."""),
416417
allow_files = True,
417418
flags = ["SKIP_CONSTRAINTS_OVERRIDE"],
418419
),
420+
"defines": attr.string_list(doc = """
421+
List of defines to add to the compile line of this and all dependent targets.
422+
Subject to <a href="${link make-variables}">"Make" variable</a> substitution and
423+
<a href="${link common-definitions#sh-tokenization}">Bourne shell tokenization</a>.
424+
Each string, which must consist of a single Bourne shell token,
425+
is prepended with <code>-D</code> and added to the compile command line to this target,
426+
as well as to every rule that depends on it. Be very careful, since this may have
427+
far-reaching effects -- the defines are added to every target that depends on
428+
this target.
429+
"""),
419430
"_use_auto_exec_groups": attr.bool(default = True),
420431
},
421432
provides = [CcInfo],

src/main/starlark/tests/builtins_bzl/cc/cc_static_library/test/BUILD.builtin_test

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ cc_test(
4444
deps = [":static_import"],
4545
)
4646

47+
cc_import(
48+
name = "lib_with_define",
49+
defines = ["IMPORT_DEFINE"],
50+
static_library = ":lib_only",
51+
)
52+
53+
cc_test(
54+
name = "define_test",
55+
srcs = ["require_define.cc"],
56+
deps = [":lib_with_define"],
57+
)
58+
4759
sh_test(
4860
name = "cc_static_library_integration_test",
4961
srcs = [
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#ifndef IMPORT_DEFINE
2+
#error "Missing expected IMPORT_DEFINE"
3+
#endif
4+
5+
int main() {
6+
return 0;
7+
}

0 commit comments

Comments
 (0)