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

Move compilation types inside of wasmer compiler #5225

Merged
merged 17 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
31 changes: 5 additions & 26 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 3 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ members = [
"lib/compiler",
"lib/config",
"lib/derive",
"lib/object",
"lib/sys-utils",
"lib/types",
"lib/virtual-io",
Expand Down Expand Up @@ -121,6 +120,8 @@ socket2 = "0.5.7"
pretty_assertions = "1.4.0"
base64 = "0.22.0"
time = "0.3.36"
target-lexicon = { version = "0.12.2", default-features = false }
object = "0.32.0"

[build-dependencies]
test-generator = { path = "tests/lib/test-generator" }
Expand Down Expand Up @@ -158,14 +159,7 @@ reqwest.workspace = true
[features]
# Don't add the compiler features in default, please add them on the Makefile
# since we might want to autoconfigure them depending on the availability on the host.
default = [
"wat",
"wast",
"cache",
"wasi",
"engine",
"middlewares",
]
default = ["wat", "wast", "cache", "wasi", "engine", "middlewares"]
# backend means that the `wasmer` crate will be compiled with the `wasmer-compiler` or the `jsc`.
# That means: that is able to execute modules
backend = []
Expand Down
2 changes: 1 addition & 1 deletion examples/engine_cross_compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

use std::str::FromStr;
use wasmer::{sys::EngineBuilder, wat2wasm, Module, RuntimeError, Store};
use wasmer_compiler::types::target::{CpuFeature, Target, Triple};
use wasmer_compiler_cranelift::Cranelift;
use wasmer_types::{CpuFeature, Target, Triple};

fn main() -> Result<(), Box<dyn std::error::Error>> {
// Let's declare the Wasm module with the text representation.
Expand Down
2 changes: 1 addition & 1 deletion examples/platform_ios_headless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
use std::path::Path;
use std::str::FromStr;
use wasmer::{wat2wasm, Module, RuntimeError, Store};
use wasmer_compiler::types::target::{CpuFeature, Target, Triple};
use wasmer_compiler_cranelift::Cranelift;
use wasmer_types::{CpuFeature, Target, Triple};
/*
use wasmer_engine_dylib::Dylib;
*/
Expand Down
7 changes: 6 additions & 1 deletion lib/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ wasmparser = { workspace = true, default-features = false, optional = true }
hashbrown = { version = "0.11", optional = true }
serde-wasm-bindgen = { version = "0.4.5" }
serde = { version = "1.0", features = ["derive"] }
target-lexicon = { workspace = true }

# - Development Dependencies for `js`.
[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
Expand Down Expand Up @@ -168,7 +169,11 @@ xz = "0.1.0"
zip = "2.2.0"

[target.'cfg(target_env = "musl")'.build-dependencies]
bindgen = { version = "0.70.1", default-features = false, features = ["static", "logging", "prettyplease"] }
bindgen = { version = "0.70.1", default-features = false, features = [
"static",
"logging",
"prettyplease",
] }

[target.'cfg(not(target_env = "musl"))'.build-dependencies]
bindgen = { version = "0.70.1" }
Expand Down
14 changes: 9 additions & 5 deletions lib/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,13 +519,17 @@ pub use value::Value;
// Reexport from other modules

pub use wasmer_derive::ValueType;

#[cfg(any(feature = "sys", feature = "jsc", feature = "wasm-c-api"))]
pub use wasmer_compiler::types::target::{CpuFeature, Target};

// TODO: OnCalledAction is needed for asyncify. It will be refactored with https://github.com/wasmerio/wasmer/issues/3451
pub use wasmer_types::{
is_wasm, Bytes, CompileError, CpuFeature, DeserializeError, ExportIndex, ExportType,
ExternType, FrameInfo, FunctionType, GlobalInit, GlobalType, ImportType, LocalFunctionIndex,
MemoryError, MemoryType, MiddlewareError, Mutability, OnCalledAction, Pages,
ParseCpuFeatureError, SerializeError, TableType, Target, Type, ValueType, WasmError,
WasmResult, WASM_MAX_PAGES, WASM_MIN_PAGES, WASM_PAGE_SIZE,
is_wasm, Bytes, CompileError, DeserializeError, ExportIndex, ExportType, ExternType, FrameInfo,
FunctionType, GlobalInit, GlobalType, ImportType, LocalFunctionIndex, MemoryError, MemoryType,
MiddlewareError, Mutability, OnCalledAction, Pages, ParseCpuFeatureError, SerializeError,
TableType, Type, ValueType, WasmError, WasmResult, WASM_MAX_PAGES, WASM_MIN_PAGES,
WASM_PAGE_SIZE,
};
#[cfg(feature = "wat")]
pub use wat::parse_bytes as wat2wasm;
Expand Down
4 changes: 2 additions & 2 deletions lib/api/src/sys/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ use std::{path::Path, sync::Arc};

use shared_buffer::OwnedBuffer;
pub use wasmer_compiler::{
Artifact, BaseTunables, CompilerConfig, Engine, EngineBuilder, Tunables,
types::target::Target, Artifact, BaseTunables, CompilerConfig, Engine, EngineBuilder, Tunables,
};
#[cfg(feature = "compiler")]
use wasmer_types::Features;
use wasmer_types::{DeserializeError, HashAlgorithm, Target};
use wasmer_types::{DeserializeError, HashAlgorithm};

/// Get the default config for the sys Engine
#[allow(unreachable_code)]
Expand Down
26 changes: 13 additions & 13 deletions lib/c-api/examples/wasmer-capi-examples-runner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ fn test_run() {
for test in TESTS.iter() {
let manifest_dir_parent = std::path::Path::new(&manifest_dir);
let manifest_dir_parent = manifest_dir_parent.parent().unwrap();
let c_file_path = manifest_dir_parent.join(&format!("{test}.c"));
let c_file_path = manifest_dir_parent.join(format!("{test}.c"));

if target.contains("msvc") {
let mut build = cc::Build::new();
Expand All @@ -208,10 +208,10 @@ fn test_run() {
let compiler = build.try_get_compiler().unwrap();
let mut command = compiler.to_command();

command.arg(&format!("{}", c_file_path.display()));
command.arg(format!("{}", c_file_path.display()));
if !config.wasmer_dir.is_empty() {
command.arg("/I");
command.arg(&format!("{}/include/", config.wasmer_dir));
command.arg(format!("{}/include/", config.wasmer_dir));
let mut log = String::new();
fixup_symlinks(
&[
Expand All @@ -225,17 +225,17 @@ fn test_run() {
println!("{log}");
}

let exe_outpath = manifest_dir_parent.join(&format!("{test}.exe"));
let exe_outpath = manifest_dir_parent.join(format!("{test}.exe"));
let exe_outpath = format!("{}", exe_outpath.display());
println!("compiling exe to {exe_outpath}");

command.arg(&format!("/Fo:{}/", manifest_dir_parent.display()));
command.arg(format!("/Fo:{}/", manifest_dir_parent.display()));
command.arg("/link");
if !config.wasmer_dir.is_empty() {
command.arg(&format!("/LIBPATH:{}/lib", config.wasmer_dir));
command.arg(&format!("{}/lib/wasmer.dll.lib", config.wasmer_dir));
command.arg(format!("/LIBPATH:{}/lib", config.wasmer_dir));
command.arg(format!("{}/lib/wasmer.dll.lib", config.wasmer_dir));
}
command.arg(&format!("/OUT:{exe_outpath}"));
command.arg(format!("/OUT:{exe_outpath}"));

// read vcvars into file, append command, then execute the bat

Expand Down Expand Up @@ -309,7 +309,7 @@ fn test_run() {

if !config.wasmer_dir.is_empty() {
command.arg("-I");
command.arg(&format!("{}/include", config.wasmer_dir));
command.arg(format!("{}/include", config.wasmer_dir));
let mut log = String::new();
fixup_symlinks(
&[
Expand All @@ -324,12 +324,12 @@ fn test_run() {
command.arg(&c_file_path);
if !config.wasmer_dir.is_empty() {
command.arg("-L");
command.arg(&format!("{}/lib/", config.wasmer_dir));
command.arg(format!("{}/lib/", config.wasmer_dir));
command.arg("-lwasmer");
command.arg(&format!("-Wl,-rpath,{}/lib/", config.wasmer_dir));
command.arg(format!("-Wl,-rpath,{}/lib/", config.wasmer_dir));
}
command.arg("-o");
command.arg(&format!("{manifest_dir}/../{test}"));
command.arg(format!("{manifest_dir}/../{test}"));

// cc -g -IC:/Users/felix/Development/wasmer/lib/c-api/examples/../tests
// -IC:/Users/felix/Development/wasmer/package/include
Expand Down Expand Up @@ -358,7 +358,7 @@ fn test_run() {
}

// execute
let mut command = std::process::Command::new(&format!("{manifest_dir}/../{test}"));
let mut command = std::process::Command::new(format!("{manifest_dir}/../{test}"));
command.env("LD_PRELOAD", &libwasmer_so_path);
command.current_dir(&exe_dir);
println!("execute: {command:#?}");
Expand Down
34 changes: 17 additions & 17 deletions lib/c-api/tests/wasmer-c-api-test-runner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,12 @@ fn test_ok() {

let mut command = compiler.to_command();

command.arg(&format!("{manifest_dir}/../{test}.c"));
command.arg(format!("{manifest_dir}/../{test}.c"));
if !config.wasmer_dir.is_empty() {
command.arg("/I");
command.arg(&format!("{}/wasm-c-api/include/", config.root_dir));
command.arg(format!("{}/wasm-c-api/include/", config.root_dir));
command.arg("/I");
command.arg(&format!("{}/include/", config.wasmer_dir));
command.arg(format!("{}/include/", config.wasmer_dir));
let mut log = String::new();
fixup_symlinks(
&[
Expand All @@ -188,10 +188,10 @@ fn test_ok() {
}
command.arg("/link");
if !config.wasmer_dir.is_empty() {
command.arg(&format!("/LIBPATH:{}/lib", config.wasmer_dir));
command.arg(&format!("{}/lib/wasmer.dll.lib", config.wasmer_dir));
command.arg(format!("/LIBPATH:{}/lib", config.wasmer_dir));
command.arg(format!("{}/lib/wasmer.dll.lib", config.wasmer_dir));
}
command.arg(&format!("/OUT:{manifest_dir}/../{test}.exe"));
command.arg(format!("/OUT:{manifest_dir}/../{test}.exe"));

println!("compiling {test}: {command:?}");

Expand All @@ -212,7 +212,7 @@ fn test_ok() {
}

// execute
let mut command = std::process::Command::new(&format!("{manifest_dir}/../{test}.exe"));
let mut command = std::process::Command::new(format!("{manifest_dir}/../{test}.exe"));
println!("newpath: {}", newpath.clone());
command.env("PATH", newpath.clone());
command.current_dir(exe_dir.clone());
Expand Down Expand Up @@ -250,9 +250,9 @@ fn test_ok() {

if !config.wasmer_dir.is_empty() {
command.arg("-I");
command.arg(&format!("{}/wasm-c-api/include/", config.root_dir));
command.arg(format!("{}/wasm-c-api/include/", config.root_dir));
command.arg("-I");
command.arg(&format!("{}/include/", config.wasmer_dir));
command.arg(format!("{}/include/", config.wasmer_dir));
let mut log = String::new();
fixup_symlinks(
&[
Expand All @@ -265,15 +265,15 @@ fn test_ok() {
)
.unwrap_or_else(|_| panic!("failed to fix symlinks: {log}"));
}
command.arg(&format!("{manifest_dir}/../{test}.c"));
command.arg(format!("{manifest_dir}/../{test}.c"));
if !config.wasmer_dir.is_empty() {
command.arg("-L");
command.arg(&format!("{}/lib/", config.wasmer_dir));
command.arg(format!("{}/lib/", config.wasmer_dir));
command.arg("-lwasmer");
command.arg(&format!("-Wl,-rpath,{}/lib/", config.wasmer_dir));
command.arg(format!("-Wl,-rpath,{}/lib/", config.wasmer_dir));
}
command.arg("-o");
command.arg(&format!("{manifest_dir}/../{test}"));
command.arg(format!("{manifest_dir}/../{test}"));

// print_wasmer_root_to_stdout(&config);

Expand All @@ -293,7 +293,7 @@ fn test_ok() {
}

// execute
let mut command = std::process::Command::new(&format!("{manifest_dir}/../{test}"));
let mut command = std::process::Command::new(format!("{manifest_dir}/../{test}"));
command.env("LD_PRELOAD", libwasmer_so_path.clone());
command.current_dir(exe_dir.clone());
println!("execute: {command:#?}");
Expand All @@ -310,9 +310,9 @@ fn test_ok() {
}

for test in CAPI_BASE_TESTS.iter() {
let _ = std::fs::remove_file(&format!("{manifest_dir}/{test}.obj"));
let _ = std::fs::remove_file(&format!("{manifest_dir}/../{test}.exe"));
let _ = std::fs::remove_file(&format!("{manifest_dir}/../{test}"));
let _ = std::fs::remove_file(format!("{manifest_dir}/{test}.obj"));
let _ = std::fs::remove_file(format!("{manifest_dir}/../{test}.exe"));
let _ = std::fs::remove_file(format!("{manifest_dir}/../{test}"));
}
}

Expand Down
Loading
Loading