Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
6b29bb6
Prevent ICE in autodiff validation by emitting user-friendly errors
Sa4dUs Mar 2, 2025
9067f7c
Explain weird quirk in user type annotation lowering
compiler-errors Mar 9, 2025
8ab05ad
Do not write user type annotation for const param value path
compiler-errors Mar 9, 2025
ed6dfdd
Do not feed anon const a type that references generics that it does n…
compiler-errors Mar 9, 2025
f525b17
Remove AdtFlags::IS_ANONYMOUS and Copy/Clone condition for anonymous ADT
compiler-errors Mar 10, 2025
02bb2d4
Disable CFI for weakly linked syscalls
1c3t3a Mar 4, 2025
e5dc1e3
Add comments for #[no_sanitize(cfi)] in stdlib
1c3t3a Mar 10, 2025
f38819c
Add some layout tests for pattern type edge cases
oli-obk Jan 30, 2025
916f955
Reject wrapping ranges of pattern types
oli-obk Jan 30, 2025
9d87d4e
Add tests for pattern type literals
oli-obk Jan 29, 2025
f87e58f
Allow int literals for pattern types with int base types
oli-obk Jan 29, 2025
53237c8
Refactor GCC compilation
Kobzol Mar 5, 2025
009aba0
Add `gcc` bootstrap config section
Kobzol Mar 5, 2025
c68a5ec
Add `[gcc] download-ci-gcc` option
Kobzol Mar 5, 2025
3de10b0
Add `download-ci-gcc-stamp` file
Kobzol Mar 5, 2025
bc6302c
Implement downloading GCC from CI
Kobzol Mar 5, 2025
2b1b09c
Add change tracker entry
Kobzol Mar 5, 2025
dcc2b30
Add triagebot entry for GCC modifications
Kobzol Mar 10, 2025
bf58a35
stabilize `ci_rustc_if_unchanged_logic` test for local environments
onur-ozkan Mar 8, 2025
cf8e1f5
Fix ICE for invalid return activity and proper error handling
Sa4dUs Mar 7, 2025
33f9a49
Combine autodiff errors together
Sa4dUs Mar 10, 2025
8546e01
Add individual activity span availability FIXME
Sa4dUs Mar 10, 2025
3846f94
miri native_calls: ensure we actually expose *mutable* provenance to …
RalfJung Mar 11, 2025
ba6c406
let the bodies hit the floor
lcnr Mar 11, 2025
75a69a4
Do not download GCC in tests
Kobzol Mar 11, 2025
8a2e3ac
Rollup merge of #137715 - oli-obk:pattern-type-literals, r=BoxyUwU
matthiaskrgr Mar 11, 2025
9746ac5
Rollup merge of #138002 - 1c3t3a:fix-std-cfi-violation, r=rcvalle
matthiaskrgr Mar 11, 2025
c007d0a
Rollup merge of #138051 - Kobzol:download-ci-gcc, r=onur-ozkan
matthiaskrgr Mar 11, 2025
caa2d00
Rollup merge of #138231 - Sa4dUs:autodiff-ice, r=ZuseZ4
matthiaskrgr Mar 11, 2025
55abd7f
Rollup merge of #138245 - onur-ozkan:ci-rustc-test-fix, r=jieyouxu
matthiaskrgr Mar 11, 2025
4ff58c9
Rollup merge of #138256 - compiler-errors:anon-const-ty, r=BoxyUwU
matthiaskrgr Mar 11, 2025
16ff824
Rollup merge of #138284 - compiler-errors:const-param-ty-annotation, …
matthiaskrgr Mar 11, 2025
954b88e
Rollup merge of #138296 - compiler-errors:deanonymous, r=lcnr
matthiaskrgr Mar 11, 2025
4feb866
Rollup merge of #138352 - RalfJung:miri-native-calls-exposed, r=oli-obk
matthiaskrgr Mar 11, 2025
4c1a186
Rollup merge of #138354 - lcnr:goodbye-TypeVerifier, r=compiler-errors
matthiaskrgr Mar 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor GCC compilation
  • Loading branch information
Kobzol committed Mar 10, 2025
commit 53237c86564deb04def176251a58bd967f941ceb
217 changes: 112 additions & 105 deletions src/bootstrap/src/core/build_steps/gcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,68 @@ use std::sync::OnceLock;

use build_helper::ci::CiEnv;

use crate::Kind;
use crate::core::builder::{Builder, Cargo, RunConfig, ShouldRun, Step};
use crate::Config;
use crate::core::builder::{Builder, Cargo, Kind, RunConfig, ShouldRun, Step};
use crate::core::config::TargetSelection;
use crate::utils::build_stamp::{BuildStamp, generate_smart_stamp_hash};
use crate::utils::exec::command;
use crate::utils::helpers::{self, t};

#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub struct Gcc {
pub target: TargetSelection,
}

#[derive(Clone)]
pub struct GccOutput {
pub libgccjit: PathBuf,
}

impl Step for Gcc {
type Output = GccOutput;

const ONLY_HOSTS: bool = true;

fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
run.path("src/gcc").alias("gcc")
}

fn make_run(run: RunConfig<'_>) {
run.builder.ensure(Gcc { target: run.target });
}

/// Compile GCC (specifically `libgccjit`) for `target`.
fn run(self, builder: &Builder<'_>) -> Self::Output {
let target = self.target;

// If GCC has already been built, we avoid building it again.
let metadata = match get_gcc_build_status(builder, target) {
GccBuildStatus::AlreadyBuilt(path) => return GccOutput { libgccjit: path },
GccBuildStatus::ShouldBuild(m) => m,
};

let _guard = builder.msg_unstaged(Kind::Build, "GCC", target);
t!(metadata.stamp.remove());
let _time = helpers::timeit(builder);

let libgccjit_path = libgccjit_built_path(&metadata.install_dir);
if builder.config.dry_run() {
return GccOutput { libgccjit: libgccjit_path };
}

build_gcc(&metadata, builder, target);

let lib_alias = metadata.install_dir.join("lib/libgccjit.so.0");
if !lib_alias.exists() {
t!(builder.symlink_file(&libgccjit_path, lib_alias));
}

t!(metadata.stamp.write());

GccOutput { libgccjit: libgccjit_path }
}
}

pub struct Meta {
stamp: BuildStamp,
out_dir: PathBuf,
Expand All @@ -38,7 +93,7 @@ pub enum GccBuildStatus {
///
/// It's used to avoid busting caches during x.py check -- if we've already built
/// GCC, it's fine for us to not try to avoid doing so.
pub fn prebuilt_gcc_config(builder: &Builder<'_>, target: TargetSelection) -> GccBuildStatus {
pub fn get_gcc_build_status(builder: &Builder<'_>, target: TargetSelection) -> GccBuildStatus {
// Initialize the gcc submodule if not initialized already.
builder.config.update_submodule("src/gcc");

Expand Down Expand Up @@ -87,104 +142,65 @@ fn libgccjit_built_path(install_dir: &Path) -> PathBuf {
install_dir.join("lib/libgccjit.so")
}

#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub struct Gcc {
pub target: TargetSelection,
}

#[derive(Clone)]
pub struct GccOutput {
pub libgccjit: PathBuf,
}

impl Step for Gcc {
type Output = GccOutput;

const ONLY_HOSTS: bool = true;

fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
run.path("src/gcc").alias("gcc")
}

fn make_run(run: RunConfig<'_>) {
run.builder.ensure(Gcc { target: run.target });
}

/// Compile GCC (specifically `libgccjit`) for `target`.
fn run(self, builder: &Builder<'_>) -> Self::Output {
let target = self.target;

// If GCC has already been built, we avoid building it again.
let Meta { stamp, out_dir, install_dir, root } = match prebuilt_gcc_config(builder, target)
{
GccBuildStatus::AlreadyBuilt(path) => return GccOutput { libgccjit: path },
GccBuildStatus::ShouldBuild(m) => m,
};

let _guard = builder.msg_unstaged(Kind::Build, "GCC", target);
t!(stamp.remove());
let _time = helpers::timeit(builder);
t!(fs::create_dir_all(&out_dir));
t!(fs::create_dir_all(&install_dir));

let libgccjit_path = libgccjit_built_path(&install_dir);
if builder.config.dry_run() {
return GccOutput { libgccjit: libgccjit_path };
fn build_gcc(metadata: &Meta, builder: &Builder, target: TargetSelection) {
let Meta { stamp: _, out_dir, install_dir, root } = metadata;

t!(fs::create_dir_all(out_dir));
t!(fs::create_dir_all(install_dir));

// GCC creates files (e.g. symlinks to the downloaded dependencies)
// in the source directory, which does not work with our CI setup, where we mount
// source directories as read-only on Linux.
// Therefore, as a part of the build in CI, we first copy the whole source directory
// to the build directory, and perform the build from there.
let src_dir = if CiEnv::is_ci() {
let src_dir = builder.gcc_out(target).join("src");
if src_dir.exists() {
builder.remove_dir(&src_dir);
}

// GCC creates files (e.g. symlinks to the downloaded dependencies)
// in the source directory, which does not work with our CI setup, where we mount
// source directories as read-only on Linux.
// Therefore, as a part of the build in CI, we first copy the whole source directory
// to the build directory, and perform the build from there.
let src_dir = if CiEnv::is_ci() {
let src_dir = builder.gcc_out(target).join("src");
if src_dir.exists() {
builder.remove_dir(&src_dir);
}
builder.create_dir(&src_dir);
builder.cp_link_r(&root, &src_dir);
src_dir
} else {
root
};

command(src_dir.join("contrib/download_prerequisites")).current_dir(&src_dir).run(builder);
let mut configure_cmd = command(src_dir.join("configure"));
configure_cmd
.current_dir(&out_dir)
// On CI, we compile GCC with Clang.
// The -Wno-everything flag is needed to make GCC compile with Clang 19.
// `-g -O2` are the default flags that are otherwise used by Make.
// FIXME(kobzol): change the flags once we have [gcc] configuration in config.toml.
.env("CXXFLAGS", "-Wno-everything -g -O2")
.env("CFLAGS", "-Wno-everything -g -O2")
.arg("--enable-host-shared")
.arg("--enable-languages=jit")
.arg("--enable-checking=release")
.arg("--disable-bootstrap")
.arg("--disable-multilib")
.arg(format!("--prefix={}", install_dir.display()));
let cc = builder.build.cc(target).display().to_string();
let cc = builder
builder.create_dir(&src_dir);
builder.cp_link_r(root, &src_dir);
src_dir
} else {
root.clone()
};

command(src_dir.join("contrib/download_prerequisites")).current_dir(&src_dir).run(builder);
let mut configure_cmd = command(src_dir.join("configure"));
configure_cmd
.current_dir(out_dir)
// On CI, we compile GCC with Clang.
// The -Wno-everything flag is needed to make GCC compile with Clang 19.
// `-g -O2` are the default flags that are otherwise used by Make.
// FIXME(kobzol): change the flags once we have [gcc] configuration in config.toml.
.env("CXXFLAGS", "-Wno-everything -g -O2")
.env("CFLAGS", "-Wno-everything -g -O2")
.arg("--enable-host-shared")
.arg("--enable-languages=jit")
.arg("--enable-checking=release")
.arg("--disable-bootstrap")
.arg("--disable-multilib")
.arg(format!("--prefix={}", install_dir.display()));
let cc = builder.build.cc(target).display().to_string();
let cc = builder
.build
.config
.ccache
.as_ref()
.map_or_else(|| cc.clone(), |ccache| format!("{ccache} {cc}"));
configure_cmd.env("CC", cc);

if let Ok(ref cxx) = builder.build.cxx(target) {
let cxx = cxx.display().to_string();
let cxx = builder
.build
.config
.ccache
.as_ref()
.map_or_else(|| cc.clone(), |ccache| format!("{ccache} {cc}"));
configure_cmd.env("CC", cc);

if let Ok(ref cxx) = builder.build.cxx(target) {
let cxx = cxx.display().to_string();
let cxx = builder
.build
.config
.ccache
.as_ref()
.map_or_else(|| cxx.clone(), |ccache| format!("{ccache} {cxx}"));
configure_cmd.env("CXX", cxx);
}
configure_cmd.run(builder);
.map_or_else(|| cxx.clone(), |ccache| format!("{ccache} {cxx}"));
configure_cmd.env("CXX", cxx);
}
configure_cmd.run(builder);

command("make")
.current_dir(&out_dir)
Expand All @@ -196,15 +212,6 @@ impl Step for Gcc {
.arg("--silent")
.arg("install")
.run_capture_stdout(builder);

let lib_alias = install_dir.join("lib/libgccjit.so.0");
if !lib_alias.exists() {
t!(builder.symlink_file(&libgccjit_path, lib_alias));
}

t!(stamp.write());

GccOutput { libgccjit: libgccjit_path }
}
}

Expand Down