Skip to content

Commit eefa83e

Browse files
Allow to bootstrap compiler with the GCC backend
1 parent a6620a4 commit eefa83e

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

src/bootstrap/src/core/build_steps/compile.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use tracing::{instrument, span};
2020

2121
use crate::core::build_steps::gcc::{Gcc, add_cg_gcc_cargo_flags};
2222
use crate::core::build_steps::tool::{RustcPrivateCompilers, SourceType, copy_lld_artifacts};
23-
use crate::core::build_steps::{dist, llvm};
23+
use crate::core::build_steps::{dist, gcc, llvm};
2424
use crate::core::builder;
2525
use crate::core::builder::{
2626
Builder, Cargo, Kind, RunConfig, ShouldRun, Step, StepMetadata, crate_description,
@@ -2348,6 +2348,19 @@ impl Step for Assemble {
23482348
dist::maybe_install_llvm_runtime(builder, target_compiler.host, &sysroot);
23492349
dist::maybe_install_llvm_target(builder, target_compiler.host, &sysroot);
23502350

2351+
if builder.config.gcc_enabled(target_compiler.host) {
2352+
let gcc::GccOutput { mut libgccjit } =
2353+
builder.ensure(gcc::Gcc { target: target_compiler.host });
2354+
let dst_libdir = sysroot.join("lib");
2355+
builder.install(&libgccjit, &dst_libdir, FileType::NativeLibrary);
2356+
if let Some(file_name) = libgccjit.file_name() {
2357+
let mut file_name = file_name.to_os_string();
2358+
file_name.push(".0");
2359+
libgccjit.set_file_name(file_name);
2360+
builder.install(&libgccjit, &dst_libdir, FileType::NativeLibrary);
2361+
}
2362+
}
2363+
23512364
// Link the compiler binary itself into place
23522365
let out_dir = builder.cargo_out(build_compiler, Mode::Rustc, host);
23532366
let rustc = out_dir.join(exe("rustc-main", host));

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,16 @@ impl Builder<'_> {
583583
rustflags.arg("--cfg=bootstrap");
584584
}
585585

586+
if self
587+
.config
588+
.default_codegen_backend(compiler.host)
589+
.is_some_and(|backend| backend.is_gcc())
590+
{
591+
let sysroot = sysroot.join("lib");
592+
let sysroot_str = sysroot.as_os_str().to_str().expect("sysroot should be UTF-8");
593+
cargo.env("LD_LIBRARY_PATH", sysroot_str);
594+
}
595+
586596
if cmd_kind == Kind::Clippy {
587597
// clippy overwrites sysroot if we pass it to cargo.
588598
// Pass it directly to clippy instead.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,6 +1774,10 @@ impl Config {
17741774
self.enabled_codegen_backends(target).contains(&CodegenBackendKind::Llvm)
17751775
}
17761776

1777+
pub fn gcc_enabled(&self, target: TargetSelection) -> bool {
1778+
self.enabled_codegen_backends(target).contains(&CodegenBackendKind::Gcc)
1779+
}
1780+
17771781
pub fn llvm_libunwind(&self, target: TargetSelection) -> LlvmLibunwind {
17781782
self.target_config
17791783
.get(&target)

0 commit comments

Comments
 (0)