Skip to content

Commit ba3a448

Browse files
Allow to compile rustc with GCC as backend
1 parent 5529041 commit ba3a448

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

src/bootstrap/src/core/build_steps/test.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1769,7 +1769,9 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
17691769
cmd.arg("--host").arg(&*compiler.host.triple);
17701770
cmd.arg("--llvm-filecheck").arg(builder.llvm_filecheck(builder.config.host_target));
17711771

1772-
if let Some(codegen_backend) = builder.config.default_codegen_backend(compiler.host) {
1772+
if let Some(codegen_backend) = builder.config.codegen_backends(compiler.host).first() {
1773+
cmd.arg("--codegen-backend").arg(codegen_backend);
1774+
} else if let Some(codegen_backend) = builder.config.default_codegen_backend(compiler.host) {
17731775
cmd.arg("--codegen-backend").arg(&codegen_backend);
17741776
}
17751777

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,12 @@ impl Builder<'_> {
563563
println!("using sysroot {sysroot_str}");
564564
}
565565

566+
if self.config.codegen_backends(target).first().map(|b| b.as_str()) == Some("gcc") {
567+
let gcc_sysroot = self.config.libgccjit_root();
568+
let gcc_sysroot = gcc_sysroot.as_os_str().to_str().expect("sysroot should be UTF-8");
569+
cargo.env("LD_LIBRARY_PATH", gcc_sysroot);
570+
}
571+
566572
let mut rustflags = Rustflags::new(target);
567573
if build_compiler_stage != 0 {
568574
if let Ok(s) = env::var("CARGOFLAGS_NOT_BOOTSTRAP") {

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,6 +1226,13 @@ impl Config {
12261226
self.out.join(self.host_target).join("ci-rustc")
12271227
}
12281228

1229+
pub(crate) fn libgccjit_root(&self) -> PathBuf {
1230+
match self.gcc_ci_mode {
1231+
GccCiMode::BuildLocally => self.out.join(self.host_target).join("gcc/install/lib"),
1232+
GccCiMode::DownloadFromCi => self.out.join(self.host_target).join("ci-gcc/lib"),
1233+
}
1234+
}
1235+
12291236
/// Determine whether llvm should be linked dynamically.
12301237
///
12311238
/// If `false`, llvm should be linked statically.

src/tools/compiletest/src/runtest.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,6 +1556,11 @@ impl<'test> TestCx<'test> {
15561556
// In stage 0, make sure we use `stage0-sysroot` instead of the bootstrap sysroot.
15571557
rustc.arg("--sysroot").arg(&self.config.sysroot_base);
15581558
}
1559+
// If the provided codegen backend is not LLVM, we need to pass it.
1560+
if !matches!(self.config.codegen_backend, crate::CodegenBackend::Llvm) {
1561+
let lib_path = self.config.sysroot_base.join(self.config.codegen_backend.as_str());
1562+
rustc.arg(format!("-Zcodegen-backend={}", lib_path));
1563+
}
15591564

15601565
// Optionally prevent default --target if specified in test compile-flags.
15611566
let custom_target = self.props.compile_flags.iter().any(|x| x.starts_with("--target"));

0 commit comments

Comments
 (0)