Skip to content

Commit

Permalink
Publish binaries for more platforms, including Windows (#490)
Browse files Browse the repository at this point in the history
  • Loading branch information
denisidoro authored Apr 11, 2021
1 parent 5a68b69 commit 9095e37
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 18 deletions.
24 changes: 17 additions & 7 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,43 @@ jobs:
asset_name: navi-${{ steps.get_version.outputs.VERSION }}.alfredworkflow

binary:
name: Publish binary for ${{ matrix.os }}
name: Publish ${{ matrix.target }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
# This should work with only the `include`s but it currently doesn't because of this bug:
# https://github.community/t5/How-to-use-Git-and-GitHub/GitHub-Actions-Matrix-options-dont-work-as-documented/td-p/29558
target: [x86_64-osx, x86_64-unknown-linux-musl, armv7-unknown-linux-musleabihf, armv7-linux-androideabi, aarch64-linux-android, x86_64-pc-windows-gnu]
target:
- x86_64-osx
- x86_64-unknown-linux-musl
- x86_64-pc-windows-gnu
- armv7-unknown-linux-musleabihf
- armv7-linux-androideabi
- aarch64-linux-android
- aarch64-apple-ios
include:
- os: macos-latest
target: x86_64-osx
- os: ubuntu-latest
target: x86_64-unknown-linux-musl
- os: ubuntu-latest
target: x86_64-pc-windows-gnu
- os: ubuntu-latest
target: armv7-unknown-linux-musleabihf
- os: ubuntu-latest
target: armv7-linux-androideabi
- os: ubuntu-latest
target: aarch64-linux-android
- os: ubuntu-latest
target: x86_64-pc-windows-gnu

- os: macos-latest
target: aarch64-apple-ios
steps:
- uses: hecrj/[email protected]
with:
rust-version: stable
- uses: actions/checkout@v1
- name: Build
id: build
run: scripts/action release ${{ matrix.target }}
- name: Get the version
id: get_version
Expand All @@ -61,6 +71,6 @@ jobs:
uses: svenstaro/upload-release-action@v1-release
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: target/tar/navi.tar.gz
file: target/tar/navi.${{ steps.build.outputs.EXTENSION }}
tag: ${{ github.ref }}
asset_name: navi-${{ steps.get_version.outputs.VERSION }}-${{ matrix.target }}.tar.gz
asset_name: navi-${{ steps.get_version.outputs.VERSION }}-${{ matrix.target }}.${{ steps.build.outputs.EXTENSION }}
80 changes: 69 additions & 11 deletions scripts/action
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,95 @@ set -euo pipefail
export NAVI_HOME="$(cd "$(dirname "$0")/.." && pwd)"
source "${NAVI_HOME}/scripts/install"

is_windows() {
local -r target="$1"
echo "$target" | grep -q "windows"
}

get_env_target() {
eval $(rustc --print cfg | grep target)
local r raw="${target_arch}-${target_vendor}-${target_os}-${target_env}"
echoerr "env_raw: $raw"
if echo "$raw" | grep -q "x86_64-apple-macos"; then
echo "x86_64-apple-darwin"
else
echo "$raw"
fi
}

as_cross_target() {
echo "$1" | sed "s/osx/apple-darwin/g"
}

_tap() {
echoerr "$@"
"$@"
}

release() {
local -r target="${1:-}"
echoerr "target: $target"
local -r cross_target="$(as_cross_target "$target")"
echoerr "cross_target: $cross_target"

TAR_DIR="${NAVI_HOME}/target/tar"
local use_zip=false
local cross=true

local -r env_target="$(get_env_target)"
echoerr "env_target: $env_target"

target="${1:-}"
if [[ $target == *"osx"* ]]; then
echoerr "OSX cross-compile is impossible. Fallbacking to cargo..."
target=""
if [[ $cross_target == $env_target ]]; then
cross=false
fi

cd "$NAVI_HOME"

rm -rf "${NAVI_HOME}/target" 2> /dev/null || true

if [ -n "$target" ]; then
if $cross; then
cargo install cross 2> /dev/null || true
cross build --release --locked --target "$target"
bin_folder="${target}/release"
_tap cross build --release --locked --target "$cross_target"
local -r bin_folder="${cross_target}/release"
else
cargo build --release --locked
bin_folder="release"
_tap cargo build --release --locked
local -r bin_folder="release"
fi

bin_path="${NAVI_HOME}/target/${bin_folder}/navi"
_ls "${bin_folder}"

if is_windows "$target"; then
local -r exe_ext=".exe"
use_zip=true
else
local -r exe_ext=""
fi

bin_path="${NAVI_HOME}/target/${bin_folder}/navi${exe_ext}"

chmod +x "$bin_path"
mkdir -p "$TAR_DIR" 2> /dev/null || true

cp "$bin_path" "$TAR_DIR"

cd "$TAR_DIR"
tar -czf navi.tar.gz *

if $use_zip; then
zip -r navi.zip *
echo ::set-output name=EXTENSION::zip
else
tar -czf navi.tar.gz *
echo ::set-output name=EXTENSION::tar.gz
fi

_ls "${bin_path}"
_ls "${TAR_DIR}"

}

_ls() {
echoerr "contents from $@:"
ls -la "$@" || true
}

workflow() {
Expand All @@ -62,4 +119,5 @@ shift
case "$cmd" in
"release") release "$@" ;;
"workflow") workflow "$@" ;;
*) exit 2 ;;
esac

0 comments on commit 9095e37

Please sign in to comment.