Skip to content

Commit b215beb

Browse files
committed
Auto merge of rust-lang#127566 - GuillaumeGomez:sync-cg_gcc, r=GuillaumeGomez
Sync rustc_codegen_gcc Follow-up of rust-lang/rustc_codegen_gcc#535. cc `@antoyo`
2 parents d819876 + 8bf65c6 commit b215beb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+2681
-1138
lines changed

compiler/rustc_codegen_gcc/.github/workflows/ci.yml

+18-6
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ jobs:
4949
# `llvm-14-tools` is needed to install the `FileCheck` binary which is used for asm tests.
5050
run: sudo apt-get install ninja-build ripgrep llvm-14-tools
5151

52-
- name: Install rustfmt
53-
run: rustup component add rustfmt
52+
- name: Install rustfmt & clippy
53+
run: rustup component add rustfmt clippy
5454

5555
- name: Download artifact
56-
run: curl -LO https://github.com/antoyo/gcc/releases/latest/download/${{ matrix.libgccjit_version.gcc }}
56+
run: curl -LO https://github.com/rust-lang/gcc/releases/latest/download/${{ matrix.libgccjit_version.gcc }}
5757

5858
- name: Setup path to libgccjit
5959
run: |
@@ -78,9 +78,16 @@ jobs:
7878
- name: Build
7979
run: |
8080
./y.sh prepare --only-libcore
81-
./y.sh build
81+
./y.sh build --sysroot
8282
cargo test
83-
./y.sh clean all
83+
84+
- name: Run y.sh cargo build
85+
run: |
86+
./y.sh cargo build --manifest-path tests/hello-world/Cargo.toml
87+
88+
- name: Clean
89+
run: |
90+
./y.sh clean all
8491
8592
- name: Prepare dependencies
8693
run: |
@@ -96,7 +103,12 @@ jobs:
96103
./y.sh test --release --clean --build-sysroot ${{ matrix.commands }}
97104
98105
- name: Check formatting
99-
run: cargo fmt -- --check
106+
run: ./y.sh fmt --check
107+
108+
- name: clippy
109+
run: |
110+
cargo clippy --all-targets -- -D warnings
111+
cargo clippy --all-targets --features master -- -D warnings
100112
101113
duplicates:
102114
runs-on: ubuntu-latest

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

+14-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
5757
- name: Download artifact
5858
if: matrix.libgccjit_version.gcc != 'libgccjit12.so'
59-
run: curl -LO https://github.com/antoyo/gcc/releases/latest/download/gcc-13.deb
59+
run: curl -LO https://github.com/rust-lang/gcc/releases/latest/download/gcc-13.deb
6060

6161
- name: Setup path to libgccjit
6262
if: matrix.libgccjit_version.gcc != 'libgccjit12.so'
@@ -94,7 +94,20 @@ jobs:
9494
run: cat tests/failing-non-lto-tests.txt >> tests/failing-ui-tests.txt
9595

9696
- name: Run tests
97+
# TODO: re-enable those tests for libgccjit 12.
98+
if: matrix.libgccjit_version.gcc != 'libgccjit12.so'
9799
id: tests
98100
run: |
99101
${{ matrix.libgccjit_version.env_extra }} ./y.sh test --release --clean --build-sysroot --test-failing-rustc ${{ matrix.libgccjit_version.extra }} | tee output_log
100102
rg --text "test result" output_log >> $GITHUB_STEP_SUMMARY
103+
104+
- name: Run failing ui pattern tests for ICE
105+
# TODO: re-enable those tests for libgccjit 12.
106+
if: matrix.libgccjit_version.gcc != 'libgccjit12.so'
107+
id: ui-tests
108+
run: |
109+
${{ matrix.libgccjit_version.env_extra }} ./y.sh test --release --test-failing-ui-pattern-tests ${{ matrix.libgccjit_version.extra }} | tee output_log_ui
110+
if grep -q "the compiler unexpectedly panicked" output_log_ui; then
111+
echo "Error: 'the compiler unexpectedly panicked' found in output logs. CI Error!!"
112+
exit 1
113+
fi

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

+20-18
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,23 @@ jobs:
6868
run: |
6969
./y.sh prepare --only-libcore --libgccjit12-patches
7070
./y.sh build --no-default-features --sysroot-panic-abort
71-
cargo test --no-default-features
72-
./y.sh clean all
73-
74-
- name: Prepare dependencies
75-
run: |
76-
git config --global user.email "user@example.com"
77-
git config --global user.name "User"
78-
./y.sh prepare --libgccjit12-patches
79-
80-
- name: Add more failing tests for GCC 12
81-
run: cat tests/failing-ui-tests12.txt >> tests/failing-ui-tests.txt
82-
83-
- name: Add more failing tests because the sysroot is not compiled with LTO
84-
run: cat tests/failing-non-lto-tests.txt >> tests/failing-ui-tests.txt
85-
86-
- name: Run tests
87-
run: |
88-
./y.sh test --release --clean --build-sysroot ${{ matrix.commands }} --no-default-features
71+
# Uncomment when we no longer need to remove global variables.
72+
#./y.sh build --sysroot --no-default-features --sysroot-panic-abort
73+
#cargo test --no-default-features
74+
#./y.sh clean all
75+
76+
#- name: Prepare dependencies
77+
#run: |
78+
#git config --global user.email "user@example.com"
79+
#git config --global user.name "User"
80+
#./y.sh prepare --libgccjit12-patches
81+
82+
#- name: Add more failing tests for GCC 12
83+
#run: cat tests/failing-ui-tests12.txt >> tests/failing-ui-tests.txt
84+
85+
#- name: Add more failing tests because the sysroot is not compiled with LTO
86+
#run: cat tests/failing-non-lto-tests.txt >> tests/failing-ui-tests.txt
87+
88+
#- name: Run tests
89+
#run: |
90+
#./y.sh test --release --clean --build-sysroot ${{ matrix.commands }} --no-default-features

compiler/rustc_codegen_gcc/.github/workflows/m68k.yml

+9-8
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,7 @@ jobs:
5454
run: curl -LO https://github.com/cross-cg-gcc-tools/cross-gcc/releases/latest/download/gcc-m68k-13.deb
5555

5656
- name: Download VM artifact
57-
uses: dawidd6/action-download-artifact@v2
58-
with:
59-
workflow: m68k.yml
60-
name: debian-m68k
61-
repo: cross-cg-gcc-tools/vms
62-
branch: master
63-
event: push
57+
run: curl -LO https://github.com/cross-cg-gcc-tools/vms/releases/latest/download/debian-m68k.img
6458

6559
- name: Setup path to libgccjit
6660
run: |
@@ -88,10 +82,17 @@ jobs:
8882
sudo mount debian-m68k.img vm
8983
sudo cp $(which qemu-m68k-static) vm/usr/bin/
9084
85+
- name: Build sample project with target defined as JSON spec
86+
run: |
87+
./y.sh prepare --only-libcore --cross
88+
./y.sh build --sysroot --target-triple m68k-unknown-linux-gnu --target ${{ github.workspace }}/target_specs/m68k-unknown-linux-gnu.json
89+
./y.sh cargo build --manifest-path=./tests/hello-world/Cargo.toml --target ${{ github.workspace }}/target_specs/m68k-unknown-linux-gnu.json
90+
./y.sh clean all
91+
9192
- name: Build
9293
run: |
9394
./y.sh prepare --only-libcore --cross
94-
./y.sh build --target-triple m68k-unknown-linux-gnu
95+
./y.sh build --sysroot --target-triple m68k-unknown-linux-gnu
9596
CG_GCC_TEST_TARGET=m68k-unknown-linux-gnu cargo test
9697
./y.sh clean all
9798

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
run: sudo apt-get install ninja-build ripgrep
3838

3939
- name: Download artifact
40-
run: curl -LO https://github.com/antoyo/gcc/releases/latest/download/gcc-13.deb
40+
run: curl -LO https://github.com/rust-lang/gcc/releases/latest/download/gcc-13.deb
4141

4242
- name: Setup path to libgccjit
4343
run: |
@@ -53,7 +53,7 @@ jobs:
5353
- name: Build
5454
run: |
5555
./y.sh prepare --only-libcore
56-
EMBED_LTO_BITCODE=1 ./y.sh build --release --release-sysroot
56+
EMBED_LTO_BITCODE=1 ./y.sh build --sysroot --release --release-sysroot
5757
cargo test
5858
./y.sh clean all
5959
@@ -62,12 +62,12 @@ jobs:
6262
git config --global user.email "user@example.com"
6363
git config --global user.name "User"
6464
./y.sh prepare
65-
# FIXME(antoyo): we cannot enable LTO for stdarch tests currently because of some failing LTO tests using proc-macros.
66-
echo -n 'lto = "fat"' >> build_sysroot/Cargo.toml
6765
6866
- name: Add more failing tests because of undefined symbol errors (FIXME)
6967
run: cat tests/failing-lto-tests.txt >> tests/failing-ui-tests.txt
7068

7169
- name: Run tests
7270
run: |
71+
# FIXME(antoyo): we cannot enable LTO for stdarch tests currently because of some failing LTO tests using proc-macros.
72+
echo -n 'lto = "fat"' >> build_system/build_sysroot/Cargo.toml
7373
EMBED_LTO_BITCODE=1 ./y.sh test --release --clean --release-sysroot --build-sysroot ${{ matrix.commands }}

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

+4-5
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
- name: Build
5959
run: |
6060
./y.sh prepare --only-libcore
61-
./y.sh build --release --release-sysroot
61+
./y.sh build --sysroot --release --release-sysroot
6262
6363
- name: Set env (part 2)
6464
run: |
@@ -89,12 +89,11 @@ jobs:
8989
- name: Run stdarch tests
9090
if: ${{ !matrix.cargo_runner }}
9191
run: |
92-
cd build_sysroot/sysroot_src/library/stdarch/
93-
CHANNEL=release TARGET=x86_64-unknown-linux-gnu CG_RUSTFLAGS="-Ainternal_features" ../../../../y.sh cargo test
92+
CHANNEL=release TARGET=x86_64-unknown-linux-gnu CG_RUSTFLAGS="-Ainternal_features" ./y.sh cargo test --manifest-path build/build_sysroot/sysroot_src/library/stdarch/Cargo.toml
9493
9594
- name: Run stdarch tests
9695
if: ${{ matrix.cargo_runner }}
9796
run: |
98-
cd build_sysroot/sysroot_src/library/stdarch/
9997
# FIXME: these tests fail when the sysroot is compiled with LTO because of a missing symbol in proc-macro.
100-
STDARCH_TEST_EVERYTHING=1 CHANNEL=release CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER="${{ matrix.cargo_runner }}" TARGET=x86_64-unknown-linux-gnu CG_RUSTFLAGS="-Ainternal_features" ../../../../y.sh cargo test -- --skip rtm --skip tbm --skip sse4a
98+
# TODO: remove --skip test_mm512_stream_ps when stdarch is updated in rustc.
99+
STDARCH_TEST_EVERYTHING=1 CHANNEL=release CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUNNER="${{ matrix.cargo_runner }}" TARGET=x86_64-unknown-linux-gnu CG_RUSTFLAGS="-Ainternal_features" ./y.sh cargo test --manifest-path build/build_sysroot/sysroot_src/library/stdarch/Cargo.toml -- --skip rtm --skip tbm --skip sse4a --skip test_mm512_stream_ps

compiler/rustc_codegen_gcc/.gitignore

-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ perf.data
66
perf.data.old
77
*.events
88
*.string*
9-
/build_sysroot/sysroot
10-
/build_sysroot/sysroot_src
11-
/build_sysroot/Cargo.lock
12-
/build_sysroot/test_target/Cargo.lock
139
gimple*
1410
*asm
1511
res

compiler/rustc_codegen_gcc/Cargo.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,18 @@ dependencies = [
7979

8080
[[package]]
8181
name = "gccjit"
82-
version = "2.0.0"
82+
version = "2.1.0"
8383
source = "registry+https://github.com/rust-lang/crates.io-index"
84-
checksum = "ecaa4c3da2d74c1a991b4faff75d49ab1d0522d9a99d8e2614b3b04d226417ce"
84+
checksum = "62e0ba949ebee07c5cc21f02cb48f28f2c8db7fcbc15fdc5120476a6c43b4636"
8585
dependencies = [
8686
"gccjit_sys",
8787
]
8888

8989
[[package]]
9090
name = "gccjit_sys"
91-
version = "0.1.0"
91+
version = "0.2.0"
9292
source = "registry+https://github.com/rust-lang/crates.io-index"
93-
checksum = "406a66fba005f1a02661f2f9443e5693dd3a667b7c58e70aa4ccc4c8b50b4758"
93+
checksum = "a5bbf85e12c2593772329a9d4e8310271f6706e6045ce4f41b041dd34fba6603"
9494
dependencies = [
9595
"libc",
9696
]

compiler/rustc_codegen_gcc/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ master = ["gccjit/master"]
2222
default = ["master"]
2323

2424
[dependencies]
25-
gccjit = "2.0"
25+
gccjit = "2.1"
2626

2727
# Local copy.
2828
#gccjit = { path = "../gccjit.rs" }

compiler/rustc_codegen_gcc/Readme.md

+38-18
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ This is a GCC codegen for rustc, which means it can be loaded by the existing ru
1212
The primary goal of this project is to be able to compile Rust code on platforms unsupported by LLVM.
1313
A secondary goal is to check if using the gcc backend will provide any run-time speed improvement for the programs compiled using rustc.
1414

15+
### Dependencies
16+
17+
**rustup:** Follow the instructions on the official [website](https://www.rust-lang.org/tools/install)
18+
19+
**DejaGnu:** Consider to install DejaGnu which is necessary for running the libgccjit test suite. [website](https://www.gnu.org/software/dejagnu/#downloading)
20+
21+
22+
1523
## Building
1624

1725
**This requires a patched libgccjit in order to work.
@@ -80,7 +88,7 @@ Then you can run commands like this:
8088

8189
```bash
8290
$ ./y.sh prepare # download and patch sysroot src and install hyperfine for benchmarking
83-
$ ./y.sh build --release
91+
$ ./y.sh build --sysroot --release
8492
```
8593

8694
To run the tests:
@@ -91,10 +99,16 @@ $ ./y.sh test --release
9199

92100
## Usage
93101

94-
`$CG_GCCJIT_DIR` is the directory you cloned this repo into in the following instructions:
102+
You have to run these commands, in the corresponding order:
95103

96104
```bash
97-
export CG_GCCJIT_DIR=[the full path to rustc_codegen_gcc]
105+
$ ./y.sh prepare
106+
$ ./y.sh build --sysroot
107+
```
108+
To check if all is working correctly, run:
109+
110+
```bash
111+
$ ./y.sh cargo build --manifest-path tests/hello-world/Cargo.toml
98112
```
99113

100114
### Cargo
@@ -107,8 +121,7 @@ If you compiled cg_gccjit in debug mode (aka you didn't pass `--release` to `./y
107121

108122
### LTO
109123

110-
To use LTO, you need to set the variable `FAT_LTO=1` and `EMBED_LTO_BITCODE=1` in addition to setting `lto = "fat"` in the `Cargo.toml`.
111-
Don't set `FAT_LTO` when compiling the sysroot, though: only set `EMBED_LTO_BITCODE=1`.
124+
To use LTO, you need to set the variable `EMBED_LTO_BITCODE=1` in addition to setting `lto = "fat"` in the `Cargo.toml`.
112125

113126
Failing to set `EMBED_LTO_BITCODE` will give you the following error:
114127

@@ -118,26 +131,33 @@ error: failed to copy bitcode to object file: No such file or directory (os erro
118131

119132
### Rustc
120133

121-
> You should prefer using the Cargo method.
134+
If you want to run `rustc` directly, you can do so with:
135+
136+
```bash
137+
$ ./y.sh rustc my_crate.rs
138+
```
139+
140+
You can do the same manually (although we don't recommend it):
122141

123142
```bash
124143
$ LIBRARY_PATH="[gcc-path value]" LD_LIBRARY_PATH="[gcc-path value]" rustc +$(cat $CG_GCCJIT_DIR/rust-toolchain | grep 'channel' | cut -d '=' -f 2 | sed 's/"//g' | sed 's/ //g') -Cpanic=abort -Zcodegen-backend=$CG_GCCJIT_DIR/target/release/librustc_codegen_gcc.so --sysroot $CG_GCCJIT_DIR/build_sysroot/sysroot my_crate.rs
125144
```
126145

127146
## Env vars
128147

129-
<dl>
130-
<dt>CG_GCCJIT_INCR_CACHE_DISABLED</dt>
131-
<dd>Don't cache object files in the incremental cache. Useful during development of cg_gccjit
132-
to make it possible to use incremental mode for all analyses performed by rustc without caching
133-
object files when their content should have been changed by a change to cg_gccjit.</dd>
134-
<dt>CG_GCCJIT_DISPLAY_CG_TIME</dt>
135-
<dd>Display the time it took to perform codegen for a crate</dd>
136-
<dt>CG_RUSTFLAGS</dt>
137-
<dd>Send additional flags to rustc. Can be used to build the sysroot without unwinding by setting `CG_RUSTFLAGS=-Cpanic=abort`.</dd>
138-
<dt>CG_GCCJIT_DUMP_TO_FILE</dt>
139-
<dd>Dump a C-like representation to /tmp/gccjit_dumps and enable debug info in order to debug this C-like representation.</dd>
140-
</dl>
148+
* _**CG_GCCJIT_DUMP_ALL_MODULES**_: Enables dumping of all compilation modules. When set to "1", a dump is created for each module during compilation and stored in `/tmp/reproducers/`.
149+
* _**CG_GCCJIT_DUMP_MODULE**_: Enables dumping of a specific module. When set with the module name, e.g., `CG_GCCJIT_DUMP_MODULE=module_name`, a dump of that specific module is created in `/tmp/reproducers/`.
150+
* _**CG_RUSTFLAGS**_: Send additional flags to rustc. Can be used to build the sysroot without unwinding by setting `CG_RUSTFLAGS=-Cpanic=abort`.
151+
* _**CG_GCCJIT_DUMP_TO_FILE**_: Dump a C-like representation to /tmp/gccjit_dumps and enable debug info in order to debug this C-like representation.
152+
* _**CG_GCCJIT_DUMP_RTL**_: Dumps RTL (Register Transfer Language) for virtual registers.
153+
* _**CG_GCCJIT_DUMP_RTL_ALL**_: Dumps all RTL passes.
154+
* _**CG_GCCJIT_DUMP_TREE_ALL**_: Dumps all tree (GIMPLE) passes.
155+
* _**CG_GCCJIT_DUMP_IPA_ALL**_: Dumps all Interprocedural Analysis (IPA) passes.
156+
* _**CG_GCCJIT_DUMP_CODE**_: Dumps the final generated code.
157+
* _**CG_GCCJIT_DUMP_GIMPLE**_: Dumps the initial GIMPLE representation.
158+
* _**CG_GCCJIT_DUMP_EVERYTHING**_: Enables dumping of all intermediate representations and passes.
159+
* _**CG_GCCJIT_KEEP_INTERMEDIATES**_: Keeps intermediate files generated during the compilation process.
160+
* _**CG_GCCJIT_VERBOSE**_: Enables verbose output from the GCC driver.
141161

142162
## Extra documentation
143163

compiler/rustc_codegen_gcc/build.rs

-6
This file was deleted.

0 commit comments

Comments
 (0)