From b38b0ea2197f69fb319fa382d826174fcbc1c9b1 Mon Sep 17 00:00:00 2001 From: UebelAndre Date: Wed, 13 May 2026 08:56:24 -0700 Subject: [PATCH] Statically link crate_universe for MSVC --- .bazelci/presubmit.yml | 8 ++++++++ crate_universe/BUILD.bazel | 10 ++++++++++ crate_universe/Cargo.toml | 3 +++ 3 files changed, 21 insertions(+) diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index 9f369c5917..05128c3dfd 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -575,6 +575,14 @@ tasks: - "//..." test_targets: - "//..." + cu_integ_cargo_workspace_windows: + name: Crate Universe - cargo_workspace + platform: windows + working_directory: crate_universe/tests/integration/cargo_workspace + build_targets: + - "//..." + test_targets: + - "//..." # --- cargo_conditional_deps --- cu_integ_cargo_conditional_deps_ubuntu2204: diff --git a/crate_universe/BUILD.bazel b/crate_universe/BUILD.bazel index 5a4234a806..184aa0566f 100644 --- a/crate_universe/BUILD.bazel +++ b/crate_universe/BUILD.bazel @@ -57,6 +57,10 @@ filegroup( visibility = ["//crate_universe:__subpackages__"], ) +MSVC_RUSTC_FLAGS = [ + "-Ctarget-feature=+crt-static", +] + rust_library( name = "cargo_bazel", srcs = glob( @@ -67,6 +71,12 @@ rust_library( compile_data = [":rust_data"], edition = "2021", proc_macro_deps = all_crate_deps(proc_macro = True), + rustc_flags = select({ + "//rust/platform:aarch64-pc-windows-msvc": MSVC_RUSTC_FLAGS, + "//rust/platform:i686-pc-windows-msvc": MSVC_RUSTC_FLAGS, + "//rust/platform:x86_64-pc-windows-msvc": MSVC_RUSTC_FLAGS, + "//conditions:default": [], + }), # This target embeds additional, stamping related information (see # https://docs.bazel.build/versions/main/user-manual.html#workspace_status # for more information). Set stamp = -1 to indicate that it should respect diff --git a/crate_universe/Cargo.toml b/crate_universe/Cargo.toml index 11a83830b6..fcb830e74d 100644 --- a/crate_universe/Cargo.toml +++ b/crate_universe/Cargo.toml @@ -60,6 +60,9 @@ repository = "https://github.com/bazelbuild/rules_rust" cargo = [] default = ["cargo"] +[target.'cfg(all(target_os = "windows", target_env = "msvc"))'] +rustflags=["-Ctarget-feature=+crt-static"] + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies]