From 31f5bd095b08fb23b401330753c2043268e92c0d Mon Sep 17 00:00:00 2001 From: veeso Date: Tue, 16 May 2023 14:38:16 +0200 Subject: [PATCH] fix: macos script --- dist/build/macos.sh | 61 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 4 deletions(-) diff --git a/dist/build/macos.sh b/dist/build/macos.sh index 4302591..2a3289b 100755 --- a/dist/build/macos.sh +++ b/dist/build/macos.sh @@ -18,11 +18,52 @@ make_pkg() { echo "$HASH" } +detect_platform() { + local platform + platform="$(uname -s | tr '[:upper:]' '[:lower:]')" + + case "${platform}" in + linux) platform="linux" ;; + darwin) platform="macos" ;; + freebsd) platform="freebsd" ;; + esac + + printf '%s' "${platform}" +} + +detect_arch() { + local arch + arch="$(uname -m | tr '[:upper:]' '[:lower:]')" + + case "${arch}" in + amd64) arch="x86_64" ;; + armv*) arch="arm" ;; + arm64) arch="aarch64" ;; + esac + + # `uname -m` in some cases mis-reports 32-bit OS as 64-bit, so double check + if [ "${arch}" = "x86_64" ] && [ "$(getconf LONG_BIT)" -eq 32 ]; then + arch="i686" + elif [ "${arch}" = "aarch64" ] && [ "$(getconf LONG_BIT)" -eq 32 ]; then + arch="arm" + fi + + printf '%s' "${arch}" +} + if [ -z "$1" ]; then echo "Usage: macos.sh " exit 1 fi +PLATFORM="$(detect_platform)" +ARCH="$(detect_arch)" + +if [ "$PLATFORM" != "macos" ]; then + echo "macos build is only available on MacOs systems" + exit 1 +fi + VERSION=$1 export BUILD_ROOT BUILD_ROOT="$(pwd)/../../" @@ -38,16 +79,28 @@ if [ ! -f Cargo.toml ]; then fi # Build release (x86_64) -cargo build --release --target x86_64-apple-darwin +X86_TARGET="" +X86_TARGET_DIR="" +if [ "$ARCH" == "aarch64" ]; then + X86_TARGET="--target x86_64-apple-darwin" + X86_TARGET_DIR="target/x86_64-apple-darwin/release/" +fi +cargo build --release $X86_TARGET # Make pkg -X86_64_HASH=$(make_pkg "x86_64" "$VERSION") +X86_64_HASH=$(make_pkg "x86_64" "$VERSION" $X86_TARGET_DIR) RET_X86_64=$? +ARM64_TARGET="" +ARM64_TARGET_DIR="" +if [ "$ARCH" == "aarch64" ]; then + ARM64_TARGET="--target aarch64-apple-darwin" + ARM64_TARGET_DIR="target/aarch64-apple-darwin/release/" +fi cd "$BUILD_ROOT" # Build ARM64 pkg -cargo build --release --target aarch64-apple-darwin +cargo build --release $ARM64_TARGET # Make pkg -ARM64_HASH=$(make_pkg "arm64" "$VERSION" "target/aarch64-apple-darwin/release/") +ARM64_HASH=$(make_pkg "arm64" "$VERSION" $ARM64_TARGET_DIR) RET_ARM64=$? echo "x86_64 hash: $X86_64_HASH"