Skip to content

Commit

Permalink
Build static-linked binaries (#6)
Browse files Browse the repository at this point in the history
* Build static-linked binaries (fix: libc.so.6: version GLIBC_2.32 not found)
* Update install.sh
  • Loading branch information
ecarrara authored Aug 18, 2023
1 parent a31634c commit a557d5e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 13 deletions.
28 changes: 21 additions & 7 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: release

on:
push:
branches:
- release-static-binaries
release:
types: [published]

Expand All @@ -12,24 +15,35 @@ jobs:
matrix:
include:
- os: ubuntu-latest
artifact_name: obsidian-garden
asset_name: obsidian-garden-linux-amd64
target: x86_64-unknown-linux-musl
- os: macos-latest
artifact_name: obsidian-garden
asset_name: obsidian-garden-macos-amd64
target: x86_64-apple-darwin
- os: macos-latest
target: aarch64-apple-darwin

steps:
- uses: actions/checkout@v3

- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
target: ${{ matrix.target }}

- name: Install cargo-rs
shell: bash
run: |
cargo install cross
- name: Build
run: cargo build --release
run: cross build --target ${{ matrix.target }} --release

- name: Upload binaries to release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: target/release/${{ matrix.artifact_name }}
asset_name: ${{ matrix.asset_name }}
file: target/${{ matrix.target }}/release/obsidian-garden
asset_name: obsidian-garden-${{ matrix.target}}
tag: ${{ github.ref }}

release-default-template:
Expand Down
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ serde = { version = "1.0.173", features = ["derive"] }
serde_yaml = "0.9.25"
thiserror = "1.0.43"
walkdir = "2.3.3"

[profile.release]
strip = true
lto = true
19 changes: 13 additions & 6 deletions install.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
set -eu
set -u

PROGRAM_NAME=obsidian-garden
BASE_URL=https://github.com/ecarrara/obsidian-garden/releases/latest/download
Expand Down Expand Up @@ -28,7 +28,7 @@ download () {

if exists curl; then
cmd="curl --silent --fail --location --output $destination $url"
elif has wget; then
elif exists wget; then
cmd="wget --quiet --output-document $destination $url"
else
message error "Unable to found curl or wget, exiting..."
Expand All @@ -37,21 +37,28 @@ download () {

message info "Downloading $url to $destination"
$sudo $cmd

if [[ "$?" -ne 0 ]]; then
message error "Download failed."
message warning "Only Linux x86_64 and MacOS are supported."
exit -1
fi
}

detect_platform () {
platform=$(uname -s | tr '[:upper:]' '[:lower:]')
case "$platform" in
linux) platform="linux" ;;
darwin) platform="macos" ;;
linux) platform="unknown-linux-musl" ;;
darwin) platform="apple-darwin" ;;
esac
echo -n "$platform"
}

detect_arch () {
arch=$(uname -m | tr '[:upper:]' '[:lower:]')
case "$arch" in
x86_64) arch="amd64" ;;
amd64) arch="x86_64" ;;
arm64) arch="aarch64" ;;
esac
echo -n "$arch"
}
Expand All @@ -64,7 +71,7 @@ if [ -z "${INSTALL_DIR-}" ]; then
INSTALL_DIR=/usr/local/bin
fi

URL=${BASE_URL}/${PROGRAM_NAME}-${PLATFORM}-${ARCH}
URL=${BASE_URL}/${PROGRAM_NAME}-${ARCH}-${PLATFORM}
TARGET=${INSTALL_DIR}/${PROGRAM_NAME}

if [ -w "$INSTALL_DIR" ]; then
Expand Down

0 comments on commit a557d5e

Please sign in to comment.