From c5c4654e3447da8ddd1bbf23c8dffa34d3e97fbc Mon Sep 17 00:00:00 2001 From: Lucas Willems Date: Sat, 16 Nov 2024 23:48:22 +0100 Subject: [PATCH 1/2] Use stable toolchain --- .github/workflows/main.yml | 13 +++++------ xsuite/src/cli/cli.test.ts | 10 ++++++--- xsuite/src/cli/helpers.ts | 4 +--- xsuite/src/cli/installRustCmd.ts | 35 ++++++++++++++++------------- xsuite/src/cli/installRustKeyCmd.ts | 12 +++++++--- 5 files changed, 42 insertions(+), 32 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5a8cff31..712db84f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -41,8 +41,10 @@ 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 @@ -51,11 +53,8 @@ jobs: ~/.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 + 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}`); }); }; From 3a896054dd7c0375b9aacbd40bf7a7c6dddd1fe0 Mon Sep 17 00:00:00 2001 From: Lucas Willems Date: Sat, 16 Nov 2024 23:55:40 +0100 Subject: [PATCH 2/2] Fix paths --- .github/workflows/main.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 712db84f..a1fb4b87 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -50,9 +50,8 @@ jobs: uses: actions/cache@v4 with: path: | - ~/.rustup/toolchains - ~/.cargo - target + ~/.cargo/ + target/ key: rust-${{ runner.os }}-${{ env.RUST_KEY }}-${{ hashFiles('**/Cargo.lock') }} restore-keys: rust-${{ runner.os }}-