From e320f7efc386754396a9552ff6600b66a8c04686 Mon Sep 17 00:00:00 2001 From: Sergey Bogolepov Date: Fri, 19 Mar 2021 07:21:39 +0000 Subject: [PATCH] Add libffi buildscript for Apple Silicon --- kotlin-native/tools/libffi/build_for_macos.sh | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100755 kotlin-native/tools/libffi/build_for_macos.sh diff --git a/kotlin-native/tools/libffi/build_for_macos.sh b/kotlin-native/tools/libffi/build_for_macos.sh new file mode 100755 index 00000000000..12dd13b855c --- /dev/null +++ b/kotlin-native/tools/libffi/build_for_macos.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +set -eou pipefail + +OUTPUT_PATH=${1?"Usage: $0 "} +if [ ! -d "$OUTPUT_PATH" ]; then + echo "$(realpath "$OUTPUT_PATH") does not exists" + exit 1 +fi + +if [ -z "$(sysctl -q hw.optional.arm64)" ] +then + ARCH=x86_64 +else + ARCH=arm64 +fi + +VERSION=1 +NAME=libffi-3.3-$VERSION-macos-$ARCH + +pushd "$(mktemp -d -t libffi)" +curl -LO https://github.com/libffi/libffi/releases/download/v3.3/libffi-3.3.tar.gz +tar -xf libffi-3.3.tar.gz +pushd libffi-3.3 + +# Apple Silicon-specific patch. +# Based on: +# * https://github.com/libffi/libffi/pull/565 +# * https://github.com/libffi/libffi/pull/621 +curl -LO https://raw.githubusercontent.com/Homebrew/formula-patches/06252df03c68aee70856e5842f85f20b259e5250/libffi/libffi-3.3-arm64.patch +patch -p1 --ignore-whitespace < "libffi-3.3-arm64.patch" + +./configure --prefix="$(pwd)/$NAME" --disable-docs --enable-shared=no +make install +tar -czf "$OUTPUT_PATH"/$NAME.tar.gz "$NAME" +popd +popd \ No newline at end of file