Skip to content

Commit

Permalink
Merge pull request #236 from arda-org/use-stable
Browse files Browse the repository at this point in the history
Use stable toolchain
  • Loading branch information
lcswillems authored Nov 16, 2024
2 parents 834d82a + 3a89605 commit 8b2ac2e
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 35 deletions.
18 changes: 8 additions & 10 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
10 changes: 7 additions & 3 deletions xsuite/src/cli/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } }));
Expand Down Expand Up @@ -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 () => {
Expand All @@ -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`,
),
"",
]);
Expand Down
4 changes: 1 addition & 3 deletions xsuite/src/cli/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
35 changes: 19 additions & 16 deletions xsuite/src/cli/installRustCmd.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { spawnSync } from "node:child_process";
import { Command } from "commander";
import {
logTitle,
Expand All @@ -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]);
};
12 changes: 9 additions & 3 deletions xsuite/src/cli/installRustKeyCmd.ts
Original file line number Diff line number Diff line change
@@ -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}`);
});
};

0 comments on commit 8b2ac2e

Please sign in to comment.