Skip to content

Introduce AtomicLevelFilter #1543

Introduce AtomicLevelFilter

Introduce AtomicLevelFilter #1543

Workflow file for this run

name: CI
on:
push:
paths-ignore:
- '**.md'
- 'LICENSE'
pull_request:
paths-ignore:
- '**.md'
- 'LICENSE'
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
# When updating this, also update:
# - src/lib.rs
# - Cargo.toml
# - README.md
rust_minver: 1.66.1
ci_targets: "['x86_64-unknown-linux-gnu', 'x86_64-pc-windows-msvc', 'aarch64-apple-darwin', 'x86_64-apple-ios', 'x86_64-unknown-freebsd', 'x86_64-unknown-illumos', 'aarch64-linux-android']"
defaults:
run:
shell: bash
jobs:
matrix:
strategy:
fail-fast: false
runs-on: ubuntu-latest
outputs:
ci_targets: ${{ steps.generate.outputs.ci_targets }}
steps:
- name: Generate matrix
id: generate
run: echo "ci_targets=${{ env.ci_targets }}" >> $GITHUB_OUTPUT
format:
strategy:
fail-fast: false
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Disable bench dependencies
run: ./.github/workflows/disable-bench-deps.sh
- uses: extractions/setup-just@v3
- name: Install Rust nightly
run: |
rustup toolchain install nightly
rustup component add rustfmt --toolchain nightly
- name: Restore cargo caches
uses: Swatinem/rust-cache@v2
- name: Check Rust formatting
run: just fmt --verbose -- --check
- name: Check justfile formatting
run: just --unstable --fmt --check
test:
strategy:
fail-fast: false
matrix:
os: ['ubuntu-latest', 'windows-latest', 'macos-latest']
fn_features: ['', 'log native libsystemd multi-thread runtime-pattern serde serde_json sval']
cfg_feature: ['', 'flexible-string', 'source-location', 'std-stream-captured']
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set a non-UTC timezone # for detecting issues related to the local timezone
uses: szenius/[email protected]
with:
timezoneLinux: "Asia/Shanghai"
timezoneMacos: "Asia/Shanghai"
timezoneWindows: "China Standard Time"
- name: Disable bench dependencies
run: ./.github/workflows/disable-bench-deps.sh
- uses: extractions/setup-just@v3
- name: Install dependencies
if: matrix.os == 'ubuntu-latest'
run: sudo bash ./.github/workflows/install-deps.sh
- name: Restore cargo caches
uses: Swatinem/rust-cache@v2
- name: Run tests with selected features
run: cargo test --features "${{ matrix.fn_features }} ${{ matrix.cfg_feature }}" --verbose
- name: Run tests with all features
if: matrix.fn_features == '' && matrix.cfg_feature == ''
run: just test
- name: Run examples
if: matrix.fn_features != ''
run: |
for example in `ls spdlog/examples/*.rs | xargs basename --suffix=.rs`; do
cargo run --features "${{ matrix.fn_features }} ${{ matrix.cfg_feature }}" --example ${example};
done
clippy:
needs: [matrix]
strategy:
fail-fast: false
matrix:
target: ${{ fromJSON(needs.matrix.outputs.ci_targets) }}
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Disable bench dependencies
if: matrix.target != fromJSON(needs.matrix.outputs.ci_targets)[0]
run: ./.github/workflows/disable-bench-deps.sh
- uses: extractions/setup-just@v3
- name: Install dependencies
run: sudo bash ./.github/workflows/install-deps.sh
- name: Install Rust nightly
run: |
rustup toolchain install nightly
rustup component add clippy --toolchain nightly
- name: Install Rust target
run: |
rustup target add ${{ matrix.target }}
rustup target add ${{ matrix.target }} --toolchain nightly
echo 'CARGO_BUILD_TARGET=${{ matrix.target }}' >> $GITHUB_ENV
- name: Restore cargo caches
uses: Swatinem/rust-cache@v2
- name: Run clippy
run: just clippy -- -D warnings
- name: Run clippy nightly
run: |
cargo +nightly clippy --all-features --tests --examples
WARNS=$(cargo +nightly clippy --all-features --tests --examples --message-format=json | jq -s '[.[] | select(.reason == "compiler-message")] | length')
if [[ $WARNS -ne 0 ]]; then
echo "::warning title=nightly clippy::Detected $WARNS warnings"
fi
- name: Run clippy nightly for benches
# Not all bench deps support all tier-2 targets
if: matrix.target == fromJSON(needs.matrix.outputs.ci_targets)[0]
run: |
cargo +nightly clippy --all-features --benches -- -A clippy::incompatible_msrv
WARNS=$(cargo +nightly clippy --all-features --benches --message-format=json -- -A clippy::incompatible_msrv | jq -s '[.[] | select(.reason == "compiler-message")] | length')
if [[ $WARNS -ne 0 ]]; then
echo "::warning title=nightly clippy::Detected $WARNS warnings"
fi
check:
needs: [matrix]
strategy:
fail-fast: false
matrix:
target: ${{ fromJSON(needs.matrix.outputs.ci_targets) }}
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Disable bench dependencies
run: ./.github/workflows/disable-bench-deps.sh
- uses: extractions/setup-just@v3
- name: Install dependencies
run: sudo bash ./.github/workflows/install-deps.sh
- name: Install Rust target
run: |
rustup target add ${{ matrix.target }}
echo 'CARGO_BUILD_TARGET=${{ matrix.target }}' >> $GITHUB_ENV
- name: Restore cargo caches
uses: Swatinem/rust-cache@v2
- name: Run check
run: just check --verbose
check-doc:
strategy:
fail-fast: false
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Disable bench dependencies
run: ./.github/workflows/disable-bench-deps.sh
- uses: extractions/setup-just@v3
- name: Install dependencies
run: sudo bash ./.github/workflows/install-deps.sh
- name: Install Rust nightly
run: rustup toolchain install nightly
- name: Restore cargo caches
uses: Swatinem/rust-cache@v2
- name: Run rustdoc nightly
run: |
RUSTDOCFLAGS='-D warnings -A rustdoc::broken-intra-doc-links'
just _doc-default-features --verbose
RUSTDOCFLAGS='-D warnings'
just doc --verbose
check-msrv:
needs: [matrix]
strategy:
fail-fast: false
matrix:
target: ${{ fromJSON(needs.matrix.outputs.ci_targets) }}
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Disable bench dependencies
run: ./.github/workflows/disable-bench-deps.sh
- name: Install dependencies
run: sudo bash ./.github/workflows/install-deps.sh
- name: Install Rust nightly
run: rustup toolchain install nightly
- name: Install Rust ${{ env.rust_minver }}
run: rustup toolchain install ${{ env.rust_minver }}
- name: Install Rust target
run: |
rustup target add ${{ matrix.target }} --toolchain nightly
rustup target add ${{ matrix.target }} --toolchain ${{ env.rust_minver }}
echo 'CARGO_BUILD_TARGET=${{ matrix.target }}' >> $GITHUB_ENV
- name: Restore cargo caches
uses: Swatinem/rust-cache@v2
- name: Avoid dev-dependencies
run: |
# Some dev-dependencies require a newer version of Rust, but it doesn't matter for MSRV check
# This is a workaround for the cargo nightly option `-Z avoid-dev-deps`
perl -pi -e 's/\[dev-dependencies]/[workaround-avoid-dev-deps]/g' ./spdlog/Cargo.toml
- name: Downgrade dependencies to minimal versions
run: cargo +nightly update -Z minimal-versions
- name: Check MSRV for core with Rust ${{ env.rust_minver }}
run: cargo +${{ env.rust_minver }} check --locked --all-features --verbose
test-native-linux:
strategy:
fail-fast: false
runs-on: 'ubuntu-latest'
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Disable bench dependencies
run: ./.github/workflows/disable-bench-deps.sh
- name: Install dependencies
run: sudo bash ./.github/workflows/install-deps.sh
- name: Restore cargo caches
uses: Swatinem/rust-cache@v2
- name: Build example
run: |
cargo build --example native_linux --features native,libsystemd,source-location --verbose
mv ./target/debug/examples/native_linux ./target/debug/examples/native_linux_srcloc
cargo build --example native_linux --features native,libsystemd --verbose
- name: Run and test
run: |
set -x
./target/debug/examples/native_linux
./target/debug/examples/native_linux_srcloc
journalctl --no-pager -o verbose -t native_linux
journalctl --no-pager -o verbose -t native_linux_srcloc
journalctl --no-pager -o json -t native_linux | jq -e -s $'.[0].MESSAGE == "[demo] [info] info message from spdlog-rs\'s JournaldSink\n"'
journalctl --no-pager -o json -t native_linux | jq -e -s $'.[0].PRIORITY == "6" and .[0].CODE_FILE == null and .[0].CODE_LINE == null and .[0].TID != null'
journalctl --no-pager -o json -t native_linux | jq -e -s $'.[1].MESSAGE == "[demo] [error] error message from spdlog-rs\'s JournaldSink { error_code=114514 }\n"'
journalctl --no-pager -o json -t native_linux | jq -e -s $'.[1].PRIORITY == "3" and .[1].CODE_FILE == null and .[1].CODE_LINE == null and .[1].TID != null'
journalctl --no-pager -o json -t native_linux_srcloc | jq -e -s $'.[0].MESSAGE == "[demo] [info] info message from spdlog-rs\'s JournaldSink\n"'
journalctl --no-pager -o json -t native_linux_srcloc | jq -e -s $'.[0].PRIORITY == "6" and .[0].CODE_FILE == "linux.rs" and .[0].CODE_LINE != null and .[0].TID != null'
journalctl --no-pager -o json -t native_linux_srcloc | jq -e -s $'.[1].MESSAGE == "[demo] [error] error message from spdlog-rs\'s JournaldSink { error_code=114514 }\n"'
journalctl --no-pager -o json -t native_linux_srcloc | jq -e -s $'.[1].PRIORITY == "3" and .[1].CODE_FILE == "linux.rs" and .[1].CODE_LINE != null and .[1].TID != null'
test-native-windows:
strategy:
fail-fast: false
runs-on: 'windows-latest'
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Disable bench dependencies
run: ./.github/workflows/disable-bench-deps.sh
- name: Install DebugView
run: choco install dbgview
- name: Restore cargo caches
uses: Swatinem/rust-cache@v2
- name: Build example
run: |
cargo build --example native_windows --features native,source-location --verbose
mv ./target/debug/examples/native_windows ./target/debug/examples/native_windows_srcloc
cargo build --example native_windows --features native --verbose
- name: Run and test
run: |
set -x
# Microsoft styled CLI options start with `/` and need to be doubled to escape in bash.
dbgview //l ./dbgview.log
# Wait for dbgview to start up and create the log file
while [ ! -f ./dbgview.log ]; do sleep 1; done
./target/debug/examples/native_windows
./target/debug/examples/native_windows_srcloc
# Wait for dbgview to flush the log file
while [ ! -s ./dbgview.log ]; do sleep 1; done
sleep 3
dbgview //q
cat ./dbgview.log
cat ./dbgview.log | grep "\[demo] \[info] info message from spdlog-rs's WinDebugSink"
cat ./dbgview.log | grep "\[demo] \[error] error message from spdlog-rs's WinDebugSink { error_code=114514 }"
cat ./dbgview.log | grep -E "\[demo] \[info] \[native_windows, .+.rs:[0-9]+] info message from spdlog-rs's WinDebugSink"
cat ./dbgview.log | grep -E "\[demo] \[error] \[native_windows, .+.rs:[0-9]+] error message from spdlog-rs's WinDebugSink { error_code=114514 }"
test-native-android:
strategy:
fail-fast: false
runs-on: 'ubuntu-latest'
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Disable bench dependencies
run: ./.github/workflows/disable-bench-deps.sh
- name: Restore cargo caches
uses: Swatinem/rust-cache@v2
- name: Install cross
run: cargo install cross --git https://github.com/cross-rs/cross --verbose
- name: Build example
run: |
cross build --target x86_64-linux-android --example native_android --features native,android-ndk,source-location --verbose
mv ./target/x86_64-linux-android/debug/examples/native_android ./target/x86_64-linux-android/debug/examples/native_android_srcloc
cross build --target x86_64-linux-android --example native_android --features native,android-ndk --verbose
- name: Enable KVM
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- name: Run emulator and test
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 29
arch: x86_64
script: |
adb root
adb push ./target/x86_64-linux-android/debug/examples/native_android /data
adb push ./target/x86_64-linux-android/debug/examples/native_android_srcloc /data
adb logcat -b all -c
adb shell /data/native_android
adb shell /data/native_android_srcloc
adb logcat -s "spdlog-rs-example" -d > ./logcat.log
cat ./logcat.log
cat ./logcat.log | grep "I spdlog-rs-example: \[demo] info message from spdlog-rs's AndroidSink"
cat ./logcat.log | grep "E spdlog-rs-example: \[demo] error message from spdlog-rs's AndroidSink { error_code=114514 }"
cat ./logcat.log | grep -E "I spdlog-rs-example: \[demo] \[native_android, .+.rs:[0-9]+] info message from spdlog-rs's AndroidSink"
cat ./logcat.log | grep -E "E spdlog-rs-example: \[demo] \[native_android, .+.rs:[0-9]+] error message from spdlog-rs's AndroidSink { error_code=114514 }"
bench:
needs: [test, check]
strategy:
fail-fast: false
runs-on: 'ubuntu-latest'
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Disable bench dependencies
run: ./.github/workflows/disable-bench-deps.sh
- uses: extractions/setup-just@v3
- name: Install Rust nightly
run: rustup toolchain install nightly
- name: Restore cargo caches
uses: Swatinem/rust-cache@v2
- name: Run benchmark
run: |
just bench \
--bench spdlog_rs \
--bench spdlog_rs_pattern \
--bench spdlog_rs_log_crate_proxy \
| tee bench-results.txt
- name: Discard irrelevant changes
run: git checkout -- spdlog/Cargo.toml
- name: Process results
uses: benchmark-action/github-action-benchmark@v1
with:
name: spdlog-rs on Linux
tool: cargo
output-file-path: bench-results.txt
benchmark-data-dir-path: docs/dev/benchmarks
github-token: ${{ secrets.GITHUB_TOKEN }}
summary-always: true
comment-on-alert: true
alert-comment-cc-users: '@SpriteOvO'
- name: Push results to GitHub Pages branch
if: github.event_name != 'pull_request' && (github.ref_name == 'main' || github.ref_name == 'main-dev')
run: git push 'https://${{ github.repository_owner }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git' gh-pages:gh-pages