Skip to content

Allow running tests with GCC #144687

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

GuillaumeGomez
Copy link
Member

@GuillaumeGomez GuillaumeGomez commented Jul 30, 2025

Part of rust-lang/compiler-team#891.

This PR does two things:

  1. Allow to build rustc with GCC (first commit)
  2. Allow to run tests with the GCC backend (second commit)

However, if you try it out, compilation will fail, hence why I didn't update the CI yet. We have a sync in progress to fix these bugs. If you want to try it, you can use this branch which includes commits from the current cg_gcc sync.

r? @Kobzol

@rustbot rustbot added A-compiletest Area: The compiletest test runner A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Jul 30, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 30, 2025

Some changes occurred in src/tools/compiletest

cc @jieyouxu

This PR modifies src/bootstrap/src/core/config.

If appropriate, please update CONFIG_CHANGE_HISTORY in src/bootstrap/src/utils/change_tracker.rs.

@@ -1769,7 +1769,10 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
cmd.arg("--host").arg(&*compiler.host.triple);
cmd.arg("--llvm-filecheck").arg(builder.llvm_filecheck(builder.config.host_target));

if let Some(codegen_backend) = builder.config.default_codegen_backend(compiler.host) {
if let Some(codegen_backend) = builder.config.codegen_backends(compiler.host).first() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we don't seem to run commands for each registered backend, I simply look at the first for now. Should I add a FIXME comment on it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this change, why didn't you just use default_codegen_backend? It does the same thing (looks at the first codegen backend).

Copy link
Member

@bjorn3 bjorn3 Jul 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default_codegen_backend() is literally implemented as codegen_backends().first().
Edit: for some reason github didn't show me Kobzol's comment before.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just submitted it now 😆 It was a pending comment, but GH uses the original time when it was written, not when it was submitted, which is a bit confusing.

@@ -1917,6 +1920,11 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
cmd.arg(exclude);
}

if builder.config.codegen_backends(target).first().map(|b| b.as_str()) == Some("gcc") {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

@@ -563,6 +563,12 @@ impl Builder<'_> {
println!("using sysroot {sysroot_str}");
}

if self.config.codegen_backends(target).first().map(|b| b.as_str()) == Some("gcc") {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

@@ -1226,6 +1226,13 @@ impl Config {
self.out.join(self.host_target).join("ci-rustc")
}

pub(crate) fn libgccjit_root(&self) -> PathBuf {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering we don't store GCC in the same ___location depending whether we build it or we download it, I found it better to handle it in one place instead, hence the creation of this method.

@rust-log-analyzer

This comment has been minimized.

if self.config.codegen_backends(target).first().map(|b| b.as_str()) == Some("gcc") {
let gcc_sysroot = self.config.libgccjit_root();
let gcc_sysroot = gcc_sysroot.as_os_str().to_str().expect("sysroot should be UTF-8");
cargo.env("LD_LIBRARY_PATH", gcc_sysroot);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is it done for cg_llvm?
Couldn't we reuse what is done there?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why isn't libgccjit copied into the sysroot like for libLLVM?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent question, absolutely no clue.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That works for build, but not for dist, we do not want to dist libgccjit.so by default with rustup (at least not yet). If build did this automatically, we would have to explicitly skip it when creating the dist archives (normally we mostly copy all .so files to them, I think).

Copy link
Member

@bjorn3 bjorn3 Jul 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dist has an explicit list of files to include in each component, right? It has to for each .so files to not end up in every component. So the cg_gcc component can include just cg_gcc.so and not libgccjit.so.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's very explicit in this case:

let libdir = builder.rustc_libdir(compiler);

To clarify, the cg_gcc rustup component should include both cg_gcc.so and libgccjit.so. But the normal rustc component shouldn't contain libgccjit.so.

if !matches!(self.config.codegen_backend, crate::CodegenBackend::Llvm) {
let lib_path = self.config.sysroot_base.join(self.config.codegen_backend.as_str());
rustc.arg(format!("-Zcodegen-backend={}", lib_path));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This always matches the default codegen backend, right? In that case no explicit -Zcodegen-backend should be necessary.

@Kobzol
Copy link
Member

Kobzol commented Jul 31, 2025

I looked at how the backends are configured today and I think that before we go forward with enabling the tests, we should first both clean the handling of the backends, and understand/decide how will the GCC lookup work in practice. Some work items:

Regarding the GCC lookup, we need to figure out a universal way of how will cg_gcc find libgccjit.so. Spamming libdir paths at all the tests that could possibly use the GCC backend is not very scalable, and won't work for using the GCC backend outside bootstrap. When I x build rustc_codegen_gcc, the resulting stage1 sysroot doesn't work with RUSTFLAGS="-Zcodegen-backend=gcc" cargo +stage1 build, because it can't find libgccjit.so. This should "just work", if it did, we don't need to do additional bootstrap magic.

@GuillaumeGomez
Copy link
Member Author

GuillaumeGomez commented Jul 31, 2025

I can link the .so files in a given ___location. Question is: where?

@Kobzol
Copy link
Member

Kobzol commented Jul 31, 2025

I suspect that the most straightforward solution would be to do what LLVM does, so either put it in the lib sysroot or use rpath. But we have to be careful around dist, so that we don't accidentally ship the GCC stuff in our distribution archives. It shouldn't be that hard though, as we won't enable GCC on dist builders for the main compiler toolchain yet.

I checked that if we put libgccjit.so in the lib sysroot, and then pass -Zcodegen-backend=gcc to rustc, it works correctly. So putting libgccjit.so into the sysroot if GCC is configured as the default codegen backend is probably a good start. We should do this in the Assemble step.

@bors
Copy link
Collaborator

bors commented Aug 1, 2025

☔ The latest upstream changes (presumably #144773) made this pull request unmergeable. Please resolve the merge conflicts.

@GuillaumeGomez
Copy link
Member Author

Gonna do that then.

@Kobzol
Copy link
Member

Kobzol commented Aug 1, 2025

Note that I'm currently refactoring the codegen backends quite a lot. So if you don't mind, I'd try to prepare this once that refactoring is done.

@GuillaumeGomez
Copy link
Member Author

Even the Assemble phase? If so, please ping me so I can do it once you're done. ;)

@Kobzol
Copy link
Member

Kobzol commented Aug 1, 2025

Yeah, that too a little bit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-compiletest Area: The compiletest test runner A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants