Skip to content

Commit ce248d5

Browse files
committed
Add a dist step for the GCC codegen backend
1 parent efc1983 commit ce248d5

File tree

5 files changed

+123
-17
lines changed

5 files changed

+123
-17
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,6 +1640,12 @@ pub struct GccCodegenBackendOutput {
16401640
stamp: BuildStamp,
16411641
}
16421642

1643+
impl GccCodegenBackendOutput {
1644+
pub fn stamp(&self) -> &BuildStamp {
1645+
&self.stamp
1646+
}
1647+
}
1648+
16431649
/// Builds the GCC codegen backend (`cg_gcc`).
16441650
/// Note that this **does not** build libgccjit, which is a dependency of cg_gcc.
16451651
/// That has to be built separately, because a separate copy of libgccjit is required

src/bootstrap/src/core/build_steps/dist.rs

Lines changed: 108 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,23 +1652,7 @@ impl Step for CraneliftCodegenBackend {
16521652
return None;
16531653
}
16541654

1655-
// Get the relative path of where the codegen backend should be stored.
1656-
let backends_dst = builder.sysroot_codegen_backends(compilers.target_compiler());
1657-
let backends_rel = backends_dst
1658-
.strip_prefix(builder.sysroot(compilers.target_compiler()))
1659-
.unwrap()
1660-
.strip_prefix(builder.sysroot_libdir_relative(compilers.target_compiler()))
1661-
.unwrap();
1662-
// Don't use custom libdir here because ^lib/ will be resolved again with installer
1663-
let backends_dst = PathBuf::from("lib").join(backends_rel);
1664-
1665-
let codegen_backend_dylib = get_codegen_backend_file(&stamp);
1666-
tarball.add_renamed_file(
1667-
&codegen_backend_dylib,
1668-
&backends_dst,
1669-
&normalize_codegen_backend_name(builder, &codegen_backend_dylib),
1670-
FileType::NativeLibrary,
1671-
);
1655+
add_codegen_backend_to_tarball(builder, &tarball, compilers.target_compiler(), &stamp);
16721656

16731657
Some(tarball.generate())
16741658
}
@@ -1681,6 +1665,113 @@ impl Step for CraneliftCodegenBackend {
16811665
}
16821666
}
16831667

1668+
/// Builds a dist component containing the GCC codegen backend.
1669+
/// Note that for this backend to work, it must have a set of libgccjit dylibs available
1670+
/// at runtime.
1671+
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
1672+
pub struct GccCodegenBackend {
1673+
pub compilers: RustcPrivateCompilers,
1674+
pub target: TargetSelection,
1675+
}
1676+
1677+
impl Step for GccCodegenBackend {
1678+
type Output = Option<GeneratedTarball>;
1679+
const IS_HOST: bool = true;
1680+
1681+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1682+
run.alias("rustc_codegen_gcc")
1683+
}
1684+
1685+
fn is_default_step(builder: &Builder<'_>) -> bool {
1686+
// We only want to build the gcc backend in `x dist` if the backend was enabled
1687+
// in rust.codegen-backends.
1688+
// Sadly, we don't have access to the actual target for which we're disting clif here..
1689+
// So we just use the host target.
1690+
builder
1691+
.config
1692+
.enabled_codegen_backends(builder.host_target)
1693+
.contains(&CodegenBackendKind::Gcc)
1694+
}
1695+
1696+
fn make_run(run: RunConfig<'_>) {
1697+
run.builder.ensure(GccCodegenBackend {
1698+
compilers: RustcPrivateCompilers::new(run.builder, run.builder.top_stage, run.target),
1699+
target: run.target,
1700+
});
1701+
}
1702+
1703+
fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
1704+
// This prevents rustc_codegen_gcc from being built for "dist"
1705+
// or "install" on the stable/beta channels. It is not yet stable and
1706+
// should not be included.
1707+
if !builder.build.unstable_features() {
1708+
return None;
1709+
}
1710+
1711+
let target = self.target;
1712+
if target != "x86_64-unknown-linux-gnu" {
1713+
builder
1714+
.info(&format!("target `{target}` not supported by rustc_codegen_gcc. skipping"));
1715+
return None;
1716+
}
1717+
1718+
let mut tarball = Tarball::new(builder, "rustc-codegen-gcc", &target.triple);
1719+
tarball.set_overlay(OverlayKind::RustcCodegenGcc);
1720+
tarball.is_preview(true);
1721+
tarball.add_legal_and_readme_to("share/doc/rustc_codegen_gcc");
1722+
1723+
let compilers = self.compilers;
1724+
let backend = builder.ensure(compile::GccCodegenBackend::for_target(compilers, target));
1725+
1726+
if builder.config.dry_run() {
1727+
return None;
1728+
}
1729+
1730+
add_codegen_backend_to_tarball(
1731+
builder,
1732+
&tarball,
1733+
compilers.target_compiler(),
1734+
backend.stamp(),
1735+
);
1736+
1737+
Some(tarball.generate())
1738+
}
1739+
1740+
fn metadata(&self) -> Option<StepMetadata> {
1741+
Some(
1742+
StepMetadata::dist("rustc_codegen_gcc", self.target)
1743+
.built_by(self.compilers.build_compiler()),
1744+
)
1745+
}
1746+
}
1747+
1748+
/// Add a codegen backend built for `compiler`, with its artifacts stored in `stamp`, to the given
1749+
/// `tarball` at the correct place.
1750+
fn add_codegen_backend_to_tarball(
1751+
builder: &Builder<'_>,
1752+
tarball: &Tarball<'_>,
1753+
compiler: Compiler,
1754+
stamp: &BuildStamp,
1755+
) {
1756+
// Get the relative path of where the codegen backend should be stored.
1757+
let backends_dst = builder.sysroot_codegen_backends(compiler);
1758+
let backends_rel = backends_dst
1759+
.strip_prefix(builder.sysroot(compiler))
1760+
.unwrap()
1761+
.strip_prefix(builder.sysroot_libdir_relative(compiler))
1762+
.unwrap();
1763+
// Don't use custom libdir here because ^lib/ will be resolved again with installer
1764+
let backends_dst = PathBuf::from("lib").join(backends_rel);
1765+
1766+
let codegen_backend_dylib = get_codegen_backend_file(stamp);
1767+
tarball.add_renamed_file(
1768+
&codegen_backend_dylib,
1769+
&backends_dst,
1770+
&normalize_codegen_backend_name(builder, &codegen_backend_dylib),
1771+
FileType::NativeLibrary,
1772+
);
1773+
}
1774+
16841775
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
16851776
pub struct Rustfmt {
16861777
pub compilers: RustcPrivateCompilers,

src/bootstrap/src/core/builder/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,7 @@ impl<'a> Builder<'a> {
967967
dist::Mingw,
968968
dist::Rustc,
969969
dist::CraneliftCodegenBackend,
970+
dist::GccCodegenBackend,
970971
dist::Std,
971972
dist::RustcDev,
972973
dist::Analysis,

src/bootstrap/src/utils/tarball.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub(crate) enum OverlayKind {
2525
Rustfmt,
2626
RustAnalyzer,
2727
RustcCodegenCranelift,
28+
RustcCodegenGcc,
2829
LlvmBitcodeLinker,
2930
}
3031

@@ -66,6 +67,11 @@ impl OverlayKind {
6667
"compiler/rustc_codegen_cranelift/LICENSE-APACHE",
6768
"compiler/rustc_codegen_cranelift/LICENSE-MIT",
6869
],
70+
OverlayKind::RustcCodegenGcc => &[
71+
"compiler/rustc_codegen_gcc/Readme.md",
72+
"compiler/rustc_codegen_gcc/LICENSE-APACHE",
73+
"compiler/rustc_codegen_gcc/LICENSE-MIT",
74+
],
6975
OverlayKind::LlvmBitcodeLinker => &[
7076
"COPYRIGHT",
7177
"LICENSE-APACHE",
@@ -93,6 +99,7 @@ impl OverlayKind {
9399
.rust_analyzer_info
94100
.version(builder, &builder.release_num("rust-analyzer/crates/rust-analyzer")),
95101
OverlayKind::RustcCodegenCranelift => builder.rust_version(),
102+
OverlayKind::RustcCodegenGcc => builder.rust_version(),
96103
OverlayKind::LlvmBitcodeLinker => builder.rust_version(),
97104
}
98105
}

src/tools/opt-dist/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ fn main() -> anyhow::Result<()> {
457457
"gcc",
458458
"generate-copyright",
459459
"bootstrap",
460+
"rustc_codegen_gcc",
460461
] {
461462
build_args.extend(["--skip".to_string(), target.to_string()]);
462463
}

0 commit comments

Comments
 (0)