*: migrate to CC toolchains and Bazel 5.4.0

Change-Id: Iff3c0ddda4413dd0c5fa657a5b7813223e98611e
Reviewed-on: https://review.monogon.dev/c/monogon/+/1079
Tested-by: Jenkins CI
Reviewed-by: Lorenz Brun <lorenz@monogon.tech>
diff --git a/build/toolchain/llvm-efi/BUILD b/build/toolchain/llvm-efi/BUILD
index 3cfa67f..5feb67f 100644
--- a/build/toolchain/llvm-efi/BUILD
+++ b/build/toolchain/llvm-efi/BUILD
@@ -4,13 +4,6 @@
 
 filegroup(name = "empty")
 
-cc_toolchain_suite(
-    name = "efi_cc_suite",
-    toolchains = {
-        "k8": ":efi_k8_cc_toolchain",
-    },
-)
-
 filegroup(
     name = "fltused",
     srcs = ["fltused.o"],
@@ -19,6 +12,8 @@
 cc_toolchain(
     name = "efi_k8_cc_toolchain",
     all_files = ":empty",
+    ar_files = ":empty",
+    as_files = ":empty",
     compiler_files = ":empty",
     dwp_files = ":empty",
     linker_files = ":fltused",
@@ -30,3 +25,17 @@
 )
 
 efi_k8_cc_toolchain_config(name = "efi_k8_cc_toolchain_config")
+
+toolchain(
+    name = "efi_k8_toolchain",
+    exec_compatible_with = [
+        "@platforms//cpu:x86_64",
+        "@platforms//os:linux",
+    ],
+    target_compatible_with = [
+        "@platforms//cpu:x86_64",
+        "//build/platforms/os:efi",
+    ],
+    toolchain = ":efi_k8_cc_toolchain",
+    toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
+)
diff --git a/build/toolchain/llvm-efi/README.md b/build/toolchain/llvm-efi/README.md
index 5f1b9c8..0360ec5 100644
--- a/build/toolchain/llvm-efi/README.md
+++ b/build/toolchain/llvm-efi/README.md
@@ -1,19 +1,18 @@
 llvm-efi
 ========
 
-llvm-efi is a Bazel cc toolchain that uses the machine's host LLVM/clang with flags targeting freestanding EFI.
+llvm-efi is a Bazel cc toolchain that uses the sandbox sysroot LLVM/clang with flags targeting freestanding EFI.
 EFI headers are not shipped as part of the toolchain, but are available as a cc_library from `@gnuefi//:gnuefi`.
 
-At some point, this toolchain should be replaced by a fully hermetic toolchain that doesn't depend on the host environment.
-
 Usage
 -----
 
 To use this toolchain explicitly while building a `cc_binary`, do:
 
-    bazel build --crosstool_top=//build/toolchain/llvm-efi:efi_cc_suite //foo/bar
+    bazel build --platforms=//build/platforms:efi_amd64 //foo/bar
 
-During an actual build however, the right toolchain should be selected using aspects or other Bazel configurability features, instead of a hardcoded `--crosstool_top`.
+During an actual build however, the right toolchain should be selected using transitions
+or other configuration mechanisms.
 
 fltused
 -------
diff --git a/build/toolchain/llvm-efi/transition.bzl b/build/toolchain/llvm-efi/transition.bzl
index e2f7a8f..1edb86b 100644
--- a/build/toolchain/llvm-efi/transition.bzl
+++ b/build/toolchain/llvm-efi/transition.bzl
@@ -3,13 +3,13 @@
     Transition that enables building for an EFI environment. Currently only supports C code.
     """
     return {
-        "//command_line_option:crosstool_top": "//build/toolchain/llvm-efi:efi_cc_suite",
+        "//command_line_option:platforms": "//build/platforms:efi_amd64"
     }
 
 build_efi_transition = transition(
     implementation = _build_efi_transition_impl,
     inputs = [],
     outputs = [
-        "//command_line_option:crosstool_top",
+        "//command_line_option:platforms",
     ],
 )