From 0678e90cbdf034637e4d2f89ec78b8c8801d4138 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Tue, 17 Jan 2023 21:02:44 +0100 Subject: [PATCH] Fix headless-minimal properly --- lib/cli/Cargo.toml | 2 +- lib/cli/src/cli.rs | 9 ++--- lib/cli/src/commands.rs | 10 +++--- lib/cli/src/commands/create_exe.rs | 5 +-- lib/cli/src/commands/create_obj.rs | 53 ++++++++++++++-------------- lib/cli/src/commands/gen_c_header.rs | 6 ++-- lib/cli/src/commands/init.rs | 4 +-- lib/cli/src/common.rs | 4 +++ 8 files changed, 47 insertions(+), 46 deletions(-) diff --git a/lib/cli/Cargo.toml b/lib/cli/Cargo.toml index bf19710af..a1960afa9 100644 --- a/lib/cli/Cargo.toml +++ b/lib/cli/Cargo.toml @@ -162,7 +162,7 @@ llvm = [ debug = ["fern", "wasmer-wasi/logging"] disable-all-logging = ["wasmer-wasi/disable-all-logging"] headless = [] -headless-minimal = ["headless", "disable-all-logging", "wasi", "webc", "static-artifact-create"] +headless-minimal = ["headless", "disable-all-logging", "wasi"] # Optional enable-serde = [ diff --git a/lib/cli/src/cli.rs b/lib/cli/src/cli.rs index be137ce53..5b65f3129 100644 --- a/lib/cli/src/cli.rs +++ b/lib/cli/src/cli.rs @@ -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}; @@ -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 @@ -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(), diff --git a/lib/cli/src/commands.rs b/lib/cli/src/commands.rs index a70d8d42d..fa241435f 100644 --- a/lib/cli/src/commands.rs +++ b/lib/cli/src/commands.rs @@ -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; @@ -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, diff --git a/lib/cli/src/commands/create_exe.rs b/lib/cli/src/commands/create_exe.rs index c804aa868..84f1db388 100644 --- a/lib/cli/src/commands/create_exe.rs +++ b/lib/cli/src/commands/create_exe.rs @@ -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; @@ -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( diff --git a/lib/cli/src/commands/create_obj.rs b/lib/cli/src/commands/create_obj.rs index 1f715ff1f..15f5a5c04 100644 --- a/lib/cli/src/commands/create_obj.rs +++ b/lib/cli/src/commands/create_obj.rs @@ -70,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); @@ -95,31 +95,32 @@ impl CreateObj { println!("Target: {}", target.triple()); println!("Format: {:?}", object_format); - 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(), - ) - }?; + 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 diff --git a/lib/cli/src/commands/gen_c_header.rs b/lib/cli/src/commands/gen_c_header.rs index 4ddff10d8..2a309af21 100644 --- a/lib/cli/src/commands/gen_c_header.rs +++ b/lib/cli/src/commands/gen_c_header.rs @@ -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 { @@ -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}"))?; @@ -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}")) diff --git a/lib/cli/src/commands/init.rs b/lib/cli/src/commands/init.rs index f6b1fb89e..584c7764d 100644 --- a/lib/cli/src/commands/init.rs +++ b/lib/cli/src/commands/init.rs @@ -428,8 +428,8 @@ fn construct_manifest( .join(&format!("{package_name}.wasm")); let canonicalized_outpath = outpath.canonicalize().unwrap_or(outpath); let outpath_str = - crate::commands::normalize_path(&canonicalized_outpath.display().to_string()); - let manifest_canonicalized = crate::commands::normalize_path( + crate::common::normalize_path(&canonicalized_outpath.display().to_string()); + let manifest_canonicalized = crate::common::normalize_path( &manifest_path .parent() .and_then(|p| p.canonicalize().ok()) diff --git a/lib/cli/src/common.rs b/lib/cli/src/common.rs index 81af03197..a06ded1fd 100644 --- a/lib/cli/src/common.rs +++ b/lib/cli/src/common.rs @@ -51,3 +51,7 @@ pub fn get_cache_dir() -> PathBuf { } } } + +pub(crate) fn normalize_path(s: &str) -> String { + s.strip_prefix(r"\\?\").unwrap_or(s).to_string() +}