[Bazel] Update rules_cc to v0.0.10 (#1989)

Updates rules_cc to v0.0.10 to reduce the steps required to get started
with creating a Bazel-based Pi Pico project.
This commit is contained in:
armandomontanez 2024-11-05 12:05:44 -08:00 committed by GitHub
parent d649c6c77a
commit e48a2e158c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 206 additions and 318 deletions

View File

@ -1,7 +1,3 @@
# Required for new toolchain resolution API.
build --incompatible_enable_cc_toolchain_resolution
build --@rules_cc//cc/toolchains:experimental_enable_rule_based_toolchains
# Silence all C/C++ warnings in external code. # Silence all C/C++ warnings in external code.
common --per_file_copt=external/.*@-w common --per_file_copt=external/.*@-w
common --host_per_file_copt=external/.*@-w common --host_per_file_copt=external/.*@-w

View File

@ -7,22 +7,7 @@ bazel_dep(name = "platforms", version = "0.0.9")
bazel_dep(name = "bazel_skylib", version = "1.6.1") bazel_dep(name = "bazel_skylib", version = "1.6.1")
bazel_dep(name = "rules_python", version = "0.22.1") bazel_dep(name = "rules_python", version = "0.22.1")
bazel_dep(name = "picotool", version = "2.0.0") bazel_dep(name = "picotool", version = "2.0.0")
bazel_dep(name = "rules_cc", version = "0.0.10")
# Note: rules_cc is special-cased repository; a dependency on rules_cc in a
# module will not ensure that the root Bazel module has that same version of
# rules_cc. For that reason, this primarily acts as a FYI. You'll still need
# to explicitly list this dependency in your own project's MODULE.bazel file.
bazel_dep(name = "rules_cc", version = "0.0.9")
# rules_cc v0.0.10 is not yet cut, so manually pull in the desired version.
# This does not apply to dependent projects, so it needs to be copied to your
# project's MODULE.bazel too.
archive_override(
module_name = "rules_cc",
integrity = "sha256-zdQo/pQWKdIAPKSflBxOSWZNwCbc86T7SechKZo/3Xw=",
strip_prefix = "rules_cc-1acf5213b6170f1f0133e273cb85ede0e732048f",
urls = "https://github.com/bazelbuild/rules_cc/archive/1acf5213b6170f1f0133e273cb85ede0e732048f.tar.gz",
)
http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

View File

@ -3,32 +3,10 @@
## Using the Pico SDK in a Bazel project. ## Using the Pico SDK in a Bazel project.
### Add pico-sdk as a dependency ### Add pico-sdk as a dependency
First, in your `MODULE.bazel` file, add a dependency on the Pico SDK: First, in your `MODULE.bazel` file, add a dependency on the Pico SDK and
`rules_cc`:
```python ```python
bazel_dep( bazel_dep(name = "pico-sdk", version = "2.0.1")
name = "pico-sdk",
version = "2.0.0",
)
```
Second, in the same file you'll need to add an explicit dependency on
`rules_cc`, as it's a special-cased Bazel module:
```python
# Note: rules_cc is special-cased repository; a dependency on rules_cc in a
# module will not ensure that the root Bazel module has that same version of
# rules_cc. For that reason, this primarily acts as a FYI. You'll still need
# to explicitly list this dependency in your own project's MODULE.bazel file.
bazel_dep(name = "rules_cc", version = "0.0.9")
# rules_cc v0.0.10 is not yet cut, so manually pull in the desired version.
# This does not apply to dependent projects, so it needs to be copied to your
# project's MODULE.bazel too.
archive_override(
module_name = "rules_cc",
urls = "https://github.com/bazelbuild/rules_cc/archive/1acf5213b6170f1f0133e273cb85ede0e732048f.zip",
strip_prefix = "rules_cc-1acf5213b6170f1f0133e273cb85ede0e732048f",
integrity = "sha256-NddP6xi6LzsIHT8bMSVJ2NtoURbN+l3xpjvmIgB6aSg=",
)
``` ```
### Register toolchains ### Register toolchains
@ -47,15 +25,6 @@ register_toolchains(
) )
``` ```
### Enable required .bazelrc flags
To use the toolchains provided by the Pico SDK, you'll need to enable a few
new features. In your project's `.bazelrc`, add the following
```
# Required for new toolchain resolution API.
build --incompatible_enable_cc_toolchain_resolution
build --@rules_cc//cc/toolchains:experimental_enable_rule_based_toolchains
```
### Ready to build! ### Ready to build!
You're now ready to start building Pico Projects in Bazel! When building, You're now ready to start building Pico Projects in Bazel! When building,
don't forget to specify `--platforms` so Bazel knows you're targeting the don't forget to specify `--platforms` so Bazel knows you're targeting the

View File

@ -51,36 +51,39 @@ cc_args(
], ],
) )
# :no_canonical_system_headers and :no_canonical_prefixes both prevent built-in
# compiler include directories from resolving to absolute paths. Prefer to use
# :bazel_no_absolute_paths, since it correctly guides based on the current
# compiler type.
cc_args( cc_args(
name = "no-canonical-system-headers", name = "no_canonical_system_headers",
actions = ["@rules_cc//cc/toolchains/actions:compile_actions"], actions = ["@rules_cc//cc/toolchains/actions:compile_actions"],
args = ["-fno-canonical-system-headers"], args = ["-fno-canonical-system-headers"],
) )
cc_args( cc_args(
name = "no-canonical-prefixes", name = "no_canonical_prefixes",
actions = ["@rules_cc//cc/toolchains/actions:compile_actions"], actions = ["@rules_cc//cc/toolchains/actions:compile_actions"],
args = ["-no-canonical-prefixes"], args = ["-no-canonical-prefixes"],
) )
cc_args(
name = "nostdlibxx",
actions = ["@rules_cc//cc/toolchains/actions:link_actions"],
args = ["-nostdlib++"],
)
cc_args(
name = "nostartfiles",
actions = ["@rules_cc//cc/toolchains/actions:link_actions"],
args = ["-nostartfiles"],
)
cc_args_list( cc_args_list(
name = "bazel_no_absolute_paths", name = "bazel_no_absolute_paths",
args = select({ args = select({
"//bazel/constraint:pico_toolchain_clang_enabled": [], "//bazel/constraint:pico_toolchain_clang_enabled": [],
"//conditions:default": [":no-canonical-system-headers"], "//conditions:default": [":no_canonical_system_headers"],
}) + [":no-canonical-prefixes"], }) + [":no_canonical_prefixes"],
)
cc_args(
name = "llvm-libc_args",
actions = ["@rules_cc//cc/toolchains/actions:link_actions"],
args = [
"-nostdlib++",
"-nostartfiles",
"-Wl,-lc++",
],
visibility = ["//visibility:private"],
) )
cc_args( cc_args(
@ -101,7 +104,6 @@ configurable_toolchain_feature(
"-ffunction-sections", "-ffunction-sections",
"-fdata-sections", "-fdata-sections",
], ],
disable_if = "//bazel/constraint:pico_no_gc_sections_enabled",
linkopts = ["-Wl,--gc-sections"], linkopts = ["-Wl,--gc-sections"],
) )
@ -111,24 +113,20 @@ configurable_toolchain_feature(
"-fno-exceptions", "-fno-exceptions",
"-fno-unwind-tables", "-fno-unwind-tables",
], ],
disable_if = "//bazel/constraint:pico_cxx_enable_exceptions_enabled",
) )
configurable_toolchain_feature( configurable_toolchain_feature(
name = "cxx_no_rtti", name = "cxx_no_rtti",
cxxopts = ["-fno-rtti"], cxxopts = ["-fno-rtti"],
disable_if = "//bazel/constraint:pico_cxx_enable_rtti_enabled",
) )
configurable_toolchain_feature( configurable_toolchain_feature(
name = "cxx_no_cxa_atexit", name = "cxx_no_cxa_atexit",
cxxopts = ["-fno-use-cxa-atexit"], cxxopts = ["-fno-use-cxa-atexit"],
disable_if = "//bazel/constraint:pico_cxx_enable_cxa_atexit_enabled",
) )
configurable_toolchain_feature( configurable_toolchain_feature(
name = "override_max_page_size", name = "override_max_page_size",
disable_if = "//bazel/constraint:pico_use_default_max_page_size_enabled",
linkopts = ["-Wl,-z,max-page-size=4096"], linkopts = ["-Wl,-z,max-page-size=4096"],
) )
@ -141,36 +139,9 @@ cc_args_list(
cc_feature( cc_feature(
name = "override_debug", name = "override_debug",
args = [":all_opt_debug_args"], args = [":all_opt_debug_args"],
enabled = True,
overrides = "@rules_cc//cc/toolchains/features:dbg", overrides = "@rules_cc//cc/toolchains/features:dbg",
) )
# TODO: https://github.com/bazelbuild/rules_cc/issues/224 - This is required for
# now, but hopefully will eventually go away.
cc_feature(
name = "legacy_features",
args = [],
enabled = True,
feature_name = "force_legacy_features",
implies = [
"@rules_cc//cc/toolchains/features/legacy:archiver_flags",
"@rules_cc//cc/toolchains/features/legacy:build_interface_libraries",
"@rules_cc//cc/toolchains/features/legacy:dynamic_library_linker_tool",
"@rules_cc//cc/toolchains/features/legacy:strip_debug_symbols",
"@rules_cc//cc/toolchains/features/legacy:linkstamps",
"@rules_cc//cc/toolchains/features/legacy:output_execpath_flags",
"@rules_cc//cc/toolchains/features/legacy:runtime_library_search_directories",
"@rules_cc//cc/toolchains/features/legacy:library_search_directories",
"@rules_cc//cc/toolchains/features/legacy:libraries_to_link",
"@rules_cc//cc/toolchains/features/legacy:force_pic_flags",
"@rules_cc//cc/toolchains/features/legacy:user_link_flags",
"@rules_cc//cc/toolchains/features/legacy:legacy_link_flags",
"@rules_cc//cc/toolchains/features/legacy:linker_param_file",
"@rules_cc//cc/toolchains/features/legacy:fission_support",
"@rules_cc//cc/toolchains/features/legacy:sysroot",
],
)
HOSTS = ( HOSTS = (
("linux", "x86_64"), ("linux", "x86_64"),
("linux", "aarch64"), ("linux", "aarch64"),
@ -192,14 +163,7 @@ _HOST_CPU_CONSTRAINTS = {
[cc_toolchain( [cc_toolchain(
name = "arm_gcc_{}-{}_toolchain_cortex-m".format(host_os, host_cpu), name = "arm_gcc_{}-{}_toolchain_cortex-m".format(host_os, host_cpu),
action_type_configs = [ tool_map = "@arm_gcc_{}-{}//:all_tools".format(host_os, host_cpu),
"@arm_gcc_{}-{}//:arm-none-eabi-ar".format(host_os, host_cpu),
"@arm_gcc_{}-{}//:arm-none-eabi-gcc".format(host_os, host_cpu),
"@arm_gcc_{}-{}//:arm-none-eabi-g++".format(host_os, host_cpu),
"@arm_gcc_{}-{}//:arm-none-eabi-ld".format(host_os, host_cpu),
"@arm_gcc_{}-{}//:arm-none-eabi-objcopy".format(host_os, host_cpu),
"@arm_gcc_{}-{}//:arm-none-eabi-strip".format(host_os, host_cpu),
],
args = select({ args = select({
"//bazel/constraint:rp2040": [":cortex-m0"], "//bazel/constraint:rp2040": [":cortex-m0"],
"//bazel/constraint:rp2350": [":cortex-m33"], "//bazel/constraint:rp2350": [":cortex-m33"],
@ -207,24 +171,13 @@ _HOST_CPU_CONSTRAINTS = {
}) + [ }) + [
":bazel_no_absolute_paths", ":bazel_no_absolute_paths",
], ],
compiler = "gcc", # Useful for distinguishing gcc vs clang.
cxx_builtin_include_directories = [
"%sysroot%/arm-none-eabi/include/newlib-nano",
"%sysroot%/arm-none-eabi/include/c++/13.2.1",
"%sysroot%/arm-none-eabi/include/c++/13.2.1/arm-none-eabi",
"%sysroot%/arm-none-eabi/include/c++/13.2.1/backward",
"%sysroot%/lib/gcc/arm-none-eabi/13.2.1/include",
"%sysroot%/lib/gcc/arm-none-eabi/13.2.1/include-fixed",
"%sysroot%/arm-none-eabi/include",
],
exec_compatible_with = [ exec_compatible_with = [
_HOST_CPU_CONSTRAINTS[host_cpu], _HOST_CPU_CONSTRAINTS[host_cpu],
_HOST_OS_CONSTRAINTS[host_os], _HOST_OS_CONSTRAINTS[host_os],
], ],
sysroot = "external/arm_gcc_{}-{}".format(host_os, host_cpu),
tags = ["manual"], # Don't try to build this in wildcard builds. tags = ["manual"], # Don't try to build this in wildcard builds.
toolchain_features = [ known_features = [
"@pico-sdk//bazel/toolchain:legacy_features", "@rules_cc//cc/toolchains/args:experimental_replace_legacy_action_config_features",
"@pico-sdk//bazel/toolchain:override_debug", "@pico-sdk//bazel/toolchain:override_debug",
"@pico-sdk//bazel/toolchain:gc_sections", "@pico-sdk//bazel/toolchain:gc_sections",
"@pico-sdk//bazel/toolchain:cxx_no_exceptions", "@pico-sdk//bazel/toolchain:cxx_no_exceptions",
@ -232,18 +185,30 @@ _HOST_CPU_CONSTRAINTS = {
"@pico-sdk//bazel/toolchain:cxx_no_cxa_atexit", "@pico-sdk//bazel/toolchain:cxx_no_cxa_atexit",
"@pico-sdk//bazel/toolchain:override_max_page_size", "@pico-sdk//bazel/toolchain:override_max_page_size",
], ],
enabled_features = [
"@rules_cc//cc/toolchains/args:experimental_replace_legacy_action_config_features",
"@pico-sdk//bazel/toolchain:override_debug",
] + select({
"//bazel/constraint:pico_no_gc_sections_enabled": [],
"//conditions:default": [":gc_sections"],
}) + select({
"//bazel/constraint:pico_cxx_enable_exceptions_enabled": [],
"//conditions:default": [":cxx_no_exceptions"],
}) + select({
"//bazel/constraint:pico_cxx_enable_rtti_enabled": [],
"//conditions:default": [":cxx_no_rtti"],
}) + select({
"//bazel/constraint:pico_cxx_enable_cxa_atexit_enabled": [],
"//conditions:default": [":cxx_no_cxa_atexit"],
}) + select({
"//bazel/constraint:pico_use_default_max_page_size_enabled": [],
"//conditions:default": [":override_max_page_size"],
}),
) for host_os, host_cpu in HOSTS] ) for host_os, host_cpu in HOSTS]
[cc_toolchain( [cc_toolchain(
name = "clang_{}-{}_toolchain_cortex-m".format(host_os, host_cpu), name = "clang_{}-{}_toolchain_cortex-m".format(host_os, host_cpu),
action_type_configs = [ tool_map = "@clang_{}-{}//:all_tools".format(host_os, host_cpu),
"@clang_{}-{}//:llvm-ar".format(host_os, host_cpu),
"@clang_{}-{}//:clang".format(host_os, host_cpu),
"@clang_{}-{}//:clang++".format(host_os, host_cpu),
"@clang_{}-{}//:lld".format(host_os, host_cpu),
"@clang_{}-{}//:llvm-objcopy".format(host_os, host_cpu),
"@clang_{}-{}//:llvm-strip".format(host_os, host_cpu),
],
args = select({ args = select({
"//bazel/constraint:rp2040": [ "//bazel/constraint:rp2040": [
":armv6m-none-eabi", ":armv6m-none-eabi",
@ -256,17 +221,15 @@ _HOST_CPU_CONSTRAINTS = {
"//conditions:default": [], "//conditions:default": [],
}) + [ }) + [
":bazel_no_absolute_paths", ":bazel_no_absolute_paths",
":nostdlibxx", ":llvm-libc_args",
":nostartfiles",
], ],
compiler = "clang", # Useful for distinguishing gcc vs clang.
exec_compatible_with = [ exec_compatible_with = [
_HOST_CPU_CONSTRAINTS[host_cpu], _HOST_CPU_CONSTRAINTS[host_cpu],
_HOST_OS_CONSTRAINTS[host_os], _HOST_OS_CONSTRAINTS[host_os],
], ],
tags = ["manual"], # Don't try to build this in wildcard builds. tags = ["manual"], # Don't try to build this in wildcard builds.
toolchain_features = [ known_features = [
"@pico-sdk//bazel/toolchain:legacy_features", "@rules_cc//cc/toolchains/args:experimental_replace_legacy_action_config_features",
"@pico-sdk//bazel/toolchain:override_debug", "@pico-sdk//bazel/toolchain:override_debug",
"@pico-sdk//bazel/toolchain:gc_sections", "@pico-sdk//bazel/toolchain:gc_sections",
"@pico-sdk//bazel/toolchain:cxx_no_exceptions", "@pico-sdk//bazel/toolchain:cxx_no_exceptions",
@ -274,6 +237,25 @@ _HOST_CPU_CONSTRAINTS = {
"@pico-sdk//bazel/toolchain:cxx_no_cxa_atexit", "@pico-sdk//bazel/toolchain:cxx_no_cxa_atexit",
"@pico-sdk//bazel/toolchain:override_max_page_size", "@pico-sdk//bazel/toolchain:override_max_page_size",
], ],
enabled_features = [
"@rules_cc//cc/toolchains/args:experimental_replace_legacy_action_config_features",
"@pico-sdk//bazel/toolchain:override_debug",
] + select({
"//bazel/constraint:pico_no_gc_sections_enabled": [],
"//conditions:default": [":gc_sections"],
}) + select({
"//bazel/constraint:pico_cxx_enable_exceptions_enabled": [],
"//conditions:default": [":cxx_no_exceptions"],
}) + select({
"//bazel/constraint:pico_cxx_enable_rtti_enabled": [],
"//conditions:default": [":cxx_no_rtti"],
}) + select({
"//bazel/constraint:pico_cxx_enable_cxa_atexit_enabled": [],
"//conditions:default": [":cxx_no_cxa_atexit"],
}) + select({
"//bazel/constraint:pico_use_default_max_page_size_enabled": [],
"//conditions:default": [":override_max_page_size"],
}),
) for host_os, host_cpu in HOSTS] ) for host_os, host_cpu in HOSTS]
[toolchain( [toolchain(

View File

@ -1,170 +1,152 @@
load("@rules_cc//cc/toolchains:action_type_config.bzl", "cc_action_type_config") load("@bazel_skylib//rules/directory:directory.bzl", "directory")
load("@bazel_skylib//rules/directory:subdirectory.bzl", "subdirectory")
load("@rules_cc//cc/toolchains:tool.bzl", "cc_tool") load("@rules_cc//cc/toolchains:tool.bzl", "cc_tool")
load("@rules_cc//cc/toolchains:tool_map.bzl", "cc_tool_map")
load("@rules_cc//cc/toolchains:args.bzl", "cc_args")
load("@rules_cc//cc/toolchains:args_list.bzl", "cc_args_list")
package(default_visibility = ["//visibility:public"]) package(default_visibility = ["//visibility:public"])
cc_tool( licenses(["notice"])
name = "llvm-ar_tool",
src = select({ # Directory-based rules in this toolchain only referece things in
"@platforms//os:windows": "//:bin/llvm-ar.exe", # lib/ or include/ subdirectories.
"//conditions:default": "//:bin/llvm-ar", directory(
}), name = "toolchain_root",
data = select({ srcs = glob([
"@platforms//os:windows": [], "lib/**",
"//conditions:default": ["//:bin/llvm"], "include/**",
}), ]),
) )
cc_action_type_config( cc_tool_map(
name = "llvm-ar", name = "all_tools",
action_types = ["@rules_cc//cc/toolchains/actions:ar_actions"], tools = {
tools = [":llvm-ar_tool"], "@rules_cc//cc/toolchains/actions:assembly_actions": ":asm",
"@rules_cc//cc/toolchains/actions:c_compile": ":clang",
"@rules_cc//cc/toolchains/actions:cpp_compile_actions": ":clang++",
"@rules_cc//cc/toolchains/actions:link_actions": ":lld",
"@rules_cc//cc/toolchains/actions:objcopy_embed_data": ":llvm-objcopy",
"@rules_cc//cc/toolchains/actions:strip": ":llvm-strip",
"@rules_cc//cc/toolchains/actions:ar_actions": ":llvm-ar",
},
)
# TODO: https://github.com/bazelbuild/rules_cc/issues/235 - Workaround until
# Bazel has a more robust way to implement `cc_tool_map`.
alias(
name = "asm",
actual = ":clang",
) )
cc_tool( cc_tool(
name = "clang_tool", name = "clang",
src = select({ src = select({
"@platforms//os:windows": "//:bin/clang.exe", "@platforms//os:windows": "//:bin/clang.exe",
"//conditions:default": "//:bin/clang", "//conditions:default": "//:bin/clang",
}), }),
data = glob([ data = glob([
"include/armv*-unknown-none-eabi/**", "bin/llvm",
"lib/clang/*/include/**", "lib/clang/*/include/**",
]) + select({ "include/armv*-unknown-none-eabi/**",
"@platforms//os:windows": [], ]),
"//conditions:default": ["//:bin/llvm"],
}),
)
cc_action_type_config(
name = "clang",
action_types = [
"@rules_cc//cc/toolchains/actions:assembly_actions",
"@rules_cc//cc/toolchains/actions:c_compile",
],
tools = [":clang_tool"],
) )
cc_tool( cc_tool(
name = "clang++_tool",
src = select({
"@platforms//os:windows": "//:bin/clang++.exe",
"//conditions:default": "//:bin/clang++",
}),
data = glob([
"include/armv*-unknown-none-eabi/**",
"include/c++/**",
"lib/clang/*/include/**",
]) + select({
# Windows doesn't have llvm.exe.
"@platforms//os:windows": [],
"//conditions:default": ["//:bin/llvm"],
}),
)
cc_action_type_config(
name = "clang++", name = "clang++",
action_types = ["@rules_cc//cc/toolchains/actions:cpp_compile_actions"],
tools = [":clang++_tool"],
)
# This tool is actually just clang++ under the hood, but this specifies a
# different set of data files to pull into the sandbox at runtime.
cc_tool(
name = "lld_tool",
src = select({ src = select({
"@platforms//os:windows": "//:bin/clang++.exe", "@platforms//os:windows": "//:bin/clang++.exe",
"//conditions:default": "//:bin/clang++", "//conditions:default": "//:bin/clang++",
}), }),
data = glob([ data = glob([
"bin/llvm",
"lib/clang/*/include/**",
"include/armv*-unknown-none-eabi/**",
"include/c++/v1/**",
]),
)
cc_tool(
name = "lld",
src = select({
"@platforms//os:windows": "//:bin/clang++.exe",
"//conditions:default": "//:bin/clang++",
}),
data = glob([
"bin/llvm",
"bin/lld*",
"bin/ld*",
"lib/**/*.a",
"lib/**/*.so*",
"lib/**/*.o",
"lib/armv*-unknown-none-eabi/**", "lib/armv*-unknown-none-eabi/**",
"lib/clang/*/lib/armv*-unknown-none-eabi/**", "lib/clang/*/lib/armv*-unknown-none-eabi/**",
]) + select({ ]),
"@platforms//os:windows": [],
"//conditions:default": ["//:bin/llvm"],
}),
)
cc_action_type_config(
name = "lld",
action_types = ["@rules_cc//cc/toolchains/actions:link_actions"],
tools = [":lld_tool"],
) )
cc_tool( cc_tool(
name = "llvm-objcopy_tool", name = "llvm-ar",
src = select({
"@platforms//os:windows": "//:bin/llvm-ar.exe",
"//conditions:default": "//:bin/llvm-ar",
}),
data = glob(["bin/llvm"]),
)
cc_tool(
name = "llvm-libtool-darwin",
src = select({
"@platforms//os:windows": "//:bin/llvm-libtool-darwin.exe",
"//conditions:default": "//:bin/llvm-libtool-darwin",
}),
data = glob(["bin/llvm"]),
)
cc_tool(
name = "llvm-objcopy",
src = select({ src = select({
"@platforms//os:windows": "//:bin/llvm-objcopy.exe", "@platforms//os:windows": "//:bin/llvm-objcopy.exe",
"//conditions:default": "//:bin/llvm-objcopy", "//conditions:default": "//:bin/llvm-objcopy",
}), }),
data = select({ data = glob(["bin/llvm"]),
"@platforms//os:windows": [],
"//conditions:default": ["//:bin/llvm"],
}),
)
cc_action_type_config(
name = "llvm-objcopy",
action_types = ["@rules_cc//cc/toolchains/actions:objcopy_embed_data"],
tools = [":llvm-objcopy_tool"],
) )
cc_tool( cc_tool(
name = "llvm-strip_tool", name = "llvm-objdump",
src = select({
"@platforms//os:windows": "//:bin/llvm-strip.exe",
"//conditions:default": "//:bin/llvm-strip",
}),
data = select({
"@platforms//os:windows": [],
"//conditions:default": ["//:bin/llvm"],
}),
)
cc_action_type_config(
name = "llvm-strip",
action_types = ["@rules_cc//cc/toolchains/actions:strip"],
tools = [":llvm-strip_tool"],
)
cc_tool(
name = "llvm-objdump_tool",
src = select({ src = select({
"@platforms//os:windows": "//:bin/llvm-objdump.exe", "@platforms//os:windows": "//:bin/llvm-objdump.exe",
"//conditions:default": "//:bin/llvm-objdump", "//conditions:default": "//:bin/llvm-objdump",
}), }),
data = select({ data = glob(["bin/llvm"]),
"@platforms//os:windows": [],
"//conditions:default": ["//:bin/llvm"],
}),
) )
# There is not yet a well-known action type for llvm-objdump.
cc_tool( cc_tool(
name = "llvm-profdata_tool", name = "llvm-cov",
src = select({
"@platforms//os:windows": "//:bin/llvm-profdata.exe",
"//conditions:default": "//:bin/llvm-profdata",
}),
data = select({
"@platforms//os:windows": [],
"//conditions:default": ["//:bin/llvm"],
}),
)
# There is not yet a well-known action type for llvm-profdata.
cc_tool(
name = "llvm-cov_tool",
src = select({ src = select({
"@platforms//os:windows": "//:bin/llvm-cov.exe", "@platforms//os:windows": "//:bin/llvm-cov.exe",
"//conditions:default": "//:bin/llvm-cov", "//conditions:default": "//:bin/llvm-cov",
}), }),
data = select({ data = glob(["bin/llvm"]),
"@platforms//os:windows": [],
"//conditions:default": ["//:bin/llvm"],
}),
) )
# There is not yet a well-known action type for llvm-cov. cc_tool(
name = "llvm-strip",
src = select({
"@platforms//os:windows": "//:bin/llvm-strip.exe",
"//conditions:default": "//:bin/llvm-strip",
}),
data = glob(["bin/llvm"]),
)
cc_tool(
name = "clang-tidy",
src = select({
"@platforms//os:windows": "//:bin/clang-tidy.exe",
"//conditions:default": "//:bin/clang-tidy",
}),
data = glob([
"bin/llvm",
"include/**",
"lib/clang/**/include/**",
]),
)

View File

@ -2,15 +2,7 @@ load("@rules_cc//cc/toolchains:args.bzl", "cc_args")
load("@rules_cc//cc/toolchains:args_list.bzl", "cc_args_list") load("@rules_cc//cc/toolchains:args_list.bzl", "cc_args_list")
load("@rules_cc//cc/toolchains:feature.bzl", "cc_feature") load("@rules_cc//cc/toolchains:feature.bzl", "cc_feature")
def configurable_toolchain_feature(name, copts = [], cxxopts = [], linkopts = [], enable_if = None, disable_if = None): def configurable_toolchain_feature(name, copts = [], cxxopts = [], linkopts = []):
if enable_if != None and disable_if != None:
fail("Cannot specify both enable_if and disable_if")
if enable_if == None and disable_if == None:
fail("Must specify at least one of enable_if and disable_if")
if enable_if == None:
enable_if = "//conditions:default"
if disable_if == None:
disable_if = "//conditions:default"
all_args = [] all_args = []
@ -47,8 +39,4 @@ def configurable_toolchain_feature(name, copts = [], cxxopts = [], linkopts = []
name = name, name = name,
feature_name = name, feature_name = name,
args = [":{}_args".format(name)], args = [":{}_args".format(name)],
enabled = select({
disable_if: False,
enable_if: True,
}),
) )

View File

@ -1,24 +1,43 @@
load("@rules_cc//cc/toolchains:action_type_config.bzl", "cc_action_type_config") load("@bazel_skylib//rules/directory:directory.bzl", "directory")
load("@bazel_skylib//rules/directory:subdirectory.bzl", "subdirectory")
load("@rules_cc//cc/toolchains:tool.bzl", "cc_tool") load("@rules_cc//cc/toolchains:tool.bzl", "cc_tool")
load("@rules_cc//cc/toolchains:tool_map.bzl", "cc_tool_map")
load("@rules_cc//cc/toolchains:args.bzl", "cc_args")
load("@rules_cc//cc/toolchains:args_list.bzl", "cc_args_list")
package(default_visibility = ["//visibility:public"]) package(default_visibility = ["//visibility:public"])
cc_tool_map(
name = "all_tools",
tools = {
"@rules_cc//cc/toolchains/actions:assembly_actions": ":asm",
"@rules_cc//cc/toolchains/actions:c_compile": ":arm-none-eabi-gcc",
"@rules_cc//cc/toolchains/actions:cpp_compile_actions": ":arm-none-eabi-g++",
"@rules_cc//cc/toolchains/actions:link_actions": ":arm-none-eabi-ld",
"@rules_cc//cc/toolchains/actions:objcopy_embed_data": ":arm-none-eabi-objcopy",
"@rules_cc//cc/toolchains/actions:strip": ":arm-none-eabi-strip",
"@rules_cc//cc/toolchains/actions:ar_actions": ":arm-none-eabi-ar",
},
)
# TODO: https://github.com/bazelbuild/rules_cc/issues/235 - Workaround until
# Bazel has a more robust way to implement `cc_tool_map`.
alias(
name = "asm",
actual = ":arm-none-eabi-gcc",
)
cc_tool( cc_tool(
name = "arm-none-eabi-ar_tool", name = "arm-none-eabi-ar",
src = select({ src = select({
"@platforms//os:windows": "//:bin/arm-none-eabi-ar.exe", "@platforms//os:windows": "//:bin/arm-none-eabi-ar.exe",
"//conditions:default": "//:bin/arm-none-eabi-ar", "//conditions:default": "//:bin/arm-none-eabi-ar",
}), }),
) )
cc_action_type_config(
name = "arm-none-eabi-ar",
action_types = ["@rules_cc//cc/toolchains/actions:ar_actions"],
tools = [":arm-none-eabi-ar_tool"],
)
cc_tool( cc_tool(
name = "arm-none-eabi-g++_tool", name = "arm-none-eabi-g++",
src = select({ src = select({
"@platforms//os:windows": "//:bin/arm-none-eabi-g++.exe", "@platforms//os:windows": "//:bin/arm-none-eabi-g++.exe",
"//conditions:default": "//:bin/arm-none-eabi-g++", "//conditions:default": "//:bin/arm-none-eabi-g++",
@ -33,14 +52,8 @@ cc_tool(
]), ]),
) )
cc_action_type_config(
name = "arm-none-eabi-g++",
action_types = ["@rules_cc//cc/toolchains/actions:cpp_compile_actions"],
tools = [":arm-none-eabi-g++_tool"],
)
cc_tool( cc_tool(
name = "arm-none-eabi-gcc_tool", name = "arm-none-eabi-gcc",
src = select({ src = select({
"@platforms//os:windows": "//:bin/arm-none-eabi-gcc.exe", "@platforms//os:windows": "//:bin/arm-none-eabi-gcc.exe",
"//conditions:default": "//:bin/arm-none-eabi-gcc", "//conditions:default": "//:bin/arm-none-eabi-gcc",
@ -62,19 +75,10 @@ cc_tool(
}), }),
) )
cc_action_type_config(
name = "arm-none-eabi-gcc",
action_types = [
"@rules_cc//cc/toolchains/actions:assembly_actions",
"@rules_cc//cc/toolchains/actions:c_compile",
],
tools = [":arm-none-eabi-gcc_tool"],
)
# This tool is actually just g++ under the hood, but this specifies a # This tool is actually just g++ under the hood, but this specifies a
# different set of data files to pull into the sandbox at runtime. # different set of data files to pull into the sandbox at runtime.
cc_tool( cc_tool(
name = "arm-none-eabi-ld_tool", name = "arm-none-eabi-ld",
src = select({ src = select({
"@platforms//os:windows": "//:bin/arm-none-eabi-g++.exe", "@platforms//os:windows": "//:bin/arm-none-eabi-g++.exe",
"//conditions:default": "//:bin/arm-none-eabi-g++", "//conditions:default": "//:bin/arm-none-eabi-g++",
@ -90,42 +94,24 @@ cc_tool(
]), ]),
) )
cc_action_type_config(
name = "arm-none-eabi-ld",
action_types = ["@rules_cc//cc/toolchains/actions:link_actions"],
tools = [":arm-none-eabi-ld_tool"],
)
cc_tool( cc_tool(
name = "arm-none-eabi-objcopy_tool", name = "arm-none-eabi-objcopy",
src = select({ src = select({
"@platforms//os:windows": "//:bin/arm-none-eabi-objcopy.exe", "@platforms//os:windows": "//:bin/arm-none-eabi-objcopy.exe",
"//conditions:default": "//:bin/arm-none-eabi-objcopy", "//conditions:default": "//:bin/arm-none-eabi-objcopy",
}), }),
) )
cc_action_type_config(
name = "arm-none-eabi-objcopy",
action_types = ["@rules_cc//cc/toolchains/actions:objcopy_embed_data"],
tools = [":arm-none-eabi-objcopy_tool"],
)
cc_tool( cc_tool(
name = "arm-none-eabi-strip_tool", name = "arm-none-eabi-strip",
src = select({ src = select({
"@platforms//os:windows": "//:bin/arm-none-eabi-strip.exe", "@platforms//os:windows": "//:bin/arm-none-eabi-strip.exe",
"//conditions:default": "//:bin/arm-none-eabi-strip", "//conditions:default": "//:bin/arm-none-eabi-strip",
}), }),
) )
cc_action_type_config(
name = "arm-none-eabi-strip",
action_types = ["@rules_cc//cc/toolchains/actions:strip"],
tools = [":arm-none-eabi-strip_tool"],
)
cc_tool( cc_tool(
name = "arm-none-eabi-objdump_tool", name = "arm-none-eabi-objdump",
src = select({ src = select({
"@platforms//os:windows": "//:bin/arm-none-eabi-objdump.exe", "@platforms//os:windows": "//:bin/arm-none-eabi-objdump.exe",
"//conditions:default": "//:bin/arm-none-eabi-objdump", "//conditions:default": "//:bin/arm-none-eabi-objdump",
@ -135,7 +121,7 @@ cc_tool(
# There is not yet a well-known action type for objdump. # There is not yet a well-known action type for objdump.
cc_tool( cc_tool(
name = "arm-none-eabi-gcov_tool", name = "arm-none-eabi-gcov",
src = select({ src = select({
"@platforms//os:windows": "//:bin/arm-none-eabi-gcov.exe", "@platforms//os:windows": "//:bin/arm-none-eabi-gcov.exe",
"//conditions:default": "//:bin/arm-none-eabi-gcov", "//conditions:default": "//:bin/arm-none-eabi-gcov",