treewide: remove build_static_transition
We now build everything statically on Linux. This means we don't need
the build_static_transition anymore, as it has become a no-op.
Change-Id: Id6b978daf09bf3e8e252d00da3795909d7ce3b75
Reviewed-on: https://review.monogon.dev/c/monogon/+/4414
Tested-by: Jenkins CI
Reviewed-by: Tim Windelschmidt <tim@monogon.tech>
diff --git a/build/static_binary_tarball/def.bzl b/build/static_binary_tarball/def.bzl
index b23f4e0..8ec1164 100644
--- a/build/static_binary_tarball/def.bzl
+++ b/build/static_binary_tarball/def.bzl
@@ -14,15 +14,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-load("//osbase/build:def.bzl", "build_static_transition")
-
def _static_binary_tarball_impl(ctx):
layer_spec = ctx.actions.declare_file(ctx.label.name + ".prototxt")
- if len(ctx.attr.executable) != 1:
- fail("executable arg can only contain one file/label")
- executable_label = ctx.attr.executable[0]
- executable = executable_label[DefaultInfo].files_to_run.executable
- runfiles = executable_label[DefaultInfo].default_runfiles
+ executable = ctx.attr.executable[DefaultInfo].files_to_run.executable
+ runfiles = ctx.attr.executable[DefaultInfo].default_runfiles
files = []
for file in runfiles.files.to_list():
layer_path = file.short_path
@@ -60,7 +55,7 @@
mandatory = True,
executable = True,
allow_single_file = True,
- cfg = build_static_transition,
+ cfg = "target",
),
"_container_binary": attr.label(
default = Label("//build/static_binary_tarball"),
diff --git a/cloud/agent/install.go b/cloud/agent/install.go
index 1ad60fc..9ada49b 100644
--- a/cloud/agent/install.go
+++ b/cloud/agent/install.go
@@ -27,7 +27,7 @@
"source.monogon.dev/osbase/supervisor"
)
-//go:embed metropolis/node/abloader/abloader_bin.efi
+//go:embed metropolis/node/abloader/abloader.efi
var abloader []byte
// install dispatches OSInstallationRequests to the appropriate installer
diff --git a/cloud/agent/takeover/BUILD.bazel b/cloud/agent/takeover/BUILD.bazel
index a884f6b..e1ba2a6 100644
--- a/cloud/agent/takeover/BUILD.bazel
+++ b/cloud/agent/takeover/BUILD.bazel
@@ -1,6 +1,5 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
load("//build/static_binary_tarball:def.bzl", "static_binary_tarball")
-load("//osbase/build:def.bzl", "build_static_target")
load("//osbase/build/genproductinfo:defs.bzl", "product_info")
load("//osbase/build/mkcpio:def.bzl", "node_initramfs")
@@ -28,22 +27,15 @@
)
go_binary(
- name = "takeover_bin",
- embed = [":takeover_lib"],
- visibility = ["//visibility:private"],
-)
-
-# Used by e2e tests, forces a static build
-build_static_target(
name = "takeover",
- dep = ":takeover_bin",
+ embed = [":takeover_lib"],
visibility = ["//visibility:public"],
)
# Used by container_images, forces a static build
static_binary_tarball(
name = "takeover_layer",
- executable = ":takeover_bin",
+ executable = ":takeover",
visibility = ["//visibility:public"],
)
diff --git a/metropolis/cli/metroctl/cmd_install_ssh.go b/metropolis/cli/metroctl/cmd_install_ssh.go
index 3dec0d4..014e6b1 100644
--- a/metropolis/cli/metroctl/cmd_install_ssh.go
+++ b/metropolis/cli/metroctl/cmd_install_ssh.go
@@ -204,7 +204,7 @@
if err != nil {
return err
}
- takeover, err := externalFile("takeover", "_main/metropolis/cli/takeover/takeover_bin_/takeover_bin", &takeoverPath)
+ takeover, err := externalFile("takeover", "_main/metropolis/cli/takeover/takeover_/takeover", &takeoverPath)
if err != nil {
return err
}
diff --git a/metropolis/cli/takeover/BUILD.bazel b/metropolis/cli/takeover/BUILD.bazel
index 8e51836..cbe1934 100644
--- a/metropolis/cli/takeover/BUILD.bazel
+++ b/metropolis/cli/takeover/BUILD.bazel
@@ -1,5 +1,4 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
-load("//osbase/build:def.bzl", "build_static_target")
load("//osbase/build/mkcpio:def.bzl", "node_initramfs")
node_initramfs(
@@ -52,13 +51,7 @@
)
go_binary(
- name = "takeover_bin",
- embed = [":takeover_lib"],
- visibility = ["//visibility:public"],
-)
-
-build_static_target(
name = "takeover",
- dep = ":takeover_bin",
+ embed = [":takeover_lib"],
visibility = ["//visibility:public"],
)
diff --git a/metropolis/cli/takeover/install.go b/metropolis/cli/takeover/install.go
index d58d89c..97e8565 100644
--- a/metropolis/cli/takeover/install.go
+++ b/metropolis/cli/takeover/install.go
@@ -18,7 +18,7 @@
"source.monogon.dev/osbase/structfs"
)
-//go:embed metropolis/node/abloader/abloader_bin.efi
+//go:embed metropolis/node/abloader/abloader.efi
var abloader []byte
// EnvInstallTarget environment variable which tells the takeover binary where
diff --git a/metropolis/installer/main.go b/metropolis/installer/main.go
index 930c472..735a8cd 100644
--- a/metropolis/installer/main.go
+++ b/metropolis/installer/main.go
@@ -31,7 +31,7 @@
"source.monogon.dev/osbase/sysfs"
)
-//go:embed metropolis/node/abloader/abloader_bin.efi
+//go:embed metropolis/node/abloader/abloader.efi
var abloader []byte
//go:embed build/copyright_line.txt
diff --git a/metropolis/node/abloader/BUILD.bazel b/metropolis/node/abloader/BUILD.bazel
index e8bd06e..cb9dc2c 100644
--- a/metropolis/node/abloader/BUILD.bazel
+++ b/metropolis/node/abloader/BUILD.bazel
@@ -1,8 +1,7 @@
load("@rules_rust//rust:defs.bzl", "rust_binary")
-load("//osbase/build:def.bzl", "ignore_unused_configuration_target")
rust_binary(
- name = "abloader_bin",
+ name = "abloader",
srcs = ["main.rs"],
edition = "2021",
platform = select({
@@ -16,16 +15,10 @@
target_compatible_with = [
"@platforms//os:uefi",
],
- visibility = ["//visibility:private"],
+ visibility = ["//visibility:public"],
deps = [
"//metropolis/node/abloader/spec:abloader_proto_rs",
"@crate_index_efi//:prost",
"@crate_index_efi//:uefi",
],
)
-
-ignore_unused_configuration_target(
- name = "abloader",
- dep = ":abloader_bin",
- visibility = ["//visibility:public"],
-)
diff --git a/metropolis/node/core/update/update.go b/metropolis/node/core/update/update.go
index d37bb38..66e7501 100644
--- a/metropolis/node/core/update/update.go
+++ b/metropolis/node/core/update/update.go
@@ -424,7 +424,7 @@
return nil
}
-//go:embed metropolis/node/abloader/abloader_bin.efi
+//go:embed metropolis/node/abloader/abloader.efi
var abloader []byte
func (s *Service) fixupPreloader() error {
diff --git a/osbase/build/def.bzl b/osbase/build/def.bzl
deleted file mode 100644
index 7b5f231..0000000
--- a/osbase/build/def.bzl
+++ /dev/null
@@ -1,93 +0,0 @@
-load("@bazel_skylib//lib:paths.bzl", "paths")
-
-def _build_static_transition_impl(_settings, _attr):
- """
- Transition that enables static build of Go and C binaries.
- """
- return {
- "@io_bazel_rules_go//go/config:static": True,
- "@toolchain_cc_mngn//buildmode:static": True,
- }
-
-build_static_transition = transition(
- implementation = _build_static_transition_impl,
- inputs = [],
- outputs = [
- "@io_bazel_rules_go//go/config:static",
- "@toolchain_cc_mngn//buildmode:static",
- ],
-)
-
-def forward_impl(ctx):
- # We can't pass DefaultInfo through as-is, since Bazel forbids executable
- # if it's a file declared in a different target. To emulate that, symlink
- # to the original executable, if there is one.
- default_info = ctx.attr.dep[DefaultInfo]
- new_executable = None
- original_executable = default_info.files_to_run.executable
- runfiles = default_info.default_runfiles
- if original_executable:
- # In order for the symlink to have the same basename as the original
- # executable (important in the case of proto plugins), put it in a
- # subdirectory named after the label to prevent collisions.
- new_executable = ctx.actions.declare_file(paths.join(ctx.label.name, original_executable.basename))
- ctx.actions.symlink(
- output = new_executable,
- target_file = original_executable,
- is_executable = True,
- )
- runfiles = runfiles.merge(ctx.runfiles([new_executable]))
-
- return [DefaultInfo(
- files = default_info.files,
- runfiles = runfiles,
- executable = new_executable,
- )]
-
-build_static_target = rule(
- cfg = build_static_transition,
- implementation = forward_impl,
- attrs = {
- "dep": attr.label(mandatory = True),
- },
- doc = """Applies build_static_transition to a target.""",
-)
-
-_new_settings = {
- # This list should be expanded with any configuration options that end
- # up reaching this rule with different values across different build
- # graph paths, but that do not actually influence the kernel build.
- # Force-setting them to a stable value forces the build configuration
- # to a stable hash.
- # See the transition's comment block for more information.
- "@io_bazel_rules_go//go/config:static": False,
- "@toolchain_cc_mngn//buildmode:static": True,
-}
-
-def _ignore_unused_configuration_impl(_settings, _attr):
- return _new_settings
-
-# Transition to flip all known-unimportant but varying configuration options to
-# a known, stable value.
-# This is to prevent Bazel from creating extra configurations for possible
-# combinations of options in case the linux_image rule is pulled through build
-# graph fragments that have different options set.
-#
-# Ideally, Bazel would let us mark in a list that we only care about some set
-# of options (or at least let us mark those that we explicitly don't care
-# about, instead of manually setting them to some value). However, this doesn't
-# seem to be possible, thus this transition is a bit of a hack.
-ignore_unused_configuration = transition(
- implementation = _ignore_unused_configuration_impl,
- inputs = [],
- outputs = list(_new_settings.keys()),
-)
-
-ignore_unused_configuration_target = rule(
- cfg = ignore_unused_configuration,
- implementation = forward_impl,
- attrs = {
- "dep": attr.label(mandatory = True),
- },
- doc = """Applies ignore_unused_configuration transition to a target.""",
-)
diff --git a/osbase/build/mkcpio/def.bzl b/osbase/build/mkcpio/def.bzl
index b917506..0dc46fa 100644
--- a/osbase/build/mkcpio/def.bzl
+++ b/osbase/build/mkcpio/def.bzl
@@ -1,4 +1,3 @@
-load("//osbase/build:def.bzl", "build_static_transition")
load("//osbase/build/fsspec:def.bzl", "FSSpecInfo", "fsspec_core_impl")
def _node_initramfs_impl(ctx):
@@ -10,8 +9,6 @@
return [DefaultInfo(runfiles = ctx.runfiles(files = [initramfs]), files = depset([initramfs]))]
node_initramfs = rule(
- # Attach static transition to ensure all binaries added to the initramfs are static binaries.
- cfg = build_static_transition,
implementation = _node_initramfs_impl,
doc = """
Build a node initramfs. The initramfs will contain a basic /dev directory and all the files specified by the
diff --git a/osbase/build/mkerofs/def.bzl b/osbase/build/mkerofs/def.bzl
index 0be0568..2b2f422 100644
--- a/osbase/build/mkerofs/def.bzl
+++ b/osbase/build/mkerofs/def.bzl
@@ -1,4 +1,3 @@
-load("//osbase/build:def.bzl", "build_static_transition")
load("//osbase/build/fsspec:def.bzl", "FSSpecInfo", "fsspec_core_impl")
def _erofs_image_impl(ctx):
@@ -10,8 +9,6 @@
return [DefaultInfo(files = depset([fs_out]))]
erofs_image = rule(
- # Attach static transition to ensure all binaries added to the EROFS are static binaries.
- cfg = build_static_transition,
implementation = _erofs_image_impl,
doc = """
Build an EROFS. All files specified in files and all specified symlinks will be contained.
diff --git a/osbase/build/mkpayload/def.bzl b/osbase/build/mkpayload/def.bzl
index 287f94d..51f2ff1 100644
--- a/osbase/build/mkpayload/def.bzl
+++ b/osbase/build/mkpayload/def.bzl
@@ -6,7 +6,6 @@
load("@rules_cc//cc:action_names.bzl", "OBJ_COPY_ACTION_NAME")
load("@rules_cc//cc:find_cc_toolchain.bzl", "CC_TOOLCHAIN_ATTRS", "find_cpp_toolchain", "use_cc_toolchain")
load("@rules_cc//cc/common:cc_common.bzl", "cc_common")
-load("//osbase/build:def.bzl", "build_static_transition")
load("//osbase/build/mkverity:def.bzl", "VerityInfo")
def _efi_unified_kernel_image_impl(ctx):
@@ -80,7 +79,6 @@
return [DefaultInfo(files = depset([image]), runfiles = ctx.runfiles(files = [image]))]
efi_unified_kernel_image = rule(
- cfg = build_static_transition,
implementation = _efi_unified_kernel_image_impl,
attrs = {
"kernel": attr.label(
diff --git a/osbase/build/mkverity/def.bzl b/osbase/build/mkverity/def.bzl
index bb5b8a4..417c883 100644
--- a/osbase/build/mkverity/def.bzl
+++ b/osbase/build/mkverity/def.bzl
@@ -1,5 +1,3 @@
-load("//osbase/build:def.bzl", "build_static_transition")
-
# VerityInfo is emitted by verity_image, and contains a file enclosing a
# singular dm-verity target table.
VerityInfo = provider(
@@ -48,7 +46,6 @@
]
verity_image = rule(
- cfg = build_static_transition,
implementation = _verity_image_impl,
doc = """
Build a dm-verity target image by appending Verity metadata to the source
diff --git a/osbase/test/ktest/ktest.bzl b/osbase/test/ktest/ktest.bzl
index 5fc93e8..96ea31f 100644
--- a/osbase/test/ktest/ktest.bzl
+++ b/osbase/test/ktest/ktest.bzl
@@ -18,7 +18,6 @@
Ktest provides a macro to run tests under a normal Metropolis node kernel
"""
-load("//osbase/build:def.bzl", "build_static_transition")
load("//osbase/build/fsspec:def.bzl", "FSSpecInfo", "fsspec_core_impl")
_KTEST_SCRIPT = """
@@ -31,7 +30,7 @@
initramfs_name = ctx.label.name + ".cpio.zst"
initramfs = ctx.actions.declare_file(initramfs_name)
- fsspec_core_impl(ctx, ctx.executable._mkcpio, initramfs, [("/init", ctx.attr._ktest_init[0]), ("/tester", ctx.attr.tester[0])], [ctx.attr._earlydev])
+ fsspec_core_impl(ctx, ctx.executable._mkcpio, initramfs, [("/init", ctx.attr._ktest_init), ("/tester", ctx.attr.tester)], [ctx.attr._earlydev])
script_file = ctx.actions.declare_file(ctx.label.name + ".sh")
@@ -46,7 +45,7 @@
is_executable = True,
)
- runfiles = ctx.runfiles(files = [ctx.file._ktest, initramfs, ctx.file.kernel, ctx.file.tester])
+ runfiles = ctx.runfiles(files = [ctx.file._ktest, initramfs, ctx.file.kernel])
runfiles = runfiles.merge(ctx.attr._ktest[DefaultInfo].default_runfiles)
return [DefaultInfo(
@@ -64,8 +63,7 @@
mandatory = True,
executable = True,
allow_single_file = True,
- # Runs inside the given kernel, needs to be build for Linux/static
- cfg = build_static_transition,
+ cfg = "target",
),
"files": attr.string_keyed_label_dict(
allow_files = True,
@@ -73,8 +71,6 @@
Dictionary of Labels to String, placing a given Label's output file in the initramfs at the location
specified by the String value. The specified labels must only have a single output.
""",
- # Attach static transition to ensure all binaries added to the initramfs are static binaries.
- cfg = build_static_transition,
),
"symlinks": attr.string_dict(
default = {},
@@ -92,7 +88,6 @@
""",
providers = [FSSpecInfo],
allow_files = True,
- cfg = build_static_transition,
),
"kernel": attr.label(
default = Label("//osbase/test/ktest:linux-testing"),
@@ -110,7 +105,7 @@
),
"_ktest_init": attr.label(
default = Label("//osbase/test/ktest/init"),
- cfg = build_static_transition,
+ cfg = "target",
executable = True,
allow_single_file = True,
),
diff --git a/third_party/edk2/def.bzl b/third_party/edk2/def.bzl
index 62a0fbe..e9562bf 100644
--- a/third_party/edk2/def.bzl
+++ b/third_party/edk2/def.bzl
@@ -7,7 +7,6 @@
load("//build/utils:detect_root.bzl", "detect_root", "detect_roots")
load("//build/utils:foreign_build.bzl", "generate_foreign_build_env", "merge_env")
load("//build/utils:target_info.bzl", "TargetInfo")
-load("//osbase/build:def.bzl", "ignore_unused_configuration")
TOOLCHAINS = [
"//build/toolchain/toolchain-bundle:make_toolchain",
@@ -115,7 +114,6 @@
Build EDK2 hermetically.
""",
implementation = _edk2_impl,
- cfg = ignore_unused_configuration,
attrs = {
"src": attr.label(
doc = """
diff --git a/third_party/linux/def.bzl b/third_party/linux/def.bzl
index 5e320bd..8e5878d 100644
--- a/third_party/linux/def.bzl
+++ b/third_party/linux/def.bzl
@@ -15,7 +15,6 @@
load("//build/utils:detect_root.bzl", "detect_root", "detect_roots")
load("//build/utils:foreign_build.bzl", "generate_foreign_build_env", "merge_env")
load("//build/utils:target_info.bzl", "TargetInfo")
-load("//osbase/build:def.bzl", "ignore_unused_configuration")
def _linux_image_impl_resources(_os, _ninputs):
"""
@@ -176,7 +175,6 @@
Build Linux kernel image hermetically in a given format.
""",
implementation = _linux_image_impl,
- cfg = ignore_unused_configuration,
attrs = {
"kernel_config": attr.label(
doc = """
@@ -219,9 +217,6 @@
default = "//third_party:openssl_crypto",
cfg = "exec",
),
- "_allowlist_function_transition": attr.label(
- default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
- ),
"_exec_toolchain": attr.label(
default = "@rules_cc//cc:current_cc_toolchain",
cfg = "exec",