Skip to content

Commit 320c384

Browse files
committed
chore: configure RUST_BACKTRACE=1 for builds by default
1 parent 961d0db commit 320c384

File tree

4 files changed

+102
-7
lines changed

4 files changed

+102
-7
lines changed

.github/workflows/rust.yml

Lines changed: 84 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ name: "Rust checks"
1919
on:
2020
pull_request:
2121
paths:
22-
- "rs/**"
22+
- "rs/**" # TODO: Add python/handlebarrz after fixing linker errors.
2323
- "Cargo.toml"
2424
- "Cargo.lock"
2525
- ".github/workflows/rust.yml"
@@ -41,11 +41,6 @@ jobs:
4141
- name: Checkout code
4242
uses: actions/checkout@v4
4343

44-
- name: Install Rust toolchain (${{ matrix.toolchain }})
45-
uses: dtolnay/rust-toolchain@master
46-
with:
47-
toolchain: ${{ matrix.toolchain }}
48-
4944
- name: Cache Cargo registry and index
5045
uses: actions/cache@v4
5146
with:
@@ -68,6 +63,89 @@ jobs:
6863
continue-on-error: ${{ matrix.toolchain == 'nightly' }}
6964

7065
- name: Run tests
66+
env:
67+
RUST_BACKTRACE: 1
7168
run: cargo test --all-targets --workspace
7269
# Allow nightly tests to fail
7370
continue-on-error: ${{ matrix.toolchain == 'nightly' }}
71+
72+
check-build-test-musl-matrix:
73+
name: Check, Build & Test (${{ matrix.toolchain }}, alpine-${{ matrix.arch }}-musl)
74+
runs-on: ubuntu-latest # Runner OS
75+
container: # Run steps inside this container
76+
image: rust:alpine # Use official Rust image based on Alpine (multi-arch)
77+
strategy:
78+
fail-fast: false
79+
matrix:
80+
include:
81+
- arch: x86_64
82+
target: x86_64-unknown-linux-musl
83+
- arch: aarch64
84+
target: aarch64-unknown-linux-musl
85+
toolchain: [stable, nightly]
86+
steps:
87+
- name: Checkout code
88+
uses: actions/checkout@v4
89+
90+
- name: Install musl build dependencies
91+
run: |
92+
apk add --no-cache musl-dev gcc bash docker-cli
93+
94+
- name: Set up QEMU
95+
uses: docker/setup-qemu-action@v3
96+
97+
- name: Install Rust toolchain (${{ matrix.toolchain }}) via rustup
98+
shell: bash
99+
run: |
100+
# Determine host triple based on architecture
101+
if [ "${{ matrix.arch }}" == "aarch64" ]; then
102+
HOST_TRIPLE="aarch64-unknown-linux-musl"
103+
else
104+
HOST_TRIPLE="x86_64-unknown-linux-musl"
105+
fi
106+
107+
echo "Setting default host: ${HOST_TRIPLE}"
108+
rustup set default-host ${HOST_TRIPLE}
109+
110+
echo "Installing toolchain: ${{ matrix.toolchain }} for host ${HOST_TRIPLE}"
111+
# Install the toolchain for the determined host, add the target, use minimal profile
112+
rustup toolchain install ${{ matrix.toolchain }} --profile minimal --target ${{ matrix.target }}
113+
rustup default ${{ matrix.toolchain }}
114+
115+
# Add target again just in case (should be included by toolchain install)
116+
# rustup target add ${{ matrix.target }}
117+
118+
echo "Rust toolchain info:"
119+
rustc --version --verbose
120+
cargo --version --verbose
121+
122+
- name: Cache Cargo registry and index (musl)
123+
uses: actions/cache@v4
124+
with:
125+
path: |
126+
/usr/local/cargo/registry/index/
127+
/usr/local/cargo/registry/cache/
128+
/usr/local/cargo/git/db/
129+
target/
130+
# Include architecture and toolchain in cache key
131+
key: linux-musl-${{ matrix.arch }}-cargo-${{ matrix.toolchain }}-${{ hashFiles('**/Cargo.lock') }}
132+
133+
- name: Check code (musl, ${{ matrix.arch }}, ${{ matrix.toolchain }})
134+
shell: bash
135+
run: cargo check --all-targets --workspace --target ${{ matrix.target }}
136+
# Allow nightly check to fail
137+
continue-on-error: ${{ matrix.toolchain == 'nightly' }}
138+
139+
- name: Build code (musl, ${{ matrix.arch }}, ${{ matrix.toolchain }})
140+
shell: bash
141+
run: cargo build --all-targets --workspace --target ${{ matrix.target }}
142+
# Allow nightly build to fail
143+
continue-on-error: ${{ matrix.toolchain == 'nightly' }}
144+
145+
- name: Run tests (musl, ${{ matrix.arch }}, ${{ matrix.toolchain }})
146+
shell: bash
147+
env:
148+
RUST_BACKTRACE: 1 # Keep the backtrace env var
149+
run: cargo test --all-targets --workspace --target ${{ matrix.target }}
150+
# Allow nightly tests to fail
151+
continue-on-error: ${{ matrix.toolchain == 'nightly' }}

rust.bazelrc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# RUST_BACKTRACE=1
2+
build --action_env=RUST_BACKTRACE=1
3+
run --run_env=RUST_BACKTRACE=1
4+
test --action_env=RUST_BACKTRACE=1
5+
test --test_env=RUST_BACKTRACE=1
6+
7+
# RUST_BACKTRACE=full
8+
build:debug --action_env=RUST_BACKTRACE=full
9+
run:debug --run_env=RUST_BACKTRACE=full
10+
test:debug --action_env=RUST_BACKTRACE=full
11+
test:debug --test_env=RUST_BACKTRACE=full

scripts/run_handlebarrz_tests

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ for arg in "$@"; do
4141
esac
4242
done
4343

44+
export RUST_BACKTRACE=1
45+
4446
if [ "$VERBOSE" = true ]; then
4547
echo "Running tests in verbose mode..."
4648
cargo test "${CARGO_ARGS[@]}"

scripts/run_rust_checks

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,16 @@ function error_exit() {
3030
}
3131

3232
# Check if rustup is installed
33-
if ! command -v rustup &> /dev/null; then
33+
if ! command -v rustup &>/dev/null; then
3434
error_exit "rustup could not be found. Please install rustup first: https://rustup.rs/"
3535
fi
3636

3737
echo "=== Running Rust tests ==="
3838

39+
# Show relevant stack traces.
40+
export RUST_BACKTRACE=1
41+
#export RUST_BACKTRACE=full # For more detailed stack traces.
42+
3943
# Install stable and nightly toolchains if they aren't already installed.
4044
echo "--- Ensuring stable and nightly toolchains are installed ---"
4145
rustup toolchain install stable --no-self-update || error_exit "Failed to install stable toolchain"

0 commit comments

Comments
 (0)