Better use of env vars
This commit is contained in:
parent
c2962a603c
commit
1980371195
16
Readme.md
16
Readme.md
@ -18,7 +18,6 @@ $ ./test.sh --release
|
||||
### Cargo
|
||||
|
||||
```bash
|
||||
$ export CG_CLIF_INCR_CACHE=1 # Enable caching of object files in the incremental cache
|
||||
$ CHANNEL="release" $cg_clif_dir/cargo.sh run
|
||||
```
|
||||
|
||||
@ -27,10 +26,23 @@ If you compiled cg_clif in debug mode you should use `CHANNEL="debug"` instead o
|
||||
### Rustc
|
||||
|
||||
```bash
|
||||
$ export CG_CLIF_INCR_CACHE=1 # Enable caching of object files in the incremental cache
|
||||
$ rustc -Cpanic=abort -Zcodegen-backend=$cg_clif_dir/target/release/librustc_codegen_cranelift.so --sysroot $cg_clif_dir/build_sysroot/sysroot my_crate.rs
|
||||
```
|
||||
|
||||
## Env vars
|
||||
|
||||
<dl>
|
||||
<dt>CG_CLIF_JIT</dt>
|
||||
<dd>Enable JIT mode to immediately run a program instead of writing an executable file.</dd>
|
||||
<dt>CG_CLIF_JIT_ARGS</dt>
|
||||
<dd>When JIT mode is enable pass these arguments to the program.</dd>
|
||||
<dt>CG_CLIF_INCR_CACHE_DISABLE</dt>
|
||||
<dd>Don't cache object files in the incremental cache. Useful during development of cg_clif
|
||||
to make it possible to use incremental mode for all analyses performed by rustc without caching
|
||||
object files when their content should have been changed by a change to cg_clif.</dd>
|
||||
<dt>CG_CLIF_DISPLAY_CG_TIME</dt>
|
||||
<dd>Display the time it took to perform codegen for a crate</dd>
|
||||
</dl>
|
||||
|
||||
## Not yet supported
|
||||
|
||||
|
@ -24,3 +24,6 @@ export RUSTC_LOG=warn # display metadata load errors
|
||||
|
||||
export LD_LIBRARY_PATH="$(pwd)/target/out:$(pwd)/build_sysroot/sysroot/lib/rustlib/$TARGET_TRIPLE/lib"
|
||||
export DYLD_LIBRARY_PATH=$LD_LIBRARY_PATH
|
||||
|
||||
export CG_CLIF_DISPLAY_CG_TIME=1
|
||||
export CG_CLIF_INCR_CACHE_DISABLED=1
|
||||
|
@ -9,7 +9,7 @@ use crate::prelude::*;
|
||||
pub static mut __cg_clif_global_atomic_mutex: libc::pthread_mutex_t = libc::PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
pub fn init_global_lock(module: &mut Module<impl Backend>, bcx: &mut FunctionBuilder<'_>) {
|
||||
if std::env::var("SHOULD_RUN").is_ok () {
|
||||
if std::env::var("CG_CLIF_JIT").is_ok () {
|
||||
// When using JIT, dylibs won't find the __cg_clif_global_atomic_mutex data object defined here,
|
||||
// so instead define it in the cg_clif dylib.
|
||||
|
||||
|
@ -21,7 +21,7 @@ pub fn codegen_crate(
|
||||
) -> Box<dyn Any> {
|
||||
tcx.sess.abort_if_errors();
|
||||
|
||||
if std::env::var("SHOULD_RUN").is_ok()
|
||||
if std::env::var("CG_CLIF_JIT").is_ok()
|
||||
&& tcx.sess.crate_types.get().contains(&CrateType::Executable)
|
||||
{
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
@ -90,12 +90,12 @@ fn run_jit(tcx: TyCtxt<'_>) -> ! {
|
||||
|
||||
let finalized_main: *const u8 = jit_module.get_finalized_function(main_func_id);
|
||||
|
||||
println!("Rustc codegen cranelift will JIT run the executable, because the SHOULD_RUN env var is set");
|
||||
println!("Rustc codegen cranelift will JIT run the executable, because the CG_CLIF_JIT env var is set");
|
||||
|
||||
let f: extern "C" fn(c_int, *const *const c_char) -> c_int =
|
||||
unsafe { ::std::mem::transmute(finalized_main) };
|
||||
|
||||
let args = ::std::env::var("JIT_ARGS").unwrap_or_else(|_| String::new());
|
||||
let args = ::std::env::var("CG_CLIF_JIT_ARGS").unwrap_or_else(|_| String::new());
|
||||
let args = args
|
||||
.split(" ")
|
||||
.chain(Some(&*tcx.crate_name(LOCAL_CRATE).as_str().to_string()))
|
||||
@ -215,14 +215,14 @@ fn run_aot(
|
||||
let obj = product.emit();
|
||||
std::fs::write(&tmp_file, obj).unwrap();
|
||||
|
||||
let work_product = if std::env::var("CG_CLIF_INCR_CACHE").is_ok() {
|
||||
let work_product = if std::env::var("CG_CLIF_INCR_CACHE_DISABLED").is_ok() {
|
||||
None
|
||||
} else {
|
||||
rustc_incremental::copy_cgu_workproducts_to_incr_comp_cache_dir(
|
||||
tcx.sess,
|
||||
&name,
|
||||
&[(WorkProductFileKind::Object, tmp_file.clone())],
|
||||
)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
ModuleCodegenResult(
|
||||
@ -251,6 +251,7 @@ fn run_aot(
|
||||
tcx.sess.cgu_reuse_tracker.set_actual_reuse(&cgu.name().as_str(), cgu_reuse);
|
||||
|
||||
match cgu_reuse {
|
||||
_ if std::env::var("CG_CLIF_INCR_CACHE_DISABLED").is_ok() => {}
|
||||
CguReuse::No => {}
|
||||
CguReuse::PreLto => {
|
||||
let incr_comp_session_dir = tcx.sess.incr_comp_session_dir();
|
||||
@ -491,12 +492,16 @@ fn trans_mono_item<'clif, 'tcx, B: Backend + 'static>(
|
||||
}
|
||||
|
||||
fn time<R>(sess: &Session, name: &'static str, f: impl FnOnce() -> R) -> R {
|
||||
if std::env::var("CG_CLIF_DISPLAY_CG_TIME").is_ok() {
|
||||
println!("[{}] start", name);
|
||||
let before = std::time::Instant::now();
|
||||
let res = sess.time(name, f);
|
||||
let after = std::time::Instant::now();
|
||||
println!("[{}] end time: {:?}", name, after - before);
|
||||
res
|
||||
} else {
|
||||
sess.time(name, f)
|
||||
}
|
||||
}
|
||||
|
||||
// Adapted from https://github.com/rust-lang/rust/blob/303d8aff6092709edd4dbd35b1c88e9aa40bf6d8/src/librustc_codegen_ssa/base.rs#L922-L953
|
||||
|
4
test.sh
4
test.sh
@ -22,7 +22,7 @@ echo "[BUILD] example"
|
||||
$RUSTC example/example.rs --crate-type lib
|
||||
|
||||
echo "[JIT] mini_core_hello_world"
|
||||
JIT_ARGS="abc bcd" SHOULD_RUN=1 $RUSTC --crate-type bin -Cprefer-dynamic example/mini_core_hello_world.rs --cfg jit
|
||||
CG_CLIF_JIT=1 CG_CLIF_JIT_ARGS="abc bcd" $RUSTC --crate-type bin -Cprefer-dynamic example/mini_core_hello_world.rs --cfg jit
|
||||
|
||||
echo "[AOT] mini_core_hello_world"
|
||||
$RUSTC example/mini_core_hello_world.rs --crate-name mini_core_hello_world --crate-type bin -g
|
||||
@ -41,7 +41,7 @@ $RUSTC example/alloc_example.rs --crate-type bin
|
||||
./target/out/alloc_example
|
||||
|
||||
echo "[JIT] std_example"
|
||||
SHOULD_RUN=1 $RUSTC --crate-type bin -Cprefer-dynamic example/std_example.rs
|
||||
CG_CLIF_JIT=1 $RUSTC --crate-type bin -Cprefer-dynamic example/std_example.rs
|
||||
|
||||
echo "[AOT] dst_field_align"
|
||||
# FIXME Re-add -Zmir-opt-level=2 once rust-lang/rust#67529 is fixed.
|
||||
|
Loading…
Reference in New Issue
Block a user