Testing cranelift for wasm32-unknown-unknown?

I'm looking at Tips for Faster Rust Compile Times | Matthias Endler and tried most of the options there. One I have not tried is switching from llvm based code gen to cranelift.

For target wasm32-unknown-unknown, is there an easy way to try out cranelift ?

I am currently building via

	cargo build --target=wasm32-unknown-unknown --release

and looking for a drop in replacement to try cranelift code gen instead.

Have you tried the instructions in the rustc_codegen_cranelift project's README?

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 (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:

$ $cg_clif_dir/build/cargo-clif build

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

For additional ways to use rustc_codegen_cranelift like the JIT mode see usage.md.

1 Like

I stumbled across this page, but ignored it, because I did not believe the "most official" way to use cranelift wasm codegen involved cloning + building from a git repo.

Will take another look. Thanks!

Rustc does include cranelift already... my impression was that it's already used for debug builds?

I don't see anything in the rustc cli docs to be able to specify using it explicitly, the closest match is the unstable option codegen_backend - The Rust Unstable Book but that wants a path

@bjorn3 : Can you take a break from compiler writing and enlighten us on this ?

What is the simplest way to do "rust code -> wasm32 that can run in Chrome browser" with cranelift , given code already builds with cargo build --target=wasm32-unknown-unknown --release

Cranelift doesn't support emitting wasm modules at the moment. It only supports wasm -> cranelift ir (using cranelift_wasm), not cranelift ir -> wasm. I opened an issue for adding it almost two years ago:


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.