From 5a11a825d84339ed2a04812b36528da23de58bf7 Mon Sep 17 00:00:00 2001 From: Simon Davies Date: Tue, 3 Nov 2026 14:29:11 +0000 Subject: [PATCH] Splits the rust version between host and guest so that they can evolve independently Signed-off-by: Simon Davies --- .github/workflows/cargo-publish.yml | 4 +-- .github/workflows/dep_benchmarks.yml | 2 +- .github/workflows/dep_build.yml | 5 +-- .github/workflows/npm-publish.yml | 5 +-- CONTRIBUTING.md | 15 ++++++++ Cargo.lock | 34 +++++++++++++++++-- Justfile | 18 +++++++--- rust-toolchain.toml | 4 +-- src/hyperlight-js-runtime/rust-toolchain.toml | 3 ++ src/hyperlight-js/Cargo.toml | 3 +- src/hyperlight-js/build.rs | 7 ++++ 11 files changed, 83 insertions(+), 17 deletions(-) create mode 100644 src/hyperlight-js-runtime/rust-toolchain.toml diff --git a/.github/workflows/cargo-publish.yml b/.github/workflows/cargo-publish.yml index 6329ae60..920dd224 100644 --- a/.github/workflows/cargo-publish.yml +++ b/.github/workflows/cargo-publish.yml @@ -49,7 +49,7 @@ jobs: - name: Hyperlight setup uses: hyperlight-dev/ci-setup-workflow@59673866360458f8dd035f4a9fa766aeebad2038 # v2.3.1 with: - rust-toolchain: "1.90" + additional-toolchain-directory: src/hyperlight-js-runtime just-version: "1.51" - name: Install cargo-overlay-registry @@ -101,7 +101,7 @@ jobs: -p hyperlight-js-runtime - name: Authenticate with crates.io - uses: rust-lang/crates-io-auth-action@3268eb413133e2960fa4ae0e963ca76380c54cd9 # v1 + uses: rust-lang/crates-io-auth-action@c6f97d42243bad5fab37ca0427f495c86d5b1a18 # v1 id: crates-io-auth - name: Publish hyperlight-js-common diff --git a/.github/workflows/dep_benchmarks.yml b/.github/workflows/dep_benchmarks.yml index 91b137a1..0b9ee388 100644 --- a/.github/workflows/dep_benchmarks.yml +++ b/.github/workflows/dep_benchmarks.yml @@ -56,7 +56,7 @@ jobs: - uses: hyperlight-dev/ci-setup-workflow@59673866360458f8dd035f4a9fa766aeebad2038 # v2.3.1 with: - rust-toolchain: "1.90" + additional-toolchain-directory: src/hyperlight-js-runtime just-version: "1.51" - name: Install github-cli (Azure Linux) diff --git a/.github/workflows/dep_build.yml b/.github/workflows/dep_build.yml index ba2b1f24..ffec4326 100644 --- a/.github/workflows/dep_build.yml +++ b/.github/workflows/dep_build.yml @@ -91,7 +91,7 @@ jobs: - uses: hyperlight-dev/ci-setup-workflow@59673866360458f8dd035f4a9fa766aeebad2038 # v2.3.1 with: - rust-toolchain: "1.90" + additional-toolchain-directory: src/hyperlight-js-runtime just-version: "1.51" # Unlike upstream hyperlight, which builds its guests once per architecture @@ -104,10 +104,11 @@ jobs: # to /usr/bin/ar when llvm-ar is missing from PATH, which yields a guest # link with every QuickJS and libc symbol undefined. Prefer a provisioned # llvm-ar when the runner image supplies one; otherwise use the active Rust - # toolchain's llvm-tools component, installing it if necessary. + # guest toolchain's llvm-tools component, installing it if necessary. - name: Set up LLVM guest toolchain (macOS) if: runner.os == 'macOS' shell: bash + working-directory: src/hyperlight-js-runtime run: | set -euo pipefail if command -v llvm-ar >/dev/null 2>&1; then diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index 49873d0a..d4217eed 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -79,7 +79,7 @@ jobs: - name: Hyperlight setup uses: hyperlight-dev/ci-setup-workflow@59673866360458f8dd035f4a9fa766aeebad2038 # v2.3.1 with: - rust-toolchain: "1.90" + additional-toolchain-directory: src/hyperlight-js-runtime just-version: "1.51" - name: Setup Node.js @@ -94,10 +94,11 @@ jobs: # cannot produce ELF archives, and cargo-hyperlight silently falls back to # it when llvm-ar is absent from PATH, leaving every QuickJS and libc # symbol undefined at the guest link. Prefer a provisioned llvm-ar and - # fall back to the active Rust toolchain's llvm-tools component. + # fall back to the guest Rust toolchain's llvm-tools component. - name: Set up LLVM guest toolchain (macOS) if: runner.os == 'macOS' shell: bash + working-directory: src/hyperlight-js-runtime run: | set -euo pipefail if command -v llvm-ar >/dev/null 2>&1; then diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d6a9c586..acad3047 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -118,3 +118,18 @@ For more detailed instructions on setting up GPG signing, see [GitHub's document ### Rust Analyzer If you are using the [Rust Analyzer](https://rust-analyzer.github.io/manual.html) then you may need to set the configuration option `rust-analyzer.rustfmt.extraArgs` to `["+nightly"]` to ensure that formatting works correctly as this project has a [`rustfmt.toml`](./rustfmt.toml) file that uses nightly features. + +### Rust Toolchains + +Host builds and tools use the root `rust-toolchain.toml`. The guest runtime +uses a separate toolchain pinned in +`src/hyperlight-js-runtime/rust-toolchain.toml`, allowing the host compiler to +advance independently of guest target support. + +Build with: + +```sh +just build +``` + +The build installs both toolchains and their required components automatically. diff --git a/Cargo.lock b/Cargo.lock index d6f1e636..07d25af1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -314,8 +314,7 @@ checksum = "8ae3f5d315924270530207e2a68396c3cc547f6dca3fbdca317cfb1a51edb593" [[package]] name = "cargo-hyperlight" version = "0.1.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c52f1c9d4b6173aefb66fdc2e3e112ddb359fe2fbdbaafe1b9ba25f7ac578b39" +source = "git+https://github.com/hyperlight-dev/cargo-hyperlight?rev=5993b956fdcfd091a02ad3c3592baff67e0a2b9f#5993b956fdcfd091a02ad3c3592baff67e0a2b9f" dependencies = [ "anyhow", "clap", @@ -333,6 +332,7 @@ dependencies = [ "serde", "serde_json", "tempfile", + "toml", "which", ] @@ -3535,6 +3535,15 @@ dependencies = [ "zmij", ] +[[package]] +name = "serde_spanned" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e7523beb55eece201a2356bee0bbca0d1ab466c14c07703b2e0ee6d42cb0c2c" +dependencies = [ + "serde_core", +] + [[package]] name = "sha2" version = "0.10.9" @@ -3900,6 +3909,21 @@ dependencies = [ "tokio", ] +[[package]] +name = "toml" +version = "1.1.3+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53c96ecdfa941c8fc4fcaed14f99ada8ebed502eef533015095a07e3301d4c3c" +dependencies = [ + "indexmap", + "serde_core", + "serde_spanned", + "toml_datetime", + "toml_parser", + "toml_writer", + "winnow", +] + [[package]] name = "toml_datetime" version = "1.1.1+spec-1.1.0" @@ -3930,6 +3954,12 @@ dependencies = [ "winnow", ] +[[package]] +name = "toml_writer" +version = "1.1.3+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06bdbd8cfc056b8d2e2e85f29b56a3bdbecb527cef81eb39e3e7b98af4652770" + [[package]] name = "tonic" version = "0.14.6" diff --git a/Justfile b/Justfile index ab63346a..2e1b8878 100644 --- a/Justfile +++ b/Justfile @@ -24,8 +24,16 @@ export CMAKE_GENERATOR := if os() == "windows" { "Ninja" } else { "" } # host, so derive it rather than hardcoding x86_64. guest-target := arch() + "-hyperlight-none" -ensure-tools: - cargo install cargo-hyperlight --locked +# Temporary pin for guest toolchain selection: hyperlight-dev/cargo-hyperlight#83. +cargo-hyperlight-rev := "5993b956fdcfd091a02ad3c3592baff67e0a2b9f" + +# Install the host and guest toolchains and components from their pin files. +ensure-toolchains: + rustup toolchain install + cd src/hyperlight-js-runtime && rustup toolchain install + +ensure-tools: ensure-toolchains + cargo install cargo-hyperlight --git https://github.com/hyperlight-dev/cargo-hyperlight --rev {{ cargo-hyperlight-rev }} --locked # Check if npm is installed, install automatically if missing (Linux) [private] @@ -46,7 +54,7 @@ check-license-headers: ./dev/check-license-headers.sh clippy target=default-target features="": (ensure-tools) - cargo hyperlight clippy -p hyperlight-js-runtime \ + cd src/hyperlight-js-runtime && cargo hyperlight clippy -p hyperlight-js-runtime \ --target={{ guest-target }} \ --profile={{ if target == "debug" {"dev"} else { target } }} \ -- -D warnings @@ -113,11 +121,11 @@ build-trace target=default-target features="": (build-rust-trace target features build-native-runtime target=default-target: cargo build --manifest-path=./src/hyperlight-js-runtime/Cargo.toml --profile={{ if target == "debug" {"dev"} else { target } }} -build-rust target=default-target features="": +build-rust target=default-target features="": ensure-toolchains cd src/hyperlight-js && \ cargo build {{ if features =="" {''} else if features=="no-default-features" {"--no-default-features" } else {"--no-default-features -F " + features } }} --profile={{ if target == "debug" {"dev"} else { target } }} -build-rust-trace target=default-target features="": +build-rust-trace target=default-target features="": ensure-toolchains cd src/hyperlight-js && \ cargo build {{ if features =="" {'-F trace_guest'} else if features=="no-default-features" {"--no-default-features -F trace_guest" } else {"--no-default-features -F trace_guest," + features } }} --profile={{ if target == "debug" {"dev"} else { target } }} diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 93d3914a..10427b94 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -channel = "1.90" -components = ["clippy", "llvm-tools", "rustfmt"] +channel = "1.99.1" +components = ["clippy", "rustfmt"] diff --git a/src/hyperlight-js-runtime/rust-toolchain.toml b/src/hyperlight-js-runtime/rust-toolchain.toml new file mode 100644 index 00000000..bad87574 --- /dev/null +++ b/src/hyperlight-js-runtime/rust-toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +channel = "1.90" +components = ["clippy", "llvm-tools", "rust-src"] \ No newline at end of file diff --git a/src/hyperlight-js/Cargo.toml b/src/hyperlight-js/Cargo.toml index f133d8a3..e93f4b36 100644 --- a/src/hyperlight-js/Cargo.toml +++ b/src/hyperlight-js/Cargo.toml @@ -37,7 +37,8 @@ libc = { version = "0.2", optional = true } windows-sys = { version = "0.61", features = ["Win32_Foundation", "Win32_System_Threading", "Win32_System_Registry", "Win32_System_WindowsProgramming"], optional = true } [build-dependencies] -cargo-hyperlight = "0.1.14" +# Temporary pin for guest toolchain selection: hyperlight-dev/cargo-hyperlight#83. +cargo-hyperlight = { git = "https://github.com/hyperlight-dev/cargo-hyperlight", rev = "5993b956fdcfd091a02ad3c3592baff67e0a2b9f" } cfg_aliases = "0.2.1" serde_json = { version = "1.0" } diff --git a/src/hyperlight-js/build.rs b/src/hyperlight-js/build.rs index 81845ff2..6bbd8f7c 100644 --- a/src/hyperlight-js/build.rs +++ b/src/hyperlight-js/build.rs @@ -230,9 +230,14 @@ fn build_js_runtime(custom: Option) -> PathBuf { .canonicalize() .expect("hyperlight-js-runtime include directory not found"); println!("cargo:rerun-if-changed={}", include_dir.display()); + let toolchain_file = include_dir.with_file_name("rust-toolchain.toml"); + println!("cargo:rerun-if-changed={}", toolchain_file.display()); let cflags = format!("-I{} {QUICKJS_CFLAGS}", include_dir.display()).replace("\\", "\\\\"); let mut cargo_cmd = cargo_hyperlight::cargo().unwrap(); + cargo_cmd + .toolchain_file(&toolchain_file) + .unwrap_or_else(|error| panic!("Could not select JS guest toolchain: {error:#}")); let cmd = cargo_cmd .arg(if is_custom { "rustc" } else { "build" }) .arg("--profile") @@ -249,6 +254,8 @@ fn build_js_runtime(custom: Option) -> PathBuf { .arg(&manifest_path) .arg("--locked") .env_clear_cargo() + // Host Clippy must not wrap the separately pinned guest compiler. + .env_remove("RUSTC_WORKSPACE_WRAPPER") .current_dir(runtime_dir) .env("HYPERLIGHT_CFLAGS", cflags);