diff --git a/.bazelrc b/.bazelrc index 498f0cd48..4657ca557 100644 --- a/.bazelrc +++ b/.bazelrc @@ -2,6 +2,7 @@ import %workspace%/bazel/defaults.bazelrc common --test_output=errors common --incompatible_disallow_empty_glob=False +common --enable_platform_specific_config # Define value used by tests common --define=SOME_VAR=SOME_VALUE @@ -10,9 +11,11 @@ common --define=SOME_VAR=SOME_VALUE common --@pypi//venv=default common --incompatible_enable_cc_toolchain_resolution -common --@toolchains_llvm_bootstrapped//config:experimental_stub_libgcc_s +common --@llvm//config:experimental_stub_libgcc_s common --@rules_cc//cc/toolchains/args/archiver_flags:use_libtool_on_macos=false +common:linux --host_platform=//bazel/platforms:linux_host + # TODO(bzlmod): Don't break proto common --per_file_copt=external/.*protobuf.*@--PROTOBUF_WAS_NOT_SUPPOSED_TO_BE_BUILT common --host_per_file_copt=external/.*protobuf.*@--PROTOBUF_WAS_NOT_SUPPOSED_TO_BE_BUILT @@ -22,6 +25,7 @@ common --repo_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1 common --repo_env=BAZEL_NO_APPLE_CPP_TOOLCHAIN=1 common:ci --toolchain_resolution_debug='@@bazel_tools//tools/cpp:toolchain_type' +common:ci --toolchain_resolution_debug='.*rust.*' common:release --build_tag_filters=release common:release --stamp diff --git a/BUILD.bazel b/BUILD.bazel index efdc898c8..6c4f1b2b2 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -13,6 +13,8 @@ load("//uv/private/manifest:defs.bzl", "gazelle_python_manifest") gazelle_python_manifest( name = "gazelle_python_manifest", hub = "pypi", + # TODO: this doesn't work on linux because it hardcodes the @platforms//host platform which won't match rust toolchains. + tags = ["manual"], venvs = [ "default", ], diff --git a/MODULE.bazel b/MODULE.bazel index 5ec2e2268..9cf5765d2 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -52,45 +52,10 @@ use_repo(tel, "aspect_tools_telemetry_report") # Dev deps are the remainder of the file # LLVM configuration -bazel_dep(name = "toolchains_llvm_bootstrapped", version = "0.2.5", dev_dependency = IS_RELEASE) -archive_override( - module_name = "toolchains_llvm_bootstrapped", - integrity = "sha256-+nddimV34BYO8YExiKLYG2kMoA2Sv+5ZoMRPQLJxNfE=", - patch_strip = 1, - patches = [ - "//bazel/patches:llvm_darwin_sysroot.patch", - ], - strip_prefix = "toolchains_llvm_bootstrapped-121c8419394e76b5652c161369743c564799b2e3", - urls = ["https://github.com/cerisier/toolchains_llvm_bootstrapped/archive/121c8419394e76b5652c161369743c564799b2e3/master.tar.gz"], -) +bazel_dep(name = "llvm", version = "0.6.1", dev_dependency = IS_RELEASE) register_toolchains( - "@toolchains_llvm_bootstrapped//toolchain:all", - dev_dependency = IS_RELEASE, -) - -# Rust configuration -bazel_dep(name = "rules_rust", version = "0.68.1", dev_dependency = IS_RELEASE) - -rust = use_extension( - "@rules_rust//rust:extensions.bzl", - "rust", - dev_dependency = IS_RELEASE, -) -rust.toolchain( - edition = "2024", - extra_target_triples = [ - "aarch64-apple-darwin", - "x86_64-apple-darwin", - "aarch64-unknown-linux-musl", - "x86_64-unknown-linux-musl", - ], - versions = ["1.88.0"], -) -use_repo(rust, "rust_toolchains") - -register_toolchains( - "@rust_toolchains//:all", + "@llvm//toolchain:all", dev_dependency = IS_RELEASE, ) @@ -98,7 +63,6 @@ bazel_dep(name = "bazelrc-preset.bzl", version = "1.4.0", dev_dependency = IS_RE bazel_dep(name = "bazel_env.bzl", version = "0.5.0", dev_dependency = IS_RELEASE) bazel_dep(name = "bzip2", version = "1.0.8.bcr.3", dev_dependency = IS_RELEASE) bazel_dep(name = "gazelle", version = "0.45.0", dev_dependency = IS_RELEASE) -bazel_dep(name = "rules_rs", version = "0.0.26", dev_dependency = IS_RELEASE) bazel_dep(name = "xz", version = "5.4.5.bcr.7", dev_dependency = IS_RELEASE) bazel_dep(name = "zstd", version = "1.5.7", dev_dependency = IS_RELEASE) bazel_dep(name = "rules_multitool", version = "1.9.0", dev_dependency = IS_RELEASE) @@ -107,6 +71,24 @@ multitool = use_extension("@rules_multitool//multitool:extension.bzl", "multitoo multitool.hub(lockfile = "//tools:tools.lock.json") use_repo(multitool, "multitool") +# Rust configuration +bazel_dep(name = "rules_rs", version = "0.0.37", dev_dependency = IS_RELEASE) + +toolchains = use_extension("@rules_rs//rs/experimental/toolchains:module_extension.bzl", "toolchains", dev_dependency = IS_RELEASE) +toolchains.toolchain( + edition = "2024", + version = "1.93.1", +) +use_repo(toolchains, "default_rust_toolchains") + +register_toolchains( + "@default_rust_toolchains//:all", + dev_dependency = IS_RELEASE, +) + +rules_rust = use_extension("@rules_rs//rs/experimental:rules_rust.bzl", "rules_rust") +use_repo(rules_rust, "rules_rust") + crate = use_extension( "@rules_rs//rs:extensions.bzl", "crate", @@ -118,10 +100,13 @@ crate.from_cargo( cargo_toml = "//:Cargo.toml", platform_triples = [ "aarch64-apple-darwin", + "aarch64-unknown-linux-gnu", "aarch64-unknown-linux-musl", "x86_64-apple-darwin", + "x86_64-unknown-linux-gnu", "x86_64-unknown-linux-musl", ], + use_experimental_platforms = True, ) crate.annotation( crate = "backtrace", @@ -148,6 +133,32 @@ crate.annotation( repositories = ["crates"], deps = ["@@xz+//:lzma"], ) +crate.annotation( + additive_build_file_content = """ +load("@rules_cc//cc:defs.bzl", "cc_import") + +cc_import( + name = "windows_import_lib", + static_library = glob(["lib/*.a"])[0], +) +""", + crate = "windows_x86_64_gnullvm", + gen_build_script = "off", + deps = [":windows_import_lib"], +) +crate.annotation( + additive_build_file_content = """ +load("@rules_cc//cc:defs.bzl", "cc_import") + +cc_import( + name = "windows_import_lib", + static_library = glob(["lib/*.a"])[0], +) +""", + crate = "windows_aarch64_gnullvm", + gen_build_script = "off", + deps = [":windows_import_lib"], +) use_repo(crate, "crates") # TODO: Replace with bazel_features? diff --git a/bazel/patches/llvm_darwin_sysroot.patch b/bazel/patches/llvm_darwin_sysroot.patch deleted file mode 100644 index 45c6170b4..000000000 --- a/bazel/patches/llvm_darwin_sysroot.patch +++ /dev/null @@ -1,27 +0,0 @@ -diff --git a/MODULE.bazel b/MODULE.bazel -index b631904..31042c1 100644 ---- a/MODULE.bazel -+++ b/MODULE.bazel -@@ -103,18 +103,12 @@ use_repo(musl, "musl_libc") - mingw = use_extension("//runtimes/mingw/extension:mingw.bzl", "mingw") - use_repo(mingw, "mingw") - --http_pkg_archive = use_repo_rule("//:http_pkg_archive.bzl", "http_pkg_archive") -- --http_pkg_archive( -+http_archive( - name = "macosx15.4.sdk", -+ urls = ["https://github.com/hexops-graveyard/sdk-macos-11.3/archive/ccbaae84cc39469a6792108b24480a4806e09d59.tar.gz"], -+ integrity = "sha256-EYcKSj04K3g0mGEIEmSSG7iDRAp+Cz3UoAc3PYcySjg=", - build_file = "//third_party/macosx.sdk:BUILD.MacOSX15.4.sdk.tpl", -- sha256 = "ba3453d62b3d2babf67f3a4a44e8073d6555c85f114856f4390a1f53bd76e24a", -- strip_files = [ -- "Library/Developer/CommandLineTools/SDKs/MacOSX15.5.sdk/System/Library/Frameworks/Ruby.framework/Versions/Current/Headers/ruby", -- ], -- strip_prefix = "Library/Developer/CommandLineTools/SDKs/MacOSX15.5.sdk", -- # urls = ["https://swcdn.apple.com/content/downloads/10/32/082-12052-A_AHPGDY76PT/1a419zaf3vh8o9t3c0usblyr8eystpnsh5/CLTools_macOSNMOS_SDK.pkg"], -- urls = ["https://swcdn.apple.com/content/downloads/52/01/082-41241-A_0747ZN8FHV/dectd075r63pppkkzsb75qk61s0lfee22j/CLTools_macOSNMOS_SDK.pkg"], -+ strip_prefix = "sdk-macos-11.3-ccbaae84cc39469a6792108b24480a4806e09d59/root", - ) - - glibc = use_extension("//runtimes/glibc/extension:glibc.bzl", "glibc") diff --git a/bazel/platforms/BUILD.bazel b/bazel/platforms/BUILD.bazel index 67469d7ac..49bf209e5 100644 --- a/bazel/platforms/BUILD.bazel +++ b/bazel/platforms/BUILD.bazel @@ -1,43 +1,16 @@ -load("//bazel/platforms/config:defs.bzl", "linker_suffix", "platforms") - -[platform( - name = "{}_{}{}".format( - p.os, - p.cpu, - linker_suffix( - "_", - p.linker, - ), - ), +platform( + name = "linux_host", constraint_values = [ - "@platforms//os:{}".format(p.os), - "@platforms//cpu:{}".format(p.cpu), - "//bazel/platforms/linkers:{}".format(p.linker), + "@llvm//constraints/libc:gnu.2.28", ], - visibility = ["//visibility:public"], -) for p in platforms] - -alias( - name = "linux_amd64", - actual = ":linux_x86_64", - visibility = ["//visibility:public"], -) - -alias( - name = "linux_arm64", - actual = ":linux_aarch64", - visibility = ["//visibility:public"], + parents = ["@platforms//host"], ) platform( name = "rbe", - constraint_values = [ - "@platforms//cpu:x86_64", - "@platforms//os:linux", - "@bazel_tools//tools/cpp:clang", - ], exec_properties = { "container-image": "docker://ubuntu:22.04", "OSFamily": "Linux", }, + parents = ["@rules_rs//rs/experimental/platforms:x86_64-unknown-linux-gnu"], ) diff --git a/bazel/platforms/config/BUILD.bazel b/bazel/platforms/config/BUILD.bazel deleted file mode 100644 index cf5d11a72..000000000 --- a/bazel/platforms/config/BUILD.bazel +++ /dev/null @@ -1,31 +0,0 @@ -load(":defs.bzl", "platforms") - -config_setting( - name = "aarch64", - constraint_values = [ - "@platforms//cpu:aarch64", - ], - visibility = ["//visibility:public"], -) - -config_setting( - name = "x86_64", - constraint_values = [ - "@platforms//cpu:x86_64", - ], - visibility = ["//visibility:public"], -) - -[config_setting( - name = "{}_{}{}".format( - p.os, - p.cpu, - "_{}".format(p.linker) if p.linker != "unknown" else "", - ), - constraint_values = [ - "@platforms//os:{}".format(p.os), - "@platforms//cpu:{}".format(p.cpu), - "//bazel/platforms/linkers:{}".format(p.linker), - ], - visibility = ["//visibility:public"], -) for p in platforms] diff --git a/bazel/platforms/config/defs.bzl b/bazel/platforms/config/defs.bzl deleted file mode 100644 index 1e06c4bfc..000000000 --- a/bazel/platforms/config/defs.bzl +++ /dev/null @@ -1,19 +0,0 @@ -"""This module generated the platforms list for the build matrix.""" - -def linker_suffix(delimiter, linker): - if linker == "unknown": - return "" - return delimiter + linker - -cpus = ["aarch64", "x86_64"] -os_to_linker = { - "linux": ["unknown"], - "macos": ["unknown"], -} - -platforms = [ - struct(os = os, cpu = cpu, linker = linker) - for os in os_to_linker - for linker in os_to_linker[os] - for cpu in cpus -] diff --git a/bazel/platforms/linkers/BUILD.bazel b/bazel/platforms/linkers/BUILD.bazel deleted file mode 100644 index 545a0e2ef..000000000 --- a/bazel/platforms/linkers/BUILD.bazel +++ /dev/null @@ -1,19 +0,0 @@ -constraint_setting( - name = "linker", - default_constraint_value = ":unknown", - visibility = ["//visibility:public"], -) - -constraint_value( - name = "musl", - constraint_setting = ":linker", - visibility = ["//visibility:public"], -) - -# Default linker for anyone not setting the linker to `musl`. -# You shouldn't ever need to set this value manually. -constraint_value( - name = "unknown", - constraint_setting = ":linker", - visibility = ["//visibility:public"], -) diff --git a/bazel/platforms/toolchains/BUILD.bazel b/bazel/platforms/toolchains/BUILD.bazel deleted file mode 100644 index a89f9325c..000000000 --- a/bazel/platforms/toolchains/BUILD.bazel +++ /dev/null @@ -1,27 +0,0 @@ -load(":defs.bzl", "platforms") - -[toolchain( - name = "{}_{}_{}_{}_llvm".format( - p.exec_os, - p.exec_cpu, - p.tgt_os, - p.tgt_cpu, - ), - exec_compatible_with = [ - "@platforms//os:{}".format(p.exec_os), - "@platforms//cpu:{}".format(p.exec_cpu), - ], - target_compatible_with = [ - "@platforms//os:{}".format(p.tgt_os), - "@platforms//cpu:{}".format(p.tgt_cpu), - "//bazel/platforms/linkers:unknown", - ], - toolchain = "@llvm_toolchain_{}_{}//:cc-clang-{}-{}".format( - p.exec_os, - p.exec_cpu, - p.tgt_cpu, - p.tgt_os if p.tgt_os != "macos" else "darwin", - ), - toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", - visibility = ["//visibility:public"], -) for p in platforms] diff --git a/bazel/platforms/toolchains/defs.bzl b/bazel/platforms/toolchains/defs.bzl deleted file mode 100644 index 2135fd108..000000000 --- a/bazel/platforms/toolchains/defs.bzl +++ /dev/null @@ -1,19 +0,0 @@ -"""This module registers all the LLVM toolchains that we want to use.""" - -execution_oses = ["macos", "linux"] -execution_cpus = ["aarch64", "x86_64"] -target_oses = ["macos", "linux"] -target_cpus = ["aarch64", "x86_64"] - -platforms = [ - struct(exec_os = exec_os, exec_cpu = exec_cpu, tgt_os = tgt_os, tgt_cpu = tgt_cpu) - for exec_os in execution_oses - for exec_cpu in execution_cpus - for tgt_os in target_oses - for tgt_cpu in target_cpus -] - -# buildifier: disable=unnamed-macro -def register_llvm_toolchains(): - for p in platforms: - native.register_toolchains("//bazel/platforms/toolchains:{}_{}_{}_{}_llvm".format(p.exec_os, p.exec_cpu, p.tgt_os, p.tgt_cpu)) diff --git a/bazel/rust/multi_platform_rust_binaries.bzl b/bazel/rust/multi_platform_rust_binaries.bzl index a124fbe90..0ec53bf46 100644 --- a/bazel/rust/multi_platform_rust_binaries.bzl +++ b/bazel/rust/multi_platform_rust_binaries.bzl @@ -7,23 +7,19 @@ load("@rules_pkg//pkg:pkg.bzl", "pkg_tar", "pkg_zip") load("//bazel/release:hashes.bzl", "hashes") TARGET_TRIPLES = [ - ("x86_64_unknown_linux_musl", "linux_x86_64"), - ("aarch64_unknown_linux_musl", "linux_aarch64"), - ("x86_64_apple_darwin", "macos_x86_64"), - ("aarch64_apple_darwin", "macos_aarch64"), + "x86_64-unknown-linux-musl", + "aarch64-unknown-linux-musl", + "x86_64-apple-darwin", + "aarch64-apple-darwin", ] -# Map a Rust naming scheme to a custom name. -TARGET_NAMING_SCHEME = {} - -def multi_platform_rust_binaries(name, target, name_scheme = TARGET_NAMING_SCHEME, target_triples = TARGET_TRIPLES, prefix = "", pkg_type = "zip", **kwargs): +def multi_platform_rust_binaries(name, target, target_triples = TARGET_TRIPLES, prefix = "", pkg_type = "zip", **kwargs): """The multi_platform_rust_binaries macro creates a filegroup containing rust binaries that are ready for release. Args: name: The name of the filegroup containing all rust targets produced by this macro. target: rust_binary that releases will be created for. - name_scheme: Mapping overriding the "standard" naming for a triple to a custom string. - target_triples: Map of target tiples to the target platform to build for. + target_triples: Map of target triples to the target platform to build for. prefix: An optional prefix added to the output rust binary file name. pkg_type: The packaging type that the {name}.packaged target outputs, can be one of 'zip' or 'tar'. **kwargs: All other args, forwarded to the output filegroups. @@ -38,18 +34,16 @@ def multi_platform_rust_binaries(name, target, name_scheme = TARGET_NAMING_SCHEM bin = Label(target).name pkg_rule = pkg_zip if pkg_type == "zip" else pkg_tar - for (target_triple, target_platform) in target_triples: - target_naming = name_scheme.get(target_triple, target_triple) - - transition_build = "{}_{}_build".format(bin, target_naming) + for target_triple in target_triples: + transition_build = "{}_{}_build".format(bin, target_triple) platform_transition_filegroup( name = transition_build, srcs = [target], - target_platform = "//bazel/platforms:{}".format(target_platform), + target_platform = "@rules_rs//rs/experimental/platforms:" + target_triple, tags = ["release"], ) - copy_name = "{}{}_{}".format(prefix, bin, target_naming) + copy_name = "{}{}_{}".format(prefix, bin, target_triple) copy_file( name = "{}_copy".format(copy_name), src = transition_build, @@ -64,7 +58,7 @@ def multi_platform_rust_binaries(name, target, name_scheme = TARGET_NAMING_SCHEM tags = ["release"], ) - pkged_files = "{}{}_{}_pkged_files".format(prefix, bin, target_naming) + pkged_files = "{}{}_{}_pkged_files".format(prefix, bin, target_triple) pkg_files( name = pkged_files, srcs = [copy_name], @@ -74,7 +68,7 @@ def multi_platform_rust_binaries(name, target, name_scheme = TARGET_NAMING_SCHEM tags = ["release"], ) - pkged = "{}{}_{}_packed".format(prefix, bin, target_naming) + pkged = "{}{}_{}_packed".format(prefix, bin, target_triple) pkg_rule( name = pkged, srcs = [ @@ -96,7 +90,7 @@ def multi_platform_rust_binaries(name, target, name_scheme = TARGET_NAMING_SCHEM bin_outs = [copy_name, bin_sha256] pkged_outs = [pkged, pkged_sha256] - if target_platform.startswith("linux"): + if "linux" in target_triple: linux_bins.extend(bin_outs) linux_pkged.extend(pkged_outs) else: diff --git a/e2e/.bazelrc b/e2e/.bazelrc index bc72d0e85..48e450d81 100644 --- a/e2e/.bazelrc +++ b/e2e/.bazelrc @@ -1,7 +1,11 @@ common --incompatible_enable_cc_toolchain_resolution -common --@toolchains_llvm_bootstrapped//config:experimental_stub_libgcc_s +common --@llvm//config:experimental_stub_libgcc_s common --@rules_cc//cc/toolchains/args/archiver_flags:use_libtool_on_macos=false +common --enable_platform_specific_config +common:linux --host_platform=@aspect_rules_py//bazel/platforms:linux_host +common --toolchain_resolution_debug='.*rust.*' + # Don't try and auto detect the cc toolchain, as we use our own llvm toolchains. common --repo_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1 common --repo_env=BAZEL_NO_APPLE_CPP_TOOLCHAIN=1 diff --git a/e2e/MODULE.bazel b/e2e/MODULE.bazel index 436b23876..708031061 100644 --- a/e2e/MODULE.bazel +++ b/e2e/MODULE.bazel @@ -8,9 +8,12 @@ bazel_dep(name = "rules_cc", version = "0.2.11") bazel_dep(name = "tar.bzl", version = "0.5.5") bazel_dep(name = "rules_python", version = "1.0.0") bazel_dep(name = "platforms", version = "1.0.0") -bazel_dep(name = "toolchains_llvm_bootstrapped", version = "0.3.1") +bazel_dep(name = "llvm", version = "0.6.1") bazel_dep(name = "rules_oci", version = "2.2.6") -bazel_dep(name = "rules_rust", version = "0.68.1") +bazel_dep(name = "rules_rs", version = "0.0.37") + +rules_rust = use_extension("@rules_rs//rs/experimental:rules_rust.bzl", "rules_rust") +use_repo(rules_rust, "rules_rust") oci = use_extension("@rules_oci//oci:extensions.bzl", "oci") oci.pull(