@@ -22,14 +22,24 @@ limitations under the License.
2222// this file is included in lib.rs. 
2323// The wasm_runtime binary is expected to be in the x64/{config} directory. 
2424
25+ use  std:: ffi:: OsString ; 
2526use  std:: fs:: OpenOptions ; 
2627use  std:: io:: Write ; 
28+ use  std:: iter:: once; 
2729use  std:: path:: { Path ,  PathBuf } ; 
2830use  std:: { env,  fs} ; 
2931
3032use  anyhow:: Result ; 
3133use  built:: write_built_file; 
3234
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+ 
3343fn  get_wasm_runtime_path ( )  -> PathBuf  { 
3444    let  manifest_dir = env:: var_os ( "CARGO_MANIFEST_DIR" ) . unwrap ( ) ; 
3545    let  manifest_dir = PathBuf :: from ( manifest_dir) ; 
@@ -95,6 +105,7 @@ fn build_wasm_runtime() -> PathBuf {
95105    let  out_dir = env:: var_os ( "OUT_DIR" ) . unwrap ( ) ; 
96106
97107    let  target_dir = Path :: new ( "" ) . join ( & out_dir) . join ( "target" ) ; 
108+     let  toolchain_dir = Path :: new ( "" ) . join ( & out_dir) . join ( "toolchain" ) ; 
98109
99110    let  in_repo_dir = get_wasm_runtime_path ( ) ; 
100111
@@ -106,34 +117,13 @@ fn build_wasm_runtime() -> PathBuf {
106117    println ! ( "cargo::rerun-if-env-changed=WIT_WORLD" ) ; 
107118    // the PROFILE env var unfortunately only gives us 1 bit of "dev or release" 
108119    let  cargo_profile = if  profile == "debug"  {  "dev"  }  else  {  "release"  } ; 
109-     let  mut  cargo_cmd = std:: process:: Command :: new ( & cargo_bin) ; 
110120
111121    // Clear the variables that control Cargo's behaviour (as listed 
112122    // at https://doc.rust-lang.org/cargo/reference/environment-variables.html): 
113123    // otherwise the nested build will build the wrong thing 
114124    let  mut  env_vars = env:: vars ( ) . collect :: < Vec < _ > > ( ) ; 
115125    env_vars. retain ( |( key,  _) | !key. starts_with ( "CARGO_" ) ) ; 
116126
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- 
137127    let  mut  cargo_cmd = std:: process:: Command :: new ( & cargo_bin) ; 
138128    let  cmd = cargo_cmd
139129        . arg ( "build" ) 
@@ -144,8 +134,9 @@ fn build_wasm_runtime() -> PathBuf {
144134        . arg ( & target_dir) 
145135        . current_dir ( & in_repo_dir) 
146136        . 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) ; 
149140    let  status = cmd
150141        . status ( ) 
151142        . unwrap_or_else ( |e| panic ! ( "could not run cargo build wasm_runtime: {}" ,  e) ) ; 
0 commit comments