forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
282 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
Got a new version up. This time all logic to handle using different codegen backends for the different stages, so you don't need to do a multi stage process. | ||
|
||
* Make sure you are running on Linux. | ||
* Clone https://github.com/bjorn3/rust | ||
* Checkout the `compile_rustc_for_wasm15` branch | ||
* Download and extract https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-22/wasi-sdk-22.0-linux.tar.gz into the rust checkout. | ||
* Run `./x.py install` to build the compiler and install it into the dist dir. | ||
* Use `wasmtime run --dir tmp::/ --dir dist dist/bin/rustc.wasm --sysroot dist --target x86_64-unknown-linux-gnu` to run rustc. | ||
|
||
Note that linking is not supported as wasi doesn't allow spawning executables. You can use something like the following to compile using the wasm32-wasi rustc and then link using native gcc: | ||
|
||
``` | ||
$ mkdir tmp | ||
$ echo 'fn main() { println!("Hello World!"); }' | wasmtime run -Sthreads=y -Spreview2=n --dir tmp::/ --dir dist --env RUST_MIN_STACK=16777216 dist/bin/rustc.wasm - --sysroot dist --target x86_64-unknown-linux-gnu -Csave-temps | ||
$ gcc -fuse-ld=lld tmp/rmeta*/lib.rmeta tmp/rust_out.* dist/lib/rustlib/x86_64-unknown-linux-gnu/lib/lib*.rlib -o rust_out | ||
$ ./rust_out | ||
Hello World! | ||
``` | ||
|
||
use LLVM | ||
Install example: | ||
WASI_SDK_PATH=`pwd`/wasi-sdk-22.0 WASI_SYSROOT=`pwd`/wasi-sdk-22.0/share/wasi-sysroot ./x.py install | ||
|
||
If you just want to run it, https://github.com/oligamiq/rust_wasm/tree/main/rustc_llvm | ||
``` | ||
$ mkdir tmp | ||
$ echo 'fn main() { println!("Hello World!"); }' | wasmtime run -Sthreads=y -Spreview2=n --dir tmp::/ --dir dist --env RUST_MIN_STACK=16777216 dist/bin/rustc.wasm - --sysroot dist --target wasm32-wasip1-threads -Csave-temps | ||
$ gcc -fuse-ld=lld tmp/rmeta*/lib.rmeta tmp/rust_out.*.o dist/lib/rustlib/x86_64-unknown-linux-gnu/lib/lib*.rlib -o rust_out | ||
$ ./rust_out | ||
Hello World! | ||
``` | ||
|
||
to Wasi | ||
``` | ||
$ mkdir tmp | ||
$ echo 'fn main() { println!("Hello World!"); }' | wasmtime run -Sthreads=y -Spreview2=n --dir tmp::/ --dir dist --env RUST_MIN_STACK=16777216 dist/bin/rustc.wasm - --sysroot dist --target wasm32-wasip1-threads -Csave-temps | ||
$ wasi-sdk-22.0/bin/wasm-ld --shared-memory --max-memory=1073741824 --import-memory --export __main_void -z stack-size=1048576 --stack-first --allow-undefined --no-demangle --import-memory --export-memory --shared-memory dist/lib/rustlib/wasm32-wasip1-threads/lib/self-contained/crt1-command.o tmp/rust_out.*.o dist/lib/rustlib/wasm32-wasip1-threads/lib/lib*.rlib -L dist/lib/rustlib/wasm32-wasip1-threads/lib/self-contained -lc -o rust_out.wasm | ||
$ wasmtime run -Sthreads=y rust_out.wasm | ||
Hello World! | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Includes one of the default files in src/bootstrap/defaults | ||
profile = "compiler" | ||
change-id = 9999999 | ||
|
||
[rust] | ||
codegen-backends = ["llvm"] | ||
deny-warnings = false | ||
llvm-bitcode-linker = false | ||
|
||
[llvm] | ||
cflags = "-march=native" | ||
cxxflags = "-march=native" | ||
static-libstdcpp = true | ||
ninja = false | ||
download-ci-llvm = false | ||
link-shared = false | ||
# thin-lto = true | ||
|
||
[build] | ||
docs = false | ||
extended = false | ||
tools = [] | ||
# host = ["wasm32-wasip1-threads", "x86_64-unknown-linux-gnu"] | ||
host = ["wasm32-wasip1-threads"] | ||
target = ["x86_64-unknown-linux-gnu", "wasm32-wasip1-threads"] | ||
# target = ["wasm32-wasip1-threads"] | ||
cargo-native-static = true | ||
|
||
[install] | ||
prefix = "dist" | ||
sysconfdir = "etc" | ||
|
||
[target.'wasm32-wasip1-threads'] | ||
wasi-root = "wasi-sdk-22.0/share/wasi-sysroot" | ||
# codegen-backends = ["cranelift"] | ||
linker = "wasi-sdk-22.0/bin/clang" | ||
codegen-backends = ["llvm"] | ||
|
||
[target.'x86_64-unknown-linux-gnu'] | ||
cc = "gcc" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule llvm-project
updated
from af8f9e to 69bd85