git.delta.rocks / jrsonnet / refs/commits / 8c5f44d1f49f

difftreelog

feat make mimalloc optional

Лач2020-07-22parent: #e4a890b.patch.diff
in: master

2 files changed

modifiedcmds/jrsonnet/Cargo.tomldiffbeforeafterboth
--- a/cmds/jrsonnet/Cargo.toml
+++ b/cmds/jrsonnet/Cargo.toml
@@ -8,12 +8,17 @@
 
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 
+[features]
+default = []
+# Use mimalloc as allocator
+mimalloc = []
+
 [dependencies]
 jrsonnet-evaluator = { path = "../../crates/jrsonnet-evaluator", version = "1.0.0" }
 jrsonnet-parser = { path = "../../crates/jrsonnet-parser", version = "1.0.0" }
 jrsonnet-cli = { path = "../../crates/jrsonnet-cli", version = "0.1.0" }
 # TODO: Fix mimalloc compile errors, and use them
-mimallocator = "0.1.3"
+mimallocator = { version = "0.1.3", optional = true }
 
 [dependencies.clap]
 git = "https://github.com/clap-rs/clap"
modifiedcmds/jrsonnet/src/main.rsdiffbeforeafterboth
after · cmds/jrsonnet/src/main.rs
1use clap::Clap;2use jrsonnet_cli::{ConfigureState, GeneralOpts, InputOpts, ManifestOpts};3use jrsonnet_evaluator::{error::Result, EvaluationState};4use std::{path::PathBuf, rc::Rc};56#[cfg(feature = "mimalloc")]7#[global_allocator]8static GLOBAL: mimallocator::Mimalloc = mimallocator::Mimalloc;910#[derive(Clap)]11// #[clap(help_heading = "DEBUG")]12struct DebugOpts {13	/// Required OS stack size, probally you shouldn't change it, unless jrsonnet is failing with stack overflow14	#[clap(long, name = "size")]15	pub os_stack: Option<usize>,16}1718#[derive(Clap)]19struct Opts {20	#[clap(flatten)]21	input: InputOpts,22	#[clap(flatten)]23	general: GeneralOpts,24	#[clap(flatten)]25	manifest: ManifestOpts,26	#[clap(flatten)]27	debug: DebugOpts,28}2930fn main() {31	let opts: Opts = Opts::parse();32	if let Some(size) = opts.debug.os_stack {33		std::thread::Builder::new()34			.stack_size(size * 1024 * 1024)35			.spawn(|| main_catch(opts))36			.expect("new thread spawned")37			.join()38			.expect("thread finished successfully");39	} else {40		main_catch(opts)41	}42}4344fn main_catch(opts: Opts) {45	let state = EvaluationState::default();46	if let Err(e) = main_real(&state, opts) {47		println!("{}", state.stringify_err(&e));48	}49}5051fn main_real(state: &EvaluationState, opts: Opts) -> Result<()> {52	opts.general.configure(&state)?;53	opts.manifest.configure(&state)?;5455	let val = if opts.input.evaluate {56		state.evaluate_snippet_raw(57			Rc::new(PathBuf::from("args")),58			(&opts.input.input as &str).into(),59		)?60	} else {61		state.evaluate_file_raw(&PathBuf::from(opts.input.input))?62	};6364	let val = state.with_tla(val)?;6566	println!("{}", state.manifest(val)?);6768	Ok(())69}