diff --git a/.github/workflows/cargo-publish.yml b/.github/workflows/cargo-publish.yml index 50977a2..920dd22 100644 --- a/.github/workflows/cargo-publish.yml +++ b/.github/workflows/cargo-publish.yml @@ -49,6 +49,7 @@ jobs: - name: Hyperlight setup uses: hyperlight-dev/ci-setup-workflow@59673866360458f8dd035f4a9fa766aeebad2038 # v2.3.1 with: + additional-toolchain-directory: src/hyperlight-js-runtime just-version: "1.51" - name: Install cargo-overlay-registry @@ -100,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 c82bd27..bd22cb4 100644 --- a/.github/workflows/dep_benchmarks.yml +++ b/.github/workflows/dep_benchmarks.yml @@ -59,6 +59,7 @@ jobs: - uses: hyperlight-dev/ci-setup-workflow@59673866360458f8dd035f4a9fa766aeebad2038 # v2.3.1 with: + 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 78b90cb..5f4239b 100644 --- a/.github/workflows/dep_build.yml +++ b/.github/workflows/dep_build.yml @@ -111,6 +111,7 @@ jobs: - uses: hyperlight-dev/ci-setup-workflow@59673866360458f8dd035f4a9fa766aeebad2038 # v2.3.1 with: + additional-toolchain-directory: src/hyperlight-js-runtime just-version: "1.51" # Unlike upstream hyperlight, which builds its guests once per architecture @@ -123,10 +124,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 e4efcf5..3aca5c8 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -82,6 +82,7 @@ jobs: - name: Hyperlight setup uses: hyperlight-dev/ci-setup-workflow@59673866360458f8dd035f4a9fa766aeebad2038 # v2.3.1 with: + additional-toolchain-directory: src/hyperlight-js-runtime just-version: "1.51" - name: Setup Node.js @@ -97,10 +98,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 d6a9c58..acad304 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 6fc29b3..cc1114b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -332,9 +332,9 @@ checksum = "8ae3f5d315924270530207e2a68396c3cc547f6dca3fbdca317cfb1a51edb593" [[package]] name = "cargo-hyperlight" -version = "0.1.14" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c52f1c9d4b6173aefb66fdc2e3e112ddb359fe2fbdbaafe1b9ba25f7ac578b39" +checksum = "cca0d3b8a8a79c7d55aecb3f68afe40675e70871ec7056f30fecee82cff1b877" dependencies = [ "anyhow", "clap", @@ -352,6 +352,7 @@ dependencies = [ "serde", "serde_json", "tempfile", + "toml", "which", ] @@ -2520,9 +2521,9 @@ dependencies = [ [[package]] name = "object" -version = "0.39.1" +version = "0.40.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e5a6c098c7a3b6547378093f5cc30bc54fd361ce711e05293a5cc589562739b" +checksum = "dd229a0361b9d0d4396176e02d65897f487eebeab7caa6d443855ee152ca0b9c" dependencies = [ "memchr", ] @@ -3569,6 +3570,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" @@ -3934,6 +3944,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" @@ -3964,6 +3989,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 49e3621..d3c12a7 100644 --- a/Justfile +++ b/Justfile @@ -24,7 +24,12 @@ export CMAKE_GENERATOR := if os() == "windows" { "Ninja" } else { "" } # host, so derive it rather than hardcoding x86_64. guest-target := arch() + "-hyperlight-none" -ensure-tools: +# 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 --locked # Check if npm is installed, install automatically if missing (Linux) @@ -46,7 +51,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 +118,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 93d3914..10427b9 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 0000000..bad8757 --- /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 0edd16b..74e55b7 100644 --- a/src/hyperlight-js/Cargo.toml +++ b/src/hyperlight-js/Cargo.toml @@ -37,7 +37,7 @@ 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" +cargo-hyperlight = "0.1.15" 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 d86ca3f..5696d53 100644 --- a/src/hyperlight-js/build.rs +++ b/src/hyperlight-js/build.rs @@ -233,7 +233,13 @@ fn build_js_runtime(custom: Option) -> PathBuf { // Forward slashes keep Clang's include path intact so it finds the ARM math shim. let cflags = format!("-I{} {QUICKJS_CFLAGS}", include_dir.display()).replace('\\', "/"); + let toolchain_file = include_dir.with_file_name("rust-toolchain.toml"); + println!("cargo:rerun-if-changed={}", toolchain_file.display()); + 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") @@ -250,6 +256,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);