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 14 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
1 change: 1 addition & 0 deletions lib/api/src/sys/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ impl Imports {
/// Resolve and return a vector of imports in the order they are defined in the `module`'s source code.
///
/// This means the returned `Vec<Extern>` might be a subset of the imports contained in `self`.
#[allow(clippy::result_large_err)]
pub fn imports_for_module(&self, module: &Module) -> Result<Vec<Extern>, LinkError> {
let mut ret = vec![];
for import in module.imports() {
Expand Down
2 changes: 2 additions & 0 deletions lib/api/src/sys/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ impl Instance {
/// Those are, as defined by the spec:
/// * Link errors that happen when plugging the imports into the instance
/// * Runtime errors that happen when running the module `start` function.
#[allow(clippy::result_large_err)]
pub fn new(
store: &mut impl AsStoreMut,
module: &Module,
Expand Down Expand Up @@ -158,6 +159,7 @@ impl Instance {
/// Those are, as defined by the spec:
/// * Link errors that happen when plugging the imports into the instance
/// * Runtime errors that happen when running the module `start` function.
#[allow(clippy::result_large_err)]
pub fn new_by_index(
store: &mut impl AsStoreMut,
module: &Module,
Expand Down
1 change: 1 addition & 0 deletions lib/api/src/sys/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ impl Module {
}
}

#[allow(clippy::result_large_err)]
#[cfg(feature = "compiler")]
pub(crate) fn instantiate(
&self,
Expand Down
23 changes: 11 additions & 12 deletions lib/api/src/sys/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,20 +174,19 @@ 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")
compile_error!("No compiler [cranelift, llvm, singlepass] enabled, use Store::headless() instead of Store::default() for a headless engine")
fschutt marked this conversation as resolved.
Show resolved Hide resolved
fschutt marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions lib/c-api/src/wasm_c_api/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ pub struct wasm_config_t {
/// cbindgen:ignore
#[no_mangle]
pub extern "C" fn wasm_config_new() -> Box<wasm_config_t> {
Box::new(wasm_config_t::default())
Box::<wasm_config_t>::default()
}

/// Delete a Wasmer config object.
Expand Down Expand Up @@ -256,11 +256,11 @@ use wasmer_api::CompilerConfig;
fn get_default_compiler_config() -> Box<dyn CompilerConfig> {
cfg_if! {
if #[cfg(feature = "cranelift")] {
Box::new(wasmer_compiler_cranelift::Cranelift::default())
Box::<wasmer_compiler_cranelift::Cranelift>::default()
} else if #[cfg(feature = "llvm")] {
Box::new(wasmer_compiler_llvm::LLVM::default())
Box::<wasmer_compiler_llvm::LLVM>::default()
} else if #[cfg(feature = "singlepass")] {
Box::new(wasmer_compiler_singlepass::Singlepass::default())
Box::<wasmer_compiler_singlepass::Singlepass>::default()
} else {
compile_error!("Please enable one of the compiler backends")
}
Expand Down Expand Up @@ -368,7 +368,7 @@ pub extern "C" fn wasm_engine_new_with_config(
wasmer_compiler_t::CRANELIFT => {
cfg_if! {
if #[cfg(feature = "cranelift")] {
Box::new(wasmer_compiler_cranelift::Cranelift::default())
Box::<wasmer_compiler_cranelift::Cranelift>::default()
} else {
return return_with_error("Wasmer has not been compiled with the `cranelift` feature.");
}
Expand Down
4 changes: 2 additions & 2 deletions lib/c-api/src/wasm_c_api/wasi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ pub unsafe extern "C" fn wasi_env_read_stdout(
buffer: *mut c_char,
buffer_len: usize,
) -> isize {
let inner_buffer = slice::from_raw_parts_mut(buffer as *mut _, buffer_len as usize);
let inner_buffer = slice::from_raw_parts_mut(buffer as *mut _, buffer_len);
let mut store_mut = env.store.store_mut();
let state = env.inner.data_mut(&mut store_mut).state();

Expand All @@ -365,7 +365,7 @@ pub unsafe extern "C" fn wasi_env_read_stderr(
buffer: *mut c_char,
buffer_len: usize,
) -> isize {
let inner_buffer = slice::from_raw_parts_mut(buffer as *mut _, buffer_len as usize);
let inner_buffer = slice::from_raw_parts_mut(buffer as *mut _, buffer_len);
let mut store_mut = env.store.store_mut();
let state = env.inner.data_mut(&mut store_mut).state();
if let Ok(mut stderr) = state.stderr() {
Expand Down
2 changes: 1 addition & 1 deletion lib/cache/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl ToString for Hash {
/// Create the hexadecimal representation of the
/// stored hash.
fn to_string(&self) -> String {
hex::encode(&self.to_array())
hex::encode(self.to_array())
}
}

Expand Down
3 changes: 3 additions & 0 deletions lib/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,17 @@ experimental-io-devices = [
]
singlepass = [
"wasmer-compiler-singlepass",
"wasmer/singlepass",
fschutt marked this conversation as resolved.
Show resolved Hide resolved
"compiler",
]
cranelift = [
"wasmer-compiler-cranelift",
"wasmer/cranelift",
fschutt marked this conversation as resolved.
Show resolved Hide resolved
"compiler",
]
llvm = [
"wasmer-compiler-llvm",
"wasmer/llvm",
fschutt marked this conversation as resolved.
Show resolved Hide resolved
"compiler",
]
debug = ["fern", "wasmer-wasi/logging"]
Expand Down
2 changes: 1 addition & 1 deletion lib/cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::process::Command;
pub fn main() {
// Set WASMER_GIT_HASH
let git_hash = Command::new("git")
.args(&["rev-parse", "HEAD"])
.args(["rev-parse", "HEAD"])
.output()
.ok()
.and_then(|output| String::from_utf8(output.stdout).ok())
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
15 changes: 6 additions & 9 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 @@ -866,7 +867,7 @@ fn write_volume_obj(
object_name,
)?;

let mut writer = BufWriter::new(File::create(&output_path)?);
let mut writer = BufWriter::new(File::create(output_path)?);
volumes_object
.write_stream(&mut writer)
.map_err(|err| anyhow::anyhow!(err.to_string()))?;
Expand Down Expand Up @@ -1049,7 +1050,7 @@ pub(crate) fn create_header_files_in_dir(
&ModuleMetadataSymbolRegistry {
prefix: prefix.clone(),
},
metadata_length as usize,
metadata_length,
);

std::fs::write(&header_file_path, &header_file_src).map_err(|e| {
Expand Down Expand Up @@ -1194,7 +1195,7 @@ fn link_exe_from_dir(
.as_ref()
.ok_or_else(|| anyhow::anyhow!("could not find zig in $PATH {}", directory.display()))?;

let mut cmd = Command::new(&zig_binary_path);
let mut cmd = Command::new(zig_binary_path);
cmd.arg("build-exe");
cmd.arg("--verbose-cc");
cmd.arg("--verbose-link");
Expand Down Expand Up @@ -1319,10 +1320,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 Expand Up @@ -1875,7 +1872,7 @@ pub(super) mod utils {
let path_var = std::env::var("PATH").unwrap_or_default();
#[cfg(unix)]
let system_path_var = std::process::Command::new("getconf")
.args(&["PATH"])
.args(["PATH"])
.output()
.map(|output| output.stdout)
.unwrap_or_default();
Expand Down Expand Up @@ -2268,7 +2265,7 @@ mod http_fetch {

pub(crate) fn list_dir(target: &Path) -> Vec<PathBuf> {
use walkdir::WalkDir;
WalkDir::new(&target)
WalkDir::new(target)
.into_iter()
.filter_map(|e| e.ok())
.map(|entry| entry.path().to_path_buf())
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
Loading