Skip to content

Commit a46c755

Browse files
committed
Auto merge of rust-lang#136921 - Kobzol:gcc-build, r=onur-ozkan
Build GCC on CI Previously, we have downloaded a specific commit of GCC and prebuilt it inside Docker using the `build-gccjit.sh` script. This PR removes that scripts and uses the bootstrap GCC step. This allows us to use the `src/gcc` submodule for determining which GCC should be built, and it also moves the logic closer to LLVM, which is also built by bootstrap. A few things to note: - The `sccache` option is currently in the `llvm` block, so the GCC build uses `llvm.ccache`, which is a bit weird :) We could either add `gcc.ccache`, or (what I think would be better) to just move `ccache` to the `build` section, as I don't think that it will be necessary to use ccache for LLVM, but not for GCC. - When the GCC codegen backend is built, it needs to depend on a step that first builds GCC. This is currently done in a hacky way. The proper solution is to create a separate step for the GCC codegen backend, but that is a larger change. Let me know what you think. r? `@onur-ozkan` try-job: i686-msvc-1 try-job: x86_64-mingw-1
2 parents cb06d12 + ba7d5d1 commit a46c755

File tree

9 files changed

+56
-63
lines changed

9 files changed

+56
-63
lines changed

license-metadata.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"directories": [],
1414
"files": [
1515
"analyzer-decls.h",
16-
"malloc-macro.h"
16+
"malloc-macro.h",
17+
"sarif-path-role.h"
1718
],
1819
"license": {
1920
"copyright": [

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

+9
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use serde_derive::Deserialize;
1919
#[cfg(feature = "tracing")]
2020
use tracing::{instrument, span};
2121

22+
use crate::core::build_steps::gcc::{Gcc, add_cg_gcc_cargo_flags};
2223
use crate::core::build_steps::tool::SourceType;
2324
use crate::core::build_steps::{dist, llvm};
2425
use crate::core::builder;
@@ -1614,6 +1615,14 @@ impl Step for CodegenBackend {
16141615
.arg(builder.src.join(format!("compiler/rustc_codegen_{backend}/Cargo.toml")));
16151616
rustc_cargo_env(builder, &mut cargo, target, compiler.stage);
16161617

1618+
// Ideally, we'd have a separate step for the individual codegen backends,
1619+
// like we have in tests (test::CodegenGCC) but that would require a lot of restructuring.
1620+
// If the logic gets more complicated, it should probably be done.
1621+
if backend == "gcc" {
1622+
let gcc = builder.ensure(Gcc { target });
1623+
add_cg_gcc_cargo_flags(&mut cargo, &gcc);
1624+
}
1625+
16171626
let tmp_stamp = BuildStamp::new(&out_dir).with_prefix("tmp");
16181627

16191628
let _guard = builder.msg_build(compiler, format_args!("codegen backend {backend}"), target);

src/bootstrap/src/core/build_steps/gcc.rs

+37-14
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
//! ensure that they're always in place if needed.
1010
1111
use std::fs;
12-
use std::path::PathBuf;
12+
use std::path::{Path, PathBuf};
1313
use std::sync::OnceLock;
1414

1515
use build_helper::ci::CiEnv;
1616

1717
use crate::Kind;
18-
use crate::core::builder::{Builder, RunConfig, ShouldRun, Step};
18+
use crate::core::builder::{Builder, Cargo, RunConfig, ShouldRun, Step};
1919
use crate::core::config::TargetSelection;
2020
use crate::utils::build_stamp::{BuildStamp, generate_smart_stamp_hash};
2121
use crate::utils::exec::command;
@@ -29,7 +29,8 @@ pub struct Meta {
2929
}
3030

3131
pub enum GccBuildStatus {
32-
AlreadyBuilt,
32+
/// libgccjit is already built at this path
33+
AlreadyBuilt(PathBuf),
3334
ShouldBuild(Meta),
3435
}
3536

@@ -41,9 +42,6 @@ pub fn prebuilt_gcc_config(builder: &Builder<'_>, target: TargetSelection) -> Gc
4142
// Initialize the gcc submodule if not initialized already.
4243
builder.config.update_submodule("src/gcc");
4344

44-
// FIXME (GuillaumeGomez): To be done once gccjit has been built in the CI.
45-
// builder.config.maybe_download_ci_gcc();
46-
4745
let root = builder.src.join("src/gcc");
4846
let out_dir = builder.gcc_out(target).join("build");
4947
let install_dir = builder.gcc_out(target).join("install");
@@ -70,19 +68,37 @@ pub fn prebuilt_gcc_config(builder: &Builder<'_>, target: TargetSelection) -> Gc
7068
stamp.path().display()
7169
));
7270
}
73-
return GccBuildStatus::AlreadyBuilt;
71+
let path = libgccjit_built_path(&install_dir);
72+
if path.is_file() {
73+
return GccBuildStatus::AlreadyBuilt(path);
74+
} else {
75+
builder.info(&format!(
76+
"GCC stamp is up-to-date, but the libgccjit.so file was not found at `{}`",
77+
path.display(),
78+
));
79+
}
7480
}
7581

7682
GccBuildStatus::ShouldBuild(Meta { stamp, out_dir, install_dir, root })
7783
}
7884

85+
/// Returns the path to a libgccjit.so file in the install directory of GCC.
86+
fn libgccjit_built_path(install_dir: &Path) -> PathBuf {
87+
install_dir.join("lib/libgccjit.so")
88+
}
89+
7990
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
8091
pub struct Gcc {
8192
pub target: TargetSelection,
8293
}
8394

95+
#[derive(Clone)]
96+
pub struct GccOutput {
97+
pub libgccjit: PathBuf,
98+
}
99+
84100
impl Step for Gcc {
85-
type Output = bool;
101+
type Output = GccOutput;
86102

87103
const ONLY_HOSTS: bool = true;
88104

@@ -94,14 +110,14 @@ impl Step for Gcc {
94110
run.builder.ensure(Gcc { target: run.target });
95111
}
96112

97-
/// Compile GCC for `target`.
98-
fn run(self, builder: &Builder<'_>) -> bool {
113+
/// Compile GCC (specifically `libgccjit`) for `target`.
114+
fn run(self, builder: &Builder<'_>) -> Self::Output {
99115
let target = self.target;
100116

101117
// If GCC has already been built, we avoid building it again.
102118
let Meta { stamp, out_dir, install_dir, root } = match prebuilt_gcc_config(builder, target)
103119
{
104-
GccBuildStatus::AlreadyBuilt => return true,
120+
GccBuildStatus::AlreadyBuilt(path) => return GccOutput { libgccjit: path },
105121
GccBuildStatus::ShouldBuild(m) => m,
106122
};
107123

@@ -110,8 +126,9 @@ impl Step for Gcc {
110126
let _time = helpers::timeit(builder);
111127
t!(fs::create_dir_all(&out_dir));
112128

129+
let libgccjit_path = libgccjit_built_path(&install_dir);
113130
if builder.config.dry_run() {
114-
return true;
131+
return GccOutput { libgccjit: libgccjit_path };
115132
}
116133

117134
// GCC creates files (e.g. symlinks to the downloaded dependencies)
@@ -173,11 +190,17 @@ impl Step for Gcc {
173190

174191
let lib_alias = install_dir.join("lib/libgccjit.so.0");
175192
if !lib_alias.exists() {
176-
t!(builder.symlink_file(install_dir.join("lib/libgccjit.so"), lib_alias,));
193+
t!(builder.symlink_file(&libgccjit_path, lib_alias));
177194
}
178195

179196
t!(stamp.write());
180197

181-
true
198+
GccOutput { libgccjit: libgccjit_path }
182199
}
183200
}
201+
202+
/// Configures a Cargo invocation so that it can build the GCC codegen backend.
203+
pub fn add_cg_gcc_cargo_flags(cargo: &mut Cargo, gcc: &GccOutput) {
204+
// Add the path to libgccjit.so to the linker search paths.
205+
cargo.rustflag(&format!("-L{}", gcc.libgccjit.parent().unwrap().to_str().unwrap()));
206+
}

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use clap_complete::shells;
1212

1313
use crate::core::build_steps::compile::run_cargo;
1414
use crate::core::build_steps::doc::DocumentationFormat;
15+
use crate::core::build_steps::gcc::{Gcc, add_cg_gcc_cargo_flags};
1516
use crate::core::build_steps::llvm::get_llvm_version;
1617
use crate::core::build_steps::synthetic_targets::MirOptPanicAbortSyntheticTarget;
1718
use crate::core::build_steps::tool::{self, SourceType, Tool};
@@ -3549,6 +3550,8 @@ impl Step for CodegenGCC {
35493550
let compiler = self.compiler;
35503551
let target = self.target;
35513552

3553+
let gcc = builder.ensure(Gcc { target });
3554+
35523555
builder.ensure(
35533556
compile::Std::new(compiler, target)
35543557
.extra_rust_args(&["-Csymbol-mangling-version=v0", "-Cpanic=abort"]),
@@ -3575,6 +3578,7 @@ impl Step for CodegenGCC {
35753578
.arg("--manifest-path")
35763579
.arg(builder.src.join("compiler/rustc_codegen_gcc/build_system/Cargo.toml"));
35773580
compile::rustc_cargo_env(builder, &mut cargo, target, compiler.stage);
3581+
add_cg_gcc_cargo_flags(&mut cargo, &gcc);
35783582

35793583
// Avoid incremental cache issues when changing rustc
35803584
cargo.env("CARGO_BUILD_INCREMENTAL", "false");
@@ -3607,9 +3611,10 @@ impl Step for CodegenGCC {
36073611
.env("CG_RUSTFLAGS", "-Alinker-messages")
36083612
.arg("--")
36093613
.arg("test")
3610-
.arg("--use-system-gcc")
36113614
.arg("--use-backend")
36123615
.arg("gcc")
3616+
.arg("--gcc-path")
3617+
.arg(gcc.libgccjit.parent().unwrap())
36133618
.arg("--out-dir")
36143619
.arg(builder.stage_out(compiler, Mode::ToolRustc).join("cg_gcc"))
36153620
.arg("--release")

src/ci/docker/host-x86_64/x86_64-gnu-llvm-18/Dockerfile

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ FROM ubuntu:24.04
33
ARG DEBIAN_FRONTEND=noninteractive
44

55
RUN apt-get update && apt-get install -y --no-install-recommends \
6+
bzip2 \
67
g++ \
78
gcc-multilib \
89
make \
@@ -55,9 +56,6 @@ ENV RUST_CONFIGURE_ARGS \
5556
--set rust.thin-lto-import-instr-limit=10
5657

5758
COPY scripts/shared.sh /scripts/
58-
COPY scripts/build-gccjit.sh /scripts/
59-
60-
RUN /scripts/build-gccjit.sh /scripts
6159

6260
ARG SCRIPT_ARG
6361

src/ci/docker/host-x86_64/x86_64-gnu-llvm-19/Dockerfile

-3
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ ENV RUST_CONFIGURE_ARGS \
5555
--set rust.thin-lto-import-instr-limit=10
5656

5757
COPY scripts/shared.sh /scripts/
58-
COPY scripts/build-gccjit.sh /scripts/
59-
60-
RUN /scripts/build-gccjit.sh /scripts
6158

6259
ARG SCRIPT_ARG
6360

src/ci/docker/host-x86_64/x86_64-gnu-tools/Dockerfile

-3
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,6 @@ ENV HOST_TARGET x86_64-unknown-linux-gnu
9090
#ENV FORCE_CI_RUSTC 1
9191

9292
COPY scripts/shared.sh /scripts/
93-
COPY scripts/build-gccjit.sh /scripts/
94-
95-
RUN /scripts/build-gccjit.sh /scripts
9693

9794
# For now, we need to use `--unsafe-perm=true` to go around an issue when npm tries
9895
# to create a new folder. For reference:

src/ci/docker/scripts/build-gccjit.sh

-37
This file was deleted.

src/gcc

Submodule gcc updated 19134 files

0 commit comments

Comments
 (0)