]> git.lizzy.rs Git - rust.git/blob - Readme.md
1146f7e415edfa7e857491d3f1bf55632f41808f
[rust.git] / Readme.md
1 # WIP Cranelift codegen backend for rust
2
3 > ⚠⚠⚠ Certain kinds of FFI don't work yet. ⚠⚠⚠
4
5 ## Building
6
7 ```bash
8 $ git clone https://github.com/bjorn3/rustc_codegen_cranelift.git
9 $ cd rustc_codegen_cranelift
10 $ ./prepare.sh # download and patch sysroot src and install hyperfine for benchmarking
11 $ ./test.sh --release
12 ```
13
14 ## Usage
15
16 `$cg_clif_dir` is the directory you cloned this repo into in the following instructions.
17
18 ### Cargo
19
20 ```bash
21 $ CHANNEL="release" $cg_clif_dir/cargo.sh run
22 ```
23
24 If you compiled cg_clif in debug mode (aka you didn't pass `--release` to `./test.sh`) you should use `CHANNEL="debug"` instead or omit `CHANNEL="release"` completely.
25
26 ### Rustc
27
28 > You should prefer using the Cargo method.
29
30 ```bash
31 $ rustc +$(cat $cg_clif_dir/rust-toolchain) -Cpanic=abort -Zcodegen-backend=$cg_clif_dir/target/release/librustc_codegen_cranelift.so --sysroot $cg_clif_dir/build_sysroot/sysroot my_crate.rs
32 ```
33
34 ### Shell
35
36 These are a few functions that allow you to easily run rust code from the shell using cg_clif as jit.
37
38 ```bash
39 function jit_naked() {
40     echo "$@" | CG_CLIF_JIT=1 rustc -Zcodegen-backend=$cg_clif_dir/target/release/librustc_codegen_cranelift.so --sysroot $cg_clif_dir/build_sysroot/sysroot - -Cprefer-dynamic
41 }
42
43 function jit() {
44     jit_naked "fn main() { $@ }"
45 }
46
47 function jit_calc() {
48     jit 'println!("0x{:x}", ' $@ ');';
49 }
50 ```
51
52 ## Env vars
53
54 <dl>
55     <dt>CG_CLIF_JIT</dt>
56     <dd>Enable JIT mode to immediately run a program instead of writing an executable file.</dd>
57     <dt>CG_CLIF_JIT_ARGS</dt>
58     <dd>When JIT mode is enable pass these arguments to the program.</dd>
59     <dt>CG_CLIF_INCR_CACHE_DISABLED</dt>
60     <dd>Don't cache object files in the incremental cache. Useful during development of cg_clif
61     to make it possible to use incremental mode for all analyses performed by rustc without caching
62     object files when their content should have been changed by a change to cg_clif.</dd>
63     <dt>CG_CLIF_DISPLAY_CG_TIME</dt>
64     <dd>Display the time it took to perform codegen for a crate</dd>
65 </dl>
66
67 ## Not yet supported
68
69 * Good non-rust abi support ([several problems](https://github.com/bjorn3/rustc_codegen_cranelift/issues/10))
70     * Proc macros
71 * Inline assembly ([no cranelift support](https://github.com/bytecodealliance/wasmtime/issues/1041), not coming soon)
72 * SIMD ([tracked here](https://github.com/bjorn3/rustc_codegen_cranelift/issues/171), some basic things work)