Unverified Commit 3e847dfe authored by Matt Mastracci's avatar Matt Mastracci Committed by GitHub

Switch to cargo-binstall and pre-built sccache binaries (#92911)

## What

- Use `cargo binstall` instead of `cargo install` for Rust tools in the
Docker image
- Download pre-built vercel/sccache from GitHub releases instead of
compiling from git

## Why

`cargo install` compiles from source which is slow on cache miss. `cargo
binstall` downloads pre-built binaries in seconds. The vercel/sccache
fork now publishes release binaries, eliminating the need for the
`build-sccache` turbo task (~2-3 min compile).

## Changes

**Dockerfile:**
- Install cargo-binstall at pinned version (1.18.1), use it for
cargo-rustflags
- Remove sccache from Docker image (not needed inside container)

**CI sccache:**
- Download pre-built binary from `vercel/sccache` GitHub releases
(~11MB)
- Cache in `~/.cache/sccache-<version>` on self-hosted runners
- Delete `scripts/build-sccache.js`, remove turbo task and package.json
entry
- `scripts/sccache-version` now contains just the release tag

<!-- NEXT_JS_LLM_PR -->
parent e9bc6190
...@@ -32,12 +32,9 @@ sccache --stop-server 2>/dev/null || true ...@@ -32,12 +32,9 @@ sccache --stop-server 2>/dev/null || true
pkill -9 -x cargo 2>/dev/null || true pkill -9 -x cargo 2>/dev/null || true
pkill -9 -x rustc 2>/dev/null || true pkill -9 -x rustc 2>/dev/null || true
# Install sccache via turbo task (cached by scripts/sccache-version). # Install vercel/sccache fork via cargo-binstall.
TURBO="pnpm dlx turbo@${TURBO_VERSION:-latest}" # cargo-binstall is installed by .github/actions/setup-rust.
$TURBO run build-sccache ${TURBO_ARGS:-} cargo binstall --no-confirm --git https://github.com/vercel/sccache sccache
SCCACHE_PATH="${GITHUB_WORKSPACE}/target/sccache/bin"
export PATH="${SCCACHE_PATH}:${PATH}"
echo "${SCCACHE_PATH}" >> "$GITHUB_PATH"
sccache --version sccache --version
# Set env vars for the sccache server (export) and subsequent steps (GITHUB_ENV). # Set env vars for the sccache server (export) and subsequent steps (GITHUB_ENV).
......
...@@ -23,6 +23,9 @@ runs: ...@@ -23,6 +23,9 @@ runs:
sudo apt-get -y -o DPkg::Lock::Timeout=60 update sudo apt-get -y -o DPkg::Lock::Timeout=60 update
sudo apt-get -o DPkg::Lock::Timeout=60 -y install lld sudo apt-get -o DPkg::Lock::Timeout=60 -y install lld
- name: 'Install cargo-binstall'
uses: cargo-bins/cargo-binstall@dc19f1e48450eefe5a29b8da6c6b00a87d730b37 # v1.18.1
- name: 'Add cargo problem matchers' - name: 'Add cargo problem matchers'
shell: bash shell: bash
run: echo "::add-matcher::${{ github.action_path }}/matchers.json" run: echo "::add-matcher::${{ github.action_path }}/matchers.json"
...@@ -247,7 +247,7 @@ jobs: ...@@ -247,7 +247,7 @@ jobs:
- name: Install nextest - name: Install nextest
if: ${{ inputs.needsNextest == 'yes' }} if: ${{ inputs.needsNextest == 'yes' }}
uses: taiki-e/install-action@3a0adc33ab45d7b9b9da91822dd2b3c0151704be # nextest run: cargo binstall --no-confirm cargo-nextest@0.9.133
- run: rustc --version - run: rustc --version
if: ${{ (inputs.uploadNativeArtifact != '') || inputs.needsNextest == 'yes' || inputs.needsRust == 'yes' }} if: ${{ (inputs.uploadNativeArtifact != '') || inputs.needsNextest == 'yes' || inputs.needsRust == 'yes' }}
......
...@@ -34,9 +34,7 @@ jobs: ...@@ -34,9 +34,7 @@ jobs:
uses: ./.github/actions/setup-rust uses: ./.github/actions/setup-rust
- name: Install cargo-codspeed - name: Install cargo-codspeed
uses: taiki-e/install-action@7627fb428e65e78e2ec9a24ae5c5bd5f8553f182 # v2.69.10 run: cargo binstall --no-confirm cargo-codspeed@3.0.5
with:
tool: cargo-codspeed@3.0.5
- name: Start sccache - name: Start sccache
uses: ./.github/actions/sccache uses: ./.github/actions/sccache
...@@ -72,9 +70,7 @@ jobs: ...@@ -72,9 +70,7 @@ jobs:
uses: ./.github/actions/setup-rust uses: ./.github/actions/setup-rust
- name: Install cargo-codspeed - name: Install cargo-codspeed
uses: taiki-e/install-action@7627fb428e65e78e2ec9a24ae5c5bd5f8553f182 # v2.69.10 run: cargo binstall --no-confirm cargo-codspeed@3.0.5
with:
tool: cargo-codspeed@3.0.5
- name: Start sccache - name: Start sccache
uses: ./.github/actions/sccache uses: ./.github/actions/sccache
...@@ -111,9 +107,7 @@ jobs: ...@@ -111,9 +107,7 @@ jobs:
uses: ./.github/actions/setup-rust uses: ./.github/actions/setup-rust
- name: Install cargo-codspeed - name: Install cargo-codspeed
uses: taiki-e/install-action@7627fb428e65e78e2ec9a24ae5c5bd5f8553f182 # v2.69.10 run: cargo binstall --no-confirm cargo-codspeed@3.0.5
with:
tool: cargo-codspeed@3.0.5
- name: Start sccache - name: Start sccache
uses: ./.github/actions/sccache uses: ./.github/actions/sccache
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
"build-native-release": "napi build --platform -p next-napi-bindings --cargo-cwd ../../ --cargo-name next_napi_bindings --release --features image-extended,tracing/release_max_level_trace --js false native", "build-native-release": "napi build --platform -p next-napi-bindings --cargo-cwd ../../ --cargo-name next_napi_bindings --release --features image-extended,tracing/release_max_level_trace --js false native",
"build-native-release-with-assertions": "napi build --platform -p next-napi-bindings --cargo-cwd ../../ --cargo-name next_napi_bindings --profile release-with-assertions --features image-extended,tracing/release_max_level_trace --js false native", "build-native-release-with-assertions": "napi build --platform -p next-napi-bindings --cargo-cwd ../../ --cargo-name next_napi_bindings --profile release-with-assertions --features image-extended,tracing/release_max_level_trace --js false native",
"build-native-wasi": "npx --package=@napi-rs/cli@3.0.0-alpha.45 napi build --platform --target wasm32-wasip1-threads -p next-napi-bindings --cwd ../../ --output-dir packages/next-swc/native --no-default-features", "build-native-wasi": "npx --package=@napi-rs/cli@3.0.0-alpha.45 napi build --platform --target wasm32-wasip1-threads -p next-napi-bindings --cwd ../../ --output-dir packages/next-swc/native --no-default-features",
"build-sccache": "node ../../scripts/build-sccache.js",
"build-wasm": "wasm-pack build ../../crates/wasm --scope=next", "build-wasm": "wasm-pack build ../../crates/wasm --scope=next",
"cache-build-native": "[ -d native ] && echo $(ls native)", "cache-build-native": "[ -d native ] && echo $(ls native)",
"rust-fingerprint": "node ../../scripts/rust-fingerprint.js", "rust-fingerprint": "node ../../scripts/rust-fingerprint.js",
......
...@@ -18,10 +18,6 @@ ...@@ -18,10 +18,6 @@
"outputs": ["../../target/.rust-fingerprint"], "outputs": ["../../target/.rust-fingerprint"],
"cache": false, "cache": false,
}, },
"build-sccache": {
"inputs": ["../../scripts/sccache-version"],
"outputs": ["../../target/sccache/**"],
},
"build-native-auto": { "build-native-auto": {
"dependsOn": ["rust-fingerprint"], "dependsOn": ["rust-fingerprint"],
"inputs": ["../../target/.rust-fingerprint"], "inputs": ["../../target/.rust-fingerprint"],
......
#!/usr/bin/env node
const { execSync } = require('child_process')
const fs = require('fs')
const path = require('path')
const root = path.resolve(__dirname, '..')
const raw = fs
.readFileSync(path.join(__dirname, 'sccache-version'), 'utf-8')
.trim()
const [url, ref] = raw.split('#')
const args = [
'install',
'--git',
url,
'--locked',
'--root',
path.join(root, 'target', 'sccache'),
]
if (ref) {
// Use --rev for commit hashes, --branch for branch names
const flag = /^[0-9a-f]{7,40}$/.test(ref) ? '--rev' : '--branch'
args.push(flag, ref)
}
args.push('sccache')
execSync(`cargo ${args.join(' ')}`, { stdio: 'inherit', cwd: root })
...@@ -85,15 +85,14 @@ RUN rustup target add \ ...@@ -85,15 +85,14 @@ RUN rustup target add \
x86_64-unknown-linux-musl \ x86_64-unknown-linux-musl \
aarch64-unknown-linux-musl aarch64-unknown-linux-musl
# Install @napi-rs/cli, cargo-rustflags, and sccache. # Install cargo-binstall, then use it for Rust tools.
# Use cargo-binstall for sccache (pre-built binary, much faster than compiling). ARG CARGO_BINSTALL_VERSION=1.18.1
RUN npm i -g @napi-rs/cli@2.18.4 && \ RUN ARCH=$(uname -m) && \
cargo install cargo-rustflags && \ curl -fsSL "https://github.com/cargo-bins/cargo-binstall/releases/download/v${CARGO_BINSTALL_VERSION}/cargo-binstall-${ARCH}-unknown-linux-musl.tgz" \
BINSTALL_ARCH=$(uname -m) && \ | tar xz -C /root/.cargo/bin && \
curl -fsSL "https://github.com/cargo-bins/cargo-binstall/releases/latest/download/cargo-binstall-${BINSTALL_ARCH}-unknown-linux-musl.tgz" | tar xz -C /root/.cargo/bin && \ npm i -g @napi-rs/cli@2.18.4 && \
cargo binstall sccache@0.14.0 --no-confirm cargo binstall --no-confirm --targets "${ARCH}-unknown-linux-musl" cargo-rustflags@0.4.0 && \
cargo binstall --no-confirm --git https://github.com/vercel/sccache sccache && \
# Verify installations node --version && rustc --version && napi -h > /dev/null && cargo rustflags --help > /dev/null && sccache --version
RUN node --version && rustc --version && napi -h > /dev/null && cargo rustflags --help > /dev/null && sccache --version
WORKDIR /build WORKDIR /build
https://github.com/vercel/sccache#b9566621e5daba0d898b73cb6bdcadd3eb989a0f
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment