1
- #![ allow( dependency_on_unit_never_type_fallback) ]
2
-
1
+ use std:: ffi:: OsString ;
3
2
use std:: fs:: File ;
4
3
use std:: io:: { Read , Write } ;
4
+ use std:: sync:: LazyLock ;
5
5
6
6
use anyhow:: Result ;
7
7
use chrono:: Local ;
@@ -14,17 +14,16 @@ use log::{LevelFilter, info};
14
14
15
15
#[ derive( Parser , Debug ) ]
16
16
#[ command( author, version, about, long_about = None ) ]
17
+ #[ command( name = "hermit-wasm" ) ]
17
18
#[ command( next_line_help = true ) ]
18
19
pub struct Config {
19
- /// File name of the WASM module
20
- #[ arg( short, long, value_name = "FILE" ) ]
21
- fname : Option < String > ,
22
-
23
- /// Defines the usage of the WebAssembly threads proposal for compilation
24
- #[ arg( short, long, default_value_t = false ) ]
25
- threads : bool ,
20
+ /// The WebAssembly module to run and arguments to pass to it.
21
+ #[ arg( value_name = "WASM" ) ]
22
+ pub module_and_args : Vec < OsString > ,
26
23
}
27
24
25
+ static CONFIG : LazyLock < Config > = LazyLock :: new ( Config :: parse) ;
26
+
28
27
pub fn main ( ) -> Result < ( ) > {
29
28
Builder :: new ( )
30
29
. filter_level ( LevelFilter :: Info )
@@ -41,34 +40,16 @@ pub fn main() -> Result<()> {
41
40
} )
42
41
. init ( ) ;
43
42
44
- let args = Config :: parse ( ) ;
45
-
46
43
// First step is to create the Wasm execution engine with some config.
47
- // In this example we are using the default configuration.
48
- let mut config = wasmtime:: Config :: new ( ) ;
49
- config. wasm_threads ( args. threads ) ;
50
-
51
- for argument in std:: env:: args ( ) {
52
- println ! ( "{argument}" ) ;
53
- }
54
-
55
- if let Some ( fname) = args. fname {
56
- info ! ( "Start Hermit-WASM!" ) ;
57
-
58
- let mut buffer = Vec :: new ( ) ;
59
- let mut f = File :: open ( fname) ?;
44
+ // Currently, we are using the default configuration.
45
+ let config = wasmtime:: Config :: new ( ) ;
60
46
61
- f . read_to_end ( & mut buffer ) ? ;
47
+ info ! ( "Start Hermit-WASM!" ) ;
62
48
63
- run_preview1 ( buffer. as_slice ( ) , & config)
64
- } else {
65
- info ! ( "Start simple demo application in Hermit-WASM!" ) ;
49
+ let mut buffer = Vec :: new ( ) ;
50
+ let mut f = File :: open ( CONFIG . module_and_args [ 0 ] . clone ( ) ) . expect ( "Unable to open wasm module" ) ;
66
51
67
- #[ cfg( not( feature = "ci" ) ) ]
68
- let module_bytes = include_bytes ! ( concat!( env!( "OUT_DIR" ) , "/wasm-test.wasm" ) ) ;
69
- #[ cfg( feature = "ci" ) ]
70
- let module_bytes = include_bytes ! ( concat!( env!( "OUT_DIR" ) , "/hello_world.wasm" ) ) ;
52
+ f. read_to_end ( & mut buffer) ?;
71
53
72
- run_preview1 ( module_bytes, & config)
73
- }
54
+ run_preview1 ( buffer. as_slice ( ) , & config, & CONFIG . module_and_args )
74
55
}
0 commit comments