From 2ea341adf07cf0dd00356928716b24a359c7afac Mon Sep 17 00:00:00 2001 From: Keming Date: Sun, 23 Feb 2025 13:42:29 +0800 Subject: [PATCH] fix: upgrade the toolchain (#325) * fix rustc version Signed-off-by: Keming * only update when rustup exists Signed-off-by: Keming * update host when toolchain specified Signed-off-by: Keming * update readme Signed-off-by: Keming * move `rustup update` up --------- Signed-off-by: Keming Co-authored-by: messense --- README.md | 2 +- dist/index.js | 5 +++-- package-lock.json | 36 +++++++++++++++++++++++++++--------- package.json | 2 +- src/index.ts | 6 ++++-- 5 files changed, 36 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 490eac7..1c75b24 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ take a look at the following examples: | target | No | The `--target` option for Cargo | string | | | container | No | manylinux docker container image name | string | Default depends on `target` and `manylinux` options, Set to `off` to disable manylinux docker build and build on the host instead. | | docker-options | No | Additional Docker run options, for passing environment variables and etc. | string | -| rust-toolchain | No | Rust toolchain name | string | Defaults to `stable` for Docker build | +| rust-toolchain | No | Rust toolchain name. | string | Defaults to `stable` for Docker build. To use the latest available version for the host build, the user must specify this in the CI config or repo config. | | rustup-components | No | Rustup components | string | Defaults to empty | | working-directory | No | The working directory to run the command in | string | Defaults to the root of the repository | | sccache | No | Enable sccache for faster builds | boolean | Defaults to `false` | diff --git a/dist/index.js b/dist/index.js index b89788c..964f0ba 100644 --- a/dist/index.js +++ b/dist/index.js @@ -11890,9 +11890,9 @@ async function dockerBuild(container, maturinRelease, hostHomeMount, args) { const rustupComponents = core.getInput('rustup-components'); const commands = [ '#!/bin/bash', - 'set -e', + 'set -euo pipefail', 'echo "::group::Install Rust"', - `which rustup > /dev/null || curl --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain ${rustToolchain}`, + `command -v rustup &> /dev/null && { rm -frv ~/.rustup/toolchains/; rustup show; } || curl --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain ${rustToolchain}`, 'export PATH="$HOME/.cargo/bin:$HOME/.local/bin:$PATH"', `echo "Install Rust toolchain ${rustToolchain}"`, `rustup override set ${rustToolchain}`, @@ -12116,6 +12116,7 @@ async function hostBuild(maturinRelease, args) { core.startGroup('Install Rust target'); if (rustToolchain && rustToolchain.length > 0) { core.info(`Installing Rust toolchain ${rustToolchain}`); + await exec.exec('rustup', ['update', '--no-self-update', rustToolchain]); await exec.exec('rustup', ['override', 'set', rustToolchain]); await exec.exec('rustup', ['component', 'add', 'llvm-tools-preview'], { ignoreReturnCode: true diff --git a/package-lock.json b/package-lock.json index d373fd4..d9e6999 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,7 +18,7 @@ "typescript": "^4.6.2" }, "devDependencies": { - "@types/node": "^18.11.3", + "@types/node": "^18.19.76", "@typescript-eslint/parser": "^5.40.1", "@vercel/ncc": "^0.36.0", "eslint": "^8.26.0", @@ -223,10 +223,13 @@ "dev": true }, "node_modules/@types/node": { - "version": "18.11.15", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.15.tgz", - "integrity": "sha512-VkhBbVo2+2oozlkdHXLrb3zjsRkpdnaU2bXmX8Wgle3PUi569eLRaHGlgETQHR7lLL1w7GiG3h9SnePhxNDecw==", - "dev": true + "version": "18.19.76", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.19.76.tgz", + "integrity": "sha512-yvR7Q9LdPz2vGpmpJX5LolrgRdWvB67MJKDPSgIIzpFbaf9a1j/f5DnLp5VDyHGMR0QZHlTr1afsD87QCXFHKw==", + "dev": true, + "dependencies": { + "undici-types": "~5.26.4" + } }, "node_modules/@types/semver": { "version": "7.3.13", @@ -2916,6 +2919,12 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", + "dev": true + }, "node_modules/update-browserslist-db": { "version": "1.0.10", "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.0.10.tgz", @@ -3179,10 +3188,13 @@ "dev": true }, "@types/node": { - "version": "18.11.15", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.15.tgz", - "integrity": "sha512-VkhBbVo2+2oozlkdHXLrb3zjsRkpdnaU2bXmX8Wgle3PUi569eLRaHGlgETQHR7lLL1w7GiG3h9SnePhxNDecw==", - "dev": true + "version": "18.19.76", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.19.76.tgz", + "integrity": "sha512-yvR7Q9LdPz2vGpmpJX5LolrgRdWvB67MJKDPSgIIzpFbaf9a1j/f5DnLp5VDyHGMR0QZHlTr1afsD87QCXFHKw==", + "dev": true, + "requires": { + "undici-types": "~5.26.4" + } }, "@types/semver": { "version": "7.3.13", @@ -5085,6 +5097,12 @@ "which-boxed-primitive": "^1.0.2" } }, + "undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", + "dev": true + }, "update-browserslist-db": { "version": "1.0.10", "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.0.10.tgz", diff --git a/package.json b/package.json index 0cff67b..780a823 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "typescript": "^4.6.2" }, "devDependencies": { - "@types/node": "^18.11.3", + "@types/node": "^18.19.76", "@typescript-eslint/parser": "^5.40.1", "@vercel/ncc": "^0.36.0", "eslint": "^8.26.0", diff --git a/src/index.ts b/src/index.ts index 1da85d2..9f8adde 100644 --- a/src/index.ts +++ b/src/index.ts @@ -632,10 +632,11 @@ async function dockerBuild( const commands = [ '#!/bin/bash', // Stop on first error - 'set -e', + 'set -euo pipefail', // Install Rust 'echo "::group::Install Rust"', - `which rustup > /dev/null || curl --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain ${rustToolchain}`, + // refer to https://github.com/rust-lang/rustup/issues/1167#issuecomment-367061388 + `command -v rustup &> /dev/null && { rm -frv ~/.rustup/toolchains/; rustup show; } || curl --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain ${rustToolchain}`, 'export PATH="$HOME/.cargo/bin:$HOME/.local/bin:$PATH"', `echo "Install Rust toolchain ${rustToolchain}"`, `rustup override set ${rustToolchain}`, @@ -936,6 +937,7 @@ async function hostBuild( core.startGroup('Install Rust target') if (rustToolchain && rustToolchain.length > 0) { core.info(`Installing Rust toolchain ${rustToolchain}`) + await exec.exec('rustup', ['update', '--no-self-update', rustToolchain]) await exec.exec('rustup', ['override', 'set', rustToolchain]) await exec.exec('rustup', ['component', 'add', 'llvm-tools-preview'], { ignoreReturnCode: true