Skip to content

Commit 7f55f57

Browse files
committed
Allow windows resource compiler to be overridden
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.
1 parent 32e3d9f commit 7f55f57

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
@@ -1227,6 +1227,11 @@ impl Builder<'_> {
12271227
rustflags.arg("-Zehcont-guard");
12281228
}
12291229

1230+
// Optionally override the rc.exe when compiling rustc on Windows.
1231+
if let Some(windows_rc) = &self.config.windows_rc {
1232+
cargo.env("RUSTC_WINDOWS_RC", windows_rc);
1233+
}
1234+
12301235
// For `cargo doc` invocations, make rustdoc print the Rust version into the docs
12311236
// This replaces spaces with tabs because RUSTDOCFLAGS does not
12321237
// 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
@@ -273,6 +273,7 @@ pub struct Config {
273273
pub gdb: Option<PathBuf>,
274274
pub lldb: Option<PathBuf>,
275275
pub python: Option<PathBuf>,
276+
pub windows_rc: Option<PathBuf>,
276277
pub reuse: Option<PathBuf>,
277278
pub cargo_native_static: bool,
278279
pub configure_args: Vec<String>,
@@ -450,6 +451,7 @@ impl Config {
450451
nodejs: build_nodejs,
451452
npm: build_npm,
452453
python: build_python,
454+
windows_rc: build_windows_rc,
453455
reuse: build_reuse,
454456
locked_deps: build_locked_deps,
455457
vendor: build_vendor,
@@ -1342,6 +1344,7 @@ impl Config {
13421344
.unwrap_or(rust_debug == Some(true)),
13431345
vendor,
13441346
verbose_tests,
1347+
windows_rc: build_windows_rc.map(PathBuf::from),
13451348
// tidy-alphabetical-end
13461349
}
13471350
}

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
@@ -551,4 +551,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[
551551
severity: ChangeSeverity::Info,
552552
summary: "There is now a bootstrap option called `rust.parallel-frontend-threads`, which can be used to set the number of threads for the compiler frontend used during compilation of Rust code.",
553553
},
554+
ChangeInfo {
555+
change_id: 146663,
556+
severity: ChangeSeverity::Info,
557+
summary: "New option `build.windows-rc` that will override which resource compiler on Windows will be used to compile Rust.",
558+
},
554559
];

0 commit comments

Comments
 (0)