Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix feature flags for make-build-wasmer-headless #3483

Merged
merged 40 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
1cb29bb
Fix feature flags for make-build-wasmer-headless
fschutt Jan 17, 2023
a674471
Disable compilers in wasi/Cargo.toml
fschutt Jan 17, 2023
9091054
Disable compiler feature for headless-minimal again.
fschutt Jan 17, 2023
71fdf26
Remove dependency on wasmer/compiler from webc-runner
fschutt Jan 17, 2023
8715e22
Allow unused variables
fschutt Jan 17, 2023
1ca0de8
Minimize dependencies of wasmer-headless build
fschutt Jan 17, 2023
0678e90
Fix headless-minimal properly
fschutt Jan 17, 2023
e2755b7
Fix make lint
fschutt Jan 17, 2023
912f21a
Fix make lint
fschutt Jan 17, 2023
8183474
Adjust feature flags
fschutt Jan 17, 2023
a483d04
Address review comments
fschutt Jan 18, 2023
a70a492
Fix feature flags and misleading error message
fschutt Jan 18, 2023
9c05248
Revert changes to Store::default and remove Store::headless again
fschutt Jan 18, 2023
7008023
Fix make lint
fschutt Jan 18, 2023
caeca9a
Revert error message text
fschutt Jan 18, 2023
8d3e7c0
Refactor WasiRunner / EmscriptenRunner to take a Store as an argument
fschutt Jan 18, 2023
3d73c53
Fix unit tests on Linux
fschutt Jan 18, 2023
de62fdd
Remove uses of Store::default in create-exe and wasmer run
fschutt Jan 18, 2023
790fcfc
Debug why get_store_for_target fails
fschutt Jan 18, 2023
2ce32db
Debug why get_store_for_target returns wrong UnwindInfo
fschutt Jan 18, 2023
be30f66
Print store information on CI
fschutt Jan 18, 2023
321c1f3
Try to imitate the previous Store creation with get_config((
fschutt Jan 18, 2023
d52ae79
Merge branch 'master' into fix-master-red-2
fschutt Jan 18, 2023
5c927b9
Fix create-exe to work
fschutt Jan 19, 2023
1042053
Revert "Fix make lint"
fschutt Jan 19, 2023
fd5962d
Revert "Fix make lint"
fschutt Jan 19, 2023
b7c868e
Fix more errors on Windows
fschutt Jan 19, 2023
c61a5d7
Store::default - create new store with BaseTunables
fschutt Jan 19, 2023
32fbfc3
Disable set_target(Some(target)) for Engine builder
fschutt Jan 19, 2023
6398b06
Enable set_target() again, but disable unwind info
fschutt Jan 19, 2023
f577164
Revert "Enable set_target() again, but disable unwind info"
fschutt Jan 19, 2023
e112604
Revert "Disable set_target(Some(target)) for Engine builder"
fschutt Jan 19, 2023
17943e5
Refactor Artifact::new into separate sub-functions
fschutt Jan 19, 2023
533b72f
Merge branch 'master' into fix-master-red-2
fschutt Jan 19, 2023
32b39e8
Remove unnecessary printlns
fschutt Jan 19, 2023
af67c86
Fix wrong documentation
fschutt Jan 19, 2023
b26b487
Move get_module_info into the Engine
fschutt Jan 19, 2023
54f0f0c
Undo Store::new_with_tunables debugging code
fschutt Jan 19, 2023
c1fec2f
Always import ModuleInfo
fschutt Jan 19, 2023
ff11cbd
Make CompilerOptions flags private again
fschutt Jan 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions lib/api/src/sys/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,18 +174,17 @@ impl Default for Store {
fn get_engine() -> Engine {
cfg_if::cfg_if! {
if #[cfg(feature = "compiler")] {

cfg_if::cfg_if! {
if #[cfg(any(feature = "cranelift", feature = "llvm", feature = "singlepass"))]
{
let config = get_config();
EngineBuilder::new(Box::new(config) as Box<dyn wasmer_compiler::CompilerConfig>)
.engine()
} else {
EngineBuilder::headless()
.engine()
cfg_if::cfg_if! {
if #[cfg(any(feature = "cranelift", feature = "llvm", feature = "singlepass"))]
{
let config = get_config();
EngineBuilder::new(Box::new(config) as Box<dyn wasmer_compiler::CompilerConfig>)
.engine()
} else {
EngineBuilder::headless()
.engine()
}
fschutt marked this conversation as resolved.
Show resolved Hide resolved
}
}
} else {
compile_error!("No default engine chosen")
}
Expand Down
9 changes: 5 additions & 4 deletions lib/cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ use crate::commands::Binfmt;
use crate::commands::Compile;
#[cfg(any(feature = "static-artifact-create", feature = "wasmer-artifact-create"))]
use crate::commands::CreateExe;
#[cfg(feature = "static-artifact-create")]
use crate::commands::CreateObj;
#[cfg(feature = "wast")]
use crate::commands::Wast;
use crate::commands::{
Add, Cache, Config, GenCHeader, Init, Inspect, List, Login, Publish, Run, SelfUpdate, Validate,
Whoami,
Add, Cache, Config, Init, Inspect, List, Login, Publish, Run, SelfUpdate, Validate, Whoami,
};
#[cfg(feature = "static-artifact-create")]
use crate::commands::{CreateObj, GenCHeader};
use crate::error::PrettyError;
use clap::{CommandFactory, ErrorKind, Parser};

Expand Down Expand Up @@ -130,6 +129,7 @@ enum WasmerCLIOptions {
CreateObj(CreateObj),

/// Generate the C static_defs.h header file for the input .wasm module
#[cfg(feature = "static-artifact-create")]
GenCHeader(GenCHeader),

/// Get various configuration information needed
Expand Down Expand Up @@ -181,6 +181,7 @@ impl WasmerCLIOptions {
Self::List(list) => list.execute(),
Self::Login(login) => login.execute(),
Self::Publish(publish) => publish.execute(),
#[cfg(feature = "static-artifact-create")]
Self::GenCHeader(gen_heder) => gen_heder.execute(),
#[cfg(feature = "wast")]
Self::Wast(wast) => wast.execute(),
Expand Down
10 changes: 5 additions & 5 deletions lib/cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mod config;
mod create_exe;
#[cfg(feature = "static-artifact-create")]
mod create_obj;
#[cfg(feature = "static-artifact-create")]
mod gen_c_header;
mod init;
mod inspect;
Expand All @@ -29,19 +30,18 @@ pub use binfmt::*;
pub use compile::*;
#[cfg(any(feature = "static-artifact-create", feature = "wasmer-artifact-create"))]
pub use create_exe::*;
#[cfg(feature = "static-artifact-create")]
pub use create_obj::*;
use serde::{Deserialize, Serialize};
#[cfg(feature = "wast")]
pub use wast::*;
pub use {
add::*, cache::*, config::*, gen_c_header::*, init::*, inspect::*, list::*, login::*,
publish::*, run::*, self_update::*, validate::*, whoami::*,
add::*, cache::*, config::*, init::*, inspect::*, list::*, login::*, publish::*, run::*,
self_update::*, validate::*, whoami::*,
};
#[cfg(feature = "static-artifact-create")]
pub use {create_obj::*, gen_c_header::*};

/// The kind of object format to emit.
#[derive(Debug, Copy, Clone, PartialEq, Eq, clap::Parser, Serialize, Deserialize)]
#[cfg(any(feature = "static-artifact-create", feature = "wasmer-artifact-create"))]
pub enum ObjectFormat {
/// Serialize the entire module into an object file.
Serialized,
Expand Down
32 changes: 13 additions & 19 deletions lib/cli/src/commands/create_exe.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Create a standalone native executable for a given Wasm file.

use super::ObjectFormat;
use crate::common::normalize_path;
use crate::store::CompilerOptions;
use anyhow::{Context, Result};
use clap::Parser;
Expand Down Expand Up @@ -224,13 +225,15 @@ impl CreateExe {
}

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

println!("Compiler: {}", compiler_type.to_string());
println!("Target: {}", target.triple());
println!("Format: {:?}", object_format);
println!(
"Using path `{}` as libwasmer path.",
cross_compilation.library.display()
);

if !cross_compilation.library.exists() {
return Err(anyhow::anyhow!("library path does not exist"));
}
Expand Down Expand Up @@ -967,16 +970,16 @@ fn get_module_infos(

let mut module_infos = BTreeMap::new();
for (atom_name, atom_bytes) in atoms {
let store = Store::default();
let module = Module::from_binary(&store, atom_bytes.as_slice())
.map_err(|e| anyhow::anyhow!("could not deserialize module {atom_name}: {e}"))?;
let module_info = Engine::get_module_info(atom_bytes.as_slice())
.map_err(|e| anyhow::anyhow!("could not get module info for atom {atom_name}: {e}"))?;

if let Some(s) = entrypoint
.atoms
.iter_mut()
.find(|a| a.atom.as_str() == atom_name.as_str())
{
s.module_info = Some(module.info().clone());
module_infos.insert(atom_name.clone(), module.info().clone());
s.module_info = Some(module_info.clone());
module_infos.insert(atom_name.clone(), module_info.clone());
}
}

Expand Down Expand Up @@ -1279,20 +1282,16 @@ fn link_exe_from_dir(
cmd.args(files_winsdk);
}

println!("running cmd: {cmd:?}");
if debug {
println!("running cmd: {cmd:?}");
cmd.stdout(Stdio::inherit());
cmd.stderr(Stdio::inherit());
}

let compilation = cmd
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.output()
.context(anyhow!("Could not execute `zig`: {cmd:?}"))?;

println!(
"file {} exists: {:?}",
out_path.display(),
out_path.exists()
);

if !compilation.status.success() {
return Err(anyhow::anyhow!(String::from_utf8_lossy(
&compilation.stderr
Expand All @@ -1302,7 +1301,6 @@ fn link_exe_from_dir(

// remove file if it exists - if not done, can lead to errors on copy
let output_path_normalized = normalize_path(&format!("{}", output_path.display()));
println!("removing {output_path_normalized}");
let _ = std::fs::remove_file(&output_path_normalized);
std::fs::copy(
&normalize_path(&format!("{}", out_path.display())),
Expand All @@ -1319,10 +1317,6 @@ fn link_exe_from_dir(
Ok(())
}

pub(crate) fn normalize_path(s: &str) -> String {
s.strip_prefix(r"\\?\").unwrap_or(s).to_string()
}

/// Link compiled objects using the system linker
#[allow(clippy::too_many_arguments)]
fn link_objects_system_linker(
Expand Down
56 changes: 27 additions & 29 deletions lib/cli/src/commands/create_obj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ use std::path::PathBuf;

use wasmer::*;

#[cfg(feature = "webc_runner")]
use webc::{ParseOptions, WebCMmap};

#[derive(Debug, Parser)]
/// The options for the `wasmer create-exe` subcommand
pub struct CreateObj {
Expand Down Expand Up @@ -73,7 +70,7 @@ pub struct CreateObj {
impl CreateObj {
/// Runs logic for the `create-obj` subcommand
pub fn execute(&self) -> Result<()> {
let path = crate::commands::create_exe::normalize_path(&format!("{}", self.path.display()));
let path = crate::common::normalize_path(&format!("{}", self.path.display()));
let target_triple = self.target_triple.clone().unwrap_or_else(Triple::host);
let starting_cd = env::current_dir()?;
let input_path = starting_cd.join(&path);
Expand All @@ -98,31 +95,32 @@ impl CreateObj {
println!("Target: {}", target.triple());
println!("Format: {:?}", object_format);

let atoms =
if let Ok(pirita) = WebCMmap::parse(input_path.clone(), &ParseOptions::default()) {
crate::commands::create_exe::compile_pirita_into_directory(
&pirita,
&output_directory_path,
&self.compiler,
&self.cpu_features,
&target_triple,
object_format,
&prefix,
crate::commands::AllowMultiWasm::Reject(self.atom.clone()),
self.debug_dir.is_some(),
)
} else {
crate::commands::create_exe::prepare_directory_from_single_wasm_file(
&input_path,
&output_directory_path,
&self.compiler,
&target_triple,
&self.cpu_features,
object_format,
&prefix,
self.debug_dir.is_some(),
)
}?;
let atoms = if let Ok(pirita) =
webc::WebCMmap::parse(input_path.clone(), &webc::ParseOptions::default())
{
crate::commands::create_exe::compile_pirita_into_directory(
&pirita,
&output_directory_path,
&self.compiler,
&self.cpu_features,
&target_triple,
object_format,
&prefix,
crate::commands::AllowMultiWasm::Reject(self.atom.clone()),
self.debug_dir.is_some(),
)
} else {
crate::commands::create_exe::prepare_directory_from_single_wasm_file(
&input_path,
&output_directory_path,
&self.compiler,
&target_triple,
&self.cpu_features,
object_format,
&prefix,
self.debug_dir.is_some(),
)
}?;

// Copy output files into target path, depending on whether
// there are one or many files being compiled
Expand Down
6 changes: 2 additions & 4 deletions lib/cli/src/commands/gen_c_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ use wasmer_types::compilation::symbols::ModuleMetadataSymbolRegistry;
use wasmer_types::{CpuFeature, MetadataHeader, Triple};
use webc::WebC;

use super::normalize_path;

#[derive(Debug, Parser)]
/// The options for the `wasmer gen-c-header` subcommand
pub struct GenCHeader {
Expand Down Expand Up @@ -50,7 +48,7 @@ pub struct GenCHeader {
impl GenCHeader {
/// Runs logic for the `gen-c-header` subcommand
pub fn execute(&self) -> Result<(), anyhow::Error> {
let path = crate::commands::normalize_path(&format!("{}", self.path.display()));
let path = crate::common::normalize_path(&format!("{}", self.path.display()));
let mut file = std::fs::read(&path)
.map_err(|e| anyhow::anyhow!("{e}"))
.with_context(|| anyhow::anyhow!("{path}"))?;
Expand Down Expand Up @@ -126,7 +124,7 @@ impl GenCHeader {
metadata_length,
);

let output = normalize_path(&self.output.display().to_string());
let output = crate::common::normalize_path(&self.output.display().to_string());

std::fs::write(&output, &header_file_src)
.map_err(|e| anyhow::anyhow!("{e}"))
Expand Down
4 changes: 2 additions & 2 deletions lib/cli/src/commands/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,8 @@ fn construct_manifest(
.join(&format!("{package_name}.wasm"));
let canonicalized_outpath = outpath.canonicalize().unwrap_or(outpath);
let outpath_str =
crate::commands::normalize_path(&canonicalized_outpath.display().to_string());
let manifest_canonicalized = crate::commands::normalize_path(
crate::common::normalize_path(&canonicalized_outpath.display().to_string());
let manifest_canonicalized = crate::common::normalize_path(
&manifest_path
.parent()
.and_then(|p| p.canonicalize().ok())
Expand Down
43 changes: 29 additions & 14 deletions lib/cli/src/commands/run.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(feature = "cache")]
use crate::common::get_cache_dir;
#[cfg(feature = "debug")]
use crate::logging;
Expand All @@ -9,7 +10,9 @@ use anyhow::{anyhow, Context, Result};
use clap::Parser;
use std::ops::Deref;
use std::path::PathBuf;
#[cfg(feature = "cache")]
use std::str::FromStr;
#[cfg(feature = "emscripten")]
use wasmer::FunctionEnv;
use wasmer::*;
#[cfg(feature = "cache")]
Expand Down Expand Up @@ -199,12 +202,13 @@ impl RunWithPathBuf {
#[cfg(feature = "webc_runner")]
{
if let Ok(pf) = WapmContainer::new(self.path.clone()) {
return Self::run_container(
pf,
&self.command_name.clone().unwrap_or_default(),
&self.args,
)
.map_err(|e| anyhow!("Could not run PiritaFile: {e}"));
return self
.run_container(
pf,
&self.command_name.clone().unwrap_or_default(),
&self.args,
)
.map_err(|e| anyhow!("Could not run PiritaFile: {e}"));
}
}
let (mut store, module) = self.get_store_module()?;
Expand Down Expand Up @@ -344,7 +348,12 @@ impl RunWithPathBuf {
}

#[cfg(feature = "webc_runner")]
fn run_container(container: WapmContainer, id: &str, args: &[String]) -> Result<(), String> {
fn run_container(
&self,
container: WapmContainer,
id: &str,
args: &[String],
) -> Result<(), anyhow::Error> {
let mut result = None;

#[cfg(feature = "wasi")]
Expand All @@ -353,12 +362,15 @@ impl RunWithPathBuf {
return r;
}

let mut runner = wasmer_wasi::runners::wasi::WasiRunner::default();
let (store, _compiler_type) = self.store.get_store()?;
let mut runner = wasmer_wasi::runners::wasi::WasiRunner::new(store);
runner.set_args(args.to_vec());
result = Some(if id.is_empty() {
runner.run(&container).map_err(|e| format!("{e}"))
runner.run(&container).map_err(|e| anyhow::anyhow!("{e}"))
} else {
runner.run_cmd(&container, id).map_err(|e| format!("{e}"))
runner
.run_cmd(&container, id)
.map_err(|e| anyhow::anyhow!("{e}"))
});
}

Expand All @@ -368,16 +380,19 @@ impl RunWithPathBuf {
return r;
}

let mut runner = wasmer_wasi::runners::emscripten::EmscriptenRunner::default();
let (store, _compiler_type) = self.store.get_store()?;
let mut runner = wasmer_wasi::runners::emscripten::EmscriptenRunner::new(store);
runner.set_args(args.to_vec());
result = Some(if id.is_empty() {
runner.run(&container).map_err(|e| format!("{e}"))
runner.run(&container).map_err(|e| anyhow::anyhow!("{e}"))
} else {
runner.run_cmd(&container, id).map_err(|e| format!("{e}"))
runner
.run_cmd(&container, id)
.map_err(|e| anyhow::anyhow!("{e}"))
});
}

result.unwrap_or_else(|| Err("neither emscripten or wasi file".to_string()))
result.unwrap_or_else(|| Err(anyhow::anyhow!("neither emscripten or wasi file")))
}

fn get_store_module(&self) -> Result<(Store, Module)> {
Expand Down
Loading