Skip to content

Commit da3091b

Browse files
authored
Rollup merge of rust-lang#78624 - bjorn3:update_cg_clif-2020-11-01, r=jyn514
Sync rustc_codegen_cranelift This fixes bootstrapping of rustc using cg_clif again. It regressed a while before rust-lang#77975 got merged. Fixes https://github.com/bjorn3/rustc_codegen_cranelift/issues/743
2 parents 7046855 + 216c4ae commit da3091b

Some content is hidden

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

53 files changed

+612
-388
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Bootstrap rustc using cg_clif
2+
3+
on:
4+
- push
5+
6+
jobs:
7+
bootstrap_rustc:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v2
12+
13+
- name: Cache cargo installed crates
14+
uses: actions/cache@v2
15+
with:
16+
path: ~/.cargo/bin
17+
key: ${{ runner.os }}-cargo-installed-crates
18+
19+
- name: Cache cargo registry and index
20+
uses: actions/cache@v2
21+
with:
22+
path: |
23+
~/.cargo/registry
24+
~/.cargo/git
25+
key: ${{ runner.os }}-cargo-registry-and-index-${{ hashFiles('**/Cargo.lock') }}
26+
27+
- name: Cache cargo target dir
28+
uses: actions/cache@v2
29+
with:
30+
path: target
31+
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }}
32+
33+
- name: Prepare dependencies
34+
run: |
35+
git config --global user.email "user@example.com"
36+
git config --global user.name "User"
37+
./prepare.sh
38+
39+
- name: Test
40+
run: |
41+
# Enable backtraces for easier debugging
42+
export RUST_BACKTRACE=1
43+
44+
./scripts/test_bootstrap.sh

compiler/rustc_codegen_cranelift/.github/workflows/main.yml

+10-1
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,13 @@ jobs:
5151
export COMPILE_RUNS=2
5252
export RUN_RUNS=2
5353
54-
./test.sh --release
54+
./test.sh
55+
56+
- name: Package prebuilt cg_clif
57+
run: tar cvfJ cg_clif.tar.xz build
58+
59+
- name: Upload prebuilt cg_clif
60+
uses: actions/upload-artifact@v2
61+
with:
62+
name: cg_clif-${{ runner.os }}
63+
path: cg_clif.tar.xz

compiler/rustc_codegen_cranelift/.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ perf.data
66
perf.data.old
77
*.events
88
*.string*
9-
/build_sysroot/sysroot
9+
/build
1010
/build_sysroot/sysroot_src
1111
/rust
1212
/rand

compiler/rustc_codegen_cranelift/Cargo.lock

+10-10
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
4444
[[package]]
4545
name = "cranelift-bforest"
4646
version = "0.67.0"
47-
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#4fd90dccabb266e983740e1f5daf8bde9266b286"
47+
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#44cbdecea03c360ea82e6482f0cf6c614effef21"
4848
dependencies = [
4949
"cranelift-entity",
5050
]
5151

5252
[[package]]
5353
name = "cranelift-codegen"
5454
version = "0.67.0"
55-
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#4fd90dccabb266e983740e1f5daf8bde9266b286"
55+
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#44cbdecea03c360ea82e6482f0cf6c614effef21"
5656
dependencies = [
5757
"byteorder",
5858
"cranelift-bforest",
@@ -70,7 +70,7 @@ dependencies = [
7070
[[package]]
7171
name = "cranelift-codegen-meta"
7272
version = "0.67.0"
73-
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#4fd90dccabb266e983740e1f5daf8bde9266b286"
73+
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#44cbdecea03c360ea82e6482f0cf6c614effef21"
7474
dependencies = [
7575
"cranelift-codegen-shared",
7676
"cranelift-entity",
@@ -79,17 +79,17 @@ dependencies = [
7979
[[package]]
8080
name = "cranelift-codegen-shared"
8181
version = "0.67.0"
82-
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#4fd90dccabb266e983740e1f5daf8bde9266b286"
82+
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#44cbdecea03c360ea82e6482f0cf6c614effef21"
8383

8484
[[package]]
8585
name = "cranelift-entity"
8686
version = "0.67.0"
87-
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#4fd90dccabb266e983740e1f5daf8bde9266b286"
87+
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#44cbdecea03c360ea82e6482f0cf6c614effef21"
8888

8989
[[package]]
9090
name = "cranelift-frontend"
9191
version = "0.67.0"
92-
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#4fd90dccabb266e983740e1f5daf8bde9266b286"
92+
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#44cbdecea03c360ea82e6482f0cf6c614effef21"
9393
dependencies = [
9494
"cranelift-codegen",
9595
"log",
@@ -100,7 +100,7 @@ dependencies = [
100100
[[package]]
101101
name = "cranelift-module"
102102
version = "0.67.0"
103-
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#4fd90dccabb266e983740e1f5daf8bde9266b286"
103+
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#44cbdecea03c360ea82e6482f0cf6c614effef21"
104104
dependencies = [
105105
"anyhow",
106106
"cranelift-codegen",
@@ -112,7 +112,7 @@ dependencies = [
112112
[[package]]
113113
name = "cranelift-native"
114114
version = "0.67.0"
115-
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#4fd90dccabb266e983740e1f5daf8bde9266b286"
115+
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#44cbdecea03c360ea82e6482f0cf6c614effef21"
116116
dependencies = [
117117
"cranelift-codegen",
118118
"raw-cpuid",
@@ -122,7 +122,7 @@ dependencies = [
122122
[[package]]
123123
name = "cranelift-object"
124124
version = "0.67.0"
125-
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#4fd90dccabb266e983740e1f5daf8bde9266b286"
125+
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#44cbdecea03c360ea82e6482f0cf6c614effef21"
126126
dependencies = [
127127
"anyhow",
128128
"cranelift-codegen",
@@ -135,7 +135,7 @@ dependencies = [
135135
[[package]]
136136
name = "cranelift-simplejit"
137137
version = "0.67.0"
138-
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#4fd90dccabb266e983740e1f5daf8bde9266b286"
138+
source = "git+https://github.com/bytecodealliance/wasmtime/?branch=main#44cbdecea03c360ea82e6482f0cf6c614effef21"
139139
dependencies = [
140140
"cranelift-codegen",
141141
"cranelift-entity",

compiler/rustc_codegen_cranelift/Readme.md

+26-11
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,56 @@
22

33
> ⚠⚠⚠ Certain kinds of FFI don't work yet. ⚠⚠⚠
44
5-
The goal of this project is to create an alternative codegen backend for the rust compiler based on [Cranelift](https://github.com/bytecodealliance/wasmtime/blob/master/cranelift). This has the potential to improve compilation times in debug mode. If your project doesn't use any of the things listed under "Not yet supported", it should work fine. If not please open an issue.
5+
The goal of this project is to create an alternative codegen backend for the rust compiler based on [Cranelift](https://github.com/bytecodealliance/wasmtime/blob/master/cranelift).
6+
This has the potential to improve compilation times in debug mode.
7+
If your project doesn't use any of the things listed under "Not yet supported", it should work fine.
8+
If not please open an issue.
69

7-
## Building
10+
## Building and testing
811

912
```bash
1013
$ git clone https://github.com/bjorn3/rustc_codegen_cranelift.git
1114
$ cd rustc_codegen_cranelift
1215
$ ./prepare.sh # download and patch sysroot src and install hyperfine for benchmarking
13-
$ ./test.sh --release
16+
$ ./build.sh
1417
```
1518

19+
To run the test suite replace the last command with:
20+
21+
```bash
22+
$ ./test.sh
23+
```
24+
25+
This will implicitly build cg_clif too. Both `build.sh` and `test.sh` accept a `--debug` argument to
26+
build in debug mode.
27+
28+
Alternatively you can download a pre built version from [GHA]. It is listed in the artifacts section
29+
of workflow runs. Unfortunately due to GHA restrictions you need to be logged in to access it.
30+
31+
[GHA]: https://github.com/bjorn3/rustc_codegen_cranelift/actions?query=branch%3Amaster+event%3Apush+is%3Asuccess
32+
1633
## Usage
1734

1835
rustc_codegen_cranelift can be used as a near-drop-in replacement for `cargo build` or `cargo run` for existing projects.
1936

20-
Assuming `$cg_clif_dir` is the directory you cloned this repo into and you followed the instructions (`prepare.sh` and `test.sh`).
37+
Assuming `$cg_clif_dir` is the directory you cloned this repo into and you followed the instructions (`prepare.sh` and `build.sh` or `test.sh`).
2138

2239
### Cargo
2340

2441
In the directory with your project (where you can do the usual `cargo build`), run:
2542

2643
```bash
27-
$ $cg_clif_dir/cargo.sh run
44+
$ $cg_clif_dir/build/cargo.sh run
2845
```
2946

3047
This should build and run your project with rustc_codegen_cranelift instead of the usual LLVM backend.
3148

32-
If you compiled cg_clif in debug mode (aka you didn't pass `--release` to `./test.sh`) you should set `CHANNEL="debug"`.
33-
3449
### Rustc
3550

3651
> You should prefer using the Cargo method.
3752
3853
```bash
39-
$ $cg_clif_dir/target/release/cg_clif my_crate.rs
54+
$ $cg_clif_dir/build/cg_clif my_crate.rs
4055
```
4156

4257
### Jit mode
@@ -47,13 +62,13 @@ In jit mode cg_clif will immediately execute your code without creating an execu
4762
> The jit mode will probably need cargo integration to make this possible.
4863
4964
```bash
50-
$ $cg_clif_dir/cargo.sh jit
65+
$ $cg_clif_dir/build/cargo.sh jit
5166
```
5267

5368
or
5469

5570
```bash
56-
$ $cg_clif_dir/target/release/cg_clif --jit my_crate.rs
71+
$ $cg_clif_dir/build/cg_clif --jit my_crate.rs
5772
```
5873

5974
### Shell
@@ -62,7 +77,7 @@ These are a few functions that allow you to easily run rust code from the shell
6277

6378
```bash
6479
function jit_naked() {
65-
echo "$@" | $cg_clif_dir/target/release/cg_clif - --jit
80+
echo "$@" | $cg_clif_dir/build/cg_clif - --jit
6681
}
6782

6883
function jit() {
+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Settings
5+
export CHANNEL="release"
6+
build_sysroot=1
7+
target_dir='build'
8+
while [[ $# != 0 ]]; do
9+
case $1 in
10+
"--debug")
11+
export CHANNEL="debug"
12+
;;
13+
"--without-sysroot")
14+
build_sysroot=0
15+
;;
16+
"--target-dir")
17+
target_dir=$2
18+
shift
19+
;;
20+
*)
21+
echo "Unknown flag '$1'"
22+
echo "Usage: ./build.sh [--debug] [--without-sysroot] [--target-dir DIR]"
23+
;;
24+
esac
25+
shift
26+
done
27+
28+
# Build cg_clif
29+
export RUSTFLAGS="-Zrun_dsymutil=no"
30+
if [[ "$CHANNEL" == "release" ]]; then
31+
cargo build --release
32+
else
33+
cargo build
34+
fi
35+
36+
rm -rf $target_dir
37+
mkdir $target_dir
38+
cp -a target/$CHANNEL/cg_clif{,_build_sysroot} target/$CHANNEL/*rustc_codegen_cranelift* $target_dir/
39+
cp -a rust-toolchain scripts/config.sh scripts/cargo.sh $target_dir
40+
41+
if [[ "$build_sysroot" == "1" ]]; then
42+
echo "[BUILD] sysroot"
43+
export CG_CLIF_INCR_CACHE_DISABLED=1
44+
dir=$(pwd)
45+
cd $target_dir
46+
time $dir/build_sysroot/build_sysroot.sh
47+
fi

compiler/rustc_codegen_cranelift/build_sysroot/build_sysroot.sh

+15-12
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,28 @@
33
# Requires the CHANNEL env var to be set to `debug` or `release.`
44

55
set -e
6-
cd $(dirname "$0")
76

8-
pushd ../ >/dev/null
9-
source ./scripts/config.sh
10-
popd >/dev/null
7+
source ./config.sh
118

12-
# Cleanup for previous run
13-
# v Clean target dir except for build scripts and incremental cache
14-
rm -r target/*/{debug,release}/{build,deps,examples,libsysroot*,native} 2>/dev/null || true
15-
rm -r sysroot/ 2>/dev/null || true
9+
dir=$(pwd)
1610

1711
# Use rustc with cg_clif as hotpluggable backend instead of the custom cg_clif driver so that
1812
# build scripts are still compiled using cg_llvm.
19-
export RUSTC=$(pwd)/../"target/"$CHANNEL"/cg_clif_build_sysroot"
13+
export RUSTC=$dir"/cg_clif_build_sysroot"
2014
export RUSTFLAGS=$RUSTFLAGS" --clif"
2115

16+
cd $(dirname "$0")
17+
18+
# Cleanup for previous run
19+
# v Clean target dir except for build scripts and incremental cache
20+
rm -r target/*/{debug,release}/{build,deps,examples,libsysroot*,native} 2>/dev/null || true
21+
22+
# We expect the target dir in the default location. Guard against the user changing it.
23+
export CARGO_TARGET_DIR=target
24+
2225
# Build libs
2326
export RUSTFLAGS="$RUSTFLAGS -Zforce-unstable-if-unmarked -Cpanic=abort"
24-
if [[ "$1" == "--release" ]]; then
27+
if [[ "$1" != "--debug" ]]; then
2528
sysroot_channel='release'
2629
# FIXME Enable incremental again once rust-lang/rust#74946 is fixed
2730
# FIXME Enable -Zmir-opt-level=2 again once it doesn't ice anymore
@@ -32,5 +35,5 @@ else
3235
fi
3336

3437
# Copy files to sysroot
35-
mkdir -p sysroot/lib/rustlib/$TARGET_TRIPLE/lib/
36-
cp -r target/$TARGET_TRIPLE/$sysroot_channel/deps/* sysroot/lib/rustlib/$TARGET_TRIPLE/lib/
38+
mkdir -p $dir/sysroot/lib/rustlib/$TARGET_TRIPLE/lib/
39+
cp -a target/$TARGET_TRIPLE/$sysroot_channel/deps/* $dir/sysroot/lib/rustlib/$TARGET_TRIPLE/lib/

compiler/rustc_codegen_cranelift/build_sysroot/prepare_sysroot_src.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fi
1212

1313
rm -rf $DST_DIR
1414
mkdir -p $DST_DIR/library
15-
cp -r $SRC_DIR/library $DST_DIR/
15+
cp -a $SRC_DIR/library $DST_DIR/
1616

1717
pushd $DST_DIR
1818
echo "[GIT] init"
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash --verbose
22
set -e
33

4-
rm -rf target/ build_sysroot/{sysroot/,sysroot_src/,target/} perf.data{,.old}
4+
rm -rf target/ build/ build_sysroot/{sysroot_src/,target/} perf.data{,.old}
55
rm -rf rand/ regex/ simple-raytracer/

compiler/rustc_codegen_cranelift/docs/env_vars.md

-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,4 @@
99
object files when their content should have been changed by a change to cg_clif.</dd>
1010
<dt>CG_CLIF_DISPLAY_CG_TIME</dt>
1111
<dd>If "1", display the time it took to perform codegen for a crate</dd>
12-
<dt>CG_CLIF_FUNCTION_SECTIONS</dt>
13-
<dd>Use a single section for each function. This will often reduce the executable size at the
14-
cost of making linking significantly slower.</dd>
1512
</dl>

compiler/rustc_codegen_cranelift/example/mini_core.rs

+10
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ unsafe impl Copy for u8 {}
4848
unsafe impl Copy for u16 {}
4949
unsafe impl Copy for u32 {}
5050
unsafe impl Copy for u64 {}
51+
unsafe impl Copy for u128 {}
5152
unsafe impl Copy for usize {}
5253
unsafe impl Copy for i8 {}
5354
unsafe impl Copy for i16 {}
@@ -283,6 +284,15 @@ impl PartialEq for u64 {
283284
}
284285
}
285286

287+
impl PartialEq for u128 {
288+
fn eq(&self, other: &u128) -> bool {
289+
(*self) == (*other)
290+
}
291+
fn ne(&self, other: &u128) -> bool {
292+
(*self) != (*other)
293+
}
294+
}
295+
286296
impl PartialEq for usize {
287297
fn eq(&self, other: &usize) -> bool {
288298
(*self) == (*other)

0 commit comments

Comments
 (0)