about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2025-01-24 00:15:54 +0100
committerGitHub <noreply@github.com>2025-01-24 00:15:54 +0100
commitda8b35a76a00ef3923f7cef918d1dbf1e7561346 (patch)
tree2dcb762e1a2368f9fa136c596959ce70285bdf58
parente67227c3d598e6a62671344715e364e7bdd43e58 (diff)
parent00381ead1af39db9e5ce24a8da4dda59b714dbf7 (diff)
downloadrust-da8b35a76a00ef3923f7cef918d1dbf1e7561346.tar.gz
rust-da8b35a76a00ef3923f7cef918d1dbf1e7561346.zip
Rollup merge of #135638 - Kobzol:gcc-ci, r=onur-ozkan
Make it possible to build GCC on CI

This is the first step towards eventually enabling download of precompiled GCC from our CI.

Currently, we prebuild `libgccjit` on CI and cache it in Docker. This PR improves the bootstrap GCC step to make it work on CI, and also to make it faster by using sccache. After this change, an actual build on CI should take only 2-3 minutes.

Note that this PR does not yet remove the `build-gccjit.sh` script and replace it with the bootstrap step, I'll leave that to a follow-up PR.

The added `flex` package and the ZSTD library fix were needed to make GCC build on CI.

CC ``````@GuillaumeGomez``````

r? ``````@onur-ozkan``````
-rw-r--r--src/bootstrap/src/core/build_steps/gcc.rs54
-rw-r--r--src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile1
-rwxr-xr-xsrc/ci/docker/scripts/build-zstd.sh6
3 files changed, 57 insertions, 4 deletions
diff --git a/src/bootstrap/src/core/build_steps/gcc.rs b/src/bootstrap/src/core/build_steps/gcc.rs
index 563b715fa64..98b8635132b 100644
--- a/src/bootstrap/src/core/build_steps/gcc.rs
+++ b/src/bootstrap/src/core/build_steps/gcc.rs
@@ -12,6 +12,8 @@ use std::fs;
 use std::path::PathBuf;
 use std::sync::OnceLock;
 
+use build_helper::ci::CiEnv;
+
 use crate::Kind;
 use crate::core::builder::{Builder, RunConfig, ShouldRun, Step};
 use crate::core::config::TargetSelection;
@@ -112,16 +114,60 @@ impl Step for Gcc {
             return true;
         }
 
-        command(root.join("contrib/download_prerequisites")).current_dir(&root).run(builder);
-        command(root.join("configure"))
+        // 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()))
-            .run(builder);
+            .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(|| cxx.clone(), |ccache| format!("{ccache} {cxx}"));
+            configure_cmd.env("CXX", cxx);
+        }
+        configure_cmd.run(builder);
+
         command("make").current_dir(&out_dir).arg(format!("-j{}", builder.jobs())).run(builder);
         command("make").current_dir(&out_dir).arg("install").run(builder);
 
diff --git a/src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile b/src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile
index dde6fe7f6d0..3a396230582 100644
--- a/src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile
+++ b/src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile
@@ -34,6 +34,7 @@ RUN yum upgrade -y && \
       python3 \
       unzip \
       wget \
+      flex \
       xz \
       zlib-devel.i686 \
       zlib-devel.x86_64 \
diff --git a/src/ci/docker/scripts/build-zstd.sh b/src/ci/docker/scripts/build-zstd.sh
index a3d37ccc311..cffa7151e38 100755
--- a/src/ci/docker/scripts/build-zstd.sh
+++ b/src/ci/docker/scripts/build-zstd.sh
@@ -25,5 +25,11 @@ cd zstd-$ZSTD
 CFLAGS=-fPIC hide_output make -j$(nproc) VERBOSE=1
 hide_output make install
 
+# It doesn't seem to be possible to move destination directory
+# of the `make install` above. We thus copy the built artifacts
+# manually to our custom rustroot, so that it can be found through
+# LD_LIBRARY_PATH.
+cp /usr/local/lib/libzstd* /rustroot/lib64
+
 cd ..
 rm -rf zstd-$ZSTD