blob: a1d22887cf09cb496ef6c01beec6db790ceced67 [file] [log] [blame]
Tim Windelschmidt16cb15a2025-02-24 18:47:48 +01001load("@rules_cc//cc:defs.bzl", "cc_toolchain")
Serge Bazanski385c12f2020-06-17 12:12:42 +02002load(":cc_toolchain_config.bzl", "host_cc_toolchain_config")
3
4# Toolchain definitions.
5#
Serge Bazanski9e861a82020-09-16 13:46:41 +02006# We currently define two toolchains:
7#
Leopoldbc93c2b2023-01-14 13:12:23 +01008# - //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 Bazanski662b5b32020-12-21 13:49:00 +010012# 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
Leopoldbc93c2b2023-01-14 13:12:23 +010014# Metropolis node image or on the (unknown) host operating system outside the sandbox.
Serge Bazanski9e861a82020-09-16 13:46:41 +020015
Leopoldbc93c2b2023-01-14 13:12:23 +010016# This file defines //build/toolchain:host_cc_toolchain.
Serge Bazanski9e861a82020-09-16 13:46:41 +020017#
Leopoldbc93c2b2023-01-14 13:12:23 +010018# 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 Bazanski385c12f2020-06-17 12:12:42 +020021# 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#
Leopoldbc93c2b2023-01-14 13:12:23 +010025# The host_cc toolchain suite is enabled for all cc_* targets whose
26# platform isn't matching a more specific toolchain.
Serge Bazanski385c12f2020-06-17 12:12:42 +020027#
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
31package(default_visibility = ["//visibility:public"])
32
33filegroup(name = "empty")
34
Serge Bazanski385c12f2020-06-17 12:12:42 +020035cc_toolchain(
36 name = "host_cc_k8_toolchain",
Serge Bazanski385c12f2020-06-17 12:12:42 +020037 all_files = ":empty",
Leopoldbc93c2b2023-01-14 13:12:23 +010038 ar_files = ":empty",
39 as_files = ":empty",
Serge Bazanski385c12f2020-06-17 12:12:42 +020040 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 Bazanskif12bedf2021-01-15 16:58:50 +010046 toolchain_config = ":host_cc_k8_toolchain_config",
47 toolchain_identifier = "host-k8-toolchain",
Serge Bazanski385c12f2020-06-17 12:12:42 +020048)
49
50host_cc_toolchain_config(name = "host_cc_k8_toolchain_config")
Leopoldbc93c2b2023-01-14 13:12:23 +010051
Jan Schär230a31a2025-05-05 12:28:50 +000052config_setting(
53 name = "is_dynamic",
Lorenz Brun043c0b42025-03-13 21:09:36 +010054 flag_values = {"@toolchain_cc_mngn//buildmode:static": "False"},
Jan Schär230a31a2025-05-05 12:28:50 +000055)
56
Leopoldbc93c2b2023-01-14 13:12:23 +010057toolchain(
58 name = "host_cc_toolchain",
59 exec_compatible_with = [
Tim Windelschmidt2d1ebd32023-05-23 01:53:12 +020060 "@platforms//os:linux",
61 "@platforms//cpu:x86_64",
Leopoldbc93c2b2023-01-14 13:12:23 +010062 ],
63 target_compatible_with = [
Tim Windelschmidt2d1ebd32023-05-23 01:53:12 +020064 "@platforms//os:linux",
65 "@platforms//cpu:x86_64",
Leopoldbc93c2b2023-01-14 13:12:23 +010066 ],
Jan Schär230a31a2025-05-05 12:28:50 +000067 target_settings = [
68 ":is_dynamic",
69 ],
Leopoldbc93c2b2023-01-14 13:12:23 +010070 toolchain = ":host_cc_k8_toolchain",
71 toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
72)