diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5a8cff31..a1fb4b87 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -41,21 +41,19 @@ jobs: - name: Build xsuite run: pnpm build-xsuite - - name: Add xSuite Rust key in env - run: echo "XSUITE_RUST=$(pnpm xsuite install-rust-key)" >> $GITHUB_ENV + - name: Install Rust + run: | + pnpm xsuite install-rust + echo "RUST_KEY=$(pnpm xsuite install-rust-key)" >> $GITHUB_ENV - name: Cache Rust uses: actions/cache@v4 with: path: | - ~/.rustup/toolchains - ~/.cargo - target - key: ${{ runner.os }}-rust-${{ env.XSUITE_RUST }}-${{ hashFiles('**/Cargo.lock') }} - restore-keys: ${{ runner.os }}-rust- - - - name: Install Rust - run: pnpm xsuite install-rust + ~/.cargo/ + target/ + key: rust-${{ runner.os }}-${{ env.RUST_KEY }}-${{ hashFiles('**/Cargo.lock') }} + restore-keys: rust-${{ runner.os }}- - name: Test xsuite run: | diff --git a/xsuite/src/cli/cli.test.ts b/xsuite/src/cli/cli.test.ts index af15ea1e..cae6cefd 100644 --- a/xsuite/src/cli/cli.test.ts +++ b/xsuite/src/cli/cli.test.ts @@ -10,7 +10,7 @@ import { Context } from "../context"; import { getAddressShard } from "../data/utils"; import { Keystore } from "../world/signer"; import { getCli } from "./cli"; -import { defaultRustToolchain, rustTarget, rustKey } from "./helpers"; +import { defaultRustToolchain, rustTarget } from "./helpers"; import { getBinaryOs } from "./testScenCmd"; setGlobalDispatcher(new Agent({ connect: { timeout: 100_000 } })); @@ -336,7 +336,10 @@ test.concurrent( test.concurrent("install-rust-key", async () => { using c = newContext(); await c.cmd("install-rust-key"); - expect(c.flushStdout().split("\n")).toEqual([rustKey, ""]); + expect(c.flushStdout().split("\n")).toEqual([ + expect.stringMatching(new RegExp(`rustc[a-z0-9]+-${rustTarget}`)), + "", + ]); }); test.concurrent("install-rust", async () => { @@ -346,8 +349,9 @@ test.concurrent("install-rust", async () => { chalk.blue( `Installing Rust: toolchain ${defaultRustToolchain} & target ${rustTarget}...`, ), + chalk.cyan(`$ ${process.env.HOME}/.cargo/bin/rustup default stable`), chalk.cyan( - `$ curl --proto =https --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain ${defaultRustToolchain} -t ${rustTarget} -y`, + `$ ${process.env.HOME}/.cargo/bin/rustup target add wasm32-unknown-unknown`, ), "", ]); diff --git a/xsuite/src/cli/helpers.ts b/xsuite/src/cli/helpers.ts index e10caa07..52e5f56d 100644 --- a/xsuite/src/cli/helpers.ts +++ b/xsuite/src/cli/helpers.ts @@ -54,8 +54,6 @@ export const pause = (ms: number) => { return new Promise((resolve) => setTimeout(resolve, ms)); }; -export const defaultRustToolchain = "1.79.0"; +export const defaultRustToolchain = "stable"; export const rustTarget = "wasm32-unknown-unknown"; - -export const rustKey = `${defaultRustToolchain}-${rustTarget}`; diff --git a/xsuite/src/cli/installRustCmd.ts b/xsuite/src/cli/installRustCmd.ts index b336e0f5..3124ac6f 100644 --- a/xsuite/src/cli/installRustCmd.ts +++ b/xsuite/src/cli/installRustCmd.ts @@ -1,3 +1,4 @@ +import { spawnSync } from "node:child_process"; import { Command } from "commander"; import { logTitle, @@ -22,20 +23,22 @@ export const addInstallRustCmd = (cmd: Command) => { const action = ({ toolchain }: { toolchain: string }) => { logTitle(`Installing Rust: toolchain ${toolchain} & target ${rustTarget}...`); - logAndRunCommand("curl", [ - "--proto", - "=https", - "--tlsv1.2", - "-sSf", - "https://sh.rustup.rs", - "|", - "sh", - "-s", - "--", - "--default-toolchain", - toolchain, - "-t", - rustTarget, - "-y", - ]); + const result = spawnSync("rustup", ["--version"]); + if (result.status !== 0) { + logAndRunCommand("curl", [ + "--proto", + "=https", + "--tlsv1.2", + "-sSf", + "https://sh.rustup.rs", + "|", + "sh", + "-s", + "--", + "-y", + ]); + } + const rustupPath = `${process.env.HOME}/.cargo/bin/rustup`; + logAndRunCommand(rustupPath, ["default", toolchain]); + logAndRunCommand(rustupPath, ["target", "add", rustTarget]); }; diff --git a/xsuite/src/cli/installRustKeyCmd.ts b/xsuite/src/cli/installRustKeyCmd.ts index 0838ed87..17312e56 100644 --- a/xsuite/src/cli/installRustKeyCmd.ts +++ b/xsuite/src/cli/installRustKeyCmd.ts @@ -1,12 +1,18 @@ +import { spawnSync } from "child_process"; import { Command } from "commander"; import { log } from "../context"; -import { rustKey } from "./helpers"; +import { rustTarget } from "./helpers"; export const addInstallRustKeyCmd = (cmd: Command) => { cmd .command("install-rust-key") - .description(`Return a key caracterizing Rust settings (${rustKey}).`) + .description("Return a key caracterizing Rust installation.") .action(() => { - log(rustKey); + const rustResult = spawnSync("rustc", ["--version"]); + const rustcVersion = rustResult.stdout + .toString() + .trim() + .replace(/[ ().-]/g, ""); + log(`${rustcVersion}-${rustTarget}`); }); };