Skip to content

Commit

Permalink
Make cli compilable again
Browse files Browse the repository at this point in the history
  • Loading branch information
syrusakbary committed Feb 24, 2023
1 parent 1f64ba1 commit 9ed86ad
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
2 changes: 2 additions & 0 deletions examples/tunables_limit_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use wasmer::{
Target, Tunables,
};
use wasmer_compiler_cranelift::Cranelift;
// This is to be able to set the tunables
use wasmer::WasmerCompilerEngine;

/// A custom tunables that allows you to set a memory limit.
///
Expand Down
10 changes: 5 additions & 5 deletions lib/cli/src/commands/create_exe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ impl CreateExe {
return Err(anyhow::anyhow!("input path cannot be a directory"));
}

let (store, compiler_type) = self.compiler.get_store_for_target(target.clone())?;
let (mut store, compiler_type) = self.compiler.get_store_for_target(target.clone())?;

println!("Compiler: {}", compiler_type.to_string());
println!("Target: {}", target.triple());
Expand Down Expand Up @@ -749,14 +749,13 @@ fn compile_atoms(
}
continue;
}
let (store, _) = compiler.get_store_for_target(target.clone())?;
match object_format {
ObjectFormat::Symbols => {
let engine = store.engine();
let (engine, _) = compiler.get_engine_for_target(target.clone())?;
let engine_inner = engine.inner();
let compiler = engine_inner.compiler()?;
let features = engine_inner.features();
let tunables = store.engine().tunables();
let tunables = engine.tunables();
let (module_info, obj, _, _) = Artifact::generate_object(
compiler,
data,
Expand All @@ -773,6 +772,7 @@ fn compile_atoms(
writer.flush()?;
}
ObjectFormat::Serialized => {
let (store, _) = compiler.get_store_for_target(target.clone())?;
let module_name = ModuleMetadataSymbolRegistry {
prefix: prefix.clone(),
}
Expand Down Expand Up @@ -963,7 +963,7 @@ pub(super) fn prepare_directory_from_single_wasm_file(
// reads the module info from the wasm module and writes the ModuleInfo for each file
// into the entrypoint.json file
fn get_module_infos(
store: &mut Store,
mut store: &mut Store,
directory: &Path,
atoms: &[(String, Vec<u8>)],
object_format: ObjectFormat,
Expand Down
5 changes: 2 additions & 3 deletions lib/cli/src/commands/gen_c_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,11 @@ impl GenCHeader {
&target_triple,
&self.cpu_features,
);
let (store, _) = CompilerOptions::default().get_store_for_target(target.clone())?;
let engine = store.engine();
let (engine, _) = CompilerOptions::default().get_engine_for_target(target.clone())?;
let engine_inner = engine.inner();
let compiler = engine_inner.compiler()?;
let features = engine_inner.features();
let tunables = store.engine().tunables();
let tunables = engine.tunables();
let (metadata, _, _) = Artifact::metadata(
compiler,
&file,
Expand Down
7 changes: 7 additions & 0 deletions lib/cli/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ impl CompilerOptions {
Ok((store, compiler_type))
}

/// Gets the Engine for a given target.
pub fn get_engine_for_target(&self, target: Target) -> Result<(Engine, CompilerType)> {
let (compiler_config, compiler_type) = self.get_compiler_config()?;
let engine = self.get_engine(target, compiler_config)?;
Ok((engine, compiler_type))
}

#[cfg(feature = "compiler")]
fn get_engine(
&self,
Expand Down

0 comments on commit 9ed86ad

Please sign in to comment.