mirror of
https://github.com/rust-lang/rust.git
synced 2025-10-24 05:59:39 +00:00
1.8 KiB
1.8 KiB
Building and testing with changes in rustc code
This is useful when changing code in rustc_codegen_cranelift as part of changing main Rust repository.
This can happen, for example, when you are implementing a new compiler intrinsic.
Instruction below uses $RustCheckoutDir as substitute for any folder where you cloned Rust repository.
You need to do this steps to successfully compile and use the cranelift backend with your changes in rustc code:
cd $RustCheckoutDir- Run
python x.py setupand choose option for compiler (b). - Build compiler and necessary tools:
python x.py build --stage=2 compiler library/std src/tools/rustdoc src/tools/rustfmt- (Optional) You can also build cargo by adding
src/tools/cargoto previous command.
- (Optional) You can also build cargo by adding
- Copy cargo from a nightly toolchain:
cp $(rustup +nightly which cargo) ./build/host/stage2/bin/cargo. Note that you would need to do this every time you rebuiltrustrepository. - Link your new
rustcto toolchain:rustup toolchain link stage2 ./build/host/stage2/. - (Windows only) compile the build system:
rustc +stage2 -O build_system/main.rs -o y.exe. - You need to prefix every
./y.sh(oryif you builtbuild_system/main.rsasy) command byrustup run stage2to make cg_clif use your local changes in rustc.
rustup run stage2 ./y.sh preparerustup run stage2 ./y.sh build- (Optional) run tests:
rustup run stage2 ./y.sh test
- Now you can use your cg_clif build to compile other Rust programs, e.g. you can open any Rust crate and run commands like
$RustCheckoutDir/compiler/rustc_codegen_cranelift/dist/cargo-clif build --release.
You can also set rust-analyzer.rustc.source to your rust workspace to get rust-analyzer to understand your changes.