From ac773718522d12b897c1e927bfcb5b083e35d19e Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 9 Jul 2020 14:23:00 +0200 Subject: [PATCH] Add a feature flag for the JIT --- Cargo.toml | 8 +++++--- src/atomic_shim.rs | 1 + src/debuginfo/emit.rs | 5 +++-- src/debuginfo/unwind.rs | 1 + src/driver/mod.rs | 8 ++++---- src/lib.rs | 1 + 6 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0a0172429f3..6c455c51dad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ crate-type = ["dylib"] cranelift-codegen = { git = "https://github.com/bytecodealliance/wasmtime/", branch = "main", features = ["unwind"] } cranelift-frontend = { git = "https://github.com/bytecodealliance/wasmtime/", branch = "main" } cranelift-module = { git = "https://github.com/bytecodealliance/wasmtime/", branch = "main" } +cranelift-simplejit = { git = "https://github.com/bytecodealliance/wasmtime/", branch = "main", optional = true } cranelift-object = { git = "https://github.com/bytecodealliance/wasmtime/", branch = "main" } target-lexicon = "0.10.0" @@ -19,6 +20,7 @@ ar = "0.8.0" byteorder = "1.2.7" indexmap = "1.0.2" cfg-if = "0.1.10" +libloading = { version = "0.6.0", optional = true } [dependencies.object] version = "0.20.0" @@ -41,9 +43,9 @@ features = ["write"] # We don't need read support #[patch.crates-io] #gimli = { path = "../" } -[target.'cfg(not(target_arch = "wasm32"))'.dependencies] -cranelift-simplejit = { git = "https://github.com/bytecodealliance/wasmtime/", branch = "main" } -libloading = "0.6.0" +[features] +default = ["jit"] +jit = ["cranelift-simplejit", "libloading"] [profile.dev] # By compiling dependencies with optimizations, performing tests gets much faster. diff --git a/src/atomic_shim.rs b/src/atomic_shim.rs index d277b33e1b6..b317f31ff90 100644 --- a/src/atomic_shim.rs +++ b/src/atomic_shim.rs @@ -5,6 +5,7 @@ use crate::prelude::*; +#[cfg(feature = "jit")] #[no_mangle] pub static mut __cg_clif_global_atomic_mutex: libc::pthread_mutex_t = libc::PTHREAD_MUTEX_INITIALIZER; diff --git a/src/debuginfo/emit.rs b/src/debuginfo/emit.rs index 9cce630fed5..219fa183051 100644 --- a/src/debuginfo/emit.rs +++ b/src/debuginfo/emit.rs @@ -1,5 +1,3 @@ -use std::convert::TryInto; - use rustc_data_structures::fx::FxHashMap; use gimli::write::{Address, AttributeValue, EndianVec, Result, Sections, Writer}; @@ -70,10 +68,13 @@ impl WriterRelocate { } } + #[cfg(feature = "jit")] pub(super) fn relocate_for_jit( mut self, jit_module: &mut cranelift_module::Module, ) -> Vec { + use std::convert::TryInto; + for reloc in self.relocs.drain(..) { match reloc.name { super::DebugRelocName::Section(_) => unreachable!(), diff --git a/src/debuginfo/unwind.rs b/src/debuginfo/unwind.rs index a8e52f99b67..4bc3859652d 100644 --- a/src/debuginfo/unwind.rs +++ b/src/debuginfo/unwind.rs @@ -69,6 +69,7 @@ impl<'tcx> UnwindContext<'tcx> { } } + #[cfg(feature = "jit")] pub(crate) unsafe fn register_jit( self, jit_module: &mut Module, diff --git a/src/driver/mod.rs b/src/driver/mod.rs index 9a60b1e6a33..112741b6191 100644 --- a/src/driver/mod.rs +++ b/src/driver/mod.rs @@ -6,7 +6,7 @@ use rustc_middle::mir::mono::{Linkage as RLinkage, MonoItem, Visibility}; use crate::prelude::*; mod aot; -#[cfg(not(target_arch = "wasm32"))] +#[cfg(feature = "jit")] mod jit; pub(crate) fn codegen_crate( @@ -19,11 +19,11 @@ pub(crate) fn codegen_crate( if std::env::var("CG_CLIF_JIT").is_ok() && tcx.sess.crate_types().contains(&rustc_session::config::CrateType::Executable) { - #[cfg(not(target_arch = "wasm32"))] + #[cfg(feature = "jit")] let _: ! = jit::run_jit(tcx); - #[cfg(target_arch = "wasm32")] - panic!("jit not supported on wasm"); + #[cfg(not(feature = "jit"))] + tcx.sess.fatal("jit support was disabled when compiling rustc_codegen_cranelift"); } aot::run_aot(tcx, metadata, need_metadata_module) diff --git a/src/lib.rs b/src/lib.rs index b1e624d87f0..93144ae09a0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,6 +4,7 @@ #![warn(unused_lifetimes)] extern crate flate2; +#[cfg(feature = "jit")] extern crate libc; extern crate rustc_middle; extern crate rustc_codegen_ssa;