diff --git a/build.sh b/build.sh index 926052caa..fb0ac0b18 100755 --- a/build.sh +++ b/build.sh @@ -52,6 +52,21 @@ if [[ "${1:-}" == "--linux-release" ]]; then exit $? fi +# Check for --mac-release flag for macOS release build (must be run on macOS) +if [[ "${1:-}" == "--mac-release" ]]; then + check_and_clean_target "macos-release" + shift + if [[ "$OSTYPE" != "darwin"* ]]; then + echo "ERROR: --mac-release must be run on a native macOS system." + echo " Copy this repo to a Mac and run: ./build.sh --mac-release $*" + exit 1 + fi + echo "Building macOS release natively..." + ./util/build-mac.sh "$@" + echo "macOS release build complete." + exit $? +fi + # run correct build script for detected OS if [[ "$OSTYPE" == "linux-gnu"* ]]; then check_and_clean_target "linux" diff --git a/src/Makefile.am b/src/Makefile.am index c5697ba3e..f17f1d4f7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -51,8 +51,12 @@ LIBHUSH=libhush.a if TARGET_WINDOWS LIBRANDOMX=RandomX/build-win64/librandomx.a else +if TARGET_DARWIN +LIBRANDOMX=RandomX/build-darwin/librandomx.a +else LIBRANDOMX=RandomX/build-linux/librandomx.a endif +endif if BUILD_BITCOIN_LIBS LIBZCASH_CONSENSUS=libzcashconsensus.la diff --git a/util/build-mac.sh b/util/build-mac.sh index 745a72238..1e8ebb5f7 100755 --- a/util/build-mac.sh +++ b/util/build-mac.sh @@ -1,10 +1,37 @@ #!/usr/bin/env bash -# Copyright (c) 2016-2024 The Hush developers +# Copyright (c) 2016-2026 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html +# +# Native macOS build script. +# Requires: Xcode Command Line Tools, cmake, autoconf, automake, libtool, pkgconfig +# Optional: Homebrew GCC (brew install gcc) for better C++ compatibility + +set -eu -o pipefail + +# --- Detect architecture --- +ARCH=$(uname -m) # arm64 or x86_64 + +# --- Detect compiler --- +# Prefer Homebrew GCC if available, otherwise use system clang +if command -v brew &>/dev/null; then + # Find newest Homebrew GCC version + GCC_PATH=$(ls -d /opt/homebrew/bin/gcc-[0-9]* /usr/local/bin/gcc-[0-9]* 2>/dev/null | sort -t- -k2 -n | tail -1 || true) + GXX_PATH=$(echo "$GCC_PATH" | sed 's/gcc-/g++-/') +fi + +if [ -n "${GCC_PATH:-}" ] && [ -x "$GCC_PATH" ]; then + export CC="$GCC_PATH" + export CXX="$GXX_PATH" + echo "Using Homebrew GCC: $CC / $CXX" + EXTRA_CXXFLAGS="-fwrapv -fno-strict-aliasing -Wno-builtin-declaration-mismatch -Werror -g" +else + export CC=clang + export CXX=clang++ + echo "Using system clang: $CC / $CXX" + EXTRA_CXXFLAGS="-fwrapv -fno-strict-aliasing -Werror -g" +fi -export CC=gcc-8 -export CXX=g++-8 export LIBTOOL=libtool export AR=ar export RANLIB=ranlib @@ -12,8 +39,6 @@ export STRIP=strip export OTOOL=otool export NM=nm -set -eu -o pipefail - if [ "x$*" = 'x--help' ] then cat <