Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Current `test-and-lint` gate includes:
- `cargo test -p rustfs get_object_chunk_fast_path`
- `cargo test -p rustfs materialize_chunk_stream_before_commit`
- `touch rustfs/build.rs`
- `cargo build -p rustfs --bins --jobs 2`
- `cargo build -p rustfs --bins`
- `cargo test -p e2e_test archive_multipart_roundtrip_preserves_bytes`
- `cargo test -p e2e_test presigned_get_and_reverse_proxy_preserve_multipart_bytes_with_fast_path`
- `cargo fmt --all --check`
Expand Down
25 changes: 25 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,31 @@ runs:
- name: Configure user-writable Rust paths
uses: ./.github/actions/rust-paths

- name: Set CARGO_BUILD_JOBS from runner resources
shell: bash
run: bash "${GITHUB_WORKSPACE}/scripts/ci/compute-cargo-build-jobs.sh"

- name: Enable lab sccache (self-hosted)
if: runner.environment == 'self-hosted'
shell: bash
run: |
set -euo pipefail
if [[ -f /usr/local/share/lab/lab-rust-sccache-env.sh ]]; then
# shellcheck disable=SC1091
source /usr/local/share/lab/lab-rust-sccache-env.sh
elif [[ -f scripts/lab-sccache-env.sh ]]; then
# shellcheck disable=SC1091
source scripts/lab-sccache-env.sh
fi
if [[ -n "${GITHUB_ENV:-}" ]]; then
[[ -n "${RUSTC_WRAPPER:-}" ]] && echo "RUSTC_WRAPPER=${RUSTC_WRAPPER}" >>"$GITHUB_ENV"
[[ -n "${CARGO_BUILD_RUSTC_WRAPPER:-}" ]] && echo "CARGO_BUILD_RUSTC_WRAPPER=${CARGO_BUILD_RUSTC_WRAPPER}" >>"$GITHUB_ENV"
[[ -n "${SCCACHE_REDIS:-}" ]] && echo "SCCACHE_REDIS=${SCCACHE_REDIS}" >>"$GITHUB_ENV"
fi
Comment on lines +94 to +98
if command -v sccache >/dev/null 2>&1; then
sccache --show-stats || true
fi

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ concurrency:
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
CARGO_BUILD_JOBS: 2

jobs:

Expand Down Expand Up @@ -119,7 +118,7 @@ jobs:
uses: ./.github/actions/setup
with:
rust-version: stable
cache-shared-key: ci-test-${{ hashFiles('**/Cargo.lock') }}
cache-shared-key: ci-${{ hashFiles('**/Cargo.lock') }}
github-token: ${{ secrets.GITHUB_TOKEN }}
cache-save-if: ${{ github.ref == 'refs/heads/main' }}

Expand Down Expand Up @@ -156,14 +155,14 @@ jobs:
uses: ./.github/actions/setup
with:
rust-version: stable
cache-shared-key: ci-rustfs-debug-binary-${{ hashFiles('**/Cargo.lock') }}
cache-shared-key: ci-${{ hashFiles('**/Cargo.lock') }}
cache-save-if: ${{ github.ref == 'refs/heads/main' }}
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Build debug binary
run: |
touch rustfs/build.rs
cargo build -p rustfs --bins --jobs 2
cargo build -p rustfs --bins

- name: Upload debug binary
uses: actions/upload-artifact@v6
Expand Down
96 changes: 96 additions & 0 deletions scripts/ci/compute-cargo-build-jobs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/usr/bin/env bash
# Set CARGO_BUILD_JOBS from CPU count and memory: up to half of logical cores,
# capped when RAM per concurrent rustc job would be too low.
#
# Usage:
# compute-cargo-build-jobs.sh # log to stderr; append to GITHUB_ENV if set
# compute-cargo-build-jobs.sh --value-only # print job count on stdout only (for Make)
#
# Override knobs (optional):
# CARGO_JOBS_RESERVE_MB — MiB reserved for OS / link peaks (default 4096)
# CARGO_JOBS_PER_RUSTC_MB — budget MiB per parallel rustc job (default 2048)

set -euo pipefail

VALUE_ONLY=0
if [[ "${1:-}" == "--value-only" ]]; then
VALUE_ONLY=1
fi

readonly RESERVE_MB="${CARGO_JOBS_RESERVE_MB:-4096}"
readonly PER_JOB_MB="${CARGO_JOBS_PER_RUSTC_MB:-2048}"

detect_resources() {
local os
os="$(uname -s 2>/dev/null || echo Unknown)"

case "$os" in
Linux)
cores="$(nproc 2>/dev/null || echo 2)"
if [[ -r /proc/meminfo ]]; then
local mem_kb
mem_kb="$(grep -E '^MemAvailable:' /proc/meminfo 2>/dev/null | awk '{print $2}' || true)"
if [[ -z "${mem_kb:-}" || "${mem_kb:-0}" -eq 0 ]]; then
mem_kb="$(grep -E '^MemTotal:' /proc/meminfo 2>/dev/null | awk '{print $2}' || echo 8388608)"
fi
mem_mb=$((mem_kb / 1024))
else
mem_mb=8192
fi
;;
Darwin)
cores="$(sysctl -n hw.ncpu 2>/dev/null || echo 2)"
local mem_bytes
mem_bytes="$(sysctl -n hw.memsize 2>/dev/null || echo 8589934592)"
mem_mb=$((mem_bytes / 1024 / 1024))
mem_mb=$((mem_mb * 8 / 10))
;;
MINGW* | MSYS* | CYGWIN* | Windows_NT)
cores="${NUMBER_OF_PROCESSORS:-2}"
if command -v powershell.exe >/dev/null 2>&1; then
local free_kb
free_kb="$(powershell.exe -NoProfile -Command \
"[int]((Get-CimInstance Win32_OperatingSystem).FreePhysicalMemory)" 2>/dev/null || echo 8388608)"
mem_mb=$((free_kb / 1024))
else
mem_mb=8192
fi
;;
*)
cores=2
mem_mb=8192
;;
esac
}

detect_resources

half=$((cores / 2))
[[ "$half" -lt 1 ]] && half=1

if ((mem_mb > RESERVE_MB)); then
usable_mb=$((mem_mb - RESERVE_MB))
else
usable_mb=$((mem_mb * 3 / 4))
fi
[[ "$usable_mb" -lt 256 ]] && usable_mb=256

max_by_mem=$((usable_mb / PER_JOB_MB))
[[ "$max_by_mem" -lt 1 ]] && max_by_mem=1

if [[ "$half" -le "$max_by_mem" ]]; then
jobs=$half
detail="half of ${cores} cores (memory sufficient)"
else
jobs=$max_by_mem
detail="capped by memory (~${mem_mb} MiB reported, ~${usable_mb} MiB budget, ${PER_JOB_MB} MiB/job)"
fi

if [[ "$VALUE_ONLY" -eq 1 ]]; then
printf '%s\n' "$jobs"
else
echo "Cargo parallelism: CARGO_BUILD_JOBS=${jobs} (${detail})" >&2
if [[ -n "${GITHUB_ENV:-}" ]]; then
echo "CARGO_BUILD_JOBS=${jobs}" >>"$GITHUB_ENV"
fi
fi
83 changes: 83 additions & 0 deletions scripts/lab-sccache-env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# shellcheck shell=bash
# Lab fleet sccache (mozilla/sccache + Redis). Source before cargo on self-hosted runners.
#
# If sccache is missing but RUSTC_WRAPPER/CARGO_BUILD_RUSTC_WRAPPER still reference it, we warn, unset
# those variables, and append clears to GITHUB_ENV when set so later Actions steps do not fail cargo.

_lab_sccache_redis_url() {
printf '%s' "${SCCACHE_REDIS:-${LAB_SCCACHE_REDIS:-${LAB_SCCACHE_REDIS_DEFAULT:-}}}"
}

_lab_sccache_tcp_ok() {
local host="$1"
local port="$2"
[[ -n "$host" && -n "$port" ]] || return 1
BASH_ENV= timeout 1 bash -c "echo > /dev/tcp/${host}/${port}" 2>/dev/null
}
Comment on lines +14 to +16

_lab_sccache_parse_redis_tcp_target() {
local url="$1"
local host port
if [[ "$url" =~ ^redis://([^:/@]+):([0-9]+)(/|$) ]]; then
host="${BASH_REMATCH[1]}"
port="${BASH_REMATCH[2]}"
elif [[ "$url" =~ ^redis://([^:/@]+)(/|$) ]]; then
host="${BASH_REMATCH[1]}"
port=6379
else
return 1
fi
printf '%s %s' "$host" "$port"
}

_lab_sccache_export_to_github_env() {
[[ -n "${GITHUB_ENV:-}" ]] || return 0
{
[[ -n "${RUSTC_WRAPPER:-}" ]] && echo "RUSTC_WRAPPER=${RUSTC_WRAPPER}"
[[ -n "${CARGO_BUILD_RUSTC_WRAPPER:-}" ]] && echo "CARGO_BUILD_RUSTC_WRAPPER=${CARGO_BUILD_RUSTC_WRAPPER}"
[[ -n "${SCCACHE_REDIS:-}" ]] && echo "SCCACHE_REDIS=${SCCACHE_REDIS}"
} >>"$GITHUB_ENV"
}

if command -v sccache >/dev/null 2>&1; then
export RUSTC_WRAPPER=sccache
export CARGO_BUILD_RUSTC_WRAPPER=sccache
_lab_url="$(_lab_sccache_redis_url)"
if [[ -n "$_lab_url" ]]; then
if [[ "$_lab_url" == rediss://* ]]; then
export SCCACHE_REDIS="$_lab_url"
elif _lab_read="$(_lab_sccache_parse_redis_tcp_target "$_lab_url")"; then
read -r _lab_h _lab_p <<<"$_lab_read"
if _lab_sccache_tcp_ok "$_lab_h" "$_lab_p"; then
export SCCACHE_REDIS="$_lab_url"
else
unset SCCACHE_REDIS 2>/dev/null || true
fi
Comment on lines +51 to +55
unset _lab_h _lab_p _lab_read 2>/dev/null || true
fi
fi
unset _lab_url 2>/dev/null || true
_lab_sccache_export_to_github_env
else
_lab_sccache_broken_wrapper=0
if [[ "${RUSTC_WRAPPER:-}" == sccache || "${CARGO_BUILD_RUSTC_WRAPPER:-}" == sccache ]]; then
_lab_sccache_broken_wrapper=1
elif [[ -n "${RUSTC_WRAPPER:-}" && "$(basename -- "${RUSTC_WRAPPER}")" == sccache && ! -x "${RUSTC_WRAPPER}" ]]; then
_lab_sccache_broken_wrapper=1
elif [[ -n "${CARGO_BUILD_RUSTC_WRAPPER:-}" && "$(basename -- "${CARGO_BUILD_RUSTC_WRAPPER}")" == sccache && ! -x "${CARGO_BUILD_RUSTC_WRAPPER}" ]]; then
_lab_sccache_broken_wrapper=1
fi
if ((_lab_sccache_broken_wrapper)); then
echo >&2 "warning: sccache is configured as the Rust compiler wrapper but sccache is not available; continuing without it (rustc directly)."
unset RUSTC_WRAPPER CARGO_BUILD_RUSTC_WRAPPER SCCACHE_REDIS 2>/dev/null || true
if [[ -n "${GITHUB_ENV:-}" ]]; then
{
echo "RUSTC_WRAPPER="
echo "CARGO_BUILD_RUSTC_WRAPPER="
} >>"$GITHUB_ENV"
fi
Comment on lines +73 to +78
fi
unset _lab_sccache_broken_wrapper 2>/dev/null || true
fi

unset -f _lab_sccache_redis_url _lab_sccache_tcp_ok _lab_sccache_parse_redis_tcp_target _lab_sccache_export_to_github_env 2>/dev/null || true
Loading