Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 139 additions & 0 deletions .github/workflows/nightly_rustc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
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"
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

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: |
echo $HOME
echo "*****"
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

- 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
# 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

- 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

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

- 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

- 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
run: |
rustc +my-toolchain -V > output
grep rustc output

- 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)
18 changes: 18 additions & 0 deletions tests/bootstraps/bootstrap.m68k-unknown-linux-gnu.toml
Original file line number Diff line number Diff line change
@@ -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"
11 changes: 11 additions & 0 deletions tests/bootstraps/bootstrap.x86_64-unknown-linux-gnu.toml
Original file line number Diff line number Diff line change
@@ -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