From f56731512de4b854645ae43476f9539f7d4e4a14 Mon Sep 17 00:00:00 2001 From: Nick Carton Date: Mon, 18 Nov 2024 09:54:54 +0100 Subject: [PATCH] cached rust builds, remove openssl dependency --- .github/workflows/rust-build.yml | 49 ++++++++++++++++++++++++++++-- .github/workflows/rust-publish.yml | 47 ++++++++++++++++++++++++++-- Cargo.toml | 7 +++-- 3 files changed, 96 insertions(+), 7 deletions(-) diff --git a/.github/workflows/rust-build.yml b/.github/workflows/rust-build.yml index b0cf6f2..2b8be18 100644 --- a/.github/workflows/rust-build.yml +++ b/.github/workflows/rust-build.yml @@ -1,10 +1,16 @@ name: Build on: - pull_request: + push: branches: - "*" +env: + RUSTC_WRAPPER: sccache + SCCACHE_GHA_ENABLED: true + SCCACHE_CACHE_SIZE: 2G + SCCACHE_DIR: /home/runner/.cache/sccache + jobs: build: name: Build for ${{ matrix.target }} @@ -47,17 +53,54 @@ jobs: artifact_name: bping steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v4 + + - name: Install build dependencies + if: runner.os == 'Linux' + run: | + sudo apt-get update + sudo apt-get install -y curl build-essential pkg-config libssl-dev - - uses: actions-rs/toolchain@v1 + - name: Install Rust + uses: actions-rs/toolchain@v1 with: profile: minimal toolchain: stable target: ${{ matrix.target }} override: true + - name: Configure sccache + run: | + echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV + echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV + + - name: Run sccache-cache + uses: mozilla-actions/sccache-action@v0.0.6 + + - name: Rust Cache + uses: Swatinem/rust-cache@v2 + with: + prefix-key: "v1-rust" + shared-key: "${{ matrix.target }}-build" + cache-targets: "true" + cache-on-failure: "true" + cache-all-crates: "true" + save-if: ${{ github.ref == 'refs/heads/master' }} + workspaces: | + . -> target + - name: Build uses: actions-rs/cargo@v1 with: command: build args: --release --target ${{ matrix.target }} + + - name: Show sccache stats + run: sccache --show-stats + + # Optional: Upload artifacts if needed + - name: Upload artifacts + uses: actions/upload-artifact@v3 + with: + name: ${{ matrix.target }}-binary + path: target/${{ matrix.target }}/release/${{ matrix.artifact_name }} diff --git a/.github/workflows/rust-publish.yml b/.github/workflows/rust-publish.yml index 6331e13..e80dc20 100644 --- a/.github/workflows/rust-publish.yml +++ b/.github/workflows/rust-publish.yml @@ -5,6 +5,12 @@ on: tags: - "*" +env: + RUSTC_WRAPPER: sccache + SCCACHE_GHA_ENABLED: true + SCCACHE_CACHE_SIZE: 2G + SCCACHE_DIR: /home/runner/.cache/sccache + jobs: publish: name: Publish for ${{ matrix.target }} @@ -47,21 +53,51 @@ jobs: asset_name: bping-x86_64-linux-musl steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v4 + + - name: Install build dependencies + if: runner.os == 'Linux' + run: | + sudo apt-get update + sudo apt-get install -y curl build-essential pkg-config libssl-dev - - uses: actions-rs/toolchain@v1 + - name: Install Rust + uses: actions-rs/toolchain@v1 with: profile: minimal toolchain: stable target: ${{ matrix.target }} override: true + - name: Configure sccache + run: | + echo "RUSTC_WRAPPER=sccache" >> $GITHUB_ENV + echo "SCCACHE_GHA_ENABLED=true" >> $GITHUB_ENV + + - name: Run sccache-cache + uses: mozilla-actions/sccache-action@v0.0.6 + + - name: Rust Cache + uses: Swatinem/rust-cache@v2 + with: + prefix-key: "v1-rust" + shared-key: "${{ matrix.target }}-release" + cache-targets: "true" + cache-on-failure: "true" + cache-all-crates: "true" + save-if: true # Always save cache for tagged releases + workspaces: | + . -> target + - name: Build uses: actions-rs/cargo@v1 with: command: build args: --release --target ${{ matrix.target }} + - name: Show sccache stats + run: sccache --show-stats + - name: Strip binary if: runner.os != 'Windows' run: strip target/${{ matrix.target }}/release/bping @@ -73,3 +109,10 @@ jobs: file: target/${{ matrix.target }}/release/bping${{ runner.os == 'Windows' && '.exe' || '' }} asset_name: ${{ matrix.asset_name }} tag: ${{ github.ref }} + + # Optional: Upload artifacts for debugging or additional processing + - name: Upload artifacts + uses: actions/upload-artifact@v3 + with: + name: ${{ matrix.target }}-release-binary + path: target/${{ matrix.target }}/release/bping${{ runner.os == 'Windows' && '.exe' || '' }} diff --git a/Cargo.toml b/Cargo.toml index 3fc1678..f9a73c0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,10 @@ opt-level = "z" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -reqwest = { version = "0.12.5", features = ["json"] } +reqwest = { version = "0.12", features = [ + "json", + "rustls-tls", +], default-features = false } spinners = "4.1.1" tokio = { version = "1.38.0", features = ["full"] } dirs = "5.0.1" @@ -24,7 +27,7 @@ colorful = "0.3.2" indicatif = "0.17.8" chrono = { version = "0.4", features = ["serde"] } celes = "2.4.0" -thiserror = "1.0.61" +thiserror = "2.0" async-stream = "0.3.5" console = "0.15.8" keshvar = { version = "0.5.0", features = ["serde", "emojis"] }