Skip to content

Commit c5c4654

Browse files
committed
Use stable toolchain
1 parent 834d82a commit c5c4654

File tree

5 files changed

+42
-32
lines changed

5 files changed

+42
-32
lines changed

.github/workflows/main.yml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ jobs:
4141
- name: Build xsuite
4242
run: pnpm build-xsuite
4343

44-
- name: Add xSuite Rust key in env
45-
run: echo "XSUITE_RUST=$(pnpm xsuite install-rust-key)" >> $GITHUB_ENV
44+
- name: Install Rust
45+
run: |
46+
pnpm xsuite install-rust
47+
echo "RUST_KEY=$(pnpm xsuite install-rust-key)" >> $GITHUB_ENV
4648
4749
- name: Cache Rust
4850
uses: actions/cache@v4
@@ -51,11 +53,8 @@ jobs:
5153
~/.rustup/toolchains
5254
~/.cargo
5355
target
54-
key: ${{ runner.os }}-rust-${{ env.XSUITE_RUST }}-${{ hashFiles('**/Cargo.lock') }}
55-
restore-keys: ${{ runner.os }}-rust-
56-
57-
- name: Install Rust
58-
run: pnpm xsuite install-rust
56+
key: rust-${{ runner.os }}-${{ env.RUST_KEY }}-${{ hashFiles('**/Cargo.lock') }}
57+
restore-keys: rust-${{ runner.os }}-
5958

6059
- name: Test xsuite
6160
run: |

xsuite/src/cli/cli.test.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { Context } from "../context";
1010
import { getAddressShard } from "../data/utils";
1111
import { Keystore } from "../world/signer";
1212
import { getCli } from "./cli";
13-
import { defaultRustToolchain, rustTarget, rustKey } from "./helpers";
13+
import { defaultRustToolchain, rustTarget } from "./helpers";
1414
import { getBinaryOs } from "./testScenCmd";
1515

1616
setGlobalDispatcher(new Agent({ connect: { timeout: 100_000 } }));
@@ -336,7 +336,10 @@ test.concurrent(
336336
test.concurrent("install-rust-key", async () => {
337337
using c = newContext();
338338
await c.cmd("install-rust-key");
339-
expect(c.flushStdout().split("\n")).toEqual([rustKey, ""]);
339+
expect(c.flushStdout().split("\n")).toEqual([
340+
expect.stringMatching(new RegExp(`rustc[a-z0-9]+-${rustTarget}`)),
341+
"",
342+
]);
340343
});
341344

342345
test.concurrent("install-rust", async () => {
@@ -346,8 +349,9 @@ test.concurrent("install-rust", async () => {
346349
chalk.blue(
347350
`Installing Rust: toolchain ${defaultRustToolchain} & target ${rustTarget}...`,
348351
),
352+
chalk.cyan(`$ ${process.env.HOME}/.cargo/bin/rustup default stable`),
349353
chalk.cyan(
350-
`$ curl --proto =https --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain ${defaultRustToolchain} -t ${rustTarget} -y`,
354+
`$ ${process.env.HOME}/.cargo/bin/rustup target add wasm32-unknown-unknown`,
351355
),
352356
"",
353357
]);

xsuite/src/cli/helpers.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ export const pause = (ms: number) => {
5454
return new Promise((resolve) => setTimeout(resolve, ms));
5555
};
5656

57-
export const defaultRustToolchain = "1.79.0";
57+
export const defaultRustToolchain = "stable";
5858

5959
export const rustTarget = "wasm32-unknown-unknown";
60-
61-
export const rustKey = `${defaultRustToolchain}-${rustTarget}`;

xsuite/src/cli/installRustCmd.ts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { spawnSync } from "node:child_process";
12
import { Command } from "commander";
23
import {
34
logTitle,
@@ -22,20 +23,22 @@ export const addInstallRustCmd = (cmd: Command) => {
2223

2324
const action = ({ toolchain }: { toolchain: string }) => {
2425
logTitle(`Installing Rust: toolchain ${toolchain} & target ${rustTarget}...`);
25-
logAndRunCommand("curl", [
26-
"--proto",
27-
"=https",
28-
"--tlsv1.2",
29-
"-sSf",
30-
"https://sh.rustup.rs",
31-
"|",
32-
"sh",
33-
"-s",
34-
"--",
35-
"--default-toolchain",
36-
toolchain,
37-
"-t",
38-
rustTarget,
39-
"-y",
40-
]);
26+
const result = spawnSync("rustup", ["--version"]);
27+
if (result.status !== 0) {
28+
logAndRunCommand("curl", [
29+
"--proto",
30+
"=https",
31+
"--tlsv1.2",
32+
"-sSf",
33+
"https://sh.rustup.rs",
34+
"|",
35+
"sh",
36+
"-s",
37+
"--",
38+
"-y",
39+
]);
40+
}
41+
const rustupPath = `${process.env.HOME}/.cargo/bin/rustup`;
42+
logAndRunCommand(rustupPath, ["default", toolchain]);
43+
logAndRunCommand(rustupPath, ["target", "add", rustTarget]);
4144
};

xsuite/src/cli/installRustKeyCmd.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
1+
import { spawnSync } from "child_process";
12
import { Command } from "commander";
23
import { log } from "../context";
3-
import { rustKey } from "./helpers";
4+
import { rustTarget } from "./helpers";
45

56
export const addInstallRustKeyCmd = (cmd: Command) => {
67
cmd
78
.command("install-rust-key")
8-
.description(`Return a key caracterizing Rust settings (${rustKey}).`)
9+
.description("Return a key caracterizing Rust installation.")
910
.action(() => {
10-
log(rustKey);
11+
const rustResult = spawnSync("rustc", ["--version"]);
12+
const rustcVersion = rustResult.stdout
13+
.toString()
14+
.trim()
15+
.replace(/[ ().-]/g, "");
16+
log(`${rustcVersion}-${rustTarget}`);
1117
});
1218
};

0 commit comments

Comments
 (0)