From 87a3dd9d0e4640fc609b3c59e312fd29ad547061 Mon Sep 17 00:00:00 2001 From: Armando Montanez Date: Fri, 6 Sep 2024 11:03:17 -0700 Subject: [PATCH] Get toolchain working --- examples/rule_based_toolchain/MODULE.bazel | 7 +++--- .../dynamic_answer/dynamic_answer.c | 2 +- examples/rule_based_toolchain/toolchain/BUILD | 23 ++++++++++++++----- .../toolchain/linux_sysroot.BUILD | 10 +++----- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/examples/rule_based_toolchain/MODULE.bazel b/examples/rule_based_toolchain/MODULE.bazel index 0273b2f..8e91dfd 100644 --- a/examples/rule_based_toolchain/MODULE.bazel +++ b/examples/rule_based_toolchain/MODULE.bazel @@ -3,8 +3,9 @@ module( version = "0.0.1", ) +bazel_dep(name = "platforms", version = "0.0.10") bazel_dep(name = "googletest", version = "1.15.2") -bazel_dep(name = "skylib", version = "1.7.1") +bazel_dep(name = "bazel_skylib", version = "1.7.1") bazel_dep(name = "rules_cc") local_path_override(module_name = "rules_cc", path = "../..") @@ -28,8 +29,6 @@ http_archive( ) register_toolchains( - [ - "//toolchain:host-linux-x86_64", - ], + "//toolchain:host-linux-x86_64", dev_dependency = True, ) diff --git a/examples/rule_based_toolchain/dynamic_answer/dynamic_answer.c b/examples/rule_based_toolchain/dynamic_answer/dynamic_answer.c index b918f3f..a4256ac 100644 --- a/examples/rule_based_toolchain/dynamic_answer/dynamic_answer.c +++ b/examples/rule_based_toolchain/dynamic_answer/dynamic_answer.c @@ -1,5 +1,5 @@ #include "dynamic_answer.h" -int dynamic_answer() { +int dynamic_answer(void) { return 24; } diff --git a/examples/rule_based_toolchain/toolchain/BUILD b/examples/rule_based_toolchain/toolchain/BUILD index 76fead2..927101e 100644 --- a/examples/rule_based_toolchain/toolchain/BUILD +++ b/examples/rule_based_toolchain/toolchain/BUILD @@ -15,7 +15,7 @@ cc_args( actions = [ "@rules_cc//cc/toolchains/actions:c_compile", "@rules_cc//cc/toolchains/actions:cpp_compile_actions", - ] + ], args = [ "-Wall", "-Wextra", @@ -23,18 +23,28 @@ cc_args( ], ) +cc_args( + name = "no_canonical_prefixes", + actions = [ + "@rules_cc//cc/toolchains/actions:c_compile", + "@rules_cc//cc/toolchains/actions:cpp_compile_actions", + ], + args = ["-no-canonical-prefixes"], +) + [ cc_toolchain( - name = "host-{}-config".format(platform), + name = "host-{}-config".format(platform_name), args = select({ "@platforms//os:linux": [ "@linux_sysroot//:sysroot", ], "//conditions:default": [], }) + [ + ":no_canonical_prefixes", ":warnings", ], - tools = "@clang-{}//:all_tools".format(platform), + tool_map = "@clang-{}//:all_tools".format(platform_name), known_features = ["@rules_cc//cc/toolchains/args:experimental_replace_legacy_action_config_features"], enabled_features = ["@rules_cc//cc/toolchains/args:experimental_replace_legacy_action_config_features"], target_compatible_with = constraints, @@ -44,10 +54,11 @@ cc_args( [ toolchain( - name = "host-{}".format(platform), + name = "host-{}".format(platform_name), exec_compatible_with = constraints, target_compatible_with = constraints, + toolchain = ":host-{}-config".format(platform_name), + toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", ) - toolchain = ":host_toolchain", - toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", + for platform_name, constraints in PLATFORMS.items() ] diff --git a/examples/rule_based_toolchain/toolchain/linux_sysroot.BUILD b/examples/rule_based_toolchain/toolchain/linux_sysroot.BUILD index 514cd9b..904d48b 100644 --- a/examples/rule_based_toolchain/toolchain/linux_sysroot.BUILD +++ b/examples/rule_based_toolchain/toolchain/linux_sysroot.BUILD @@ -8,8 +8,7 @@ cc_sysroot( name = "sysroot", sysroot = ":root", data = [":root"], - implicit_include_directories = [ - ":usr-local-include", + allowlist_include_directories = [ ":usr-include-x86_64-linux-gnu", ":usr-include", ], @@ -20,17 +19,14 @@ directory( srcs = glob(["**/*"]), ) -subdirectory( - name = "usr-local-include", - path = "usr/local/include", -) - subdirectory( name = "usr-include-x86_64-linux-gnu", path = "usr/include/x86_64-linux-gnu", + parent = ":root", ) subdirectory( name = "usr-include", path = "usr/include", + parent = ":root", )