@@ -22,14 +22,24 @@ limitations under the License.
22
22
// this file is included in lib.rs.
23
23
// The wasm_runtime binary is expected to be in the x64/{config} directory.
24
24
25
+ use std:: ffi:: OsString ;
25
26
use std:: fs:: OpenOptions ;
26
27
use std:: io:: Write ;
28
+ use std:: iter:: once;
27
29
use std:: path:: { Path , PathBuf } ;
28
30
use std:: { env, fs} ;
29
31
30
32
use anyhow:: Result ;
31
33
use built:: write_built_file;
32
34
35
+ fn path_with ( path : impl Into < PathBuf > ) -> OsString {
36
+ let path = path. into ( ) ;
37
+ let paths = env:: var_os ( "PATH" ) . unwrap_or_default ( ) ;
38
+ let paths = env:: split_paths ( & paths) ;
39
+ let paths = once ( path) . chain ( paths) ;
40
+ env:: join_paths ( paths) . unwrap ( )
41
+ }
42
+
33
43
fn get_wasm_runtime_path ( ) -> PathBuf {
34
44
let manifest_dir = env:: var_os ( "CARGO_MANIFEST_DIR" ) . unwrap ( ) ;
35
45
let manifest_dir = PathBuf :: from ( manifest_dir) ;
@@ -95,6 +105,7 @@ fn build_wasm_runtime() -> PathBuf {
95
105
let out_dir = env:: var_os ( "OUT_DIR" ) . unwrap ( ) ;
96
106
97
107
let target_dir = Path :: new ( "" ) . join ( & out_dir) . join ( "target" ) ;
108
+ let toolchain_dir = Path :: new ( "" ) . join ( & out_dir) . join ( "toolchain" ) ;
98
109
99
110
let in_repo_dir = get_wasm_runtime_path ( ) ;
100
111
@@ -106,34 +117,13 @@ fn build_wasm_runtime() -> PathBuf {
106
117
println ! ( "cargo::rerun-if-env-changed=WIT_WORLD" ) ;
107
118
// the PROFILE env var unfortunately only gives us 1 bit of "dev or release"
108
119
let cargo_profile = if profile == "debug" { "dev" } else { "release" } ;
109
- let mut cargo_cmd = std:: process:: Command :: new ( & cargo_bin) ;
110
120
111
121
// Clear the variables that control Cargo's behaviour (as listed
112
122
// at https://doc.rust-lang.org/cargo/reference/environment-variables.html):
113
123
// otherwise the nested build will build the wrong thing
114
124
let mut env_vars = env:: vars ( ) . collect :: < Vec < _ > > ( ) ;
115
125
env_vars. retain ( |( key, _) | !key. starts_with ( "CARGO_" ) ) ;
116
126
117
- // we need to build hyperlight-guest-bin dependency of wasm_runtime, before wasm_runtime
118
- let cmd = cargo_cmd
119
- . arg ( "build" )
120
- . arg ( "--profile" )
121
- . arg ( cargo_profile)
122
- . arg ( "--package" )
123
- . arg ( "hyperlight-guest-bin" )
124
- . arg ( "-v" )
125
- . arg ( "--target-dir" )
126
- . arg ( & target_dir)
127
- . current_dir ( & in_repo_dir)
128
- . env_clear ( )
129
- . envs ( env_vars. clone ( ) ) ;
130
- let status = cmd
131
- . status ( )
132
- . unwrap_or_else ( |e| panic ! ( "could not run cargo build hyperlight-guest-bin: {}" , e) ) ;
133
- if !status. success ( ) {
134
- panic ! ( "could not compile wasm_runtime" ) ;
135
- }
136
-
137
127
let mut cargo_cmd = std:: process:: Command :: new ( & cargo_bin) ;
138
128
let cmd = cargo_cmd
139
129
. arg ( "build" )
@@ -144,8 +134,9 @@ fn build_wasm_runtime() -> PathBuf {
144
134
. arg ( & target_dir)
145
135
. current_dir ( & in_repo_dir)
146
136
. env_clear ( )
147
- . envs ( env_vars) ;
148
-
137
+ . envs ( env_vars)
138
+ . env ( "PATH" , path_with ( & toolchain_dir) )
139
+ . env ( "HYPERLIGHT_GUEST_TOOLCHAIN_ROOT" , & toolchain_dir) ;
149
140
let status = cmd
150
141
. status ( )
151
142
. unwrap_or_else ( |e| panic ! ( "could not run cargo build wasm_runtime: {}" , e) ) ;
0 commit comments