Skip to content

Commit cb3f5fb

Browse files
authored
Rollup merge of rust-lang#146663 - erickt:win, r=wesleywiser
Allow windows resource compiler to be overridden In rust-lang#146018, it is now required to provide a resource compiler on windows when compiling rust. This allows toolchain builders to explicitly provide a path to an alternative, such as llvm-rc, instead of the one that's provided by the Windows SDK. cc `@lambdageek`
2 parents 231b09c + 11cc0bc commit cb3f5fb

File tree

6 files changed

+22
-2
lines changed

6 files changed

+22
-2
lines changed

bootstrap.example.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,9 @@
325325
# Defaults to the Python interpreter used to execute x.py.
326326
#build.python = "python"
327327

328+
# The path to (or name of) the resource compiler executable to use on Windows.
329+
#build.windows-rc = "rc.exe"
330+
328331
# The path to the REUSE executable to use. Note that REUSE is not required in
329332
# most cases, as our tooling relies on a cached (and shrunk) copy of the
330333
# REUSE output present in the git repository and in our source tarballs.

compiler/rustc_windows_rc/src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,11 @@ pub fn compile_windows_resource_file(
3535
resources_dir.push("resources");
3636
fs::create_dir_all(&resources_dir).unwrap();
3737

38-
let resource_compiler =
39-
find_resource_compiler(&env::var("CARGO_CFG_TARGET_ARCH").unwrap()).expect("found rc.exe");
38+
let resource_compiler = if let Ok(path) = env::var("RUSTC_WINDOWS_RC") {
39+
path.into()
40+
} else {
41+
find_resource_compiler(&env::var("CARGO_CFG_TARGET_ARCH").unwrap()).expect("found rc.exe")
42+
};
4043

4144
let rc_path = resources_dir.join(file_stem.with_extension("rc"));
4245

src/bootstrap/src/core/builder/cargo.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,11 @@ impl Builder<'_> {
12211221
rustflags.arg("-Zehcont-guard");
12221222
}
12231223

1224+
// Optionally override the rc.exe when compiling rustc on Windows.
1225+
if let Some(windows_rc) = &self.config.windows_rc {
1226+
cargo.env("RUSTC_WINDOWS_RC", windows_rc);
1227+
}
1228+
12241229
// For `cargo doc` invocations, make rustdoc print the Rust version into the docs
12251230
// This replaces spaces with tabs because RUSTDOCFLAGS does not
12261231
// support arguments with regular spaces. Hopefully someday Cargo will

src/bootstrap/src/core/config/config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ pub struct Config {
272272
pub gdb: Option<PathBuf>,
273273
pub lldb: Option<PathBuf>,
274274
pub python: Option<PathBuf>,
275+
pub windows_rc: Option<PathBuf>,
275276
pub reuse: Option<PathBuf>,
276277
pub cargo_native_static: bool,
277278
pub configure_args: Vec<String>,
@@ -449,6 +450,7 @@ impl Config {
449450
nodejs: build_nodejs,
450451
npm: build_npm,
451452
python: build_python,
453+
windows_rc: build_windows_rc,
452454
reuse: build_reuse,
453455
locked_deps: build_locked_deps,
454456
vendor: build_vendor,
@@ -1339,6 +1341,7 @@ impl Config {
13391341
.unwrap_or(rust_debug == Some(true)),
13401342
vendor,
13411343
verbose_tests,
1344+
windows_rc: build_windows_rc.map(PathBuf::from),
13421345
// tidy-alphabetical-end
13431346
}
13441347
}

src/bootstrap/src/core/config/toml/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ define_config! {
3737
nodejs: Option<String> = "nodejs",
3838
npm: Option<String> = "npm",
3939
python: Option<String> = "python",
40+
windows_rc: Option<String> = "windows-rc",
4041
reuse: Option<String> = "reuse",
4142
locked_deps: Option<bool> = "locked-deps",
4243
vendor: Option<bool> = "vendor",

src/bootstrap/src/utils/change_tracker.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,4 +546,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
546546
severity: ChangeSeverity::Info,
547547
summary: "The default value of the `gcc.download-ci-gcc` option has been changed to `true`.",
548548
},
549+
ChangeInfo {
550+
change_id: 146663,
551+
severity: ChangeSeverity::Info,
552+
summary: "New option `build.windows-rc` that will override which resource compiler on Windows will be used to compile Rust.",
553+
},
549554
];

0 commit comments

Comments
 (0)