Skip to content

Commit cde9728

Browse files
committed
Updates for cargo plugin
Signed-off-by: James Sturtevant <[email protected]>
1 parent b666a54 commit cde9728

File tree

6 files changed

+22
-60
lines changed

6 files changed

+22
-60
lines changed

.github/workflows/Benchmarks.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ jobs:
4040

4141
- name: Build Wasm Runtime Binary
4242
working-directory: ./src/hyperlight_wasm
43-
run: just build-wasm-runtime ${{ matrix.config }}
43+
run: |
44+
just ensure-tools
45+
just build-wasm-runtime ${{ matrix.config }}
4446
4547
- uses: dtolnay/[email protected]
4648
with:

.github/workflows/dep_rust.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ jobs:
6969

7070
- name: Build Wasm Runtime Binary
7171
working-directory: ./src/hyperlight_wasm
72-
run: just build-wasm-runtime ${{ matrix.config }}
72+
run: |
73+
just ensure-tools
74+
just build-wasm-runtime ${{ matrix.config }}
7375
7476
- name: Download Wasm Modules
7577
uses: actions/download-artifact@v5
@@ -81,7 +83,6 @@ jobs:
8183
run: |
8284
# this must be build before the formatting and other jobs run
8385
# because the component model example depends on the wasm component built here
84-
just ensure-tools
8586
just compile-wit
8687
just build-rust-component-examples ${{ matrix.config }}
8788

Justfile

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ ensure-tools:
1818
cargo install wasm-tools --locked --version 1.235.0
1919
cargo install cargo-component --locked --version 0.21.1
2020
cargo install wit-bindgen-cli --locked --version 0.43.0
21+
cargo install --git https://github.com/hyperlight-dev/cargo-hyperlight cargo-hyperlight
2122

22-
build-all target=default-target features="": (build target features) (build-wasm-examples target features) (build-rust-wasm-examples target features) (build-rust-component-examples target) (build-wasm-runtime target features)
23+
build-all target=default-target features="": (build target features) (build-examples target features) (build-wasm-runtime target features)
2324

2425
build target=default-target features="": (fmt-check)
2526
cargo build {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --verbose --profile={{ if target == "debug" {"dev"} else { target } }}
@@ -33,9 +34,11 @@ compile-wit:
3334
wasm-tools component wit ./src/component_sample/wit/example.wit -w -o ./src/component_sample/wit/component-world.wasm
3435

3536
build-wasm-runtime target=default-target features="":
36-
cd ./src/wasm_runtime && cargo build --verbose {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--features " + features } }} --profile={{ if target == "debug" {"dev"} else { target } }} && rm -R target
37+
cd ./src/wasm_runtime && cargo hyperlight build --verbose {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--features " + features } }} --profile={{ if target == "debug" {"dev"} else { target } }} && rm -R target
3738

38-
build-wasm-examples target=default-target features="": (compile-wit)
39+
build-examples target=default-target features="": (build-wasm-examples target features) (build-rust-wasm-examples target features) (build-rust-component-examples target features)
40+
41+
build-wasm-examples target=default-target features="": (compile-wit)
3942
{{ build-wasm-examples-command }} {{target}} {{features}}
4043

4144
build-rust-wasm-examples target=default-target features="": (mkdir-redist target)
@@ -54,7 +57,7 @@ check target=default-target:
5457
cargo check --profile={{ if target == "debug" {"dev"} else { target } }}
5558
cd src/rust_wasm_samples && cargo check --profile={{ if target == "debug" {"dev"} else { target } }}
5659
cd src/component_sample && cargo check --profile={{ if target == "debug" {"dev"} else { target } }}
57-
cd src/wasm_runtime && cargo check --profile={{ if target == "debug" {"dev"} else { target } }}
60+
cd src/wasm_runtime && cargo hyperlight check --profile={{ if target == "debug" {"dev"} else { target } }}
5861
cd src/hyperlight_wasm_macro && cargo check --profile={{ if target == "debug" {"dev"} else { target } }}
5962

6063
fmt-check:
@@ -79,7 +82,7 @@ clippy target=default-target: (check target)
7982
cargo clippy --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --all-features -- -D warnings
8083
cd src/rust_wasm_samples && cargo clippy --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --all-features -- -D warnings
8184
cd src/component_sample && cargo clippy --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --all-features -- -D warnings
82-
cd src/wasm_runtime && cargo clippy --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --all-features -- -D warnings
85+
cd src/wasm_runtime && cargo hyperlight clippy --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --all-features -- -D warnings
8386
cd src/hyperlight_wasm_macro && cargo clippy --profile={{ if target == "debug" {"dev"} else { target } }} --all-targets --all-features -- -D warnings
8487

8588
# TESTING

src/hyperlight_wasm/build.rs

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,14 @@ 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;
2625
use std::fs::OpenOptions;
2726
use std::io::Write;
28-
use std::iter::once;
2927
use std::path::{Path, PathBuf};
3028
use std::{env, fs};
3129

3230
use anyhow::Result;
3331
use built::write_built_file;
3432

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-
4333
fn get_wasm_runtime_path() -> PathBuf {
4434
let manifest_dir = env::var_os("CARGO_MANIFEST_DIR").unwrap();
4535
let manifest_dir = PathBuf::from(manifest_dir);
@@ -105,7 +95,6 @@ fn build_wasm_runtime() -> PathBuf {
10595
let out_dir = env::var_os("OUT_DIR").unwrap();
10696

10797
let target_dir = Path::new("").join(&out_dir).join("target");
108-
let toolchain_dir = Path::new("").join(&out_dir).join("toolchain");
10998

11099
let in_repo_dir = get_wasm_runtime_path();
111100

@@ -126,19 +115,17 @@ fn build_wasm_runtime() -> PathBuf {
126115

127116
let mut cargo_cmd = std::process::Command::new(&cargo_bin);
128117
let mut cmd = cargo_cmd
118+
.arg("hyperlight")
129119
.arg("build")
120+
.arg("--target-dir")
121+
.arg(&target_dir)
130122
.arg("--profile")
131123
.arg(cargo_profile)
132124
.arg("-v")
133-
.arg("--target-dir")
134-
.arg(&target_dir)
135125
.current_dir(&in_repo_dir)
136126
.env_clear()
137-
// On windows when `gdb` features is enabled this is not set correctly
138-
.env("CFLAGS_x86_64_unknown_none", "-fPIC")
139127
.envs(env_vars)
140-
.env("PATH", path_with(&toolchain_dir))
141-
.env("HYPERLIGHT_GUEST_TOOLCHAIN_ROOT", &toolchain_dir);
128+
.env("CFLAGS_x86_64_unknown_none", "-fPIC"); // Should this go on cargo hyperlight
142129

143130
// Add --features gdb if the gdb feature is enabled for this build script
144131
if std::env::var("CARGO_FEATURE_GDB").is_ok() {
@@ -156,7 +143,7 @@ fn build_wasm_runtime() -> PathBuf {
156143
panic!("could not compile wasm_runtime");
157144
}
158145
let resource = target_dir
159-
.join("x86_64-unknown-none")
146+
.join("x86_64-hyperlight-none")
160147
.join(profile)
161148
.join("wasm_runtime");
162149

src/wasm_runtime/.cargo/config.toml

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/wasm_runtime/build.rs

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

17-
use std::path::{Path, PathBuf};
17+
use std::path::Path;
1818
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-
3223
println!("cargo:rerun-if-changed=.");
3324
let mut cfg = cc::Build::new();
3425

@@ -63,7 +54,8 @@ fn main() {
6354

6455
cfg.include("src/include");
6556
cfg.file("src/platform.c");
66-
cfg.compiler(clang_path);
57+
cfg.flag("-ffreestanding");
58+
cfg.flag("-nostdlib");
6759
if cfg!(windows) {
6860
env::set_var("AR_x86_64_unknown_none", "llvm-ar");
6961
}

0 commit comments

Comments
 (0)