Skip to content

Commit 3242d06

Browse files
authored
try to fix release workflow (#161)
Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
1 parent 0805a79 commit 3242d06

File tree

2 files changed

+26
-35
lines changed

2 files changed

+26
-35
lines changed

src/hyperlight_wasm/build.rs

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -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;
2526
use std::fs::OpenOptions;
2627
use std::io::Write;
28+
use std::iter::once;
2729
use std::path::{Path, PathBuf};
2830
use std::{env, fs};
2931

3032
use anyhow::Result;
3133
use 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+
3343
fn 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));

src/wasm_runtime/build.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,23 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
use std::path::Path;
18-
use std::{env, fs, path};
17+
use std::path::{Path, PathBuf};
18+
use std::{env, fs};
1919

2020
use cargo_metadata::{MetadataCommand, Package};
2121

2222
fn main() {
23+
let toolchain_dir = env::var_os("HYPERLIGHT_GUEST_TOOLCHAIN_ROOT").unwrap();
24+
let toolchain_dir = PathBuf::from(toolchain_dir);
25+
let clang_path = toolchain_dir.join("clang");
26+
27+
assert!(
28+
clang_path.exists(),
29+
"could not find clang at {clang_path:?}"
30+
);
31+
2332
println!("cargo:rerun-if-changed=.");
2433
let mut cfg = cc::Build::new();
25-
if let Some(path) = env::var_os("PATH") {
26-
let paths: Vec<_> = env::split_paths(&path).collect();
27-
let toolchain_path =
28-
path::PathBuf::from(env::var_os("HYPERLIGHT_GUEST_TOOLCHAIN_ROOT").unwrap());
29-
let joined = env::join_paths(std::iter::once(toolchain_path).chain(paths)).unwrap();
30-
env::set_var("PATH", &joined);
31-
}
32-
33-
// Get the wasmtime_platform.h file from the appropriate wasm release
3434

3535
// get the version of the wasmtime crate
3636

@@ -63,7 +63,7 @@ fn main() {
6363

6464
cfg.include("src/include");
6565
cfg.file("src/platform.c");
66-
cfg.compiler("clang");
66+
cfg.compiler(clang_path);
6767
if cfg!(windows) {
6868
env::set_var("AR_x86_64_unknown_none", "llvm-ar");
6969
}

0 commit comments

Comments
 (0)