Skip to content

Commit 788d159

Browse files
authored
[libc][bazel] Allow configure options to alter all targets (llvm#89251)
The previous state was leading to inconsistencies. Some targets would get the options and some wouldn't. As an example, the `MEMORY_COPTS` definitions would only apply to the `:string_memory_utils` target but not to the `:memcpy` target. This patch makes sure definitions are applied throughout the LLVM libc targets as `local_defines`. This ensures that the preprocessor definitions don't propagate to depending targets outside of LLVM libc, and that all libc targets have consistent preprocessor definitions.
1 parent 603ba4c commit 788d159

File tree

4 files changed

+58
-30
lines changed

4 files changed

+58
-30
lines changed

utils/bazel/llvm-project-overlay/libc/BUILD.bazel

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,6 @@ package(
2323

2424
licenses(["notice"])
2525

26-
PRINTF_COPTS = [
27-
"LIBC_COPT_STDIO_USE_SYSTEM_FILE",
28-
"LIBC_COPT_PRINTF_DISABLE_WRITE_INT",
29-
]
30-
31-
MEMORY_COPTS = [
32-
# "LIBC_COPT_MEMCPY_X86_USE_REPMOVSB_FROM_SIZE=0",
33-
# "LIBC_COPT_MEMCPY_X86_USE_SOFTWARE_PREFETCHING",
34-
# "LIBC_COPT_MEMSET_X86_USE_SOFTWARE_PREFETCHING",
35-
]
36-
3726
# A flag to pick which `mpfr` to use for math tests.
3827
# Usage: `--@llvm-project//libc:mpfr=<disable|external|system>`.
3928
# Flag documentation: https://bazel.build/extending/config
@@ -2421,7 +2410,6 @@ libc_support_library(
24212410
"src/string/memory_utils/op_x86.h",
24222411
"src/string/memory_utils/utils.h",
24232412
],
2424-
defines = MEMORY_COPTS,
24252413
textual_hdrs = [
24262414
"src/string/memory_utils/aarch64/inline_bcmp.h",
24272415
"src/string/memory_utils/aarch64/inline_memcmp.h",
@@ -3191,15 +3179,13 @@ libc_function(
31913179
libc_support_library(
31923180
name = "printf_config",
31933181
hdrs = ["src/stdio/printf_core/printf_config.h"],
3194-
defines = PRINTF_COPTS,
31953182
deps = [
31963183
],
31973184
)
31983185

31993186
libc_support_library(
32003187
name = "printf_core_structs",
32013188
hdrs = ["src/stdio/printf_core/core_structs.h"],
3202-
defines = PRINTF_COPTS,
32033189
deps = [
32043190
":__support_cpp_string_view",
32053191
":__support_fputil_fp_bits",
@@ -3210,7 +3196,6 @@ libc_support_library(
32103196
libc_support_library(
32113197
name = "printf_parser",
32123198
hdrs = ["src/stdio/printf_core/parser.h"],
3213-
defines = PRINTF_COPTS,
32143199
deps = [
32153200
":__support_arg_list",
32163201
":__support_common",
@@ -3231,7 +3216,7 @@ libc_support_library(
32313216
libc_support_library(
32323217
name = "printf_mock_parser",
32333218
hdrs = ["src/stdio/printf_core/parser.h"],
3234-
defines = PRINTF_COPTS + ["LIBC_COPT_MOCK_ARG_LIST"],
3219+
local_defines = ["LIBC_COPT_MOCK_ARG_LIST"],
32353220
deps = [
32363221
":__support_arg_list",
32373222
":__support_common",
@@ -3251,7 +3236,6 @@ libc_support_library(
32513236
name = "printf_writer",
32523237
srcs = ["src/stdio/printf_core/writer.cpp"],
32533238
hdrs = ["src/stdio/printf_core/writer.h"],
3254-
defines = PRINTF_COPTS,
32553239
deps = [
32563240
":__support_cpp_string_view",
32573241
":__support_macros_optimization",
@@ -3276,7 +3260,6 @@ libc_support_library(
32763260
"src/stdio/printf_core/string_converter.h",
32773261
"src/stdio/printf_core/write_int_converter.h",
32783262
],
3279-
defines = PRINTF_COPTS,
32803263
deps = [
32813264
":__support_big_int",
32823265
":__support_common",
@@ -3300,7 +3283,6 @@ libc_support_library(
33003283
name = "printf_main",
33013284
srcs = ["src/stdio/printf_core/printf_main.cpp"],
33023285
hdrs = ["src/stdio/printf_core/printf_main.h"],
3303-
defines = PRINTF_COPTS,
33043286
deps = [
33053287
":__support_arg_list",
33063288
":printf_converter",
@@ -3313,7 +3295,6 @@ libc_support_library(
33133295
libc_support_library(
33143296
name = "vfprintf_internal",
33153297
hdrs = ["src/stdio/printf_core/vfprintf_internal.h"],
3316-
defines = PRINTF_COPTS,
33173298
deps = [
33183299
":__support_arg_list",
33193300
":__support_file_file",
@@ -3327,7 +3308,6 @@ libc_function(
33273308
name = "sprintf",
33283309
srcs = ["src/stdio/sprintf.cpp"],
33293310
hdrs = ["src/stdio/sprintf.h"],
3330-
defines = PRINTF_COPTS,
33313311
deps = [
33323312
":__support_arg_list",
33333313
":__support_cpp_limits",
@@ -3341,7 +3321,6 @@ libc_function(
33413321
name = "snprintf",
33423322
srcs = ["src/stdio/snprintf.cpp"],
33433323
hdrs = ["src/stdio/snprintf.h"],
3344-
defines = PRINTF_COPTS,
33453324
deps = [
33463325
":__support_arg_list",
33473326
":errno",
@@ -3354,7 +3333,6 @@ libc_function(
33543333
name = "printf",
33553334
srcs = ["src/stdio/printf.cpp"],
33563335
hdrs = ["src/stdio/printf.h"],
3357-
defines = PRINTF_COPTS,
33583336
deps = [
33593337
":__support_arg_list",
33603338
":__support_file_file",
@@ -3367,7 +3345,6 @@ libc_function(
33673345
name = "fprintf",
33683346
srcs = ["src/stdio/fprintf.cpp"],
33693347
hdrs = ["src/stdio/fprintf.h"],
3370-
defines = PRINTF_COPTS,
33713348
deps = [
33723349
":__support_arg_list",
33733350
":__support_file_file",
@@ -3380,7 +3357,6 @@ libc_function(
33803357
name = "vsprintf",
33813358
srcs = ["src/stdio/vsprintf.cpp"],
33823359
hdrs = ["src/stdio/vsprintf.h"],
3383-
defines = PRINTF_COPTS,
33843360
deps = [
33853361
":__support_arg_list",
33863362
":__support_cpp_limits",
@@ -3394,7 +3370,6 @@ libc_function(
33943370
name = "vsnprintf",
33953371
srcs = ["src/stdio/vsnprintf.cpp"],
33963372
hdrs = ["src/stdio/vsnprintf.h"],
3397-
defines = PRINTF_COPTS,
33983373
deps = [
33993374
":__support_arg_list",
34003375
":errno",
@@ -3407,7 +3382,6 @@ libc_function(
34073382
name = "vprintf",
34083383
srcs = ["src/stdio/vprintf.cpp"],
34093384
hdrs = ["src/stdio/vprintf.h"],
3410-
defines = PRINTF_COPTS,
34113385
deps = [
34123386
":__support_arg_list",
34133387
":__support_file_file",
@@ -3420,7 +3394,6 @@ libc_function(
34203394
name = "vfprintf",
34213395
srcs = ["src/stdio/vfprintf.cpp"],
34223396
hdrs = ["src/stdio/vfprintf.h"],
3423-
defines = PRINTF_COPTS,
34243397
deps = [
34253398
":__support_arg_list",
34263399
":__support_file_file",

utils/bazel/llvm-project-overlay/libc/libc_build_rules.bzl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
load("@bazel_skylib//lib:paths.bzl", "paths")
88
load("@bazel_skylib//lib:selects.bzl", "selects")
9+
load(":libc_configure_options.bzl", "LIBC_CONFIGURE_OPTIONS")
910
load(":libc_namespace.bzl", "LIBC_NAMESPACE")
1011
load(":platforms.bzl", "PLATFORM_CPU_ARM64", "PLATFORM_CPU_X86_64")
1112

@@ -21,13 +22,14 @@ def libc_common_copts():
2122
"-DLIBC_NAMESPACE=" + LIBC_NAMESPACE,
2223
]
2324

24-
def _libc_library(name, hidden, copts = [], deps = [], **kwargs):
25+
def _libc_library(name, hidden, copts = [], deps = [], local_defines = [], **kwargs):
2526
"""Internal macro to serve as a base for all other libc library rules.
2627
2728
Args:
2829
name: Target name.
2930
copts: The special compiler options for the target.
3031
deps: The list of target dependencies if any.
32+
local_defines: The list of target local_defines if any.
3133
hidden: Whether the symbols should be explicitly hidden or not.
3234
**kwargs: All other attributes relevant for the cc_library rule.
3335
"""
@@ -40,6 +42,7 @@ def _libc_library(name, hidden, copts = [], deps = [], **kwargs):
4042
native.cc_library(
4143
name = name,
4244
copts = copts + libc_common_copts(),
45+
local_defines = local_defines + LIBC_CONFIGURE_OPTIONS,
4346
deps = deps,
4447
linkstatic = 1,
4548
**kwargs
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# This file is licensed under the Apache License v2.0 with LLVM Exceptions.
2+
# See https://llvm.org/LICENSE.txt for license information.
3+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
5+
"""LLVM libc configuration options.
6+
The canonical list of user options is in 'libc/config/config.json'.
7+
These options are then processed by CMake and turned into preprocessor
8+
definitions. We don't have this logic in Bazel yet but the list of definitions
9+
is discoverable with the following command:
10+
11+
> git grep -hoE '\bLIBC_COPT_\\w*' -- '*.h' '*.cpp' | sort -u
12+
"""
13+
14+
# This list of definitions is used to customize LLVM libc.
15+
LIBC_CONFIGURE_OPTIONS = [
16+
# Documentation in libc/docs/dev/printf_behavior.rst
17+
# "LIBC_COPT_FLOAT_TO_STR_NO_SPECIALIZE_LD",
18+
# "LIBC_COPT_FLOAT_TO_STR_NO_TABLE",
19+
# "LIBC_COPT_FLOAT_TO_STR_USE_DYADIC_FLOAT",
20+
# "LIBC_COPT_FLOAT_TO_STR_USE_DYADIC_FLOAT_LD",
21+
# "LIBC_COPT_FLOAT_TO_STR_USE_INT_CALC",
22+
# "LIBC_COPT_FLOAT_TO_STR_USE_MEGA_LONG_DOUBLE_TABLE",
23+
24+
# Documentation in libc/src/string/memory_utils/...
25+
# "LIBC_COPT_MEMCPY_USE_EMBEDDED_TINY",
26+
# "LIBC_COPT_MEMCPY_X86_USE_REPMOVSB_FROM_SIZE",
27+
# "LIBC_COPT_MEMCPY_X86_USE_SOFTWARE_PREFETCHING",
28+
# "LIBC_COPT_MEMSET_X86_USE_SOFTWARE_PREFETCHING",
29+
30+
# Documentation in libc/docs/dev/printf_behavior.rst
31+
# "LIBC_COPT_PRINTF_CONV_ATLAS",
32+
# "LIBC_COPT_PRINTF_DISABLE_FIXED_POINT",
33+
# "LIBC_COPT_PRINTF_DISABLE_FLOAT",
34+
# "LIBC_COPT_PRINTF_DISABLE_INDEX_MODE",
35+
"LIBC_COPT_PRINTF_DISABLE_WRITE_INT",
36+
# "LIBC_COPT_PRINTF_HEX_LONG_DOUBLE",
37+
# "LIBC_COPT_PRINTF_INDEX_ARR_LEN",
38+
# "LIBC_COPT_PRINTF_NO_NULLPTR_CHECKS",
39+
# "LIBC_COPT_SCANF_DISABLE_FLOAT",
40+
# "LIBC_COPT_SCANF_DISABLE_INDEX_MODE",
41+
"LIBC_COPT_STDIO_USE_SYSTEM_FILE",
42+
# "LIBC_COPT_STRING_UNSAFE_WIDE_READ",
43+
# "LIBC_COPT_STRTOFLOAT_DISABLE_CLINGER_FAST_PATH",
44+
# "LIBC_COPT_STRTOFLOAT_DISABLE_EISEL_LEMIRE",
45+
# "LIBC_COPT_STRTOFLOAT_DISABLE_SIMPLE_DECIMAL_CONVERSION",
46+
47+
# Documentation in libc/src/__support/libc_assert.h
48+
# "LIBC_COPT_USE_C_ASSERT",
49+
]

utils/bazel/llvm-project-overlay/libc/test/libc_test_rules.bzl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ When performing tests we make sure to always use the internal version.
1313
"""
1414

1515
load("//libc:libc_build_rules.bzl", "libc_common_copts", "libc_internal_target")
16+
load("//libc:libc_configure_options.bzl", "LIBC_CONFIGURE_OPTIONS")
1617

17-
def libc_test(name, srcs, libc_function_deps = [], copts = [], deps = [], **kwargs):
18+
def libc_test(name, srcs, libc_function_deps = [], copts = [], deps = [], local_defines = [], **kwargs):
1819
"""Add target for a libc test.
1920
2021
Args:
@@ -23,12 +24,14 @@ def libc_test(name, srcs, libc_function_deps = [], copts = [], deps = [], **kwar
2324
libc_function_deps: List of libc_function targets used by this test.
2425
copts: The list of options to add to the C++ compilation command.
2526
deps: The list of other libraries to be linked in to the test target.
27+
local_defines: The list of target local_defines if any.
2628
**kwargs: Attributes relevant for a libc_test. For example, name, srcs.
2729
"""
2830
all_function_deps = libc_function_deps + ["//libc:errno"]
2931
native.cc_test(
3032
name = name,
3133
srcs = srcs,
34+
local_defines = local_defines + LIBC_CONFIGURE_OPTIONS,
3235
deps = [libc_internal_target(d) for d in all_function_deps] + [
3336
"//libc/test/UnitTest:LibcUnitTest",
3437
] + deps,

0 commit comments

Comments
 (0)