about summary refs log tree commit diff
path: root/compiler/rustc_codegen_cranelift/docs/rustc_testing.md
diff options
context:
space:
mode:
authorbjorn3 <17426603+bjorn3@users.noreply.github.com>2024-04-05 16:20:23 +0000
committerbjorn3 <17426603+bjorn3@users.noreply.github.com>2024-04-05 16:20:23 +0000
commit6cf6fd38ec06decc2e5896ca3659cd74b0b03363 (patch)
tree7e5bd04721f85d7da3b02e5fdde8ac775bd0e8c5 /compiler/rustc_codegen_cranelift/docs/rustc_testing.md
parent5958f5e08fa88ee95ede8c00f1b89befe0372d54 (diff)
parentfbda869b4e230c788b6bce426038ba8419956f2d (diff)
downloadrust-6cf6fd38ec06decc2e5896ca3659cd74b0b03363.tar.gz
rust-6cf6fd38ec06decc2e5896ca3659cd74b0b03363.zip
Merge commit 'fbda869b4e230c788b6bce426038ba8419956f2d' into sync_cg_clif-2024-04-05
Diffstat (limited to 'compiler/rustc_codegen_cranelift/docs/rustc_testing.md')
-rw-r--r--compiler/rustc_codegen_cranelift/docs/rustc_testing.md23
1 files changed, 23 insertions, 0 deletions
diff --git a/compiler/rustc_codegen_cranelift/docs/rustc_testing.md b/compiler/rustc_codegen_cranelift/docs/rustc_testing.md
new file mode 100644
index 00000000000..88c55557231
--- /dev/null
+++ b/compiler/rustc_codegen_cranelift/docs/rustc_testing.md
@@ -0,0 +1,23 @@
+# 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](https://github.com/rust-lang/rust/).
+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:
+
+1. `cd $RustCheckoutDir`
+2. Run `python x.py setup` and choose option for compiler (`b`).
+3. 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/cargo` to previous command.
+4. 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 rebuilt `rust` repository.
+5. Link your new `rustc` to toolchain: `rustup toolchain link stage2 ./build/host/stage2/`.
+6. (Windows only) compile the build system: `rustc +stage2 -O build_system/main.rs -o y.exe`.
+7. You need to prefix every `./y.sh` (or `y` if you built `build_system/main.rs` as `y`) command by `rustup run stage2` to make cg_clif use your local changes in rustc.
+  * `rustup run stage2 ./y.sh prepare`
+  * `rustup run stage2 ./y.sh build`
+  * (Optional) run tests: `rustup run stage2 ./y.sh test`
+8. 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.