Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
3296d5c
Add support for SHA256 source file hashing for LLVM 11+.
arlosi Oct 13, 2020
2be0596
Use with_no_trimmed_paths
bjorn3 Oct 27, 2020
4206f9f
Prefer numeric associated constants in example
bstrie Oct 27, 2020
9842954
Merge pull request #1096 from bstrie/patch-1
bjorn3 Oct 27, 2020
5103a25
Rustup to rustc 1.49.0-nightly (07e968b64 2020-10-27)
bjorn3 Oct 28, 2020
4cc6b4f
Fix many clippy warnings
bjorn3 Oct 28, 2020
114be42
Rustup to rustc 1.49.0-nightly (ffe52882e 2020-10-30)
bjorn3 Oct 31, 2020
c067be0
Implement -Zfunction-sections
bjorn3 Oct 31, 2020
34be539
Use Pointer::dangling for ZST's in trans_const_value
bjorn3 Oct 31, 2020
6b1902a
Update Cranelift
bjorn3 Oct 31, 2020
f4e8af2
Update Cranelift
bjorn3 Nov 1, 2020
8063c37
Merge pull request #1099 from bjorn3/fix_rustc_bootstrap
bjorn3 Nov 1, 2020
d27f2f0
Rename trans to codegen
mominul Nov 1, 2020
c1cad03
Merge pull request #1100 from mominul/trans->codegen
bjorn3 Nov 1, 2020
c674c2c
Hide anonymous allocations from linked artifact
bjorn3 Nov 1, 2020
8b9c213
Fix transmutes between vectors and integers
bjorn3 Nov 1, 2020
324e63d
Ensure that sysroot build works with CARGO_TARGET_DIR set
bjorn3 Nov 1, 2020
cb36760
Split the actual tests out into scripts/tests.sh
bjorn3 Nov 1, 2020
1ea618a
Make it easier to use build_sysroot.sh
bjorn3 Nov 1, 2020
9410b58
Update build instructions
bjorn3 Nov 1, 2020
0e2337a
Deny #[deprecated] on trait impl blocks.
m-ou-se Oct 31, 2020
706bc33
Use the right span for errors about #[deprecated] attributes.
m-ou-se Nov 1, 2020
6f1992a
Turn 'useless #[deprecated]' error into a lint.
m-ou-se Nov 1, 2020
9fc991a
Add test for #[deprecated] attribute on trait impl block.
m-ou-se Nov 1, 2020
ace02c4
Corrected suggestion for generic parameters in `function_item_referen…
ayrtonm Nov 2, 2020
9c647d1
Improve deprecation attribute diagnostic messages.
m-ou-se Nov 2, 2020
0c34f5a
Refactor the build system
bjorn3 Nov 2, 2020
8315730
Upload prebuilt cg_clif
bjorn3 Nov 2, 2020
520a61f
Merge pull request #1104 from bjorn3/build_system_refactor
bjorn3 Nov 2, 2020
646b00f
Revert unintentional change
bjorn3 Nov 2, 2020
54b1d10
Test bootstrapping of rustc using cg_clif
bjorn3 Nov 1, 2020
03f01bb
Merge pull request #1105 from bjorn3/test_rustc_bootstrapping
bjorn3 Nov 2, 2020
1aedcd3
Suggest library/std when running all stage 0 tests
jyn514 Nov 2, 2020
216c4ae
Merge commit '03f01bbe901d60b71cf2c5ec766aef5e532ab79d' into update_c…
bjorn3 Nov 3, 2020
c32de75
lldb_batchmode: show more error information
pietroalbini Nov 3, 2020
2172adb
Fix panic in bootstrap for non-workspace path dependencies.
ehuss Nov 3, 2020
52405f7
Rollup merge of #77950 - arlosi:sha256, r=eddyb
m-ou-se Nov 3, 2020
39f5563
Rollup merge of #78624 - bjorn3:update_cg_clif-2020-11-01, r=jyn514
m-ou-se Nov 3, 2020
f011292
Rollup merge of #78626 - fusion-engineering-forks:deprecated-trait-im…
m-ou-se Nov 3, 2020
f347dab
Rollup merge of #78659 - ayrtonm:fn-ref-lint-fix, r=oli-obk
m-ou-se Nov 3, 2020
8a1f9e0
Rollup merge of #78687 - jyn514:bootstrap-help, r=Mark-Simulacrum
m-ou-se Nov 3, 2020
f9dd8d3
Rollup merge of #78699 - pietroalbini:lldb-error, r=jyn514
m-ou-se Nov 3, 2020
a65507b
Rollup merge of #78709 - ehuss:fix-in_tree_crates-non-member, r=Mark-…
m-ou-se Nov 3, 2020
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
Prev Previous commit
Next Next commit
Refactor the build system
  • Loading branch information
bjorn3 committed Nov 2, 2020
commit 0c34f5aba8544e2319c1587ac067c188a2d97877
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ perf.data
perf.data.old
*.events
*.string*
/build_sysroot/sysroot
/build
/build_sysroot/sysroot_src
/rust
/rand
Expand Down
29 changes: 16 additions & 13 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,51 @@

> ⚠⚠⚠ Certain kinds of FFI don't work yet. ⚠⚠⚠

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

## Building and testing

```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
$ ./test.sh --release
$ ./build.sh
```

If you want to only build but not test you should replace the last command with:
To run the test suite replace the last command with:

```bash
$ cargo build --release
$ ./build_sysroot/build_sysroot.sh
$ ./test.sh
```

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

## Usage

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 `test.sh`).
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`).

### Cargo

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

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

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

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

### Rustc

> You should prefer using the Cargo method.

```bash
$ $cg_clif_dir/target/release/cg_clif my_crate.rs
$ $cg_clif_dir/build/cg_clif my_crate.rs
```

### Jit mode
Expand All @@ -54,13 +57,13 @@ In jit mode cg_clif will immediately execute your code without creating an execu
> The jit mode will probably need cargo integration to make this possible.

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

or

```bash
$ $cg_clif_dir/target/release/cg_clif --jit my_crate.rs
$ $cg_clif_dir/build/cg_clif --jit my_crate.rs
```

### Shell
Expand All @@ -69,7 +72,7 @@ These are a few functions that allow you to easily run rust code from the shell

```bash
function jit_naked() {
echo "$@" | $cg_clif_dir/target/release/cg_clif - --jit
echo "$@" | $cg_clif_dir/build/cg_clif - --jit
}

function jit() {
Expand Down
47 changes: 47 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash
set -e

# Settings
export CHANNEL="release"
build_sysroot=1
target_dir='build'
while [[ $# != 0 ]]; do
case $1 in
"--debug")
export CHANNEL="debug"
;;
"--without-sysroot")
build_sysroot=0
;;
"--target-dir")
target_dir=$2
shift
;;
*)
echo "Unknown flag '$1'"
echo "Usage: ./build.sh [--debug] [--without-sysroot] [--target-dir DIR]"
;;
esac
shift
done

# Build cg_clif
export RUSTFLAGS="-Zrun_dsymutil=no"
if [[ "$CHANNEL" == "release" ]]; then
cargo build --release
else
cargo build
fi

rm -rf $target_dir
mkdir $target_dir
cp -a target/$CHANNEL/cg_clif{,_build_sysroot} target/$CHANNEL/*rustc_codegen_cranelift* $target_dir/
cp -a rust-toolchain scripts/config.sh scripts/cargo.sh $target_dir

if [[ "$build_sysroot" == "1" ]]; then
echo "[BUILD] sysroot"
export CG_CLIF_INCR_CACHE_DISABLED=1
dir=$(pwd)
cd $target_dir
time $dir/build_sysroot/build_sysroot.sh
fi
30 changes: 13 additions & 17 deletions build_sysroot/build_sysroot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,24 @@
# Requires the CHANNEL env var to be set to `debug` or `release.`

set -e
cd $(dirname "$0")

if [ -z $CHANNEL ]; then
export CHANNEL='release'
fi
source ./config.sh

pushd ../ >/dev/null
source ./scripts/config.sh
popd >/dev/null
dir=$(pwd)

# We expect the target dir in the default location. Guard against the user changing it.
export CARGO_TARGET_DIR=target
# Use rustc with cg_clif as hotpluggable backend instead of the custom cg_clif driver so that
# build scripts are still compiled using cg_llvm.
export RUSTC=$dir"/cg_clif_build_sysroot"
export RUSTFLAGS=$RUSTFLAGS" --clif"

cd $(dirname "$0")

# Cleanup for previous run
# v Clean target dir except for build scripts and incremental cache
rm -r target/*/{debug,release}/{build,deps,examples,libsysroot*,native} 2>/dev/null || true
rm -r sysroot/ 2>/dev/null || true
#rm -r target/*/{debug,release}/{build,deps,examples,libsysroot*,native} 2>/dev/null || true

# Use rustc with cg_clif as hotpluggable backend instead of the custom cg_clif driver so that
# build scripts are still compiled using cg_llvm.
export RUSTC=$(pwd)/../"target/"$CHANNEL"/cg_clif_build_sysroot"
export RUSTFLAGS=$RUSTFLAGS" --clif"
# We expect the target dir in the default location. Guard against the user changing it.
export CARGO_TARGET_DIR=target

# Build libs
export RUSTFLAGS="$RUSTFLAGS -Zforce-unstable-if-unmarked -Cpanic=abort"
Expand All @@ -39,5 +35,5 @@ else
fi

# Copy files to sysroot
mkdir -p sysroot/lib/rustlib/$TARGET_TRIPLE/lib/
cp -r target/$TARGET_TRIPLE/$sysroot_channel/deps/* sysroot/lib/rustlib/$TARGET_TRIPLE/lib/
mkdir -p $dir/sysroot/lib/rustlib/$TARGET_TRIPLE/lib/
cp -a target/$TARGET_TRIPLE/$sysroot_channel/deps/* $dir/sysroot/lib/rustlib/$TARGET_TRIPLE/lib/
2 changes: 1 addition & 1 deletion build_sysroot/prepare_sysroot_src.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fi

rm -rf $DST_DIR
mkdir -p $DST_DIR/library
cp -r $SRC_DIR/library $DST_DIR/
cp -a $SRC_DIR/library $DST_DIR/

pushd $DST_DIR
echo "[GIT] init"
Expand Down
2 changes: 1 addition & 1 deletion clean_all.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash --verbose
set -e

rm -rf target/ build_sysroot/{sysroot/,sysroot_src/,target/} perf.data{,.old}
rm -rf target/ build/ build_sysroot/{sysroot_src/,target/} perf.data{,.old}
rm -rf rand/ regex/ simple-raytracer/
14 changes: 4 additions & 10 deletions cargo.sh → scripts/cargo.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
#!/bin/bash

if [ -z $CHANNEL ]; then
export CHANNEL='release'
fi

pushd $(dirname "$0") >/dev/null
source scripts/config.sh
dir=$(dirname "$0")
source $dir/config.sh

# read nightly compiler from rust-toolchain file
TOOLCHAIN=$(cat rust-toolchain)

popd >/dev/null
TOOLCHAIN=$(cat $dir/rust-toolchain)

cmd=$1
shift
shift || true

if [[ "$cmd" = "jit" ]]; then
cargo +${TOOLCHAIN} rustc $@ -- --jit
Expand Down
9 changes: 5 additions & 4 deletions scripts/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,19 @@ echo
export RUSTC_WRAPPER=
fi

export RUSTC=$(pwd)/"target/"$CHANNEL"/cg_clif"
dir=$(cd $(dirname "$BASH_SOURCE"); pwd)

export RUSTC=$dir"/cg_clif"
export RUSTFLAGS=$linker
export RUSTDOCFLAGS=$linker' -Ztrim-diagnostic-paths=no -Cpanic=abort -Zpanic-abort-tests '\
'-Zcodegen-backend='$(pwd)'/target/'$CHANNEL'/librustc_codegen_cranelift.'$dylib_ext' --sysroot '$(pwd)'/build_sysroot/sysroot'
'-Zcodegen-backend='$dir'/librustc_codegen_cranelift.'$dylib_ext' --sysroot '$dir'/sysroot'

# FIXME remove once the atomic shim is gone
if [[ `uname` == 'Darwin' ]]; then
export RUSTFLAGS="$RUSTFLAGS -Clink-arg=-undefined -Clink-arg=dynamic_lookup"
fi

export LD_LIBRARY_PATH="$(pwd)/target/out:$(pwd)/build_sysroot/sysroot/lib/rustlib/"$TARGET_TRIPLE"/lib:\
$(pwd)/target/"$CHANNEL":$(rustc --print sysroot)/lib"
export LD_LIBRARY_PATH="$dir:$(rustc --print sysroot)/lib:$dir/target/out:$dir/sysroot/lib/rustlib/"$TARGET_TRIPLE"/lib"
export DYLD_LIBRARY_PATH=$LD_LIBRARY_PATH

export CG_CLIF_DISPLAY_CG_TIME=1
3 changes: 1 addition & 2 deletions scripts/filter_profile.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#!/bin/bash
#![forbid(unsafe_code)]/* This line is ignored by bash
# This block is ignored by rustc
CHANNEL="release"
pushd $(dirname "$0")/../
source scripts/config.sh
source build/config.sh
popd
PROFILE=$1 OUTPUT=$2 exec $RUSTC $RUSTFLAGS --jit $0
#*/
Expand Down
9 changes: 9 additions & 0 deletions scripts/rustup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ case $1 in
git add rust-toolchain build_sysroot/Cargo.lock
git commit -m "Rustup to $(rustc -V)"
;;
"push")
cg_clif=$(pwd)
pushd ../rust
branch=update_cg_clif-$(date +%Y-%m-%d)
git checkout -b $branch
git subtree pull --prefix=compiler/rustc_codegen_cranelift/ https://github.com/bjorn3/rustc_codegen_cranelift.git master
git push -u my $branch
popd
;;
*)
echo "Unknown command '$1'"
echo "Usage: ./rustup.sh prepare|commit"
Expand Down
Loading