From 01c2ded79e62702c1430e90326279d0705d8c6f2 Mon Sep 17 00:00:00 2001 From: Titus Fortner Date: Fri, 11 Sep 2026 12:11:50 -0500 Subject: [PATCH] [build] add --manager=all to cross-compile every Selenium Manager binary from one host --- .bazelrc | 6 ++++ MODULE.bazel | 32 ++++++++++++++++++++-- common/BUILD.bazel | 8 ++++++ common/manager/BUILD.bazel | 4 +++ rust/BUILD.bazel | 56 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 103 insertions(+), 3 deletions(-) diff --git a/.bazelrc b/.bazelrc index 39bceea20986c..8c40b86e5d8ff 100644 --- a/.bazelrc +++ b/.bazelrc @@ -154,8 +154,14 @@ test:node_debug --test_output=streamed --test_strategy=exclusive --test_timeout= test:ruby_debug --test_output=streamed --test_env=RUBY_DEBUG_FORK_MODE=parent --run_under="@bundle//bin:rdbg --nonstop --open --command" +# @llvm defaults to 14.0. +build --macos_minimum_os=11.0 + build:release --stamp build:release --compilation_mode=opt +# Match [profile.release] in rust/Cargo.toml, which Bazel doesn't read. +build:release --@rules_rust//rust/settings:lto=fat +build:release --@rules_rust//rust/settings:extra_rustc_flags=-Copt-level=z,-Ccodegen-units=1,-Cpanic=abort,-Cstrip=symbols # As regular `release` but all the build work happens on the RBE build:rbe_release --config=release diff --git a/MODULE.bazel b/MODULE.bazel index b16c7410efd12..3a58fad37c376 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -50,6 +50,11 @@ single_version_override( ], ) +# Build the `*-sys` C sources with the LLVM cc toolchain so they cross-compile to musl. +bazel_dep(name = "bzip2", version = "1.0.8.bcr.3") +bazel_dep(name = "xz", version = "5.4.5.bcr.8") +bazel_dep(name = "zstd", version = "1.5.7.bcr.1") + single_version_override( module_name = "rules_jvm_external", patch_strip = 1, @@ -429,6 +434,14 @@ llvm_toolchains.exec( arch = "x86_64", os = "macos", ) +llvm_toolchains.exec( + arch = "x86_64", + os = "linux", +) +llvm_toolchains.exec( + arch = "aarch64", + os = "linux", +) use_repo(llvm_toolchains, "llvm_toolchains") # Registered only for Windows in .bazelrc so it cannot shadow @llvm elsewhere. @@ -446,23 +459,36 @@ crate.from_cargo( "aarch64-apple-darwin", "aarch64-pc-windows-msvc", "aarch64-unknown-linux-gnu", + "aarch64-unknown-linux-musl", "x86_64-apple-darwin", + "x86_64-pc-windows-gnullvm", "x86_64-pc-windows-msvc", "x86_64-unknown-linux-gnu", + "x86_64-unknown-linux-musl", ], ) crate.annotation( crate = "bzip2-sys", - gen_build_script = "on", + gen_build_script = "off", + deps = ["@bzip2//:bz2"], ) crate.annotation( crate = "lzma-sys", - gen_build_script = "on", + gen_build_script = "off", + deps = ["@xz//:lzma"], ) crate.annotation( crate = "zstd-sys", - gen_build_script = "on", + gen_build_script = "off", + deps = ["@zstd"], ) + +inject_repo(crate, "bzip2") + +inject_repo(crate, "xz") + +inject_repo(crate, "zstd") + use_repo(crate, "crates") selenium_manager_artifacts = use_extension("//common:selenium_manager.bzl", "selenium_manager_artifacts") diff --git a/common/BUILD.bazel b/common/BUILD.bazel index 64570467d1e18..1b7171d07d22e 100644 --- a/common/BUILD.bazel +++ b/common/BUILD.bazel @@ -20,6 +20,7 @@ string_flag( values = [ "download", "host", + "all", ], ) @@ -30,6 +31,13 @@ config_setting( }, ) +config_setting( + name = "manager_all", + flag_values = { + ":manager": "all", + }, +) + bool_flag( name = "headless", build_setting_default = False, diff --git a/common/manager/BUILD.bazel b/common/manager/BUILD.bazel index 9a852a0ad0401..5fc994fc2433f 100644 --- a/common/manager/BUILD.bazel +++ b/common/manager/BUILD.bazel @@ -12,6 +12,7 @@ package( alias( name = "selenium-manager-linux-x86_64", actual = select({ + "//common:manager_all": "//rust:_xc_file-linux-x86_64", "//common:manager_host": "//rust:selenium-manager-linux-x86_64", "//conditions:default": "@download_sm_linux_x86_64//file", }), @@ -20,6 +21,7 @@ alias( alias( name = "selenium-manager-linux-arm64", actual = select({ + "//common:manager_all": "//rust:_xc_file-linux-arm64", "//common:manager_host": "//rust:selenium-manager-linux-arm64", "//conditions:default": "@download_sm_linux_arm64//file", }), @@ -28,6 +30,7 @@ alias( alias( name = "selenium-manager-macos", actual = select({ + "//common:manager_all": "//rust:_xc_file-macos", "//common:manager_host": "//rust:selenium-manager-macos", "//conditions:default": "@download_sm_macos//file", }), @@ -36,6 +39,7 @@ alias( alias( name = "selenium-manager-windows", actual = select({ + "//common:manager_all": "//rust:_xc_file-windows", "//common:manager_host": "//rust:selenium-manager-windows", "//conditions:default": "@download_sm_windows//file", }), diff --git a/rust/BUILD.bazel b/rust/BUILD.bazel index 63f8caa1e9b6f..fbd7275a896d7 100644 --- a/rust/BUILD.bazel +++ b/rust/BUILD.bazel @@ -1,3 +1,5 @@ +load("@aspect_bazel_lib//lib:output_files.bzl", "output_files") +load("@aspect_bazel_lib//lib:transitions.bzl", "platform_transition_binary") load("@crates//:defs.bzl", "aliases", "all_crate_deps") load("//rust:defs.bzl", "rust_binary", "rust_library", "rust_test", "rustfmt_config") @@ -19,6 +21,60 @@ SELENIUM_MANAGER_PLATFORMS = [ "windows", ] +# musl: Rust's glibc stdlib needs `-lgcc_s`, which @llvm doesn't ship. +# gnullvm: @llvm links a PE binary without a Windows SDK. +SELENIUM_MANAGER_TRIPLES = { + "linux-arm64": "aarch64-unknown-linux-musl", + "linux-x86_64": "x86_64-unknown-linux-musl", + "macos-arm64": "aarch64-apple-darwin", + "macos-x86_64": "x86_64-apple-darwin", + "windows": "x86_64-pc-windows-gnullvm", +} + +[ + platform_transition_binary( + name = "_xc-%s" % target, + basename = "selenium-manager.exe" if target == "windows" else "selenium-manager", + binary = ":selenium-manager", + tags = ["manual"], + target_platform = "@rules_rs//rs/platforms:%s" % triple, + ) + for (target, triple) in SELENIUM_MANAGER_TRIPLES.items() +] + +# platform_transition_binary also forwards the rust_binary at a colliding path; keep only the wrapper. +# Windows hosts can't cross-compile until upstream fixes ship. +[ + output_files( + name = "_xc_file-%s" % target, + paths = ["rust/_xc-%s/selenium-manager%s" % ( + target, + ".exe" if target == "windows" else "", + )], + tags = ["manual"], + target = ":_xc-%s" % target, + target_compatible_with = select({ + "//common:windows": ["@platforms//:incompatible"], + "//conditions:default": [], + }), + visibility = ["//common/manager:__pkg__"], + ) + for target in SELENIUM_MANAGER_TRIPLES +] + +genrule( + name = "_xc_file-macos", + srcs = [ + ":_xc_file-macos-arm64", + ":_xc_file-macos-x86_64", + ], + outs = ["_xc-macos/selenium-manager"], + cmd = "$(execpath @llvm//tools:llvm-lipo) -create -output $@ $(execpath :_xc_file-macos-arm64) $(execpath :_xc_file-macos-x86_64)", + tags = ["manual"], + tools = ["@llvm//tools:llvm-lipo"], + visibility = ["//common/manager:__pkg__"], +) + [ alias( name = "selenium-manager-%s" % platform,