Skip to content
Merged
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
39 changes: 38 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,40 @@ MSQUIC_VERSION="$1"
TARGET_SO='priv/libquicer_nif.so'
PKGNAME="$(./pkgname.sh)"

detect_macos_arch() {
local arch=""

# The NIF must match the architecture of the running Erlang VM. Prefer
# Erlang's own target triplet so Rosetta shells don't accidentally choose
# the host/shell architecture instead of the VM architecture.
if command -v erl >/dev/null 2>&1; then
arch="$(erl -noshell -eval 'io:format("~s", [erlang:system_info(system_architecture)]), halt().' 2>/dev/null | cut -d- -f1 || true)"
fi

case "$arch" in
aarch64 | arm64)
echo arm64
;;
x86_64 | amd64)
echo x86_64
;;
*)
arch="$(uname -m)"
case "$arch" in
aarch64 | arm64)
echo arm64
;;
x86_64 | amd64)
echo x86_64
;;
*)
echo "$arch"
;;
esac
;;
esac
}

build() {
# default: 4 concurrent jobs
JOBS=4
Expand All @@ -19,7 +53,10 @@ build() {
fi
if [ "$(uname -s)" = 'Darwin' ]; then
JOBS="$(sysctl -n hw.ncpu)"
export SDKROOT="$(xcrun --sdk macosx --show-sdk-path)"
export CMAKE_OSX_ARCHITECTURES="${CMAKE_OSX_ARCHITECTURES:-$(detect_macos_arch)}"
if [ -z "${SDKROOT:-}" ]; then
export SDKROOT="$(xcrun --sdk macosx --show-sdk-path)"
fi
else
JOBS="$(nproc)"
fi
Expand Down
Loading