Skip to content

Commit

Permalink
Swap config_setting(constraint_values=[X]) -> X, where possible (#247)
Browse files Browse the repository at this point in the history
Bazel no longer requires wrapping single constraint_value()s in config settings; they can be selected upon directly. This allows for some code to deleted and simplified.

I've also added notes to the cases where we can't yet delete constraint_values, but will likely be able to in the near future, as well as the relevant blocking bugs.

Co-authored-by: Nelson Elhage <nelhage@nelhage.com>
  • Loading branch information
cpsauer and nelhage authored Jan 25, 2022
1 parent 4202d5f commit ef58870
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 177 deletions.
125 changes: 27 additions & 98 deletions BUILD.boost
Original file line number Diff line number Diff line change
Expand Up @@ -4,75 +4,20 @@ load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
load("@com_github_nelhage_rules_boost//:boost/boost.bzl", "boost_library", "boost_so_library", "hdr_list")

_w_no_deprecated = selects.with_or({
(":linux", ":osx", ":ios", ":watchos", ":tvos"): [
("@platforms//os:linux", "@platforms//os:osx", "@platforms//os:ios", "@platforms//os:watchos", "@platforms//os:tvos"): [
"-Wno-deprecated-declarations",
],
"//conditions:default": [],
})

config_setting(
name = "linux",
constraint_values = [
"@platforms//os:linux",
],
visibility = ["//visibility:public"],
)

config_setting(
name = "android",
constraint_values = [
"@platforms//os:android",
],
visibility = ["//visibility:public"],
)

config_setting(
name = "osx",
constraint_values = [
"@platforms//os:osx",
],
visibility = ["//visibility:public"],
)

config_setting(
name = "ios",
constraint_values = [
"@platforms//os:ios",
],
visibility = ["//visibility:public"],
)

config_setting(
name = "watchos",
constraint_values = [
"@platforms//os:watchos",
],
visibility = ["//visibility:public"],
)

config_setting(
name = "tvos",
constraint_values = [
"@platforms//os:tvos",
],
visibility = ["//visibility:public"],
)

config_setting(
name = "windows",
constraint_values = [
"@platforms//os:windows",
],
visibility = ["//visibility:public"],
)
# Hopefully, the need for these OSxCPU config_setting()s will be obviated by a fix to https://github.com/bazelbuild/platforms/issues/36

config_setting(
name = "linux_arm",
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:arm",
],
visibility = ["//visibility:public"],
)

config_setting(
Expand All @@ -81,7 +26,6 @@ config_setting(
"@platforms//os:linux",
"@platforms//cpu:ppc",
],
visibility = ["//visibility:public"],
)

config_setting(
Expand All @@ -90,7 +34,6 @@ config_setting(
"@platforms//os:linux",
"@platforms//cpu:aarch64",
],
visibility = ["//visibility:public"],
)

config_setting(
Expand All @@ -99,7 +42,6 @@ config_setting(
"@platforms//os:linux",
"@platforms//cpu:x86_64",
],
visibility = ["//visibility:public"],
)

config_setting(
Expand All @@ -108,7 +50,6 @@ config_setting(
"@platforms//os:osx",
"@platforms//cpu:aarch64",
],
visibility = ["//visibility:public"],
)

config_setting(
Expand All @@ -117,7 +58,6 @@ config_setting(
"@platforms//os:osx",
"@platforms//cpu:x86_64",
],
visibility = ["//visibility:public"],
)

config_setting(
Expand All @@ -126,15 +66,6 @@ config_setting(
"@platforms//os:windows",
"@platforms//cpu:x86_64",
],
visibility = ["//visibility:public"],
)

config_setting(
name = "x86_64",
constraint_values = [
"@platforms//cpu:x86_64",
],
visibility = ["//visibility:public"],
)

config_setting(
Expand All @@ -143,7 +74,6 @@ config_setting(
"@platforms//os:android",
"@platforms//cpu:arm",
],
visibility = ["//visibility:public"],
)

config_setting(
Expand All @@ -152,7 +82,6 @@ config_setting(
"@platforms//os:android",
"@platforms//cpu:aarch64",
],
visibility = ["//visibility:public"],
)

# Rename .asm to .S so that it will be handled with the C preprocessor.
Expand Down Expand Up @@ -187,7 +116,7 @@ BOOST_CTX_ASM_SOURCES = selects.with_or({
"libs/context/src/asm/make_x86_64_sysv_elf_gas.S",
"libs/context/src/asm/ontop_x86_64_sysv_elf_gas.S",
],
(":osx", ":ios", ":watchos", ":tvos") : ["apple_ctx_asm_sources"],
("@platforms//os:osx", "@platforms//os:ios", "@platforms//os:watchos", "@platforms//os:tvos") : ["apple_ctx_asm_sources"],
":windows_x86_64": [
"libs/context/src/asm/make_x86_64_ms_pe_masm.S",
"libs/context/src/asm/jump_x86_64_ms_pe_masm.S",
Expand Down Expand Up @@ -220,7 +149,7 @@ filegroup(
boost_library(
name = "context",
srcs = BOOST_CTX_ASM_SOURCES + selects.with_or({
(":linux", ":android", ":osx", ":ios", ":watchos", ":tvos"): [
("@platforms//os:linux", "@platforms//os:android", "@platforms//os:osx", "@platforms//os:ios", "@platforms//os:watchos", "@platforms//os:tvos"): [
"libs/context/src/posix/stack_traits.cpp",
],
":windows_x86_64": [
Expand Down Expand Up @@ -284,7 +213,7 @@ boost_library(
}),
exclude_src = ["libs/fiber/src/numa/**/*.cpp"],
linkopts = selects.with_or({
(":linux", ":osx", ":ios", ":watchos", ":tvos"): ["-lpthread"],
("@platforms//os:linux", "@platforms//os:osx", "@platforms//os:ios", "@platforms//os:watchos", "@platforms//os:tvos"): ["-lpthread"],
"//conditions:default": [],
}),
visibility = ["//visibility:public"],
Expand Down Expand Up @@ -410,7 +339,7 @@ boost_library(
copts = ["-Iexternal/boost/libs/atomic/src"],
exclude_src = ["libs/atomic/src/wait_on_address.cpp"] + BOOST_ATOMIC_SSE_SRCS,
deps = BOOST_ATOMIC_DEPS + select({
":x86_64": [":atomic_sse"],
"@platforms//cpu:x86_64": [":atomic_sse"],
"//conditions:default": [],
}),
)
Expand Down Expand Up @@ -475,7 +404,7 @@ boost_library(
defines = [
"BOOST_ASIO_SEPARATE_COMPILATION",
] + selects.with_or({
(":osx", ":ios", ":watchos", ":tvos"): [
("@platforms//os:osx", "@platforms//os:ios", "@platforms//os:watchos", "@platforms//os:tvos"): [
"BOOST_ASIO_DISABLE_STD_EXPERIMENTAL_STRING_VIEW",
],
"//conditions:default": [],
Expand All @@ -487,7 +416,7 @@ boost_library(
"//conditions:default": [],
}),
linkopts = select({
":android": [],
"@platforms//os:android": [],
"//conditions:default": ["-lpthread"],
}) + select({
":asio_io_uring": ["-luring"],
Expand Down Expand Up @@ -632,7 +561,7 @@ boost_library(
linkopts = selects.with_or({
# OpenCL (required for Boost.Compute) is deprecated on macOS and not supported on other Apple OSs.
# This will at least produce the right error message, indicating that OpenCL is not present
(":osx", ":ios", ":watchos", ":tvos"): [
("@platforms//os:osx", "@platforms//os:ios", "@platforms//os:watchos", "@platforms//os:tvos"): [
"-framework OpenCL",
],
"//conditions:default": [
Expand Down Expand Up @@ -733,7 +662,7 @@ boost_library(
)

BOOST_CORO_SRCS = selects.with_or({
(":linux", ":android", ":osx", ":ios", ":watchos", ":tvos"): [
("@platforms//os:linux", "@platforms//os:android", "@platforms//os:osx", "@platforms//os:ios", "@platforms//os:watchos", "@platforms//os:tvos"): [
"libs/coroutine/src/posix/stack_traits.cpp",
],
":windows_x86_64": [
Expand Down Expand Up @@ -1069,7 +998,7 @@ boost_library(
boost_library(
name = "interprocess",
linkopts = select({
":linux": [
"@platforms//os:linux": [
"-lpthread",
"-lrt",
],
Expand Down Expand Up @@ -1243,13 +1172,13 @@ BOOST_LOCALE_WIN32_COPTS = [
boost_library(
name = "locale",
srcs = selects.with_or({
":android": BOOST_LOCALE_STD_SOURCES,
(":linux", ":osx", ":ios", ":watchos", ":tvos"): BOOST_LOCALE_POSIX_SOURCES,
"@platforms//os:android": BOOST_LOCALE_STD_SOURCES,
("@platforms//os:linux", "@platforms//os:osx", "@platforms//os:ios", "@platforms//os:watchos", "@platforms//os:tvos"): BOOST_LOCALE_POSIX_SOURCES,
":windows_x86_64": BOOST_LOCALE_WIN32_SOURCES,
}),
copts = selects.with_or({
":android": BOST_LOCALE_STD_COPTS,
(":linux", ":osx", ":ios", ":watchos", ":tvos"): BOOST_LOCALE_POSIX_COPTS,
"@platforms//os:android": BOST_LOCALE_STD_COPTS,
("@platforms//os:linux", "@platforms//os:osx", "@platforms//os:ios", "@platforms//os:watchos", "@platforms//os:tvos"): BOOST_LOCALE_POSIX_COPTS,
":windows_x86_64": BOOST_LOCALE_WIN32_COPTS,
}) + _w_no_deprecated,
deps = [
Expand Down Expand Up @@ -1476,7 +1405,7 @@ boost_library(
"boost/numeric/odeint.hpp",
],
linkopts = select({
"@boost//:android": ["-lm"],
"@platforms//os:android": ["-lm"],
"//conditions:default": [],
}),
deps = [
Expand Down Expand Up @@ -1631,7 +1560,7 @@ boost_library(
boost_library(
name = "qvm",
linkopts = select({
"@boost//:android": ["-lm"],
"@platforms//os:android": ["-lm"],
"//conditions:default": [],
}),
deps = [
Expand Down Expand Up @@ -1881,7 +1810,7 @@ boost_library(
)

BOOST_STACKTRACE_SOURCES = selects.with_or({
":android": [
"@platforms//os:android": [
"libs/stacktrace/src/basic.cpp",
#"libs/stacktrace/src/noop.cpp",
],
Expand All @@ -1899,7 +1828,7 @@ BOOST_STACKTRACE_SOURCES = selects.with_or({
":linux_x86_64": [
"libs/stacktrace/src/backtrace.cpp",
],
(":osx", ":ios", ":watchos", ":tvos"): [
("@platforms//os:osx", "@platforms//os:ios", "@platforms//os:watchos", "@platforms//os:tvos"): [
"libs/stacktrace/src/addr2line.cpp",
],
":windows_x86_64": [
Expand All @@ -1913,7 +1842,7 @@ boost_library(
name = "stacktrace",
srcs = BOOST_STACKTRACE_SOURCES,
defines = selects.with_or({
(":osx", ":ios", ":watchos", ":tvos"): [
("@platforms//os:osx", "@platforms//os:ios", "@platforms//os:watchos", "@platforms//os:tvos"): [
"BOOST_STACKTRACE_GNU_SOURCE_NOT_REQUIRED",
],
"//conditions:default": [],
Expand Down Expand Up @@ -2004,7 +1933,7 @@ boost_library(
boost_library(
name = "thread",
srcs = selects.with_or({
(":linux", ":android", ":osx", ":ios", ":watchos", ":tvos"): [
("@platforms//os:linux", "@platforms//os:android", "@platforms//os:osx", "@platforms//os:ios", "@platforms//os:watchos", "@platforms//os:tvos"): [
"libs/thread/src/pthread/once.cpp",
"libs/thread/src/pthread/thread.cpp",
],
Expand All @@ -2015,18 +1944,18 @@ boost_library(
],
}),
hdrs = selects.with_or({
(":linux", ":android", ":osx", ":ios", ":watchos", ":tvos"): [
("@platforms//os:linux", "@platforms//os:android", "@platforms//os:osx", "@platforms//os:ios", "@platforms//os:watchos", "@platforms//os:tvos"): [
"libs/thread/src/pthread/once_atomic.cpp",
],
":windows_x86_64": [],
}),
linkopts = selects.with_or({
(":linux", ":osx", ":ios", ":watchos", ":tvos"): ["-lpthread"],
("@platforms//os:linux", "@platforms//os:osx", "@platforms//os:ios", "@platforms//os:watchos", "@platforms//os:tvos"): ["-lpthread"],
":windows_x86_64": [],
":android": [],
"@platforms//os:android": [],
}),
local_defines = selects.with_or({
(":linux", ":osx", ":ios", ":watchos", ":tvos"): [],
("@platforms//os:linux", "@platforms//os:osx", "@platforms//os:ios", "@platforms//os:watchos", "@platforms//os:tvos"): [],
":windows_x86_64": [
"BOOST_ALL_NO_LIB",
"BOOST_THREAD_BUILD_LIB",
Expand Down Expand Up @@ -2354,7 +2283,7 @@ boost_library(
)

BOOST_LOG_CFLAGS = select({
":x86_64": [
"@platforms//cpu:x86_64": [
"-msse4.2",
],
"//conditions:default": [
Expand Down Expand Up @@ -2385,7 +2314,7 @@ BOOST_LOG_DEPS = [
]

BOOST_LOG_SSSE3_DEP = select({
":x86_64": [
"@platforms//cpu:x86_64": [
":log_dump_ssse3",
],
"//conditions:default": [
Expand Down
Loading

0 comments on commit ef58870

Please sign in to comment.