Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
fschutt committed Nov 1, 2022
1 parent 84feb95 commit 7c37cc9
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 6 deletions.
12 changes: 10 additions & 2 deletions lib/cli/src/commands/create_exe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ impl CreateExe {
}
#[cfg(feature = "static-artifact-create")]
ObjectFormat::Symbols => {
println!("2");
let engine = store.engine();
let engine_inner = engine.inner();
let compiler = engine_inner.compiler()?;
Expand Down Expand Up @@ -485,10 +486,16 @@ impl CreateExe {
#[cfg(windows)]
let c_src_obj = tempdir_path.join("wasmer_main.obj");

let contents = WASMER_MAIN_C_SOURCE
.replace("// WASI_DEFINES", "#define WASI");

println!("---- wasmer_main.c contents");
println!("{contents}");
println!("----");

std::fs::write(
&c_src_path,
WASMER_MAIN_C_SOURCE
.replace("// WASI_DEFINES", "#define WASI")
contents
.as_bytes(),
)?;

Expand Down Expand Up @@ -684,6 +691,7 @@ impl CreateExe {
}
#[cfg(feature = "static-artifact-create")]
ObjectFormat::Symbols => {
println!("3");
let engine = store.engine();
let engine_inner = engine.inner();
let compiler = engine_inner.compiler()?;
Expand Down
1 change: 1 addition & 0 deletions lib/cli/src/commands/create_obj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ impl CreateObj {
writer.flush()?;
}
ObjectFormat::Symbols => {
println!("1");
let engine = store.engine();
let engine_inner = engine.inner();
let compiler = engine_inner.compiler()?;
Expand Down
27 changes: 23 additions & 4 deletions tests/integration/cli/tests/create_exe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ impl WasmerCreateObj {
.arg(&self.output_object_path)
.output()?;

println!("wasmer create-obj: {output:?}");

if !output.status.success() {
bail!(
"wasmer create-obj failed with: stdout: {}\n\nstderr: {}",
Expand Down Expand Up @@ -331,6 +333,7 @@ fn create_obj_serialized() -> anyhow::Result<()> {
}

fn create_exe_with_object_input(args: Vec<&'static str>) -> anyhow::Result<()> {
println!("create_exe_with_object_input");
let temp_dir = tempfile::tempdir()?;
let operating_dir: PathBuf = temp_dir.path().to_owned();

Expand All @@ -341,17 +344,29 @@ fn create_exe_with_object_input(args: Vec<&'static str>) -> anyhow::Result<()> {
#[cfg(windows)]
let object_path = operating_dir.join("wasm.obj");

WasmerCreateObj {
let co = WasmerCreateObj {
current_dir: operating_dir.clone(),
wasm_path,
output_object_path: object_path.clone(),
compiler: Compiler::Cranelift,
extra_cli_flags: args,
..Default::default()
}
};

println!("running co: {co:#?}");

co
.run()
.context("Failed to create-obj wasm with Wasmer")?;

let wasm_h_path = operating_dir.join("wasm.h");
println!("reading {}", wasm_h_path.display());
let s = std::fs::read_to_string(&wasm_h_path).unwrap();

println!("wasm.h: ----");
println!("{s}");
println!("----");

assert!(
object_path.exists(),
"create-obj successfully completed but object output file `{}` missing",
Expand All @@ -370,14 +385,18 @@ fn create_exe_with_object_input(args: Vec<&'static str>) -> anyhow::Result<()> {
#[cfg(windows)]
let executable_path = operating_dir.join("wasm.exe");

WasmerCreateExe {
let ce = WasmerCreateExe {
current_dir: operating_dir.clone(),
wasm_path: object_path,
native_executable_path: executable_path.clone(),
compiler: Compiler::Cranelift,
extra_cli_flags: vec!["--header", "wasm.h"],
..Default::default()
}
};

println!("running ce: {ce:#?}");

ce
.run()
.context("Failed to create-exe wasm with Wasmer")?;

Expand Down
21 changes: 21 additions & 0 deletions tests/integration/cli/tests/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,27 @@ fn test_wasmer_create_exe_pirita_works() -> anyhow::Result<()> {
let native_target = target_lexicon::HOST;
let root_path = get_repo_root_path().unwrap();
let package_path = root_path.join("package");

// make && make build-capi && make package-capi && make package
let mut c1 = std::process::Command::new("make");
c1.current_dir(&root_path);
let _ = c1.output().unwrap();

let mut c1 = std::process::Command::new("make");
c1.arg("build-capi");
c1.current_dir(&root_path);
let _ = c1.output().unwrap();

let mut c1 = std::process::Command::new("make");
c1.arg("package-capi");
c1.current_dir(&root_path);
let _ = c1.output().unwrap();

let mut c1 = std::process::Command::new("make");
c1.arg("package");
c1.current_dir(&root_path);
let _ = c1.output().unwrap();

if !package_path.exists() {
panic!("package path {} does not exist", package_path.display());
}
Expand Down

0 comments on commit 7c37cc9

Please sign in to comment.