Skip to content

Commit 10776a4

Browse files
committed
Auto merge of #149348 - GuillaumeGomez:subtree-update_cg_gcc_2025-11-26, r=GuillaumeGomez
cg_gcc subtree sync cc `@antoyo`
2 parents e6edf3a + f94e90f commit 10776a4

File tree

30 files changed

+317
-140
lines changed

30 files changed

+317
-140
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ jobs:
5454
if: matrix.libgccjit_version.gcc == 'libgccjit12.so'
5555
run: |
5656
echo 'gcc-path = "/usr/lib/gcc/x86_64-linux-gnu/12"' > config.toml
57-
echo "LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/12" >> $GITHUB_ENV
58-
echo "LD_LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/12" >> $GITHUB_ENV
5957
6058
- name: Download artifact
6159
if: matrix.libgccjit_version.gcc != 'libgccjit12.so'

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,6 @@ jobs:
5151
- name: Setup path to libgccjit
5252
run: echo 'gcc-path = "/usr/lib/gcc/x86_64-linux-gnu/12"' > config.toml
5353

54-
- name: Set env
55-
run: |
56-
echo "workspace="$GITHUB_WORKSPACE >> $GITHUB_ENV
57-
echo "LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/12" >> $GITHUB_ENV
58-
echo "LD_LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/12" >> $GITHUB_ENV
59-
6054
#- name: Cache rust repository
6155
## We only clone the rust repository for rustc tests
6256
#if: ${{ contains(matrix.commands, 'rustc') }}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ jobs:
7272
git config --global user.name "User"
7373
./y.sh prepare
7474
75+
- name: Add more failing tests (some panic and debuginfo tests fail)
76+
run: cat tests/failing-lto-tests.txt >> tests/failing-ui-tests.txt
77+
7578
- name: Run tests
7679
run: |
7780
# FIXME(antoyo): we cannot enable LTO for stdarch tests currently because of some failing LTO tests using proc-macros.

compiler/rustc_codegen_gcc/.github/workflows/stdarch.yml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,15 @@ jobs:
5959
sudo ln -s /usr/share/intel-sde/sde /usr/bin/sde
6060
sudo ln -s /usr/share/intel-sde/sde64 /usr/bin/sde64
6161
62-
- name: Set env
62+
- name: Set config
6363
run: |
64-
echo "workspace="$GITHUB_WORKSPACE >> $GITHUB_ENV
6564
echo 'download-gccjit = true' > config.toml
6665
6766
- name: Build
6867
run: |
6968
./y.sh prepare --only-libcore
7069
./y.sh build --sysroot --release --release-sysroot
7170
72-
- name: Set env (part 2)
73-
run: |
74-
# Set the `LD_LIBRARY_PATH` and `LIBRARY_PATH` env variables...
75-
echo "LD_LIBRARY_PATH="$(./y.sh info | grep -v Using) >> $GITHUB_ENV
76-
echo "LIBRARY_PATH="$(./y.sh info | grep -v Using) >> $GITHUB_ENV
77-
7871
- name: Clean
7972
if: ${{ !matrix.cargo_runner }}
8073
run: |

compiler/rustc_codegen_gcc/Cargo.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,18 @@ dependencies = [
5656

5757
[[package]]
5858
name = "gccjit"
59-
version = "2.10.0"
59+
version = "3.1.1"
6060
source = "registry+https://github.com/rust-lang/crates.io-index"
61-
checksum = "60362e038e71e4bdc1a5b23fb45e1aba587b5947fe0db58f4871d95608f89eca"
61+
checksum = "ff80f4d6d0749eab3a69122210b3a1fdd52edb6162781aadd7c4842e26983683"
6262
dependencies = [
6363
"gccjit_sys",
6464
]
6565

6666
[[package]]
6767
name = "gccjit_sys"
68-
version = "0.9.0"
68+
version = "1.1.1"
6969
source = "registry+https://github.com/rust-lang/crates.io-index"
70-
checksum = "ddd542c8414e122217551c6af6b7d33acf51a227aee85276f218c087525e01bb"
70+
checksum = "263da4f60b7bb5d6a5b21efda961741051ebdbf0e380a09118b03cce66a8c77e"
7171
dependencies = [
7272
"libc",
7373
]

compiler/rustc_codegen_gcc/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ default = ["master"]
2424
[dependencies]
2525
object = { version = "0.37.0", default-features = false, features = ["std", "read"] }
2626
tempfile = "3.20"
27-
gccjit = "2.10"
28-
#gccjit = { git = "https://github.com/rust-lang/gccjit.rs" }
27+
gccjit = { version = "3.1.1", features = ["dlopen"] }
28+
#gccjit = { git = "https://github.com/rust-lang/gccjit.rs", branch = "error-dlopen", features = ["dlopen"] }
2929

3030
# Local copy.
31-
#gccjit = { path = "../gccjit.rs" }
31+
#gccjit = { path = "../gccjit.rs", features = ["dlopen"] }
3232

3333
[dev-dependencies]
3434
boml = "0.3.1"

compiler/rustc_codegen_gcc/build_system/src/build.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use std::collections::HashMap;
22
use std::ffi::OsStr;
33
use std::fs;
4-
use std::path::Path;
4+
use std::os::unix::fs::symlink;
5+
use std::path::{Path, PathBuf};
56

67
use crate::config::{Channel, ConfigInfo};
78
use crate::utils::{
@@ -100,6 +101,18 @@ fn cleanup_sysroot_previous_build(library_dir: &Path) {
100101
pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Result<(), String> {
101102
let start_dir = get_sysroot_dir();
102103

104+
// Symlink libgccjit.so to sysroot.
105+
let lib_path = start_dir.join("sysroot").join("lib");
106+
let libgccjit_path =
107+
PathBuf::from(config.gcc_path.as_ref().expect("libgccjit should be set by this point"))
108+
.join("libgccjit.so");
109+
let libgccjit_in_sysroot_path = lib_path.join("libgccjit.so");
110+
// First remove the file to be able to create the symlink even when the file already exists.
111+
let _ = fs::remove_file(&libgccjit_in_sysroot_path);
112+
create_dir(&lib_path)?;
113+
symlink(libgccjit_path, libgccjit_in_sysroot_path)
114+
.map_err(|error| format!("Cannot create symlink for libgccjit.so: {}", error))?;
115+
103116
let library_dir = start_dir.join("sysroot_src").join("library");
104117
cleanup_sysroot_previous_build(&library_dir);
105118

@@ -148,7 +161,7 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
148161
run_command_with_output_and_env(&args, Some(&sysroot_dir), Some(&env))?;
149162

150163
// Copy files to sysroot
151-
let sysroot_path = start_dir.join(format!("sysroot/lib/rustlib/{}/lib/", config.target_triple));
164+
let sysroot_path = lib_path.join(format!("rustlib/{}/lib/", config.target_triple));
152165
// To avoid errors like "multiple candidates for `rmeta` dependency `core` found", we clean the
153166
// sysroot directory before copying the sysroot build artifacts.
154167
let _ = fs::remove_dir_all(&sysroot_path);
@@ -175,13 +188,6 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
175188
fn build_codegen(args: &mut BuildArg) -> Result<(), String> {
176189
let mut env = HashMap::new();
177190

178-
let gcc_path =
179-
args.config_info.gcc_path.clone().expect(
180-
"The config module should have emitted an error if the GCC path wasn't provided",
181-
);
182-
env.insert("LD_LIBRARY_PATH".to_string(), gcc_path.clone());
183-
env.insert("LIBRARY_PATH".to_string(), gcc_path);
184-
185191
if args.config_info.no_default_features {
186192
env.insert("RUSTFLAGS".to_string(), "-Csymbol-mangling-version=v0".to_string());
187193
}

compiler/rustc_codegen_gcc/build_system/src/config.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -429,19 +429,6 @@ impl ConfigInfo {
429429
// display metadata load errors
430430
env.insert("RUSTC_LOG".to_string(), "warn".to_string());
431431

432-
let sysroot = current_dir
433-
.join(get_sysroot_dir())
434-
.join(format!("sysroot/lib/rustlib/{}/lib", self.target_triple));
435-
let ld_library_path = format!(
436-
"{target}:{sysroot}:{gcc_path}",
437-
target = self.cargo_target_dir,
438-
sysroot = sysroot.display(),
439-
gcc_path = gcc_path,
440-
);
441-
env.insert("LIBRARY_PATH".to_string(), ld_library_path.clone());
442-
env.insert("LD_LIBRARY_PATH".to_string(), ld_library_path.clone());
443-
env.insert("DYLD_LIBRARY_PATH".to_string(), ld_library_path);
444-
445432
// NOTE: To avoid the -fno-inline errors, use /opt/gcc/bin/gcc instead of cc.
446433
// To do so, add a symlink for cc to /opt/gcc/bin/gcc in our PATH.
447434
// Another option would be to add the following Rust flag: -Clinker=/opt/gcc/bin/gcc

compiler/rustc_codegen_gcc/build_system/src/test.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,6 @@ fn cargo_tests(test_env: &Env, test_args: &TestArg) -> Result<(), String> {
214214
// We don't want to pass things like `RUSTFLAGS`, since they contain the -Zcodegen-backend flag.
215215
// That would force `cg_gcc` to *rebuild itself* and only then run tests, which is undesirable.
216216
let mut env = HashMap::new();
217-
env.insert(
218-
"LD_LIBRARY_PATH".into(),
219-
test_env.get("LD_LIBRARY_PATH").expect("LD_LIBRARY_PATH missing!").to_string(),
220-
);
221-
env.insert(
222-
"LIBRARY_PATH".into(),
223-
test_env.get("LIBRARY_PATH").expect("LIBRARY_PATH missing!").to_string(),
224-
);
225217
env.insert(
226218
"CG_RUSTFLAGS".into(),
227219
test_env.get("CG_RUSTFLAGS").map(|s| s.as_str()).unwrap_or("").to_string(),
@@ -1065,6 +1057,7 @@ where
10651057
&test_dir,
10661058
&"--compiletest-rustc-args",
10671059
&rustc_args,
1060+
&"--bypass-ignore-backends",
10681061
];
10691062

10701063
if run_ignored_tests {
@@ -1275,11 +1268,6 @@ pub fn run() -> Result<(), String> {
12751268

12761269
if !args.use_system_gcc {
12771270
args.config_info.setup_gcc_path()?;
1278-
let gcc_path = args.config_info.gcc_path.clone().expect(
1279-
"The config module should have emitted an error if the GCC path wasn't provided",
1280-
);
1281-
env.insert("LIBRARY_PATH".to_string(), gcc_path.clone());
1282-
env.insert("LD_LIBRARY_PATH".to_string(), gcc_path);
12831271
}
12841272

12851273
build_if_no_backend(&env, &args)?;

compiler/rustc_codegen_gcc/doc/tips.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ be useful.
99
CG_RUSTFLAGS="-Clink-args=-save-temps -v" ../y.sh cargo build
1010
```
1111

12+
### How to send arguments to GCC
13+
14+
The `-Cllvm-args` `rustc` flag is repurposed by `rustc_codegen_gcc` to pass arguments directly to the GCC backend. You can use it via the `CG_RUSTFLAGS` environment variable. For example, to pass a `-f` flag to GCC:
15+
16+
```
17+
CG_RUSTFLAGS="-Cllvm-args=-fflag-name" ../y.sh cargo build
18+
```
19+
1220
### How to see the personality functions in the asm dump
1321

1422
```

0 commit comments

Comments
 (0)