diff --git a/.github/actions/rustup/action.yml b/.github/actions/rustup/action.yml new file mode 100644 index 0000000000..1002d47018 --- /dev/null +++ b/.github/actions/rustup/action.yml @@ -0,0 +1,85 @@ +# This action installs the minimal Rust profile and configures Swatinem/rust-cache. +# +# It is needed to install as few Rust components as possbile because +# it takes a few minutes to install some of components on Windows and Mac, especially rust-doc. + +name: Rustup + +description: Install Rust with cache + +inputs: + key: + description: The cache key for cargo + required: true + save-if: + description: Should save toolchain cache or not + default: "false" + required: false + +runs: + using: composite + steps: + - name: Install rustup, if needed + shell: bash + run: | # zizmor: ignore[github-env] This action would only run on pull_request + if ! command -v rustup &> /dev/null ; then + curl --proto '=https' --tlsv1.2 --retry 10 --retry-connrefused -fsSL "https://sh.rustup.rs" | sh -s -- --default-toolchain none -y + + # Resolve the correct CARGO_HOME path depending on OS + if [[ "$RUNNER_OS" == "Windows" ]]; then + echo "${CARGO_HOME:-$USERPROFILE/.cargo}/bin" | sed 's|/|\\|g' >> $GITHUB_PATH + else + printf '%s\n' "${CARGO_HOME:-$HOME/.cargo}/bin" >> "$GITHUB_PATH" + fi + fi + env: + RUNNER_OS: "${{ runner.os }}" + + - name: Get toolchain + id: get-toolchain + shell: bash + run: | + set -euo pipefail + if [[ -f rust-toolchain.toml ]]; then + toolchain="$(grep -E '^\s*channel\s*=' rust-toolchain.toml | head -n1 | sed -E 's/.*=\s*"([^"]+)".*/\1/')" + elif [[ -f rust-toolchain ]]; then + toolchain="$(cat rust-toolchain)" + else + toolchain="stable" + fi + printf 'toolchain=%s\n' "${toolchain}" >> "$GITHUB_OUTPUT" + - name: Restore rustup cache + id: restore + if: ${{ inputs.save-if == 'true' }} + uses: lynx-infra/cache/restore@5c6160a6a4c7fca80a2f3057bb9dfc9513fcb732 + with: + path: ~/.rustup/toolchains + key: rustup-cache-v3-${{ runner.os }}-${{ steps.get-toolchain.outputs.toolchain }} + + # install components for nightly toolchain + - name: Install + shell: bash + env: + toolchain: ${{ steps.get-toolchain.outputs.toolchain }} + run: | + rustup toolchain install "$toolchain" \ + -c rustc \ + -c cargo \ + -c rust-std \ + -c clippy \ + -c rustfmt + rustup target add --toolchain "$toolchain" wasm32-unknown-unknown + - name: Save rustup cache + uses: lynx-infra/cache/save@5c6160a6a4c7fca80a2f3057bb9dfc9513fcb732 + if: ${{ inputs.save-if == 'true' && steps.restore.outputs.cache-hit != 'true' }} + with: + path: ~/.rustup/toolchains + key: rustup-cache-v3-${{ runner.os }}-${{ steps.get-toolchain.outputs.toolchain }} + + - name: Cargo cache + uses: stormslowly/rust-cache@8269079380bc35105b3ed8b0f1f7c9557c6dec93 # v0.0.2 + with: + prefix-key: "RCache-L-5" + shared-key: ${{ inputs.key }} + save-if: ${{ inputs.save-if }} + fullmatch-only: "true" diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index ff9bd0ab44..d2cf7aa0cc 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -36,9 +36,10 @@ jobs: - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5 with: persist-credentials: false - - uses: actions-rust-lang/setup-rust-toolchain@fb51252c7ba57d633bc668f941da052e410add48 # v1 + - uses: ./.github/actions/rustup with: - cache-key: test-${{ runner.os }} + key: test + save-if: ${{ github.ref_name == 'main' }} - name: Install llvm-cov and nextest uses: taiki-e/install-action@ad95d4e02e061d4390c4b66ef5ed56c7fee3d2ce # v2 with: diff --git a/.github/workflows/workflow-build.yml b/.github/workflows/workflow-build.yml index 1bf378d40d..6912832a8c 100644 --- a/.github/workflows/workflow-build.yml +++ b/.github/workflows/workflow-build.yml @@ -83,6 +83,11 @@ jobs: - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4 with: node-version: "24" + - name: Setup Rust + uses: ./.github/actions/rustup + with: + key: build + save-if: ${{ github.ref_name == 'main' }} - name: TurboCache uses: lynx-infra/cache@5c6160a6a4c7fca80a2f3057bb9dfc9513fcb732 with: @@ -122,15 +127,3 @@ jobs: retention-days: 1 overwrite: true include-hidden-files: true - - name: Setup Rust and retry build if failed - if: steps.build.outcome == 'failure' - uses: actions-rust-lang/setup-rust-toolchain@fb51252c7ba57d633bc668f941da052e410add48 # v1 - with: - target: wasm32-unknown-unknown - cache-key: test-${{ runner.os }} - - name: Retry Build - if: steps.build.outcome == 'failure' - run: | - pnpm turbo build --summarize - env: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/package.json b/package.json index 45c88f7604..c47eaf2b93 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,6 @@ "license": "Apache-2.0", "type": "module", "scripts": { - "_internal:cargo:version": "cargo --version", "build": "tsc --build", "prepare": "husky && ts-patch install", "test": "vitest" diff --git a/packages/react/transform/turbo.json b/packages/react/transform/turbo.json index 1d02e1dc01..e8fc800b4e 100644 --- a/packages/react/transform/turbo.json +++ b/packages/react/transform/turbo.json @@ -7,9 +7,7 @@ "outputs": ["index.d.ts", "index.cjs", "*.node"] }, "build:wasm": { - "dependsOn": [ - "//#_internal:cargo:version" - ], + "dependsOn": [], "inputs": ["src/**/*.rs", "src/wasm.js", "build.rs", "Cargo.toml", "scripts/build_wasm.sh"], "outputs": ["dist/wasm.cjs"] }, diff --git a/packages/web-platform/web-style-transformer/turbo.json b/packages/web-platform/web-style-transformer/turbo.json index 60525bc314..81e596b288 100644 --- a/packages/web-platform/web-style-transformer/turbo.json +++ b/packages/web-platform/web-style-transformer/turbo.json @@ -4,7 +4,6 @@ "tasks": { "build": { "dependsOn": [ - "//#_internal:cargo:version", "build:wasm-bindgen" ], "inputs": [ diff --git a/turbo.json b/turbo.json index bc38d82bfe..a90df341d8 100644 --- a/turbo.json +++ b/turbo.json @@ -25,15 +25,6 @@ "dependsOn": [], "cache": false }, - "//#_internal:cargo:version": { - "env": ["GITHUB_SHA"], - "dependsOn": [], - "inputs": [ - "rust-toolchain", - "rust-toolchain.toml" - ], - "outputs": [] - }, "//#build": { "cache": false, "dependsOn": [],