| Tim Windelschmidt | 16cb15a | 2025-02-24 18:47:48 +0100 | [diff] [blame] | 1 | load("@rules_cc//cc:defs.bzl", "cc_toolchain") |
| Serge Bazanski | 385c12f | 2020-06-17 12:12:42 +0200 | [diff] [blame] | 2 | load(":cc_toolchain_config.bzl", "host_cc_toolchain_config") |
| 3 | |
| 4 | # Toolchain definitions. |
| 5 | # |
| Serge Bazanski | 9e861a8 | 2020-09-16 13:46:41 +0200 | [diff] [blame] | 6 | # We currently define two toolchains: |
| 7 | # |
| Leopold | bc93c2b | 2023-01-14 13:12:23 +0100 | [diff] [blame] | 8 | # - //build/toolchain:host_cc_toolchain , which points to our hermetic sandbox |
| 9 | # sysroot default compiler toolchain. It is mainly used to target the execution platform |
| 10 | # inside the sandbox (i.e. build tooling). |
| 11 | # - //build/toolchain/musl-host-gcc:musl_host_toolchain , which combines the sandbox sysroot |
| Serge Bazanski | 662b5b3 | 2020-12-21 13:49:00 +0100 | [diff] [blame] | 12 | # gcc compiler with a sysroot tarball that targets the Metropolis node |
| 13 | # runtime. This can be used to build C libraries/tools running within the |
| Leopold | bc93c2b | 2023-01-14 13:12:23 +0100 | [diff] [blame] | 14 | # Metropolis node image or on the (unknown) host operating system outside the sandbox. |
| Serge Bazanski | 9e861a8 | 2020-09-16 13:46:41 +0200 | [diff] [blame] | 15 | |
| Leopold | bc93c2b | 2023-01-14 13:12:23 +0100 | [diff] [blame] | 16 | # This file defines //build/toolchain:host_cc_toolchain. |
| Serge Bazanski | 9e861a8 | 2020-09-16 13:46:41 +0200 | [diff] [blame] | 17 | # |
| Leopold | bc93c2b | 2023-01-14 13:12:23 +0100 | [diff] [blame] | 18 | # This is a C++ toolchain that uses GCC from the sandbox sysroot at hardcoded paths. We |
| 19 | # can get away with this, as currently the entire build is performed in a hermetic |
| 20 | # sandbox sysroot (see: //third_party/sandboxroot). We define this toolchain so |
| Serge Bazanski | 385c12f | 2020-06-17 12:12:42 +0200 | [diff] [blame] | 21 | # that we have full control over all configuration of it, which we need as we |
| 22 | # are building some fairly odd C binaries (notably, a qboot bootloader for |
| 23 | # testing). |
| 24 | # |
| Leopold | bc93c2b | 2023-01-14 13:12:23 +0100 | [diff] [blame] | 25 | # The host_cc toolchain suite is enabled for all cc_* targets whose |
| 26 | # platform isn't matching a more specific toolchain. |
| Serge Bazanski | 385c12f | 2020-06-17 12:12:42 +0200 | [diff] [blame] | 27 | # |
| 28 | # This, and :cc_toolchain_config.bzl is based on the following tutorial: |
| 29 | # https://docs.bazel.build/versions/master/tutorial/cc-toolchain-config.html |
| 30 | |
| 31 | package(default_visibility = ["//visibility:public"]) |
| 32 | |
| 33 | filegroup(name = "empty") |
| 34 | |
| Serge Bazanski | 385c12f | 2020-06-17 12:12:42 +0200 | [diff] [blame] | 35 | cc_toolchain( |
| 36 | name = "host_cc_k8_toolchain", |
| Serge Bazanski | 385c12f | 2020-06-17 12:12:42 +0200 | [diff] [blame] | 37 | all_files = ":empty", |
| Leopold | bc93c2b | 2023-01-14 13:12:23 +0100 | [diff] [blame] | 38 | ar_files = ":empty", |
| 39 | as_files = ":empty", |
| Serge Bazanski | 385c12f | 2020-06-17 12:12:42 +0200 | [diff] [blame] | 40 | compiler_files = ":empty", |
| 41 | dwp_files = ":empty", |
| 42 | linker_files = ":empty", |
| 43 | objcopy_files = ":empty", |
| 44 | strip_files = ":empty", |
| 45 | supports_param_files = 0, |
| Serge Bazanski | f12bedf | 2021-01-15 16:58:50 +0100 | [diff] [blame] | 46 | toolchain_config = ":host_cc_k8_toolchain_config", |
| 47 | toolchain_identifier = "host-k8-toolchain", |
| Serge Bazanski | 385c12f | 2020-06-17 12:12:42 +0200 | [diff] [blame] | 48 | ) |
| 49 | |
| 50 | host_cc_toolchain_config(name = "host_cc_k8_toolchain_config") |
| Leopold | bc93c2b | 2023-01-14 13:12:23 +0100 | [diff] [blame] | 51 | |
| Jan Schär | 230a31a | 2025-05-05 12:28:50 +0000 | [diff] [blame^] | 52 | config_setting( |
| 53 | name = "is_dynamic", |
| 54 | flag_values = {"//build/platforms/linkmode:static": "False"}, |
| 55 | ) |
| 56 | |
| Leopold | bc93c2b | 2023-01-14 13:12:23 +0100 | [diff] [blame] | 57 | toolchain( |
| 58 | name = "host_cc_toolchain", |
| 59 | exec_compatible_with = [ |
| Tim Windelschmidt | 2d1ebd3 | 2023-05-23 01:53:12 +0200 | [diff] [blame] | 60 | "@platforms//os:linux", |
| 61 | "@platforms//cpu:x86_64", |
| Leopold | bc93c2b | 2023-01-14 13:12:23 +0100 | [diff] [blame] | 62 | ], |
| 63 | target_compatible_with = [ |
| Tim Windelschmidt | 2d1ebd3 | 2023-05-23 01:53:12 +0200 | [diff] [blame] | 64 | "@platforms//os:linux", |
| 65 | "@platforms//cpu:x86_64", |
| Leopold | bc93c2b | 2023-01-14 13:12:23 +0100 | [diff] [blame] | 66 | ], |
| Jan Schär | 230a31a | 2025-05-05 12:28:50 +0000 | [diff] [blame^] | 67 | target_settings = [ |
| 68 | ":is_dynamic", |
| 69 | ], |
| Leopold | bc93c2b | 2023-01-14 13:12:23 +0100 | [diff] [blame] | 70 | toolchain = ":host_cc_k8_toolchain", |
| 71 | toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", |
| 72 | ) |