diff --git a/lib/cli/src/commands.rs b/lib/cli/src/commands.rs index 8baf6a014..943959910 100644 --- a/lib/cli/src/commands.rs +++ b/lib/cli/src/commands.rs @@ -43,8 +43,10 @@ pub use { #[cfg(any(feature = "static-artifact-create", feature = "wasmer-artifact-create"))] pub enum ObjectFormat { /// Serialize the entire module into an object file. + #[clap(name = "serialized")] Serialized, /// Serialize only the module metadata into an object file and emit functions as symbols. + #[clap(name = "symbols")] Symbols, } diff --git a/lib/cli/src/commands/create_exe.rs b/lib/cli/src/commands/create_exe.rs index 5be4c3b20..0d8ad7d39 100644 --- a/lib/cli/src/commands/create_exe.rs +++ b/lib/cli/src/commands/create_exe.rs @@ -163,6 +163,7 @@ impl CreateExe { let input_path = starting_cd.join(&path); let output_path = starting_cd.join(&self.output); let object_format = self.object_format.unwrap_or_default(); + let cross_compilation = utils::get_cross_compile_setup(&mut cc, &target_triple, &starting_cd, &object_format)?; @@ -182,14 +183,15 @@ impl CreateExe { return Err(anyhow::anyhow!("library path does not exist")); } + let temp = tempfile::tempdir(); + let tempdir = match self.debug_dir.as_ref() { + Some(s) => s.clone(), + None => temp?.path().to_path_buf(), + }; + std::fs::create_dir_all(&tempdir)?; + if let Ok(pirita) = WebCMmap::parse(input_path.clone(), &ParseOptions::default()) { // pirita file - let temp = tempdir::TempDir::new("pirita-compile")?; - let tempdir = match self.debug_dir.as_ref() { - Some(s) => s.clone(), - None => temp.path().to_path_buf(), - }; - std::fs::create_dir_all(&tempdir)?; let atoms = compile_pirita_into_directory( &pirita, &tempdir, @@ -215,12 +217,6 @@ impl CreateExe { )?; } else { // wasm file - let temp = tempdir::TempDir::new("pirita-compile")?; - let tempdir = match self.debug_dir.as_ref() { - Some(s) => s.clone(), - None => temp.path().to_path_buf(), - }; - std::fs::create_dir_all(&tempdir)?; let atoms = prepare_directory_from_single_wasm_file( &input_path, &tempdir, diff --git a/lib/cli/src/commands/create_obj.rs b/lib/cli/src/commands/create_obj.rs index 1d5ccfe80..c80ca787f 100644 --- a/lib/cli/src/commands/create_obj.rs +++ b/lib/cli/src/commands/create_obj.rs @@ -77,10 +77,10 @@ impl CreateObj { 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); - let temp_dir = tempdir::TempDir::new("create-obj-intermediate")?; + let temp_dir = tempfile::tempdir(); let output_directory_path = match self.debug_dir.as_ref() { - Some(s) => s.as_path(), - None => temp_dir.path(), + Some(s) => s.clone(), + None => temp_dir?.path().to_path_buf(), }; std::fs::create_dir_all(&output_directory_path)?; let object_format = self.object_format.unwrap_or_default(); @@ -102,7 +102,7 @@ impl CreateObj { if let Ok(pirita) = WebCMmap::parse(input_path.clone(), &ParseOptions::default()) { crate::commands::create_exe::compile_pirita_into_directory( &pirita, - output_directory_path, + &output_directory_path, &self.compiler, &self.cpu_features, &target_triple, @@ -114,7 +114,7 @@ impl CreateObj { } else { crate::commands::create_exe::prepare_directory_from_single_wasm_file( &input_path, - output_directory_path, + &output_directory_path, &self.compiler, &target_triple, &self.cpu_features, diff --git a/tests/integration/cli/tests/create_exe.rs b/tests/integration/cli/tests/create_exe.rs index 0733907a8..62c8892cc 100644 --- a/tests/integration/cli/tests/create_exe.rs +++ b/tests/integration/cli/tests/create_exe.rs @@ -61,9 +61,10 @@ impl WasmerCreateExe { output.args(self.extra_cli_flags.iter()); output.arg("-o"); output.arg(&self.native_executable_path); - let cmd = format!("{:?}", output); + println!("(integration-test) running create-exe: {cmd}"); + let output = output.output()?; if !output.status.success() { @@ -126,6 +127,8 @@ impl WasmerCreateObj { let cmd = format!("{:?}", output); + println!("(integration-test) running create-obj: {cmd}"); + let output = output.output()?; if !output.status.success() { @@ -385,7 +388,7 @@ fn create_obj_serialized() -> anyhow::Result<()> { ) } -fn create_exe_with_object_input(mut args: Vec) -> anyhow::Result<()> { +fn create_exe_with_object_input(args: Vec) -> anyhow::Result<()> { let temp_dir = tempfile::tempdir()?; let operating_dir: PathBuf = temp_dir.path().to_owned(); @@ -396,15 +399,21 @@ fn create_exe_with_object_input(mut args: Vec) -> anyhow::Result<()> { #[cfg(windows)] let object_path = operating_dir.join("wasm.obj"); - args.push("--prefix".to_string()); - args.push("abc123".to_string()); + let mut create_obj_args = args.clone(); + create_obj_args.push("--prefix".to_string()); + create_obj_args.push("abc123".to_string()); + create_obj_args.push("--debug-dir".to_string()); + create_obj_args.push(format!( + "{}", + operating_dir.join("compile-create-obj").display() + )); WasmerCreateObj { current_dir: operating_dir.clone(), wasm_path: wasm_path.clone(), output_object_path: object_path.clone(), compiler: Compiler::Cranelift, - extra_cli_flags: args, + extra_cli_flags: create_obj_args, ..Default::default() } .run() @@ -421,15 +430,21 @@ fn create_exe_with_object_input(mut args: Vec) -> anyhow::Result<()> { #[cfg(windows)] let executable_path = operating_dir.join("wasm.exe"); + let mut create_exe_args = args.clone(); + create_exe_args.push("--precompiled-atom".to_string()); + create_exe_args.push(format!("qjs:abc123:{}", object_path.display())); + create_exe_args.push("--debug-dir".to_string()); + create_exe_args.push(format!( + "{}", + operating_dir.join("compile-create-exe").display() + )); + let create_exe_stdout = WasmerCreateExe { current_dir: std::env::current_dir().unwrap(), wasm_path, native_executable_path: executable_path.clone(), compiler: Compiler::Cranelift, - extra_cli_flags: vec![ - "--precompiled-atom".to_string(), - format!("qjs:abc123:{}", object_path.display()), - ], + extra_cli_flags: create_exe_args, ..Default::default() } .run()