wasmer_cli/
common.rs

1//! Common module with common used structures across different
2//! commands.
3
4use clap::{Parser, ValueEnum};
5
6#[derive(Debug, Parser, Clone, Default)]
7/// The WebAssembly features that can be passed through the
8/// Command Line args.
9pub struct WasmFeatures {
10    /// Enable support for the SIMD proposal.
11    #[clap(long = "enable-simd")]
12    pub simd: bool,
13
14    /// Disable support for the threads proposal.
15    #[clap(long = "disable-threads")]
16    pub disable_threads: bool,
17
18    /// Deprecated, threads are enabled by default.
19    #[clap(long = "enable-threads")]
20    pub _threads: bool,
21
22    /// Enable support for the reference types proposal.
23    #[clap(long = "enable-reference-types")]
24    pub reference_types: bool,
25
26    /// Enable support for the multi value proposal.
27    #[clap(long = "enable-multi-value")]
28    pub multi_value: bool,
29
30    /// Enable support for the bulk memory proposal.
31    #[clap(long = "enable-bulk-memory")]
32    pub bulk_memory: bool,
33
34    /// Enable support for all pre-standard proposals.
35    #[clap(long = "enable-all")]
36    pub all: bool,
37}
38
39pub(crate) fn normalize_path(s: &str) -> String {
40    s.strip_prefix(r"\\?\").unwrap_or(s).to_string()
41}
42
43/// Hashing algorithm to be used for the module info
44#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, ValueEnum)]
45pub enum HashAlgorithm {
46    /// Sha256
47    Sha256,
48    /// XXHash
49    XXHash,
50}
51
52impl Default for HashAlgorithm {
53    fn default() -> Self {
54        Self::Sha256
55    }
56}
57
58impl From<HashAlgorithm> for wasmer_types::HashAlgorithm {
59    fn from(value: HashAlgorithm) -> Self {
60        match value {
61            HashAlgorithm::Sha256 => wasmer_types::HashAlgorithm::Sha256,
62            HashAlgorithm::XXHash => wasmer_types::HashAlgorithm::XXHash,
63        }
64    }
65}