Skip to content

Commit

Permalink
Store::default - create new store with BaseTunables
Browse files Browse the repository at this point in the history
  • Loading branch information
fschutt committed Jan 19, 2023
1 parent b7c868e commit 3934693
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 64 deletions.
65 changes: 2 additions & 63 deletions lib/cli/src/commands/create_exe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use super::ObjectFormat;
use crate::common::normalize_path;
use crate::store::{CompilerOptions, CompilerType};
use crate::store::CompilerOptions;
use anyhow::{Context, Result};
use clap::Parser;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -224,22 +224,7 @@ impl CreateExe {
return Err(anyhow::anyhow!("input path cannot be a directory"));
}

let (_, ct) = self.compiler.get_store_for_target(target.clone())?;

let compiler_type = if self.compiler.singlepass {
CompilerType::Singlepass
} else if self.compiler.cranelift {
CompilerType::Cranelift
} else if self.compiler.llvm {
CompilerType::LLVM
} else {
ct // default compiler type
};

let engine = EngineBuilder::new(get_config(&compiler_type)?).engine();

let tunables = BaseTunables::for_target(engine.target());
let store = Store::new_with_tunables(&engine, tunables);
let (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 @@ -318,52 +303,6 @@ impl CreateExe {
}
}

fn get_config(
compiler: &CompilerType,
) -> Result<Box<dyn wasmer_compiler::CompilerConfig>, anyhow::Error> {
match compiler {
CompilerType::Cranelift => {
#[cfg(feature = "cranelift")]
{
Ok(Box::new(wasmer_compiler_cranelift::Cranelift::default()))
}
#[cfg(not(feature = "cranelift"))]
{
Err(anyhow::anyhow!(
"compiler \"cranelift\" not embedded in wasmer-cli"
))
}
}
CompilerType::Singlepass => {
#[cfg(feature = "singlepass")]
{
Ok(Box::new(wasmer_compiler_singlepass::Singlepass::default()))
}
#[cfg(not(feature = "singlepass"))]
{
Err(anyhow::anyhow!(
"compiler \"singlepass\" not embedded in wasmer-cli"
))
}
}
CompilerType::LLVM => {
#[cfg(feature = "llvm")]
{
Ok(Box::new(wasmer_compiler_llvm::LLVM::default()))
}
#[cfg(not(feature = "llvm"))]
{
Err(anyhow::anyhow!(
"compiler \"llvm\" not embedded in wasmer-cli"
))
}
}
CompilerType::Headless => Err(anyhow::anyhow!(
"cannot compile .wasm files to object files with compiler \"headless\""
)),
}
}

fn write_entrypoint(directory: &Path, entrypoint: &Entrypoint) -> Result<(), anyhow::Error> {
std::fs::write(
directory.join("entrypoint.json"),
Expand Down
3 changes: 2 additions & 1 deletion lib/cli/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,8 @@ impl StoreOptions {
pub fn get_store_for_target(&self, target: Target) -> Result<(Store, CompilerType)> {
let (compiler_config, compiler_type) = self.compiler.get_compiler_config()?;
let engine = self.get_engine_with_compiler(target, compiler_config)?;
let store = Store::new(engine);
let tunables = BaseTunables::for_target(engine.target());
let store = Store::new_with_tunables(&engine, tunables);
Ok((store, compiler_type))
}

Expand Down

0 comments on commit 3934693

Please sign in to comment.