Add a feature flag for the JIT

This commit is contained in:
bjorn3 2020-07-09 14:23:00 +02:00
parent b6150be206
commit ac77371852
6 changed files with 15 additions and 9 deletions

View File

@ -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.

View File

@ -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;

View File

@ -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<cranelift_simplejit::SimpleJITBackend>,
) -> Vec<u8> {
use std::convert::TryInto;
for reloc in self.relocs.drain(..) {
match reloc.name {
super::DebugRelocName::Section(_) => unreachable!(),

View File

@ -69,6 +69,7 @@ impl<'tcx> UnwindContext<'tcx> {
}
}
#[cfg(feature = "jit")]
pub(crate) unsafe fn register_jit(
self,
jit_module: &mut Module<cranelift_simplejit::SimpleJITBackend>,

View File

@ -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)

View File

@ -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;