diff --git a/.github/workflows/pipe.yaml b/.github/workflows/pipe.yaml index 9e76273..a5d0619 100644 --- a/.github/workflows/pipe.yaml +++ b/.github/workflows/pipe.yaml @@ -128,6 +128,8 @@ jobs: name: Build feature branch needs: [ check-repo, check-code-style, check-code, test ] runs-on: ubuntu-latest + env: + CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER: x86_64-w64-mingw32-gcc if: github.ref != 'refs/heads/main' strategy: fail-fast: false @@ -143,6 +145,13 @@ jobs: profile: minimal toolchain: stable + - name: Install target toolchain and linkers + if: matrix.target != 'x86_64-unknown-linux-gnu' + run: | + rustup target add ${{ matrix.target }} + sudo apt-get update + sudo apt-get install -y mingw-w64 + - uses: Swatinem/rust-cache@v2 with: cache-on-failure: true @@ -150,16 +159,10 @@ jobs: - name: Build binary run: | - # Build the binary with regular cargo build - cargo build --release - - # Set the target directory path - CARGO_BUILD_TARGET=$(rustc -vV | grep host | cut -d' ' -f2) - echo "Using host target: ${CARGO_BUILD_TARGET}" - echo "CARGO_BUILD_TARGET=${CARGO_BUILD_TARGET}" >> $GITHUB_ENV - - echo "Binary built at: target/release/binvec" - ls -la "target/release/binvec" || echo "Binary not found!" + cargo build --release --target ${{ matrix.target }} + + echo "Binary built at: target/${{ matrix.target }}/release/binvec" + ls -la "target/${{ matrix.target }}/release/binvec"* || echo "Binary not found!" create-release: name: Create new release @@ -229,6 +232,11 @@ jobs: matrix: target: [ 'x86_64-unknown-linux-gnu', 'aarch64-unknown-linux-gnu', 'armv7-unknown-linux-gnueabihf', 'arm-unknown-linux-gnueabihf', 'x86_64-pc-windows-gnu' ] runs-on: ubuntu-latest + env: + CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc + CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER: arm-linux-gnueabihf-gcc + CARGO_TARGET_ARM_UNKNOWN_LINUX_GNUEABIHF_LINKER: arm-linux-gnueabihf-gcc + CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER: x86_64-w64-mingw32-gcc steps: - name: Checkout code uses: actions/checkout@v7 @@ -259,7 +267,7 @@ jobs: echo "Error: VERSION environment variable is not set" exit 1 fi - sed -i 's/version = "0.0.0"/version = "${{ env.VERSION }}"/g' Cargo.toml + sed -i -E 's/^version = "[^"]*"/version = "${{ env.VERSION }}"/' Cargo.toml echo "Cargo version is now" $(cargo metadata --no-deps --format-version 1 | jq -r ".packages[0].version") - name: Install rust toolchain @@ -268,6 +276,18 @@ jobs: profile: minimal toolchain: stable + - name: Install target toolchain and linkers + run: | + rustup target add ${{ matrix.target }} + if [[ "${{ matrix.target }}" != "x86_64-unknown-linux-gnu" ]]; then + sudo apt-get update + case "${{ matrix.target }}" in + aarch64-unknown-linux-gnu) sudo apt-get install -y gcc-aarch64-linux-gnu ;; + armv7-unknown-linux-gnueabihf|arm-unknown-linux-gnueabihf) sudo apt-get install -y gcc-arm-linux-gnueabihf ;; + x86_64-pc-windows-gnu) sudo apt-get install -y mingw-w64 ;; + esac + fi + - uses: Swatinem/rust-cache@v2 with: cache-on-failure: true @@ -276,28 +296,20 @@ jobs: - name: Build and prepare binary for upload run: | - # Build the binary with regular cargo build - cargo build --release - - # Set the target directory path - CARGO_BUILD_TARGET=$(rustc -vV | grep host | cut -d' ' -f2) - echo "Using host target: ${CARGO_BUILD_TARGET}" - echo "CARGO_BUILD_TARGET=${CARGO_BUILD_TARGET}" >> $GITHUB_ENV - - ORIGINAL_BINARY_PATH="target/release/binvec" - - # Add .exe extension for Windows targets + cargo build --release --target ${{ matrix.target }} + + ORIGINAL_BINARY_PATH="target/${{ matrix.target }}/release/binvec" + + # Cargo appends .exe to binaries built for Windows targets if [[ "${{ matrix.target }}" == *"windows"* ]]; then + ORIGINAL_BINARY_PATH="${ORIGINAL_BINARY_PATH}.exe" RENAMED_BINARY_NAME="binvec-${{ matrix.target }}.exe" else RENAMED_BINARY_NAME="binvec-${{ matrix.target }}" fi - - DEST_DIR="target/release" - RENAMED_BINARY_PATH="${DEST_DIR}/${RENAMED_BINARY_NAME}" - echo "Original binary path: $ORIGINAL_BINARY_PATH" - echo "Will be renamed to: $RENAMED_BINARY_PATH" + DEST_DIR="target/${{ matrix.target }}/release" + RENAMED_BINARY_PATH="${DEST_DIR}/${RENAMED_BINARY_NAME}" if [ -f "$ORIGINAL_BINARY_PATH" ]; then echo "Binary found at: $ORIGINAL_BINARY_PATH" @@ -322,7 +334,7 @@ jobs: uses: softprops/action-gh-release@v3 with: tag_name: ${{ env.VERSION }} - files: target/release/binvec-${{ matrix.target }}* + files: target/${{ matrix.target }}/release/binvec-${{ matrix.target }}* name: Release ${{ env.VERSION }} token: ${{ secrets.GITHUB_TOKEN }} fail_on_unmatched_files: true diff --git a/.releaserc b/.releaserc index e635902..6e1700e 100644 --- a/.releaserc +++ b/.releaserc @@ -12,7 +12,7 @@ "@semantic-release/release-notes-generator", "@semantic-release/changelog", ["@semantic-release/exec", { - "prepareCmd": "sed -i \"s/Version=1.0/Version=${nextRelease.version}/\" .desktop/binvec.desktop && sed -i 's/version = \"0.0.0\"/version = \"${nextRelease.version}\"/g' Cargo.toml" + "prepareCmd": "sed -i -E \"s/^Version=.*/Version=${nextRelease.version}/\" .desktop/binvec.desktop && sed -i -E 's/^version = \"[^\"]*\"/version = \"${nextRelease.version}\"/' Cargo.toml" }], ["@semantic-release/git", { "assets": ["CHANGELOG.md", ".desktop/binvec.desktop", "Cargo.toml"], diff --git a/Cargo.lock b/Cargo.lock index 6680166..7360537 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -399,7 +399,7 @@ checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" [[package]] name = "binvec" -version = "1.20.8" +version = "1.20.27" dependencies = [ "iced", "image", @@ -3354,9 +3354,9 @@ dependencies = [ [[package]] name = "quinn-proto" -version = "0.11.14" +version = "0.11.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "434b42fec591c96ef50e21e886936e66d3cc3f737104fdb9b737c40ffb94c098" +checksum = "4fcb935c5bec503c2f0e306bdd3e58bb9029dcb14fa8d9ac76e3a5256ac0763e" dependencies = [ "bytes", "getrandom 0.3.3", diff --git a/Cargo.toml b/Cargo.toml index ed40dc6..56347c4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "binvec" -version = "1.20.8" +version = "1.20.27" edition = "2024" [dependencies] diff --git a/src/updater.rs b/src/updater.rs index f7af8a4..86fa716 100644 --- a/src/updater.rs +++ b/src/updater.rs @@ -4,6 +4,10 @@ use std::{env, io, process, thread}; use self_update::cargo_crate_version; +/// Marker set on the restart-after-update command so a binary that still +/// reports an outdated version can be detected instead of looping forever. +const RESTART_MARKER: &str = "BINVEC_UPDATED"; + /// Checks for updates /// If an update is available, download and install it /// If no update is available, do nothing @@ -32,6 +36,12 @@ pub fn update() { } Ok(self_update::Status::Updated(version)) => { println!("binvec updated to {version}"); + if env::var_os(RESTART_MARKER).is_some() { + eprintln!( + "Already restarted for an update, but the new binary still reports an outdated version. Not restarting again to avoid an update loop." + ); + return; + } restart_process(current_executable); } } @@ -41,7 +51,11 @@ pub fn update() { fn restart_process(current_executable: PathBuf) { println!("Waiting 3s before restarting {current_executable:?} ..."); thread::sleep(Duration::from_secs(3)); - let err = exec(process::Command::new(current_executable.clone()).args(env::args().skip(1))); + let err = exec( + process::Command::new(current_executable.clone()) + .args(env::args().skip(1)) + .env(RESTART_MARKER, "1"), + ); eprintln!("Error: Failed to restart process {current_executable:?}: {err}"); std::process::exit(1); } @@ -57,11 +71,11 @@ fn exec(command: &mut process::Command) -> io::Error { } #[cfg(windows)] -fn exec(command: &mut process::Command) -> Result<(), io::Error> { - // On Windows, we cannot replace the current process, so we just spawn a new one - // and exit the current one. +fn exec(command: &mut process::Command) -> io::Error { + // On Windows, we cannot replace the current process, so we spawn the new + // one and exit. Success never returns; failure returns the spawn error. match command.spawn() { - Ok(_) => return Ok(()), // Exit successfully, allowing cleanup + Ok(_) => std::process::exit(0), Err(err) => err, } }