From 7c37cc9266ff242d231ec5afc1196236325ce074 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Tue, 1 Nov 2022 12:33:17 +0100 Subject: [PATCH] WIP --- lib/cli/src/commands/create_exe.rs | 12 ++++++++-- lib/cli/src/commands/create_obj.rs | 1 + tests/integration/cli/tests/create_exe.rs | 27 +++++++++++++++++++---- tests/integration/cli/tests/run.rs | 21 ++++++++++++++++++ 4 files changed, 55 insertions(+), 6 deletions(-) diff --git a/lib/cli/src/commands/create_exe.rs b/lib/cli/src/commands/create_exe.rs index d60bf704eb1..573048a3e8a 100644 --- a/lib/cli/src/commands/create_exe.rs +++ b/lib/cli/src/commands/create_exe.rs @@ -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()?; @@ -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(), )?; @@ -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()?; diff --git a/lib/cli/src/commands/create_obj.rs b/lib/cli/src/commands/create_obj.rs index a662724f7e2..592ffa59e53 100644 --- a/lib/cli/src/commands/create_obj.rs +++ b/lib/cli/src/commands/create_obj.rs @@ -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()?; diff --git a/tests/integration/cli/tests/create_exe.rs b/tests/integration/cli/tests/create_exe.rs index 866bef6a5ae..e0beef0ac83 100644 --- a/tests/integration/cli/tests/create_exe.rs +++ b/tests/integration/cli/tests/create_exe.rs @@ -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: {}", @@ -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(); @@ -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", @@ -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")?; diff --git a/tests/integration/cli/tests/run.rs b/tests/integration/cli/tests/run.rs index e55854e4054..6ec1306858f 100644 --- a/tests/integration/cli/tests/run.rs +++ b/tests/integration/cli/tests/run.rs @@ -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()); }