diff --git a/MODULE.bazel b/MODULE.bazel index 471dc6e706..cd771adb12 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -112,6 +112,7 @@ rules_rust = use_extension("@rules_rs//rs/experimental:rules_rust.bzl", "rules_r # `libssp_nonshared`, so strip the forwarded stack-protector flags there. rules_rust.patch( patches = [ + "//patches:rules_rust_repository_set_replacement.patch", "//patches:rules_rust_windows_gnullvm_build_script.patch", "//patches:rules_rust_windows_exec_msvc_build_script_env.patch", "//patches:rules_rust_windows_bootstrap_process_wrapper_linker.patch", @@ -140,7 +141,7 @@ nightly_rust.toolchain( # ABI so proc macros, build scripts, and the lint driver share one hermetic # LLVM/MinGW toolchain. nightly_rust.repository_set( - name = "rust_windows_x86_64_gnullvm", + name = "rust_windows_x86_64", dev_components = True, edition = "2024", exec_compatible_with = [ diff --git a/patches/BUILD.bazel b/patches/BUILD.bazel index ed14137170..82609770b5 100644 --- a/patches/BUILD.bazel +++ b/patches/BUILD.bazel @@ -15,6 +15,7 @@ exports_files([ "rules_rust_windows_msvc_direct_link_args.patch", "rules_rust_windows_gnullvm_build_script.patch", "rules_cc_rusty_v8_custom_libcxx.patch", + "rules_rust_repository_set_replacement.patch", "rules_rs_build_script_deps_annotation.patch", "rules_rs_windows_gnullvm_exec.patch", "rules_rs_windows_exec_linker.patch", diff --git a/patches/rules_rs_windows_exec_linker.patch b/patches/rules_rs_windows_exec_linker.patch index d4e56c37d8..3a93c01d46 100644 --- a/patches/rules_rs_windows_exec_linker.patch +++ b/patches/rules_rs_windows_exec_linker.patch @@ -21,10 +21,10 @@ diff --git a/rs/experimental/toolchains/declare_rustc_toolchains.bzl b/rs/experi "@platforms//os:ios": ["-lSystem", "-lobjc", "-Wl,-framework,Security", "-Wl,-framework,Foundation", "-lresolv"], - # TODO: windows + "@rules_rs//rs/experimental/platforms/constraints:windows_gnullvm": [ -+ "advapi32.lib", -+ "ws2_32.lib", -+ "userenv.lib", -+ "Bcrypt.lib", ++ "-ladvapi32", ++ "-lws2_32", ++ "-luserenv", ++ "-lbcrypt", + ], + "@rules_rs//rs/experimental/platforms/constraints:windows_msvc": [ + "advapi32.lib", diff --git a/patches/rules_rust_repository_set_replacement.patch b/patches/rules_rust_repository_set_replacement.patch new file mode 100644 index 0000000000..a4c96e274d --- /dev/null +++ b/patches/rules_rust_repository_set_replacement.patch @@ -0,0 +1,24 @@ +# What: replace a default repository set by its documented repository name. +# Why: changing the exec triple (for example, MSVC to gnullvm) also changes the +# lookup key, so matching by both the old triple and name leaves the default +# toolchain registered and lets it win toolchain resolution. + +diff --git a/rust/extensions.bzl b/rust/extensions.bzl +--- a/rust/extensions.bzl ++++ b/rust/extensions.bzl +@@ -100,8 +100,13 @@ def _rust_impl(module_ctx): + **repository_set + ) + extra_toolchain_infos.update(**toolchain_infos) +- if toolchain_triples.get(repository_set["exec_triple"]) == repository_set["name"]: +- toolchain_triples.pop(repository_set["exec_triple"], None) ++ replaced_exec_triples = [ ++ exec_triple ++ for exec_triple, name in toolchain_triples.items() ++ if name == repository_set["name"] ++ ] ++ for exec_triple in replaced_exec_triples: ++ toolchain_triples.pop(exec_triple) + + toolchains = root.tags.toolchain + if not toolchains and rules_rust: