Skip to content

Commit 129a7c9

Browse files
authored
Statically link crate_universe for MSVC (bazelbuild#4031)
closes bazelbuild#3833
1 parent 51c5e0f commit 129a7c9

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

.bazelci/presubmit.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,14 @@ tasks:
576576
- "//..."
577577
test_targets:
578578
- "//..."
579+
cu_integ_cargo_workspace_windows:
580+
name: Crate Universe - cargo_workspace
581+
platform: windows
582+
working_directory: crate_universe/tests/integration/cargo_workspace
583+
build_targets:
584+
- "//..."
585+
test_targets:
586+
- "//..."
579587

580588
# --- cargo_conditional_deps ---
581589
cu_integ_cargo_conditional_deps_ubuntu2204:

crate_universe/BUILD.bazel

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ filegroup(
5757
visibility = ["//crate_universe:__subpackages__"],
5858
)
5959

60+
MSVC_RUSTC_FLAGS = [
61+
"-Ctarget-feature=+crt-static",
62+
]
63+
6064
rust_library(
6165
name = "cargo_bazel",
6266
srcs = glob(
@@ -67,6 +71,12 @@ rust_library(
6771
compile_data = [":rust_data"],
6872
edition = "2021",
6973
proc_macro_deps = all_crate_deps(proc_macro = True),
74+
rustc_flags = select({
75+
"//rust/platform:aarch64-pc-windows-msvc": MSVC_RUSTC_FLAGS,
76+
"//rust/platform:i686-pc-windows-msvc": MSVC_RUSTC_FLAGS,
77+
"//rust/platform:x86_64-pc-windows-msvc": MSVC_RUSTC_FLAGS,
78+
"//conditions:default": [],
79+
}),
7080
# This target embeds additional, stamping related information (see
7181
# https://docs.bazel.build/versions/main/user-manual.html#workspace_status
7282
# for more information). Set stamp = -1 to indicate that it should respect

crate_universe/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ repository = "https://github.com/bazelbuild/rules_rust"
6060
cargo = []
6161
default = ["cargo"]
6262

63+
[target.'cfg(all(target_os = "windows", target_env = "msvc"))']
64+
rustflags=["-Ctarget-feature=+crt-static"]
65+
6366
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
6467

6568
[dependencies]

0 commit comments

Comments
 (0)