From 80b9e36709019f98f6bdc33e632641861e470128 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 17 Jul 2021 16:32:55 +0200 Subject: [PATCH 1/2] Put all cg_clif specific options behind -Zunstable-features --- docs/usage.md | 4 ++-- scripts/cargo.rs | 12 ++++++++++-- scripts/filter_profile.rs | 2 +- scripts/tests.sh | 8 ++++---- src/lib.rs | 3 +++ 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/docs/usage.md b/docs/usage.md index 956d5905a97..87eec0e818b 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -36,7 +36,7 @@ $ $cg_clif_dir/build/cargo jit or ```bash -$ $cg_clif_dir/build/bin/cg_clif -Cllvm-args=mode=jit -Cprefer-dynamic my_crate.rs +$ $cg_clif_dir/build/bin/cg_clif -Zunstable-features -Cllvm-args=mode=jit -Cprefer-dynamic my_crate.rs ``` There is also an experimental lazy jit mode. In this mode functions are only compiled once they are @@ -52,7 +52,7 @@ These are a few functions that allow you to easily run rust code from the shell ```bash function jit_naked() { - echo "$@" | $cg_clif_dir/build/bin/cg_clif - -Cllvm-args=mode=jit -Cprefer-dynamic + echo "$@" | $cg_clif_dir/build/bin/cg_clif - -Zunstable-features -Cllvm-args=mode=jit -Cprefer-dynamic } function jit() { diff --git a/scripts/cargo.rs b/scripts/cargo.rs index b7e8dd44974..89ec8da77d3 100644 --- a/scripts/cargo.rs +++ b/scripts/cargo.rs @@ -44,7 +44,11 @@ fn main() { ); std::array::IntoIter::new(["rustc".to_string()]) .chain(env::args().skip(2)) - .chain(["--".to_string(), "-Cllvm-args=mode=jit".to_string()]) + .chain([ + "--".to_string(), + "-Zunstable-features".to_string(), + "-Cllvm-args=mode=jit".to_string(), + ]) .collect() } Some("lazy-jit") => { @@ -54,7 +58,11 @@ fn main() { ); std::array::IntoIter::new(["rustc".to_string()]) .chain(env::args().skip(2)) - .chain(["--".to_string(), "-Cllvm-args=mode=jit-lazy".to_string()]) + .chain([ + "--".to_string(), + "-Zunstable-features".to_string(), + "-Cllvm-args=mode=jit-lazy".to_string(), + ]) .collect() } _ => env::args().skip(1).collect(), diff --git a/scripts/filter_profile.rs b/scripts/filter_profile.rs index 9e196afbe4f..c4801a0a87b 100755 --- a/scripts/filter_profile.rs +++ b/scripts/filter_profile.rs @@ -5,7 +5,7 @@ source scripts/config.sh RUSTC="$(pwd)/build/bin/cg_clif" popd -PROFILE=$1 OUTPUT=$2 exec $RUSTC -Cllvm-args=mode=jit -Cprefer-dynamic $0 +PROFILE=$1 OUTPUT=$2 exec $RUSTC -Zunstable-options -Cllvm-args=mode=jit -Cprefer-dynamic $0 #*/ //! This program filters away uninteresting samples and trims uninteresting frames for stackcollapse diff --git a/scripts/tests.sh b/scripts/tests.sh index 5df04c533a7..08c07dfad42 100755 --- a/scripts/tests.sh +++ b/scripts/tests.sh @@ -16,10 +16,10 @@ function no_sysroot_tests() { if [[ "$JIT_SUPPORTED" = "1" ]]; then echo "[JIT] mini_core_hello_world" - CG_CLIF_JIT_ARGS="abc bcd" $MY_RUSTC -Cllvm-args=mode=jit -Cprefer-dynamic example/mini_core_hello_world.rs --cfg jit --target "$HOST_TRIPLE" + CG_CLIF_JIT_ARGS="abc bcd" $MY_RUSTC -Zunstable-options -Cllvm-args=mode=jit -Cprefer-dynamic example/mini_core_hello_world.rs --cfg jit --target "$HOST_TRIPLE" echo "[JIT-lazy] mini_core_hello_world" - CG_CLIF_JIT_ARGS="abc bcd" $MY_RUSTC -Cllvm-args=mode=jit-lazy -Cprefer-dynamic example/mini_core_hello_world.rs --cfg jit --target "$HOST_TRIPLE" + CG_CLIF_JIT_ARGS="abc bcd" $MY_RUSTC -Zunstable-options -Cllvm-args=mode=jit-lazy -Cprefer-dynamic example/mini_core_hello_world.rs --cfg jit --target "$HOST_TRIPLE" else echo "[JIT] mini_core_hello_world (skipped)" fi @@ -44,10 +44,10 @@ function base_sysroot_tests() { if [[ "$JIT_SUPPORTED" = "1" ]]; then echo "[JIT] std_example" - $MY_RUSTC -Cllvm-args=mode=jit -Cprefer-dynamic example/std_example.rs --target "$HOST_TRIPLE" + $MY_RUSTC -Zunstable-options -Cllvm-args=mode=jit -Cprefer-dynamic example/std_example.rs --target "$HOST_TRIPLE" echo "[JIT-lazy] std_example" - $MY_RUSTC -Cllvm-args=mode=jit-lazy -Cprefer-dynamic example/std_example.rs --target "$HOST_TRIPLE" + $MY_RUSTC -Zunstable-options -Cllvm-args=mode=jit-lazy -Cprefer-dynamic example/std_example.rs --target "$HOST_TRIPLE" else echo "[JIT] std_example (skipped)" fi diff --git a/src/lib.rs b/src/lib.rs index c7b3ad96048..366b9a7e24c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -184,6 +184,9 @@ fn codegen_crate( let config = if let Some(config) = self.config.clone() { config } else { + if !tcx.sess.unstable_options() && !tcx.sess.opts.cg.llvm_args.is_empty() { + tcx.sess.fatal("`-Z unstable-options` must be passed to allow configuring cg_clif"); + } BackendConfig::from_opts(&tcx.sess.opts.cg.llvm_args) .unwrap_or_else(|err| tcx.sess.fatal(&err)) }; From c2a9839686c538eb3cf850bb8947ebfe6f28141d Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 17 Jul 2021 16:40:54 +0200 Subject: [PATCH 2/2] Disable jit and inline-asm when building as part of rustc Both features are not yet ready. Inline-asm is only supported on Linux and requires explicitly specifying registers instead of register classes. The jit has usability issues and may require the cg_clif executable in the future. --- Cargo.toml | 3 ++- build_system/build_backend.rs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2e34717f419..02098b135f7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,8 @@ smallvec = "1.6.1" #gimli = { path = "../" } [features] -default = ["jit", "inline_asm"] +# Enable features not ready to be enabled when compiling as part of rustc +unstable-features = ["jit", "inline_asm"] jit = ["cranelift-jit", "libloading"] inline_asm = [] diff --git a/build_system/build_backend.rs b/build_system/build_backend.rs index 1df2bcc4541..150b6d01a6b 100644 --- a/build_system/build_backend.rs +++ b/build_system/build_backend.rs @@ -4,7 +4,7 @@ pub(crate) fn build_backend(channel: &str, host_triple: &str) -> PathBuf { let mut cmd = Command::new("cargo"); - cmd.arg("build").arg("--target").arg(host_triple); + cmd.arg("build").arg("--target").arg(host_triple).arg("--features").arg("unstable-features"); match channel { "debug" => {}