Skip to content

Commit f753850

Browse files
committed
Auto merge of #136024 - GuillaumeGomez:cg_gcc-subtree, r=GuillaumeGomez
Update rustc_codegen_gcc subtree cc `@antoyo`
2 parents 5545959 + 7c177d5 commit f753850

File tree

12 files changed

+85
-41
lines changed

12 files changed

+85
-41
lines changed

compiler/rustc_codegen_gcc/.github/workflows/ci.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ env:
1313

1414
jobs:
1515
build:
16-
runs-on: ubuntu-22.04
16+
runs-on: ubuntu-24.04
1717

1818
strategy:
1919
fail-fast: false
2020
matrix:
2121
libgccjit_version:
22-
- { gcc: "gcc-13.deb" }
23-
- { gcc: "gcc-13-without-int128.deb" }
22+
- { gcc: "gcc-15.deb" }
23+
- { gcc: "gcc-15-without-int128.deb" }
2424
commands: [
2525
"--std-tests",
2626
# FIXME: re-enable asm tests when GCC can emit in the right syntax.
@@ -108,13 +108,13 @@ jobs:
108108
cargo clippy --all-targets --features master -- -D warnings
109109
110110
duplicates:
111-
runs-on: ubuntu-latest
111+
runs-on: ubuntu-24.04
112112
steps:
113113
- uses: actions/checkout@v4
114114
- run: python tools/check_intrinsics_duplicates.py
115115

116116
build_system:
117-
runs-on: ubuntu-latest
117+
runs-on: ubuntu-24.04
118118
steps:
119119
- uses: actions/checkout@v4
120120
- name: Test build system

compiler/rustc_codegen_gcc/.github/workflows/failures.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ env:
1313

1414
jobs:
1515
build:
16-
runs-on: ubuntu-22.04
16+
runs-on: ubuntu-24.04
1717

1818
strategy:
1919
fail-fast: false
@@ -56,12 +56,12 @@ jobs:
5656
5757
- name: Download artifact
5858
if: matrix.libgccjit_version.gcc != 'libgccjit12.so'
59-
run: curl -LO https://github.com/rust-lang/gcc/releases/latest/download/gcc-13.deb
59+
run: curl -LO https://github.com/rust-lang/gcc/releases/latest/download/gcc-15.deb
6060

6161
- name: Setup path to libgccjit
6262
if: matrix.libgccjit_version.gcc != 'libgccjit12.so'
6363
run: |
64-
sudo dpkg --force-overwrite -i gcc-13.deb
64+
sudo dpkg --force-overwrite -i gcc-15.deb
6565
echo 'gcc-path = "/usr/lib"' > config.toml
6666
echo "LIBRARY_PATH=/usr/lib" >> $GITHUB_ENV
6767
echo "LD_LIBRARY_PATH=/usr/lib" >> $GITHUB_ENV

compiler/rustc_codegen_gcc/.github/workflows/gcc12.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ env:
1717

1818
jobs:
1919
build:
20-
runs-on: ubuntu-22.04
20+
runs-on: ubuntu-24.04
2121

2222
strategy:
2323
fail-fast: false

compiler/rustc_codegen_gcc/.github/workflows/m68k.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ env:
1717

1818
jobs:
1919
build:
20-
runs-on: ubuntu-22.04
20+
runs-on: ubuntu-24.04
2121

2222
strategy:
2323
fail-fast: false
@@ -47,17 +47,17 @@ jobs:
4747
- name: Install packages
4848
run: |
4949
sudo apt-get update
50-
sudo apt-get install qemu qemu-user-static
50+
sudo apt-get install qemu-system qemu-user-static
5151
5252
- name: Download artifact
53-
run: curl -LO https://github.com/cross-cg-gcc-tools/cross-gcc/releases/latest/download/gcc-m68k-13.deb
53+
run: curl -LO https://github.com/cross-cg-gcc-tools/cross-gcc/releases/latest/download/gcc-m68k-15.deb
5454

5555
- name: Download VM artifact
5656
run: curl -LO https://github.com/cross-cg-gcc-tools/vms/releases/latest/download/debian-m68k.img
5757

5858
- name: Setup path to libgccjit
5959
run: |
60-
sudo dpkg -i gcc-m68k-13.deb
60+
sudo dpkg -i gcc-m68k-15.deb
6161
echo 'gcc-path = "/usr/lib/"' > config.toml
6262
6363
- name: Set env

compiler/rustc_codegen_gcc/.github/workflows/release.yml

+9-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ env:
1313

1414
jobs:
1515
build:
16-
runs-on: ubuntu-22.04
16+
runs-on: ubuntu-24.04
1717

1818
strategy:
1919
fail-fast: false
@@ -37,11 +37,11 @@ jobs:
3737
run: sudo apt-get install ninja-build ripgrep
3838

3939
- name: Download artifact
40-
run: curl -LO https://github.com/rust-lang/gcc/releases/latest/download/gcc-13.deb
40+
run: curl -LO https://github.com/rust-lang/gcc/releases/latest/download/gcc-15.deb
4141

4242
- name: Setup path to libgccjit
4343
run: |
44-
sudo dpkg --force-overwrite -i gcc-13.deb
44+
sudo dpkg --force-overwrite -i gcc-15.deb
4545
echo 'gcc-path = "/usr/lib/"' > config.toml
4646
4747
- name: Set env
@@ -76,4 +76,9 @@ jobs:
7676
- name: Run y.sh cargo build
7777
run: |
7878
EMBED_LTO_BITCODE=1 CHANNEL="release" ./y.sh cargo build --release --manifest-path tests/hello-world/Cargo.toml
79-
# TODO: grep the asm output for "call my_func" and fail if it is found.
79+
call_found=$(objdump -dj .text tests/hello-world/target/release/hello_world | grep -c "call .*mylib.*my_func" ) ||:
80+
if [ $call_found -gt 0 ]; then
81+
echo "ERROR: call my_func found in asm"
82+
echo "Test is done with LTO enabled, hence inlining should occur across crates"
83+
exit 1
84+
fi

compiler/rustc_codegen_gcc/build_system/src/build.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
150150
"debug"
151151
};
152152

153+
// We have a different environment variable than RUSTFLAGS to make sure those flags are only
154+
// sent to rustc_codegen_gcc and not the LLVM backend.
153155
if let Ok(cg_rustflags) = std::env::var("CG_RUSTFLAGS") {
154156
rustflags.push(' ');
155157
rustflags.push_str(&cg_rustflags);
@@ -184,8 +186,12 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
184186
fn build_codegen(args: &mut BuildArg) -> Result<(), String> {
185187
let mut env = HashMap::new();
186188

187-
env.insert("LD_LIBRARY_PATH".to_string(), args.config_info.gcc_path.clone());
188-
env.insert("LIBRARY_PATH".to_string(), args.config_info.gcc_path.clone());
189+
let gcc_path =
190+
args.config_info.gcc_path.clone().expect(
191+
"The config module should have emitted an error if the GCC path wasn't provided",
192+
);
193+
env.insert("LD_LIBRARY_PATH".to_string(), gcc_path.clone());
194+
env.insert("LIBRARY_PATH".to_string(), gcc_path);
189195

190196
if args.config_info.no_default_features {
191197
env.insert("RUSTFLAGS".to_string(), "-Csymbol-mangling-version=v0".to_string());

compiler/rustc_codegen_gcc/build_system/src/config.rs

+44-13
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ pub struct ConfigInfo {
112112
pub sysroot_panic_abort: bool,
113113
pub cg_backend_path: String,
114114
pub sysroot_path: String,
115-
pub gcc_path: String,
115+
pub gcc_path: Option<String>,
116116
config_file: Option<String>,
117117
// This is used in particular in rust compiler bootstrap because it doesn't run at the root
118118
// of the `cg_gcc` folder, making it complicated for us to get access to local files we need
@@ -173,6 +173,14 @@ impl ConfigInfo {
173173
"--release-sysroot" => self.sysroot_release_channel = true,
174174
"--release" => self.channel = Channel::Release,
175175
"--sysroot-panic-abort" => self.sysroot_panic_abort = true,
176+
"--gcc-path" => match args.next() {
177+
Some(arg) if !arg.is_empty() => {
178+
self.gcc_path = Some(arg.into());
179+
}
180+
_ => {
181+
return Err("Expected a value after `--gcc-path`, found nothing".to_string());
182+
}
183+
},
176184
"--cg_gcc-path" => match args.next() {
177185
Some(arg) if !arg.is_empty() => {
178186
self.cg_gcc_path = Some(arg.into());
@@ -260,8 +268,9 @@ impl ConfigInfo {
260268
create_symlink(&libgccjit_so, output_dir.join(&format!("{}.0", libgccjit_so_name)))?;
261269
}
262270

263-
self.gcc_path = output_dir.display().to_string();
264-
println!("Using `{}` as path for libgccjit", self.gcc_path);
271+
let gcc_path = output_dir.display().to_string();
272+
println!("Using `{}` as path for libgccjit", gcc_path);
273+
self.gcc_path = Some(gcc_path);
265274
Ok(())
266275
}
267276

@@ -273,6 +282,15 @@ impl ConfigInfo {
273282
}
274283

275284
pub fn setup_gcc_path(&mut self) -> Result<(), String> {
285+
// If the user used the `--gcc-path` option, no need to look at `config.toml` content
286+
// since we already have everything we need.
287+
if let Some(gcc_path) = &self.gcc_path {
288+
println!(
289+
"`--gcc-path` was provided, ignoring config file. Using `{}` as path for libgccjit",
290+
gcc_path
291+
);
292+
return Ok(());
293+
}
276294
let config_file = match self.config_file.as_deref() {
277295
Some(config_file) => config_file.into(),
278296
None => self.compute_path("config.toml"),
@@ -283,12 +301,15 @@ impl ConfigInfo {
283301
self.download_gccjit_if_needed()?;
284302
return Ok(());
285303
}
286-
self.gcc_path = match gcc_path {
287-
Some(path) => path,
288-
None => {
289-
return Err(format!("missing `gcc-path` value from `{}`", config_file.display(),));
290-
}
304+
let Some(gcc_path) = gcc_path else {
305+
return Err(format!("missing `gcc-path` value from `{}`", config_file.display()));
291306
};
307+
println!(
308+
"GCC path retrieved from `{}`. Using `{}` as path for libgccjit",
309+
config_file.display(),
310+
gcc_path
311+
);
312+
self.gcc_path = Some(gcc_path);
292313
Ok(())
293314
}
294315

@@ -299,10 +320,17 @@ impl ConfigInfo {
299320
) -> Result<(), String> {
300321
env.insert("CARGO_INCREMENTAL".to_string(), "0".to_string());
301322

302-
if self.gcc_path.is_empty() && !use_system_gcc {
303-
self.setup_gcc_path()?;
304-
}
305-
env.insert("GCC_PATH".to_string(), self.gcc_path.clone());
323+
let gcc_path = if !use_system_gcc {
324+
if self.gcc_path.is_none() {
325+
self.setup_gcc_path()?;
326+
}
327+
self.gcc_path.clone().expect(
328+
"The config module should have emitted an error if the GCC path wasn't provided",
329+
)
330+
} else {
331+
String::new()
332+
};
333+
env.insert("GCC_PATH".to_string(), gcc_path.clone());
306334

307335
if self.cargo_target_dir.is_empty() {
308336
match env.get("CARGO_TARGET_DIR").filter(|dir| !dir.is_empty()) {
@@ -381,6 +409,8 @@ impl ConfigInfo {
381409
}
382410

383411
// This environment variable is useful in case we want to change options of rustc commands.
412+
// We have a different environment variable than RUSTFLAGS to make sure those flags are
413+
// only sent to rustc_codegen_gcc and not the LLVM backend.
384414
if let Some(cg_rustflags) = env.get("CG_RUSTFLAGS") {
385415
rustflags.extend_from_slice(&split_args(&cg_rustflags)?);
386416
}
@@ -414,7 +444,7 @@ impl ConfigInfo {
414444
"{target}:{sysroot}:{gcc_path}",
415445
target = self.cargo_target_dir,
416446
sysroot = sysroot.display(),
417-
gcc_path = self.gcc_path,
447+
gcc_path = gcc_path,
418448
);
419449
env.insert("LIBRARY_PATH".to_string(), ld_library_path.clone());
420450
env.insert("LD_LIBRARY_PATH".to_string(), ld_library_path.clone());
@@ -459,6 +489,7 @@ impl ConfigInfo {
459489
--release-sysroot : Build sysroot in release mode
460490
--sysroot-panic-abort : Build the sysroot without unwinding support
461491
--config-file : Location of the config file to be used
492+
--gcc-path : Location of the GCC root folder
462493
--cg_gcc-path : Location of the rustc_codegen_gcc root folder (used
463494
when ran from another directory)
464495
--no-default-features : Add `--no-default-features` flag to cargo commands

compiler/rustc_codegen_gcc/build_system/src/info.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ pub fn run() -> Result<(), String> {
1414
}
1515
config.no_download = true;
1616
config.setup_gcc_path()?;
17-
println!("{}", config.gcc_path);
17+
if let Some(gcc_path) = config.gcc_path {
18+
println!("{}", gcc_path);
19+
}
1820
Ok(())
1921
}

compiler/rustc_codegen_gcc/build_system/src/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ Options:
3434
--help : Displays this help message.
3535
3636
Commands:
37-
cargo : Executes a cargo command.
37+
cargo : Executes a cargo command.
3838
rustc : Compiles the program using the GCC compiler.
3939
clean : Cleans the build directory, removing all compiled files and artifacts.
4040
prepare : Prepares the environment for building, including fetching dependencies and setting up configurations.
41-
build : Compiles the project.
41+
build : Compiles the project.
4242
test : Runs tests for the project.
4343
info : Displays information about the build environment and project configuration.
4444
clone-gcc : Clones the GCC compiler from a specified source.

compiler/rustc_codegen_gcc/build_system/src/test.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1229,8 +1229,11 @@ pub fn run() -> Result<(), String> {
12291229

12301230
if !args.use_system_gcc {
12311231
args.config_info.setup_gcc_path()?;
1232-
env.insert("LIBRARY_PATH".to_string(), args.config_info.gcc_path.clone());
1233-
env.insert("LD_LIBRARY_PATH".to_string(), args.config_info.gcc_path.clone());
1232+
let gcc_path = args.config_info.gcc_path.clone().expect(
1233+
"The config module should have emitted an error if the GCC path wasn't provided",
1234+
);
1235+
env.insert("LIBRARY_PATH".to_string(), gcc_path.clone());
1236+
env.insert("LD_LIBRARY_PATH".to_string(), gcc_path);
12341237
}
12351238

12361239
build_if_no_backend(&env, &args)?;
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
45648c2edd4ecd862d9f08196d3d6c6ccba79f07
1+
e607be166673a8de9fc07f6f02c60426e556c5f2

compiler/rustc_codegen_gcc/messages.ftl

-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ codegen_gcc_unknown_ctarget_feature_prefix =
55
codegen_gcc_invalid_minimum_alignment =
66
invalid minimum global alignment: {$err}
77
8-
codegen_gcc_lto_not_supported =
9-
LTO is not supported. You may get a linker error.
10-
118
codegen_gcc_forbidden_ctarget_feature =
129
target feature `{$feature}` cannot be toggled with `-Ctarget-feature`: {$reason}
1310

0 commit comments

Comments
 (0)