1
1
use anyhow:: Result ;
2
+ use containerd_shim_wasm:: sandbox:: oci;
2
3
use nix:: unistd:: { dup, dup2} ;
3
4
use oci_spec:: runtime:: Spec ;
4
5
@@ -8,7 +9,7 @@ use std::os::unix::io::RawFd;
8
9
9
10
use wasmedge_sdk:: {
10
11
config:: { CommonConfigOptions , ConfigBuilder , HostRegistrationConfigOptions } ,
11
- params, VmBuilder ,
12
+ params, VmBuilder
12
13
} ;
13
14
14
15
const EXECUTOR_NAME : & str = "wasmedge" ;
@@ -21,16 +22,6 @@ pub struct WasmEdgeExecutor {
21
22
22
23
impl Executor for WasmEdgeExecutor {
23
24
fn exec ( & self , spec : & Spec ) -> Result < ( ) , ExecutorError > {
24
- // parse wasi parameters
25
- let args = get_args ( spec) ;
26
- if args. is_empty ( ) {
27
- return Err ( ExecutorError :: InvalidArg ) ;
28
- }
29
-
30
- let mut cmd = args[ 0 ] . clone ( ) ;
31
- if let Some ( stripped) = args[ 0 ] . strip_prefix ( std:: path:: MAIN_SEPARATOR ) {
32
- cmd = stripped. to_string ( ) ;
33
- }
34
25
let envs = env_to_wasi ( spec) ;
35
26
36
27
// create configuration with `wasi` option enabled
@@ -51,14 +42,23 @@ impl Executor for WasmEdgeExecutor {
51
42
. ok_or_else ( || anyhow:: Error :: msg ( "Not found wasi module" ) )
52
43
. map_err ( |err| ExecutorError :: Execution ( err. into ( ) ) ) ?;
53
44
45
+ let module_args = oci:: get_module_args ( spec) ;
54
46
wasi_module. initialize (
55
- Some ( args . iter ( ) . map ( |s| s as & str ) . collect ( ) ) ,
47
+ Some ( module_args . iter ( ) . map ( |s| s as & str ) . collect ( ) ) ,
56
48
Some ( envs. iter ( ) . map ( |s| s as & str ) . collect ( ) ) ,
57
49
None ,
58
50
) ;
59
51
52
+ let ( module_name, method) = oci:: get_module ( spec) ;
53
+ let module_name = match module_name {
54
+ Some ( m) => m,
55
+ None => {
56
+ return Err ( ExecutorError :: Execution ( anyhow:: Error :: msg ( "no module provided, cannot load module from file within container" ) . into ( ) ) )
57
+ }
58
+ } ;
59
+
60
60
let vm = vm
61
- . register_module_from_file ( "main" , cmd )
61
+ . register_module_from_file ( "main" , module_name )
62
62
. map_err ( |err| ExecutorError :: Execution ( err) ) ?;
63
63
64
64
if let Some ( stdin) = self . stdin {
@@ -74,9 +74,7 @@ impl Executor for WasmEdgeExecutor {
74
74
let _ = dup2 ( stderr, STDERR_FILENO ) ;
75
75
}
76
76
77
- // TODO: How to get exit code?
78
- // This was relatively straight forward in go, but wasi and wasmtime are totally separate things in rust
79
- match vm. run_func ( Some ( "main" ) , "_start" , params ! ( ) ) {
77
+ match vm. run_func ( Some ( "main" ) , method, params ! ( ) ) {
80
78
Ok ( _) => std:: process:: exit ( 0 ) ,
81
79
Err ( _) => std:: process:: exit ( 137 ) ,
82
80
} ;
@@ -91,18 +89,6 @@ impl Executor for WasmEdgeExecutor {
91
89
}
92
90
}
93
91
94
- fn get_args ( spec : & Spec ) -> & [ String ] {
95
- let p = match spec. process ( ) {
96
- None => return & [ ] ,
97
- Some ( p) => p,
98
- } ;
99
-
100
- match p. args ( ) {
101
- None => & [ ] ,
102
- Some ( args) => args. as_slice ( ) ,
103
- }
104
- }
105
-
106
92
fn env_to_wasi ( spec : & Spec ) -> Vec < String > {
107
93
let default = vec ! [ ] ;
108
94
let env = spec
0 commit comments