From 38e8e85443634a2b3093e149dc1b0f90dbd84912 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Tue, 16 Dec 2025 11:05:14 -0500 Subject: [PATCH 01/15] Add CI compiling rustc --- .github/workflows/nightly_rustc.yml | 66 +++++++++++++++++++ .../bootstrap.m68k-unknown-linux-gnu.toml | 18 +++++ .../bootstrap.x86_64-unknown-linux-gnu.toml | 11 ++++ 3 files changed, 95 insertions(+) create mode 100644 .github/workflows/nightly_rustc.yml create mode 100644 tests/bootstraps/bootstrap.m68k-unknown-linux-gnu.toml create mode 100644 tests/bootstraps/bootstrap.x86_64-unknown-linux-gnu.toml diff --git a/.github/workflows/nightly_rustc.yml b/.github/workflows/nightly_rustc.yml new file mode 100644 index 00000000000..d8e1e877db1 --- /dev/null +++ b/.github/workflows/nightly_rustc.yml @@ -0,0 +1,66 @@ +name: Nightly compilation of rustc with rustc_codegen_gcc + +on: + pull_request: + # TODO: remove pull_request and add schedule to run during the night. + +env: + # Enable backtraces for easier debugging + RUST_BACKTRACE: 1 + +jobs: + build: + runs-on: ubuntu-24.04 + + strategy: + fail-fast: false + matrix: + arch: + - host_target: "x86_64-unknown-linux-gnu" + gcc_urls: > + https://github.com/rust-lang/gcc/releases/latest/download/gcc-15.deb + - host_target: "m68k-unknown-linux-gnu" + gcc_urls: > + https://github.com/rust-lang/gcc/releases/latest/download/gcc-15.deb + https://github.com/cross-cg-gcc-tools/cross-gcc/releases/latest/download/gcc-m68k-15.deb + + steps: + - uses: actions/checkout@v4 + with: + path: "rustc_codegen_gcc" + + - uses: actions/checkout@v4 + with: + repository: "rust-lang/rust" + path: "rust" + fetch-depth: 10 + + - run: | + ls + echo "*****" + ls .. + echo "*****" + ls rust + echo "*****" + + # `rustup show` installs from rust-toolchain.toml + - name: Setup rust toolchain + run: rustup show + + - name: Setup rust cache + uses: Swatinem/rust-cache@v2 + + - name: Download and install artifacts + run: | + urls=(${{ matrix.arch.gcc_urls }}) + for url in "${urls[@]}"; do + curl -L -o package.deb $url + sudo dpkg --force-overwrite -i package.deb + done + + # TODO: patch linux-raw-sys and rustix. + + - name: Compile rustc + run: | + cd rust + ./x build --host=${{ matrix.arch.host_target }} --stage 2 --config ../rustc_codegen_gcc/tests/bootstraps/bootstrap.${{ matrix.arch.host_target }}.toml diff --git a/tests/bootstraps/bootstrap.m68k-unknown-linux-gnu.toml b/tests/bootstraps/bootstrap.m68k-unknown-linux-gnu.toml new file mode 100644 index 00000000000..e7a7626ad01 --- /dev/null +++ b/tests/bootstraps/bootstrap.m68k-unknown-linux-gnu.toml @@ -0,0 +1,18 @@ +profile = "compiler" +change-id = 140732 + +[build] +target = ["m68k-unknown-linux-gnu"] + +[rust] +codegen-backends = ["gcc"] +deny-warnings = false +debug-assertions = false +debug-assertions-std = false + +[gcc] +download-ci-gcc = true +libgccjit-libs-dir = "/home/runner/libgccjit-libs-dir" + +[target.m68k-unknown-linux-gnu] +cc = "/home/runner/work/rustc_codegen_gcc/rustc_codegen_gcc/cross-gcc/usr/bin/m68k-unknown-linux-gnu-gcc" diff --git a/tests/bootstraps/bootstrap.x86_64-unknown-linux-gnu.toml b/tests/bootstraps/bootstrap.x86_64-unknown-linux-gnu.toml new file mode 100644 index 00000000000..32daaa57237 --- /dev/null +++ b/tests/bootstraps/bootstrap.x86_64-unknown-linux-gnu.toml @@ -0,0 +1,11 @@ +profile = "compiler" +change-id = 140732 + +[rust] +codegen-backends = ["gcc"] +deny-warnings = false +debug-assertions = false +debug-assertions-std = false + +[gcc] +download-ci-gcc = true From 3860631c56fc417fcc81263d0433c066017a39f6 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Tue, 16 Dec 2025 13:52:41 -0500 Subject: [PATCH 02/15] Compile program in the nightly CI --- .github/workflows/nightly_rustc.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.github/workflows/nightly_rustc.yml b/.github/workflows/nightly_rustc.yml index d8e1e877db1..c3ee506e99f 100644 --- a/.github/workflows/nightly_rustc.yml +++ b/.github/workflows/nightly_rustc.yml @@ -64,3 +64,20 @@ jobs: run: | cd rust ./x build --host=${{ matrix.arch.host_target }} --stage 2 --config ../rustc_codegen_gcc/tests/bootstraps/bootstrap.${{ matrix.arch.host_target }}.toml + + - name: Link toolchain + run: rustup toolchain link my-toolchain build/${{ matrix.arch.host_target }}/stage2 + + - name: Compile test program + run: | + cd rustc_codegen_gcc/tests/hello-world + cargo +my-toolchain build + + objcopy --dump-section .comment=comment target/debug/hello_world + grep "rustc version .* with libgccjit" comment + grep 'GCC: ' comment + + cargo +my-toolchain run > hello_world_stdout + + expected_output="40" + test $(cat hello_world_stdout) == $expected_output || (echo "Output differs. Actual output: $(cat hello_world_stdout)"; exit 1) From 577068a04f904d95a25908a9ac39a588f8071001 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Tue, 16 Dec 2025 14:26:44 -0500 Subject: [PATCH 03/15] Add smoke test --- .github/workflows/nightly_rustc.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/nightly_rustc.yml b/.github/workflows/nightly_rustc.yml index c3ee506e99f..db653e3c895 100644 --- a/.github/workflows/nightly_rustc.yml +++ b/.github/workflows/nightly_rustc.yml @@ -68,6 +68,11 @@ jobs: - name: Link toolchain run: rustup toolchain link my-toolchain build/${{ matrix.arch.host_target }}/stage2 + - name: Smoke test + run: | + rustc +my-toolchain -V > output + grep rustc output + - name: Compile test program run: | cd rustc_codegen_gcc/tests/hello-world From b3fbe1d331c9d94c44c5872632cfe4b1cbd10de7 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Tue, 16 Dec 2025 15:22:42 -0500 Subject: [PATCH 04/15] Fix link toolchain --- .github/workflows/nightly_rustc.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/nightly_rustc.yml b/.github/workflows/nightly_rustc.yml index db653e3c895..abca033b87e 100644 --- a/.github/workflows/nightly_rustc.yml +++ b/.github/workflows/nightly_rustc.yml @@ -66,7 +66,14 @@ jobs: ./x build --host=${{ matrix.arch.host_target }} --stage 2 --config ../rustc_codegen_gcc/tests/bootstraps/bootstrap.${{ matrix.arch.host_target }}.toml - name: Link toolchain - run: rustup toolchain link my-toolchain build/${{ matrix.arch.host_target }}/stage2 + run: | + cd rust + ls + echo **** + ls build + echo **** + ls build/${{ matrix.arch.host_target }} + rustup toolchain link my-toolchain build/${{ matrix.arch.host_target }}/stage2 - name: Smoke test run: | From 869b8af1ab258379fbae352b68b181ba1c459962 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Tue, 16 Dec 2025 14:06:18 -0500 Subject: [PATCH 05/15] Create libgccjit-libs-dir --- .github/workflows/nightly_rustc.yml | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/.github/workflows/nightly_rustc.yml b/.github/workflows/nightly_rustc.yml index abca033b87e..8a7ab9bd8b4 100644 --- a/.github/workflows/nightly_rustc.yml +++ b/.github/workflows/nightly_rustc.yml @@ -17,12 +17,13 @@ jobs: matrix: arch: - host_target: "x86_64-unknown-linux-gnu" + cross_target: "" gcc_urls: > https://github.com/rust-lang/gcc/releases/latest/download/gcc-15.deb - host_target: "m68k-unknown-linux-gnu" + cross_target: "m68k" gcc_urls: > https://github.com/rust-lang/gcc/releases/latest/download/gcc-15.deb - https://github.com/cross-cg-gcc-tools/cross-gcc/releases/latest/download/gcc-m68k-15.deb steps: - uses: actions/checkout@v4 @@ -36,6 +37,8 @@ jobs: fetch-depth: 10 - run: | + echo $HOME + echo "*****" ls echo "*****" ls .. @@ -59,9 +62,32 @@ jobs: done # TODO: patch linux-raw-sys and rustix. + - name: Move libgccjit.so in libgccjit-libs-dir + if: ${{ matrix.arch.cross_target != '' }} + run: | + curl -LO https://github.com/cross-cg-gcc-tools/cross-gcc/releases/latest/download/gcc-${{ matrix.arch.cross_target }}-15.deb + + sudo dpkg-deb -x gcc-${{ matrix.arch.cross_target }}-15.deb cross-gcc + echo **** + ls cross-gcc + echo **** + ls cross-gcc/usr/lib + echo **** + ls -R + dir=$HOME/libgccjit-libs-dir/x86_64-unknown-linux-gnu/${{ matrix.arch.host_target }} + mkdir -p $dir + # TODO: create a symlink instead of a copy. + cp cross-gcc/usr/lib/libgccjit.so.0.0.1 $dir/libgccjit.so + + echo "$(pwd)/cross-gcc/usr/bin" >> $GITHUB_PATH + + ls /home/runner/libgccjit-libs-dir/x86_64-unknown-linux-gnu/m68k-unknown-linux-gnu/libgccjit.so + echo **** + ls -R /home/runner/libgccjit-libs-dir - name: Compile rustc run: | + echo $PATH cd rust ./x build --host=${{ matrix.arch.host_target }} --stage 2 --config ../rustc_codegen_gcc/tests/bootstraps/bootstrap.${{ matrix.arch.host_target }}.toml From fb83dfb1bec60b8537ebe0dd9f4350e9de819641 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Sat, 20 Dec 2025 08:05:09 -0500 Subject: [PATCH 06/15] Download native libgccjit.so for m68k --- .github/workflows/nightly_rustc.yml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/nightly_rustc.yml b/.github/workflows/nightly_rustc.yml index 8a7ab9bd8b4..3e204841de2 100644 --- a/.github/workflows/nightly_rustc.yml +++ b/.github/workflows/nightly_rustc.yml @@ -61,19 +61,12 @@ jobs: sudo dpkg --force-overwrite -i package.deb done - # TODO: patch linux-raw-sys and rustix. - - name: Move libgccjit.so in libgccjit-libs-dir + - name: Download cross-compiling libgccjit.so and move it in libgccjit-libs-dir if: ${{ matrix.arch.cross_target != '' }} run: | curl -LO https://github.com/cross-cg-gcc-tools/cross-gcc/releases/latest/download/gcc-${{ matrix.arch.cross_target }}-15.deb sudo dpkg-deb -x gcc-${{ matrix.arch.cross_target }}-15.deb cross-gcc - echo **** - ls cross-gcc - echo **** - ls cross-gcc/usr/lib - echo **** - ls -R dir=$HOME/libgccjit-libs-dir/x86_64-unknown-linux-gnu/${{ matrix.arch.host_target }} mkdir -p $dir # TODO: create a symlink instead of a copy. @@ -81,9 +74,16 @@ jobs: echo "$(pwd)/cross-gcc/usr/bin" >> $GITHUB_PATH - ls /home/runner/libgccjit-libs-dir/x86_64-unknown-linux-gnu/m68k-unknown-linux-gnu/libgccjit.so - echo **** - ls -R /home/runner/libgccjit-libs-dir + - name: Download native libgccjit.so and move it in libgccjit-libs-dir + if: ${{ matrix.arch.cross_target != '' }} + run: | + curl -LO https://github.com/cross-cg-gcc-tools/native-gcc/releases/latest/download/libgccjit-${{ matrix.arch.cross_target }}.so + + dir=$HOME/libgccjit-libs-dir/${{ matrix.arch.host_target }}/${{ matrix.arch.host_target }} + mkdir -p $dir + mv libgccjit-${{ matrix.arch.cross_target }}.so $dir/libgccjit.so + + # TODO: patch linux-raw-sys and rustix. - name: Compile rustc run: | From 26c3f6085c3bd894518e803317b9356a1203e711 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Sat, 20 Dec 2025 09:28:49 -0500 Subject: [PATCH 07/15] Patch linux-raw-sys and rustix --- .github/workflows/nightly_rustc.yml | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/.github/workflows/nightly_rustc.yml b/.github/workflows/nightly_rustc.yml index 3e204841de2..815cd8717c6 100644 --- a/.github/workflows/nightly_rustc.yml +++ b/.github/workflows/nightly_rustc.yml @@ -83,7 +83,29 @@ jobs: mkdir -p $dir mv libgccjit-${{ matrix.arch.cross_target }}.so $dir/libgccjit.so - # TODO: patch linux-raw-sys and rustix. + - name: Patch linux-raw-sys and rustix. + if: ${{ matrix.arch.cross_target != '' }} + run: | + cd rust + + cat <<'EOF' > patch.toml + [patch.crates-io] + linux-raw-sys = { git = "https://github.com/antoyo/linux-raw-sys", branch = "m68k-support" } + rustix = { git = "https://github.com/antoyo/rustix", branch = "m68k-support" } + EOF + + cat patch.toml >> Cargo.toml + cat patch.toml >> compiler/rustc_codegen_gcc/Cargo.toml + + cargo update -p rustix + cd compiler/rustc_codegen_gcc/ + cargo update -p rustix + + echo Checking Rust + cargo tree -i linux-raw-sys 2>&1 | grep "was not used in the crate graph" && (echo "Unused patches found"; cargo tree; exit 1) || exit 0 + + echo Checking rustc_codegen_gcc + cargo tree --manifest-path compiler/rustc_codegen_gcc/Cargo.toml -i linux-raw-sys 2>&1 | grep "was not used in the crate graph" && (echo "Unused patches found"; cargo tree; exit 1) || exit 0 - name: Compile rustc run: | From 2b47c6f0e79fe5bbd908ee66bef1063dc94412c1 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Sat, 20 Dec 2025 11:09:47 -0500 Subject: [PATCH 08/15] Move libgccjit instead of copying it --- .github/workflows/nightly_rustc.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/nightly_rustc.yml b/.github/workflows/nightly_rustc.yml index 815cd8717c6..dd8f90f2571 100644 --- a/.github/workflows/nightly_rustc.yml +++ b/.github/workflows/nightly_rustc.yml @@ -69,8 +69,7 @@ jobs: sudo dpkg-deb -x gcc-${{ matrix.arch.cross_target }}-15.deb cross-gcc dir=$HOME/libgccjit-libs-dir/x86_64-unknown-linux-gnu/${{ matrix.arch.host_target }} mkdir -p $dir - # TODO: create a symlink instead of a copy. - cp cross-gcc/usr/lib/libgccjit.so.0.0.1 $dir/libgccjit.so + sudo mv cross-gcc/usr/lib/libgccjit.so.0.0.1 $dir/libgccjit.so echo "$(pwd)/cross-gcc/usr/bin" >> $GITHUB_PATH From a749693d0dcd92e13f8db57a1096ada36ca176b1 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Sat, 20 Dec 2025 12:08:05 -0500 Subject: [PATCH 09/15] Free disk space in the CI since the m68k rustc build runs out of disk space --- .github/workflows/nightly_rustc.yml | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/.github/workflows/nightly_rustc.yml b/.github/workflows/nightly_rustc.yml index dd8f90f2571..953f029222d 100644 --- a/.github/workflows/nightly_rustc.yml +++ b/.github/workflows/nightly_rustc.yml @@ -36,15 +36,17 @@ jobs: path: "rust" fetch-depth: 10 - - run: | - echo $HOME - echo "*****" - ls - echo "*****" - ls .. - echo "*****" - ls rust - echo "*****" + - name: Free Disk Space + uses: endersonmenezes/free-disk-space@v3 + with: + remove_android: true + remove_dotnet: true + remove_haskell: true + remove_tool_cache: true + remove_swap: true + remove_packages: "azure-cli google-cloud-cli microsoft-edge-stable google-chrome-stable firefox postgresql* temurin-* *llvm* mysql* dotnet-sdk-*" + remove_packages_one_command: true + remove_folders: "/usr/share/swift /usr/share/miniconda /usr/share/az* /usr/local/lib/node_modules /usr/local/share/chromium /usr/local/share/powershell /usr/local/julia /usr/local/aws-cli /usr/local/aws-sam-cli /usr/share/gradle" # `rustup show` installs from rust-toolchain.toml - name: Setup rust toolchain @@ -115,11 +117,6 @@ jobs: - name: Link toolchain run: | cd rust - ls - echo **** - ls build - echo **** - ls build/${{ matrix.arch.host_target }} rustup toolchain link my-toolchain build/${{ matrix.arch.host_target }}/stage2 - name: Smoke test From 11fa3bf77f3378e5f691fe4b83bf38787d94aaf3 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Sat, 20 Dec 2025 14:08:57 -0500 Subject: [PATCH 10/15] Execute smoke test in VM for m68k --- .github/workflows/nightly_rustc.yml | 37 +++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/.github/workflows/nightly_rustc.yml b/.github/workflows/nightly_rustc.yml index 953f029222d..efd80a5e03e 100644 --- a/.github/workflows/nightly_rustc.yml +++ b/.github/workflows/nightly_rustc.yml @@ -48,6 +48,12 @@ jobs: remove_packages_one_command: true remove_folders: "/usr/share/swift /usr/share/miniconda /usr/share/az* /usr/local/lib/node_modules /usr/local/share/chromium /usr/local/share/powershell /usr/local/julia /usr/local/aws-cli /usr/local/aws-sam-cli /usr/share/gradle" + - name: Install packages + if: ${{ matrix.arch.cross_target != '' }} + run: | + sudo apt-get update + sudo apt-get install qemu-system qemu-user-static + # `rustup show` installs from rust-toolchain.toml - name: Setup rust toolchain run: rustup show @@ -63,6 +69,10 @@ jobs: sudo dpkg --force-overwrite -i package.deb done + - name: Download VM artifact + if: ${{ matrix.arch.cross_target != '' }} + run: curl -LO https://github.com/cross-cg-gcc-tools/vms/releases/latest/download/debian-${{ matrix.arch.cross_target }}.img + - name: Download cross-compiling libgccjit.so and move it in libgccjit-libs-dir if: ${{ matrix.arch.cross_target != '' }} run: | @@ -84,6 +94,13 @@ jobs: mkdir -p $dir mv libgccjit-${{ matrix.arch.cross_target }}.so $dir/libgccjit.so + - name: Prepare VM + if: ${{ matrix.arch.cross_target != '' }} + run: | + mkdir vm + sudo mount debian-${{ matrix.arch.cross_target }}.img vm + sudo cp $(which qemu-${{ matrix.arch.cross_target }}-static) vm/usr/bin/ + - name: Patch linux-raw-sys and rustix. if: ${{ matrix.arch.cross_target != '' }} run: | @@ -115,15 +132,35 @@ jobs: ./x build --host=${{ matrix.arch.host_target }} --stage 2 --config ../rustc_codegen_gcc/tests/bootstraps/bootstrap.${{ matrix.arch.host_target }}.toml - name: Link toolchain + if: ${{ matrix.arch.cross_target == '' }} run: | cd rust rustup toolchain link my-toolchain build/${{ matrix.arch.host_target }}/stage2 - name: Smoke test + if: ${{ matrix.arch.cross_target == '' }} run: | rustc +my-toolchain -V > output grep rustc output + - name: Copy toolchain in VM + if: ${{ matrix.arch.cross_target != '' }} + run: | + echo 1 . + ls + echo 2 vm + ls vm + echo 3 vm/home + ls vm/home + echo **** + sudo rsync -a --exclude=stage2/lib/rustlib/src --exclude=stage2/lib/rustlib/rustc-src/ rust/build/m68k-unknown-linux-gnu/stage2 vm/home/stage2 + + - name: Smoke test + if: ${{ matrix.arch.cross_target != '' }} + run: | + sudo chroot vm qemu-m68k-static /home/stage2/rustc > output + grep rustc output + - name: Compile test program run: | cd rustc_codegen_gcc/tests/hello-world From e45981956fdef31f0657c365565e06fb18d60ebb Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Sat, 20 Dec 2025 20:55:19 -0500 Subject: [PATCH 11/15] Generate VM instead of downloading it because we need a bigger one --- .github/workflows/nightly_rustc.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/nightly_rustc.yml b/.github/workflows/nightly_rustc.yml index efd80a5e03e..df23c5656e6 100644 --- a/.github/workflows/nightly_rustc.yml +++ b/.github/workflows/nightly_rustc.yml @@ -22,6 +22,7 @@ jobs: https://github.com/rust-lang/gcc/releases/latest/download/gcc-15.deb - host_target: "m68k-unknown-linux-gnu" cross_target: "m68k" + debian_url: "http://ftp.ports.debian.org/debian-ports" gcc_urls: > https://github.com/rust-lang/gcc/releases/latest/download/gcc-15.deb @@ -52,7 +53,7 @@ jobs: if: ${{ matrix.arch.cross_target != '' }} run: | sudo apt-get update - sudo apt-get install qemu-system qemu-user-static + sudo apt-get install debootstrap qemu-system qemu-user-static # `rustup show` installs from rust-toolchain.toml - name: Setup rust toolchain @@ -69,9 +70,15 @@ jobs: sudo dpkg --force-overwrite -i package.deb done - - name: Download VM artifact + - name: Generate Debian qemu image if: ${{ matrix.arch.cross_target != '' }} - run: curl -LO https://github.com/cross-cg-gcc-tools/vms/releases/latest/download/debian-${{ matrix.arch.cross_target }}.img + run: | + dd if=/dev/zero of=debian.img bs=1M count=15360 + mkfs.ext4 debian.img -L root + mkdir vm + sudo mount debian.img vm + sudo debootstrap --no-check-gpg --arch=${{ matrix.arch.cross_target }} --foreign unstable vm ${{ matrix.arch.debian_url }} + sudo cp $(which qemu-${{ matrix.arch.cross_target }}-static) vm/usr/bin/ - name: Download cross-compiling libgccjit.so and move it in libgccjit-libs-dir if: ${{ matrix.arch.cross_target != '' }} @@ -94,13 +101,6 @@ jobs: mkdir -p $dir mv libgccjit-${{ matrix.arch.cross_target }}.so $dir/libgccjit.so - - name: Prepare VM - if: ${{ matrix.arch.cross_target != '' }} - run: | - mkdir vm - sudo mount debian-${{ matrix.arch.cross_target }}.img vm - sudo cp $(which qemu-${{ matrix.arch.cross_target }}-static) vm/usr/bin/ - - name: Patch linux-raw-sys and rustix. if: ${{ matrix.arch.cross_target != '' }} run: | From 359be2c001e9103de40fccb2036d4be617ee44e4 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Sun, 21 Dec 2025 07:53:06 -0500 Subject: [PATCH 12/15] Fix smoke test for cross-compilation --- .github/workflows/nightly_rustc.yml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/nightly_rustc.yml b/.github/workflows/nightly_rustc.yml index df23c5656e6..da43d256637 100644 --- a/.github/workflows/nightly_rustc.yml +++ b/.github/workflows/nightly_rustc.yml @@ -150,15 +150,22 @@ jobs: ls echo 2 vm ls vm + sudo rsync -a --exclude=stage2/lib/rustlib/src --exclude=stage2/lib/rustlib/rustc-src/ rust/build/${{ matrix.arch.host_target }}/stage2/ vm/home/stage2 echo 3 vm/home ls vm/home - echo **** - sudo rsync -a --exclude=stage2/lib/rustlib/src --exclude=stage2/lib/rustlib/rustc-src/ rust/build/m68k-unknown-linux-gnu/stage2 vm/home/stage2 + echo 4 vm/home/stage2 + ls -l vm/home/stage2 + echo 5 vm/home/stage2/stage2 + ls vm/home/stage2/stage2 || true + echo 6 vm/home/stage2/bin + ls vm/home/stage2/bin + echo 7 - name: Smoke test if: ${{ matrix.arch.cross_target != '' }} run: | - sudo chroot vm qemu-m68k-static /home/stage2/rustc > output + sudo chroot vm qemu-${{ matrix.arch.cross_target }}-static /bin/sh -c '/home/stage2/bin/rustc' > output + echo output grep rustc output - name: Compile test program From 9d9105ea74a6c1f790f1f5db86638dfc06284544 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Sun, 21 Dec 2025 14:16:30 -0500 Subject: [PATCH 13/15] Cleanup --- .github/workflows/nightly_rustc.yml | 31 +++++++---------------------- 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/.github/workflows/nightly_rustc.yml b/.github/workflows/nightly_rustc.yml index da43d256637..bda3d25031d 100644 --- a/.github/workflows/nightly_rustc.yml +++ b/.github/workflows/nightly_rustc.yml @@ -18,13 +18,9 @@ jobs: arch: - host_target: "x86_64-unknown-linux-gnu" cross_target: "" - gcc_urls: > - https://github.com/rust-lang/gcc/releases/latest/download/gcc-15.deb - host_target: "m68k-unknown-linux-gnu" cross_target: "m68k" debian_url: "http://ftp.ports.debian.org/debian-ports" - gcc_urls: > - https://github.com/rust-lang/gcc/releases/latest/download/gcc-15.deb steps: - uses: actions/checkout@v4 @@ -37,6 +33,7 @@ jobs: path: "rust" fetch-depth: 10 + # The compilation of rustc for m68k requires a lot of disk space, so free some space up. - name: Free Disk Space uses: endersonmenezes/free-disk-space@v3 with: @@ -64,11 +61,8 @@ jobs: - name: Download and install artifacts run: | - urls=(${{ matrix.arch.gcc_urls }}) - for url in "${urls[@]}"; do - curl -L -o package.deb $url - sudo dpkg --force-overwrite -i package.deb - done + curl -L -o package.deb https://github.com/rust-lang/gcc/releases/latest/download/gcc-15.deb + sudo dpkg --force-overwrite -i package.deb - name: Generate Debian qemu image if: ${{ matrix.arch.cross_target != '' }} @@ -119,6 +113,8 @@ jobs: cd compiler/rustc_codegen_gcc/ cargo update -p rustix + cd ../.. + echo Checking Rust cargo tree -i linux-raw-sys 2>&1 | grep "was not used in the crate graph" && (echo "Unused patches found"; cargo tree; exit 1) || exit 0 @@ -127,7 +123,6 @@ jobs: - name: Compile rustc run: | - echo $PATH cd rust ./x build --host=${{ matrix.arch.host_target }} --stage 2 --config ../rustc_codegen_gcc/tests/bootstraps/bootstrap.${{ matrix.arch.host_target }}.toml @@ -146,29 +141,17 @@ jobs: - name: Copy toolchain in VM if: ${{ matrix.arch.cross_target != '' }} run: | - echo 1 . - ls - echo 2 vm - ls vm sudo rsync -a --exclude=stage2/lib/rustlib/src --exclude=stage2/lib/rustlib/rustc-src/ rust/build/${{ matrix.arch.host_target }}/stage2/ vm/home/stage2 - echo 3 vm/home - ls vm/home - echo 4 vm/home/stage2 - ls -l vm/home/stage2 - echo 5 vm/home/stage2/stage2 - ls vm/home/stage2/stage2 || true - echo 6 vm/home/stage2/bin - ls vm/home/stage2/bin - echo 7 - name: Smoke test if: ${{ matrix.arch.cross_target != '' }} run: | sudo chroot vm qemu-${{ matrix.arch.cross_target }}-static /bin/sh -c '/home/stage2/bin/rustc' > output - echo output grep rustc output - name: Compile test program + # TODO: also compile a test program for m68k when the compiler works. + if: ${{ matrix.arch.cross_target == '' }} run: | cd rustc_codegen_gcc/tests/hello-world cargo +my-toolchain build From f4caf7f6a8e5051858b5c9d7dfa72bfefbcb1d4e Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Sun, 21 Dec 2025 14:20:16 -0500 Subject: [PATCH 14/15] Split nightly action in two actions --- .github/workflows/nightly_cross_rustc.yml | 144 ++++++++++++++++++++++ .github/workflows/nightly_rustc.yml | 95 -------------- 2 files changed, 144 insertions(+), 95 deletions(-) create mode 100644 .github/workflows/nightly_cross_rustc.yml diff --git a/.github/workflows/nightly_cross_rustc.yml b/.github/workflows/nightly_cross_rustc.yml new file mode 100644 index 00000000000..6aecb6207e1 --- /dev/null +++ b/.github/workflows/nightly_cross_rustc.yml @@ -0,0 +1,144 @@ +name: Nightly cross-compilation of rustc with rustc_codegen_gcc + +on: + pull_request: + # TODO: remove pull_request and add schedule to run during the night. + +env: + # Enable backtraces for easier debugging + RUST_BACKTRACE: 1 + +jobs: + build: + runs-on: ubuntu-24.04 + + strategy: + fail-fast: false + matrix: + arch: + - host_target: "m68k-unknown-linux-gnu" + cross_target: "m68k" + debian_url: "http://ftp.ports.debian.org/debian-ports" + + steps: + - uses: actions/checkout@v4 + with: + path: "rustc_codegen_gcc" + + - uses: actions/checkout@v4 + with: + repository: "rust-lang/rust" + path: "rust" + fetch-depth: 10 + + # The compilation of rustc for m68k requires a lot of disk space, so free some space up. + - name: Free Disk Space + uses: endersonmenezes/free-disk-space@v3 + with: + remove_android: true + remove_dotnet: true + remove_haskell: true + remove_tool_cache: true + remove_swap: true + remove_packages: "azure-cli google-cloud-cli microsoft-edge-stable google-chrome-stable firefox postgresql* temurin-* *llvm* mysql* dotnet-sdk-*" + remove_packages_one_command: true + remove_folders: "/usr/share/swift /usr/share/miniconda /usr/share/az* /usr/local/lib/node_modules /usr/local/share/chromium /usr/local/share/powershell /usr/local/julia /usr/local/aws-cli /usr/local/aws-sam-cli /usr/share/gradle" + + - name: Install packages + run: | + sudo apt-get update + sudo apt-get install debootstrap qemu-system qemu-user-static + + # `rustup show` installs from rust-toolchain.toml + - name: Setup rust toolchain + run: rustup show + + - name: Setup rust cache + uses: Swatinem/rust-cache@v2 + + - name: Download and install artifacts + run: | + curl -L -o package.deb https://github.com/rust-lang/gcc/releases/latest/download/gcc-15.deb + sudo dpkg --force-overwrite -i package.deb + + - name: Generate Debian qemu image + run: | + dd if=/dev/zero of=debian.img bs=1M count=15360 + mkfs.ext4 debian.img -L root + mkdir vm + sudo mount debian.img vm + sudo debootstrap --no-check-gpg --arch=${{ matrix.arch.cross_target }} --foreign unstable vm ${{ matrix.arch.debian_url }} + sudo cp $(which qemu-${{ matrix.arch.cross_target }}-static) vm/usr/bin/ + + - name: Download cross-compiling libgccjit.so and move it in libgccjit-libs-dir + run: | + curl -LO https://github.com/cross-cg-gcc-tools/cross-gcc/releases/latest/download/gcc-${{ matrix.arch.cross_target }}-15.deb + + sudo dpkg-deb -x gcc-${{ matrix.arch.cross_target }}-15.deb cross-gcc + dir=$HOME/libgccjit-libs-dir/x86_64-unknown-linux-gnu/${{ matrix.arch.host_target }} + mkdir -p $dir + sudo mv cross-gcc/usr/lib/libgccjit.so.0.0.1 $dir/libgccjit.so + + echo "$(pwd)/cross-gcc/usr/bin" >> $GITHUB_PATH + + - name: Download native libgccjit.so and move it in libgccjit-libs-dir + run: | + curl -LO https://github.com/cross-cg-gcc-tools/native-gcc/releases/latest/download/libgccjit-${{ matrix.arch.cross_target }}.so + + dir=$HOME/libgccjit-libs-dir/${{ matrix.arch.host_target }}/${{ matrix.arch.host_target }} + mkdir -p $dir + mv libgccjit-${{ matrix.arch.cross_target }}.so $dir/libgccjit.so + + - name: Patch linux-raw-sys and rustix. + run: | + cd rust + + cat <<'EOF' > patch.toml + [patch.crates-io] + linux-raw-sys = { git = "https://github.com/antoyo/linux-raw-sys", branch = "m68k-support" } + rustix = { git = "https://github.com/antoyo/rustix", branch = "m68k-support" } + EOF + + cat patch.toml >> Cargo.toml + cat patch.toml >> compiler/rustc_codegen_gcc/Cargo.toml + + cargo update -p rustix + cd compiler/rustc_codegen_gcc/ + cargo update -p rustix + + cd ../.. + + echo Checking Rust + cargo tree -i linux-raw-sys 2>&1 | grep "was not used in the crate graph" && (echo "Unused patches found"; cargo tree; exit 1) || exit 0 + + echo Checking rustc_codegen_gcc + cargo tree --manifest-path compiler/rustc_codegen_gcc/Cargo.toml -i linux-raw-sys 2>&1 | grep "was not used in the crate graph" && (echo "Unused patches found"; cargo tree; exit 1) || exit 0 + + - name: Compile rustc + run: | + cd rust + ./x build --host=${{ matrix.arch.host_target }} --stage 2 --config ../rustc_codegen_gcc/tests/bootstraps/bootstrap.${{ matrix.arch.host_target }}.toml + + - name: Copy toolchain in VM + run: | + sudo rsync -a --exclude=stage2/lib/rustlib/src --exclude=stage2/lib/rustlib/rustc-src/ rust/build/${{ matrix.arch.host_target }}/stage2/ vm/home/stage2 + + - name: Smoke test + run: | + sudo chroot vm qemu-${{ matrix.arch.cross_target }}-static /bin/sh -c '/home/stage2/bin/rustc' > output + grep rustc output + + # TODO: compile a test program for m68k when the compiler works. + #- name: Compile test program + #run: | + #cd rustc_codegen_gcc/tests/hello-world + #cargo +my-toolchain build + + #objcopy --dump-section .comment=comment target/debug/hello_world + #grep "rustc version .* with libgccjit" comment + #grep 'GCC: ' comment + + #cargo +my-toolchain run > hello_world_stdout + + #expected_output="40" + #test $(cat hello_world_stdout) == $expected_output || (echo "Output differs. Actual output: $(cat hello_world_stdout)"; exit 1) diff --git a/.github/workflows/nightly_rustc.yml b/.github/workflows/nightly_rustc.yml index bda3d25031d..49477bca81f 100644 --- a/.github/workflows/nightly_rustc.yml +++ b/.github/workflows/nightly_rustc.yml @@ -17,10 +17,6 @@ jobs: matrix: arch: - host_target: "x86_64-unknown-linux-gnu" - cross_target: "" - - host_target: "m68k-unknown-linux-gnu" - cross_target: "m68k" - debian_url: "http://ftp.ports.debian.org/debian-ports" steps: - uses: actions/checkout@v4 @@ -33,25 +29,6 @@ jobs: path: "rust" fetch-depth: 10 - # The compilation of rustc for m68k requires a lot of disk space, so free some space up. - - name: Free Disk Space - uses: endersonmenezes/free-disk-space@v3 - with: - remove_android: true - remove_dotnet: true - remove_haskell: true - remove_tool_cache: true - remove_swap: true - remove_packages: "azure-cli google-cloud-cli microsoft-edge-stable google-chrome-stable firefox postgresql* temurin-* *llvm* mysql* dotnet-sdk-*" - remove_packages_one_command: true - remove_folders: "/usr/share/swift /usr/share/miniconda /usr/share/az* /usr/local/lib/node_modules /usr/local/share/chromium /usr/local/share/powershell /usr/local/julia /usr/local/aws-cli /usr/local/aws-sam-cli /usr/share/gradle" - - - name: Install packages - if: ${{ matrix.arch.cross_target != '' }} - run: | - sudo apt-get update - sudo apt-get install debootstrap qemu-system qemu-user-static - # `rustup show` installs from rust-toolchain.toml - name: Setup rust toolchain run: rustup show @@ -64,94 +41,22 @@ jobs: curl -L -o package.deb https://github.com/rust-lang/gcc/releases/latest/download/gcc-15.deb sudo dpkg --force-overwrite -i package.deb - - name: Generate Debian qemu image - if: ${{ matrix.arch.cross_target != '' }} - run: | - dd if=/dev/zero of=debian.img bs=1M count=15360 - mkfs.ext4 debian.img -L root - mkdir vm - sudo mount debian.img vm - sudo debootstrap --no-check-gpg --arch=${{ matrix.arch.cross_target }} --foreign unstable vm ${{ matrix.arch.debian_url }} - sudo cp $(which qemu-${{ matrix.arch.cross_target }}-static) vm/usr/bin/ - - - name: Download cross-compiling libgccjit.so and move it in libgccjit-libs-dir - if: ${{ matrix.arch.cross_target != '' }} - run: | - curl -LO https://github.com/cross-cg-gcc-tools/cross-gcc/releases/latest/download/gcc-${{ matrix.arch.cross_target }}-15.deb - - sudo dpkg-deb -x gcc-${{ matrix.arch.cross_target }}-15.deb cross-gcc - dir=$HOME/libgccjit-libs-dir/x86_64-unknown-linux-gnu/${{ matrix.arch.host_target }} - mkdir -p $dir - sudo mv cross-gcc/usr/lib/libgccjit.so.0.0.1 $dir/libgccjit.so - - echo "$(pwd)/cross-gcc/usr/bin" >> $GITHUB_PATH - - - name: Download native libgccjit.so and move it in libgccjit-libs-dir - if: ${{ matrix.arch.cross_target != '' }} - run: | - curl -LO https://github.com/cross-cg-gcc-tools/native-gcc/releases/latest/download/libgccjit-${{ matrix.arch.cross_target }}.so - - dir=$HOME/libgccjit-libs-dir/${{ matrix.arch.host_target }}/${{ matrix.arch.host_target }} - mkdir -p $dir - mv libgccjit-${{ matrix.arch.cross_target }}.so $dir/libgccjit.so - - - name: Patch linux-raw-sys and rustix. - if: ${{ matrix.arch.cross_target != '' }} - run: | - cd rust - - cat <<'EOF' > patch.toml - [patch.crates-io] - linux-raw-sys = { git = "https://github.com/antoyo/linux-raw-sys", branch = "m68k-support" } - rustix = { git = "https://github.com/antoyo/rustix", branch = "m68k-support" } - EOF - - cat patch.toml >> Cargo.toml - cat patch.toml >> compiler/rustc_codegen_gcc/Cargo.toml - - cargo update -p rustix - cd compiler/rustc_codegen_gcc/ - cargo update -p rustix - - cd ../.. - - echo Checking Rust - cargo tree -i linux-raw-sys 2>&1 | grep "was not used in the crate graph" && (echo "Unused patches found"; cargo tree; exit 1) || exit 0 - - echo Checking rustc_codegen_gcc - cargo tree --manifest-path compiler/rustc_codegen_gcc/Cargo.toml -i linux-raw-sys 2>&1 | grep "was not used in the crate graph" && (echo "Unused patches found"; cargo tree; exit 1) || exit 0 - - name: Compile rustc run: | cd rust ./x build --host=${{ matrix.arch.host_target }} --stage 2 --config ../rustc_codegen_gcc/tests/bootstraps/bootstrap.${{ matrix.arch.host_target }}.toml - name: Link toolchain - if: ${{ matrix.arch.cross_target == '' }} run: | cd rust rustup toolchain link my-toolchain build/${{ matrix.arch.host_target }}/stage2 - name: Smoke test - if: ${{ matrix.arch.cross_target == '' }} run: | rustc +my-toolchain -V > output grep rustc output - - name: Copy toolchain in VM - if: ${{ matrix.arch.cross_target != '' }} - run: | - sudo rsync -a --exclude=stage2/lib/rustlib/src --exclude=stage2/lib/rustlib/rustc-src/ rust/build/${{ matrix.arch.host_target }}/stage2/ vm/home/stage2 - - - name: Smoke test - if: ${{ matrix.arch.cross_target != '' }} - run: | - sudo chroot vm qemu-${{ matrix.arch.cross_target }}-static /bin/sh -c '/home/stage2/bin/rustc' > output - grep rustc output - - name: Compile test program - # TODO: also compile a test program for m68k when the compiler works. - if: ${{ matrix.arch.cross_target == '' }} run: | cd rustc_codegen_gcc/tests/hello-world cargo +my-toolchain build From f106af5596e604ef7f76034f5cfb8f3fa5ef55ae Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Sun, 21 Dec 2025 14:21:08 -0500 Subject: [PATCH 15/15] Show unused patch error after the output of `cargo tree` --- .github/workflows/nightly_cross_rustc.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/nightly_cross_rustc.yml b/.github/workflows/nightly_cross_rustc.yml index 6aecb6207e1..5d5554cd461 100644 --- a/.github/workflows/nightly_cross_rustc.yml +++ b/.github/workflows/nightly_cross_rustc.yml @@ -109,10 +109,10 @@ jobs: cd ../.. echo Checking Rust - cargo tree -i linux-raw-sys 2>&1 | grep "was not used in the crate graph" && (echo "Unused patches found"; cargo tree; exit 1) || exit 0 + cargo tree -i linux-raw-sys 2>&1 | grep "was not used in the crate graph" && { cargo tree; echo "Error: Unused patches found"; exit 1; } || exit 0 echo Checking rustc_codegen_gcc - cargo tree --manifest-path compiler/rustc_codegen_gcc/Cargo.toml -i linux-raw-sys 2>&1 | grep "was not used in the crate graph" && (echo "Unused patches found"; cargo tree; exit 1) || exit 0 + cargo tree --manifest-path compiler/rustc_codegen_gcc/Cargo.toml -i linux-raw-sys 2>&1 | grep "was not used in the crate graph" && { cargo tree; echo "Error: Unused patches found"; exit 1; } || exit 0 - name: Compile rustc run: | @@ -126,7 +126,7 @@ jobs: - name: Smoke test run: | sudo chroot vm qemu-${{ matrix.arch.cross_target }}-static /bin/sh -c '/home/stage2/bin/rustc' > output - grep rustc output + grep rustc2 output # TODO: compile a test program for m68k when the compiler works. #- name: Compile test program