]> git.lizzy.rs Git - rust.git/blob - Readme.md
Sync from rust c9228570668803e3e6402770d55f23a12c9ae686
[rust.git] / Readme.md
1 # WIP Cranelift codegen backend for rust
2
3 > ⚠⚠⚠ Certain kinds of FFI don't work yet. ⚠⚠⚠
4
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.
9
10 ## Building and testing
11
12 ```bash
13 $ git clone https://github.com/bjorn3/rustc_codegen_cranelift.git
14 $ cd rustc_codegen_cranelift
15 $ ./prepare.sh # download and patch sysroot src and install hyperfine for benchmarking
16 $ ./build.sh
17 ```
18
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
33 ## Usage
34
35 rustc_codegen_cranelift can be used as a near-drop-in replacement for `cargo build` or `cargo run` for existing projects.
36
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`).
38
39 ### Cargo
40
41 In the directory with your project (where you can do the usual `cargo build`), run:
42
43 ```bash
44 $ $cg_clif_dir/build/cargo.sh run
45 ```
46
47 This should build and run your project with rustc_codegen_cranelift instead of the usual LLVM backend.
48
49 ### Rustc
50
51 > You should prefer using the Cargo method.
52
53 ```bash
54 $ $cg_clif_dir/build/bin/cg_clif my_crate.rs
55 ```
56
57 ### Jit mode
58
59 In jit mode cg_clif will immediately execute your code without creating an executable file.
60
61 > This requires all dependencies to be available as dynamic library.
62 > The jit mode will probably need cargo integration to make this possible.
63
64 ```bash
65 $ $cg_clif_dir/build/cargo.sh jit
66 ```
67
68 or
69
70 ```bash
71 $ $cg_clif_dir/build/bin/cg_clif --jit my_crate.rs
72 ```
73
74 ### Shell
75
76 These are a few functions that allow you to easily run rust code from the shell using cg_clif as jit.
77
78 ```bash
79 function jit_naked() {
80     echo "$@" | $cg_clif_dir/build/bin/cg_clif - --jit
81 }
82
83 function jit() {
84     jit_naked "fn main() { $@ }"
85 }
86
87 function jit_calc() {
88     jit 'println!("0x{:x}", ' $@ ');';
89 }
90 ```
91
92 ## Env vars
93
94 [see env_vars.md](docs/env_vars.md)
95
96 ## Not yet supported
97
98 * Good non-rust abi support ([several problems](https://github.com/bjorn3/rustc_codegen_cranelift/issues/10))
99 * Inline assembly ([no cranelift support](https://github.com/bytecodealliance/wasmtime/issues/1041)
100     * On Linux there is support for invoking an external assembler for `global_asm!` and `asm!`.
101       `llvm_asm!` will remain unimplemented forever. `asm!` doesn't yet support reg classes. You
102       have to specify specific registers instead.
103 * SIMD ([tracked here](https://github.com/bjorn3/rustc_codegen_cranelift/issues/171), some basic things work)