Skip to content

Commit

Permalink
Rollup merge of rust-lang#86927 - bjorn3:sync_cg_clif-2021-07-07, r=b…
Browse files Browse the repository at this point in the history
…jorn3

Sync rustc_codegen_cranelift

The main hightlight this sync is basic support for AArch64. Most things should work on Linux, but there does seem to be an ABI incompatibility causing proc-macros to crash, see rust-lang/rustc_codegen_cranelift#1184. Thanks to ``@afonso360`` for implementing all Cranelift features that were necessary to compile for AArch64 using cg_clif. Also thanks to ``@shamatar`` for implementing the `llvm.x86.addcarry.64` and `llvm.x86.subborrow.64` llvm intrinsics used by num-bigint (rust-lang/rustc_codegen_cranelift#1178) and ``@eggyal`` for implementing multi-threading support for the lazy jit mode. (rust-lang/rustc_codegen_cranelift#1166)

r? ``@ghost``

``@rustbot`` label +A-codegen +A-cranelift +T-compiler
  • Loading branch information
JohnTitor committed Jul 7, 2021
2 parents 0ea3362 + 00b2f56 commit 8445192
Show file tree
Hide file tree
Showing 56 changed files with 1,284 additions and 446 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/.cirrus.yml
Expand Up @@ -14,7 +14,7 @@ task:
- . $HOME/.cargo/env
- git config --global user.email "user@example.com"
- git config --global user.name "User"
- ./prepare.sh
- ./y.rs prepare
test_script:
- . $HOME/.cargo/env
- # Enable backtraces for easier debugging
Expand Down
73 changes: 72 additions & 1 deletion compiler/rustc_codegen_cranelift/.github/workflows/main.yml
Expand Up @@ -19,6 +19,9 @@ jobs:
- os: ubuntu-latest
env:
TARGET_TRIPLE: x86_64-pc-windows-gnu
- os: ubuntu-latest
env:
TARGET_TRIPLE: aarch64-unknown-linux-gnu

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -49,11 +52,19 @@ jobs:
sudo apt-get install -y gcc-mingw-w64-x86-64 wine-stable
rustup target add x86_64-pc-windows-gnu
- name: Install AArch64 toolchain and qemu
if: matrix.os == 'ubuntu-latest' && matrix.env.TARGET_TRIPLE == 'aarch64-unknown-linux-gnu'
run: |
sudo apt-get install -y gcc-aarch64-linux-gnu qemu-user
- name: Prepare dependencies
run: |
git config --global user.email "user@example.com"
git config --global user.name "User"
./prepare.sh
./y.rs prepare
- name: Build
run: ./y.rs build --sysroot none

- name: Test
env:
Expand Down Expand Up @@ -87,3 +98,63 @@ jobs:
with:
name: cg_clif-${{ runner.os }}-cross-x86_64-mingw
path: cg_clif.tar.xz

build_windows:
runs-on: windows-latest
timeout-minutes: 60

steps:
- uses: actions/checkout@v2

#- name: Cache cargo installed crates
# uses: actions/cache@v2
# with:
# path: ~/.cargo/bin
# key: ${{ runner.os }}-cargo-installed-crates

#- name: Cache cargo registry and index
# uses: actions/cache@v2
# with:
# path: |
# ~/.cargo/registry
# ~/.cargo/git
# key: ${{ runner.os }}-cargo-registry-and-index-${{ hashFiles('**/Cargo.lock') }}

#- name: Cache cargo target dir
# uses: actions/cache@v2
# with:
# path: target
# key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }}

- name: Prepare dependencies
run: |
git config --global user.email "user@example.com"
git config --global user.name "User"
git config --global core.autocrlf false
rustup set default-host x86_64-pc-windows-gnu
rustc y.rs -o y.exe -g
./y.exe prepare
- name: Build
#name: Test
run: |
# Enable backtraces for easier debugging
#export RUST_BACKTRACE=1
# Reduce amount of benchmark runs as they are slow
#export COMPILE_RUNS=2
#export RUN_RUNS=2
# Enable extra checks
#export CG_CLIF_ENABLE_VERIFIER=1
./y.exe build
#- name: Package prebuilt cg_clif
# run: tar cvfJ cg_clif.tar.xz build

#- name: Upload prebuilt cg_clif
# uses: actions/upload-artifact@v2
# with:
# name: cg_clif-${{ runner.os }}
# path: cg_clif.tar.xz
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_cranelift/.github/workflows/rustc.yml
Expand Up @@ -34,7 +34,7 @@ jobs:
run: |
git config --global user.email "user@example.com"
git config --global user.name "User"
./prepare.sh
./y.rs prepare
- name: Test
run: |
Expand Down Expand Up @@ -72,7 +72,7 @@ jobs:
run: |
git config --global user.email "user@example.com"
git config --global user.name "User"
./prepare.sh
./y.rs prepare
- name: Test
run: |
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_codegen_cranelift/.gitignore
Expand Up @@ -6,9 +6,11 @@ perf.data
perf.data.old
*.events
*.string*
/y.bin
/build
/build_sysroot/sysroot_src
/build_sysroot/compiler-builtins
/build_sysroot/rustc_version
/rust
/rand
/regex
Expand Down
21 changes: 20 additions & 1 deletion compiler/rustc_codegen_cranelift/.vscode/settings.json
@@ -1,7 +1,9 @@
{
// source for rustc_* is not included in the rust-src component; disable the errors about this
"rust-analyzer.diagnostics.disabled": ["unresolved-extern-crate", "unresolved-macro-call"],
"rust-analyzer.assist.importMergeBehavior": "last",
"rust-analyzer.assist.importGranularity": "module",
"rust-analyzer.assist.importEnforceGranularity": true,
"rust-analyzer.assist.importPrefix": "crate",
"rust-analyzer.cargo.runBuildScripts": true,
"rust-analyzer.linkedProjects": [
"./Cargo.toml",
Expand Down Expand Up @@ -49,6 +51,23 @@
"cfg": [],
},
]
},
{
"roots": ["./y.rs"],
"crates": [
{
"root_module": "./y.rs",
"edition": "2018",
"deps": [{ "crate": 1, "name": "std" }],
"cfg": [],
},
{
"root_module": "./build_sysroot/sysroot_src/library/std/src/lib.rs",
"edition": "2018",
"deps": [],
"cfg": [],
},
]
}
]
}
56 changes: 32 additions & 24 deletions compiler/rustc_codegen_cranelift/Cargo.lock
Expand Up @@ -33,16 +33,16 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"

[[package]]
name = "cranelift-bforest"
version = "0.74.0"
source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#76c6b83f6a21a12a11d4f890490f8acb6329a600"
version = "0.75.0"
source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#c71ad9490e7f3e19bbcae7e28bbe50f8a0b4a5d8"
dependencies = [
"cranelift-entity",
]

[[package]]
name = "cranelift-codegen"
version = "0.74.0"
source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#76c6b83f6a21a12a11d4f890490f8acb6329a600"
version = "0.75.0"
source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#c71ad9490e7f3e19bbcae7e28bbe50f8a0b4a5d8"
dependencies = [
"cranelift-bforest",
"cranelift-codegen-meta",
Expand All @@ -57,27 +57,27 @@ dependencies = [

[[package]]
name = "cranelift-codegen-meta"
version = "0.74.0"
source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#76c6b83f6a21a12a11d4f890490f8acb6329a600"
version = "0.75.0"
source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#c71ad9490e7f3e19bbcae7e28bbe50f8a0b4a5d8"
dependencies = [
"cranelift-codegen-shared",
"cranelift-entity",
]

[[package]]
name = "cranelift-codegen-shared"
version = "0.74.0"
source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#76c6b83f6a21a12a11d4f890490f8acb6329a600"
version = "0.75.0"
source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#c71ad9490e7f3e19bbcae7e28bbe50f8a0b4a5d8"

[[package]]
name = "cranelift-entity"
version = "0.74.0"
source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#76c6b83f6a21a12a11d4f890490f8acb6329a600"
version = "0.75.0"
source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#c71ad9490e7f3e19bbcae7e28bbe50f8a0b4a5d8"

[[package]]
name = "cranelift-frontend"
version = "0.74.0"
source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#76c6b83f6a21a12a11d4f890490f8acb6329a600"
version = "0.75.0"
source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#c71ad9490e7f3e19bbcae7e28bbe50f8a0b4a5d8"
dependencies = [
"cranelift-codegen",
"log",
Expand All @@ -87,8 +87,8 @@ dependencies = [

[[package]]
name = "cranelift-jit"
version = "0.74.0"
source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#76c6b83f6a21a12a11d4f890490f8acb6329a600"
version = "0.75.0"
source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#c71ad9490e7f3e19bbcae7e28bbe50f8a0b4a5d8"
dependencies = [
"anyhow",
"cranelift-codegen",
Expand All @@ -104,8 +104,8 @@ dependencies = [

[[package]]
name = "cranelift-module"
version = "0.74.0"
source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#76c6b83f6a21a12a11d4f890490f8acb6329a600"
version = "0.75.0"
source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#c71ad9490e7f3e19bbcae7e28bbe50f8a0b4a5d8"
dependencies = [
"anyhow",
"cranelift-codegen",
Expand All @@ -115,17 +115,18 @@ dependencies = [

[[package]]
name = "cranelift-native"
version = "0.74.0"
source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#76c6b83f6a21a12a11d4f890490f8acb6329a600"
version = "0.75.0"
source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#c71ad9490e7f3e19bbcae7e28bbe50f8a0b4a5d8"
dependencies = [
"cranelift-codegen",
"libc",
"target-lexicon",
]

[[package]]
name = "cranelift-object"
version = "0.74.0"
source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#76c6b83f6a21a12a11d4f890490f8acb6329a600"
version = "0.75.0"
source = "git+https://github.com/bytecodealliance/wasmtime.git?branch=main#c71ad9490e7f3e19bbcae7e28bbe50f8a0b4a5d8"
dependencies = [
"anyhow",
"cranelift-codegen",
Expand Down Expand Up @@ -171,9 +172,9 @@ dependencies = [

[[package]]
name = "libc"
version = "0.2.86"
version = "0.2.97"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7282d924be3275cec7f6756ff4121987bc6481325397dde6ba3e7802b1a8b1c"
checksum = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6"

[[package]]
name = "libloading"
Expand Down Expand Up @@ -203,14 +204,21 @@ dependencies = [
"libc",
]

[[package]]
name = "memchr"
version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc"

[[package]]
name = "object"
version = "0.24.0"
version = "0.25.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a5b3dd1c072ee7963717671d1ca129f1048fda25edea6b752bfc71ac8854170"
checksum = "a38f2be3697a57b4060074ff41b44c16870d916ad7877c17696e063257482bc7"
dependencies = [
"crc32fast",
"indexmap",
"memchr",
]

[[package]]
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_cranelift/Cargo.toml
Expand Up @@ -9,15 +9,15 @@ crate-type = ["dylib"]

[dependencies]
# These have to be in sync with each other
cranelift-codegen = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "main", features = ["unwind"] }
cranelift-codegen = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "main", features = ["unwind", "all-arch"] }
cranelift-frontend = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "main" }
cranelift-module = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "main" }
cranelift-native = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "main" }
cranelift-jit = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "main", optional = true }
cranelift-object = { git = "https://github.com/bytecodealliance/wasmtime.git", branch = "main" }
target-lexicon = "0.12.0"
gimli = { version = "0.24.0", default-features = false, features = ["write"]}
object = { version = "0.24.0", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] }
object = { version = "0.25.0", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] }

ar = { git = "https://github.com/bjorn3/rust-ar.git", branch = "do_not_remove_cg_clif_ranlib" }
indexmap = "1.0.2"
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_codegen_cranelift/Readme.md
Expand Up @@ -10,8 +10,8 @@ If not please open an issue.
```bash
$ git clone https://github.com/bjorn3/rustc_codegen_cranelift.git
$ cd rustc_codegen_cranelift
$ ./prepare.sh # download and patch sysroot src and install hyperfine for benchmarking
$ ./build.sh
$ ./y.rs prepare # download and patch sysroot src and install hyperfine for benchmarking
$ ./y.rs build
```

To run the test suite replace the last command with:
Expand All @@ -20,7 +20,7 @@ To run the test suite replace the last command with:
$ ./test.sh
```

This will implicitly build cg_clif too. Both `build.sh` and `test.sh` accept a `--debug` argument to
This will implicitly build cg_clif too. Both `y.rs build` and `test.sh` accept a `--debug` argument to
build in debug mode.

Alternatively you can download a pre built version from [GHA]. It is listed in the artifacts section
Expand All @@ -32,12 +32,12 @@ of workflow runs. Unfortunately due to GHA restrictions you need to be logged in

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

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`).
Assuming `$cg_clif_dir` is the directory you cloned this repo into and you followed the instructions (`y.rs prepare` and `y.rs build` or `test.sh`).

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

```bash
$ $cg_clif_dir/build/cargo.sh build
$ $cg_clif_dir/build/cargo build
```

This will build your project with rustc_codegen_cranelift instead of the usual LLVM backend.
Expand Down

0 comments on commit 8445192

Please sign in to comment.