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
68 changes: 40 additions & 28 deletions .github/workflows/pipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -143,23 +145,24 @@ 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
shared-key: "feature-build-${{ matrix.target }}"

- 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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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"
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .releaserc
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "binvec"
version = "1.20.8"
version = "1.20.27"
edition = "2024"

[dependencies]
Expand Down
24 changes: 19 additions & 5 deletions src/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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);
}
Expand All @@ -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,
}
}
Loading