Skip to content

Commit 4e36fc2

Browse files
authored
feat: support arm64 macos (#18)
* feat: support arm64 macos * fix build * make shellcheck happy * make shfmt happy * add comment
1 parent ae977ed commit 4e36fc2

File tree

3 files changed

+48
-22
lines changed

3 files changed

+48
-22
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
/node_modules/
1+
node_modules/
2+
build/

deps/build_libs.sh

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
true # Dummy command required to prevent first ShellCheck directive from having global scope.
44

55
# shellcheck disable=SC2153 # Fix false positive of ShellCheck rule SC2153.
6-
export PREFIX=/opt/lib/${CROSS_COMPILE}
6+
7+
LIB_PATH=${LIB_PATH:-/opt/lib}
8+
NPROC=${NPROC:-"$(nproc)"}
9+
export PREFIX=${PREFIX:-/opt/lib/${CROSS_COMPILE}}
710

811
if [ "$CROSS_COMPILER" == "" ]; then
912
CROSS_COMPILER=${CROSS_COMPILE}-gcc
@@ -15,31 +18,31 @@ else
1518
CROSS_COMPILER=$CC
1619
# CROSS_COMPILER_CXX=$CXX
1720
fi
18-
cd /opt/lib/libusb-1.0.28
21+
cd "${LIB_PATH}/libusb-1.0.28"
1922
LIBUSB_DIR=$(pwd)
2023
export LIBUSB_DIR
2124
./configure --prefix="${PREFIX}" --with-pic --disable-udev --enable-static --disable-shared --host="${CROSS_COMPILE}"
2225
make distclean
2326
./configure --prefix="${PREFIX}" --with-pic --disable-udev --enable-static --disable-shared --host="${CROSS_COMPILE}"
24-
make -j"$(nproc)"
27+
make -j"${NPROC}"
2528
make install
2629

2730
export PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig
2831

29-
if [[ $CROSS_COMPILE == "x86_64-apple-darwin13" ]]; then
32+
if [[ $CROSS_COMPILE == "x86_64-apple-darwin13" || $CROSS_COMPILE == "aarch64-apple-darwin" ]]; then
3033
export LIBUSB_1_0_CFLAGS=-I${PREFIX}/include/libusb-1.0
3134
export LIBUSB_1_0_LIBS="-L${PREFIX}/lib -lusb-1.0"
3235
fi
33-
cd /opt/lib/libusb-compat-0.1.8
36+
cd "${LIB_PATH}/libusb-compat-0.1.8"
3437
LIBUSB0_DIR=$(pwd)
3538
export LIBUSB0_DIR
3639
PKG_CONFIG_PATH="$PREFIX/lib/pkgconfig" ./configure --prefix="${PREFIX}" --enable-static --disable-shared --host="${CROSS_COMPILE}"
3740
make distclean
3841
PKG_CONFIG_PATH="$PREFIX/lib/pkgconfig" ./configure --prefix="${PREFIX}" --enable-static --disable-shared --host="${CROSS_COMPILE}"
39-
make -j"$(nproc)"
42+
make -j"${NPROC}"
4043
make install
4144

42-
cd /opt/lib/libftdi1-1.4
45+
cd "${LIB_PATH}/libftdi1-1.4"
4346
rm -rf build && mkdir build && cd build
4447

4548
CMAKE_EXTRA_FLAG="-DSHAREDLIBS=OFF -DBUILD_TESTS=OFF -DPYTHON_BINDINGS=OFF -DEXAMPLES=OFF -DFTDI_EEPROM=OFF"
@@ -48,7 +51,7 @@ if [[ $CROSS_COMPILE == "i686-w64-mingw32" ]]; then
4851
CMAKE_EXTRA_FLAG="$CMAKE_EXTRA_FLAG -DCMAKE_TOOLCHAIN_FILE=./cmake/Toolchain-i686-w64-mingw32.cmake"
4952
fi
5053

51-
if [[ $CROSS_COMPILE == "x86_64-apple-darwin13" ]]; then
54+
if [[ $CROSS_COMPILE == "x86_64-apple-darwin13" || $CROSS_COMPILE == "aarch64-apple-darwin" ]]; then
5255
CMAKE_EXTRA_FLAG="$CMAKE_EXTRA_FLAG -DCMAKE_AR=$AR -DCMAKE_RANLIB=$RANLIB"
5356
fi
5457

@@ -57,13 +60,13 @@ fi
5760
#make -j"$(nproc)"
5861
#make install
5962

60-
cd /opt/lib/libelf-0.8.13
63+
cd "${LIB_PATH}/libelf-0.8.13"
6164
LIBELF_DIR=$(pwd)
6265
export LIBELF_DIR
6366
./configure --disable-shared --host="$CROSS_COMPILE" --prefix="${PREFIX}"
6467
make distclean
6568
./configure --disable-shared --host="$CROSS_COMPILE" --prefix="${PREFIX}"
66-
make -j"$(nproc)"
69+
make -j"${NPROC}"
6770
make install
6871

6972
echo "*****************"
@@ -72,47 +75,47 @@ echo "*****************"
7275

7376
export CPPFLAGS="-P"
7477

75-
cd /opt/lib/ncurses-6.3
78+
cd "${LIB_PATH}/ncurses-6.3"
7679
NCURSES_DIR=$(pwd)
7780
export NCURSES_DIR
7881

7982
./configure "$EXTRAFLAGS" --target="$CROSS_COMPILE" --without-pthread --enable-database --enable-sp-funcs --enable-term-driver --without-shared --without-debug --without-ada --enable-termcap --without-manpages --without-progs --without-tests --host="$CROSS_COMPILE" --prefix="${PREFIX}"
8083
make distclean
8184
./configure "$EXTRAFLAGS" --target="$CROSS_COMPILE" --without-pthread --enable-database --enable-sp-funcs --enable-term-driver --without-shared --without-debug --without-ada --enable-termcap --without-manpages --without-progs --without-tests --host="$CROSS_COMPILE" --prefix="${PREFIX}"
82-
make -j"$(nproc)"
85+
make -j"${NPROC}"
8386
make install.libs
8487

85-
cd /opt/lib/readline-8.0
88+
cd "${LIB_PATH}/readline-8.0"
8689
READLINE_DIR=$(pwd)
8790
export READLINE_DIR
8891
./configure --prefix="$PREFIX" --disable-shared --host="$CROSS_COMPILE"
8992
make distclean
9093
./configure --prefix="$PREFIX" --disable-shared --host="$CROSS_COMPILE"
91-
make -j"$(nproc)"
94+
make -j"${NPROC}"
9295
make install-static
9396

94-
if [[ $CROSS_COMPILE != "i686-w64-mingw32" && $CROSS_COMPILE != "x86_64-apple-darwin13" ]]; then
95-
cd /opt/lib/eudev-3.2.10
97+
if [[ $CROSS_COMPILE != "i686-w64-mingw32" && $CROSS_COMPILE != "x86_64-apple-darwin13" && $CROSS_COMPILE != "aarch64-apple-darwin" ]]; then
98+
cd "${LIB_PATH}/eudev-3.2.10"
9699
./autogen.sh
97100
./configure --enable-static --disable-gudev --disable-introspection --disable-shared --disable-blkid --disable-kmod --disable-manpages --prefix="$PREFIX" --host="${CROSS_COMPILE}"
98101
make distclean
99102
./autogen.sh
100103
./configure --enable-static --disable-gudev --disable-introspection --disable-shared --disable-blkid --disable-kmod --disable-manpages --prefix="$PREFIX" --host="${CROSS_COMPILE}"
101-
make -j"$(nproc)"
104+
make -j"${NPROC}"
102105
make install
103106
fi
104107

105-
cd /opt/lib/hidapi-0.12.0
108+
cd "${LIB_PATH}/hidapi-0.12.0"
106109
export PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig
107110
./bootstrap
108111
./configure --prefix="$PREFIX" --enable-static --disable-shared --host="$CROSS_COMPILE"
109112
make distclean
110113
./bootstrap
111114
./configure --prefix="$PREFIX" --enable-static --disable-shared --host="$CROSS_COMPILE"
112-
make -j"$(nproc)"
115+
make -j"${NPROC}"
113116
make install
114117

115-
tar -xzf /opt/lib/libxml2-2.14.3.tar.gz -C /tmp && cd /tmp/libxml2-2.14.3
118+
tar -xzf "${LIB_PATH}/libxml2-2.14.3.tar.gz" -C /tmp && cd /tmp/libxml2-2.14.3
116119
./autogen.sh --prefix="$PREFIX" --disable-shared --enable-static --without-python --without-iconv --host="$CROSS_COMPILE"
117-
make -j"$(nproc)"
120+
make -j"${NPROC}"
118121
make install

scripts/build_mac.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/sh
2+
# This scripts builds all dependencies in ./deps for macOS and places them in ./build/macos/dist.
3+
# It is intended to be used in a native macOS environment or github macos runner.
4+
# It requires the necessary build tools including pkg-config, autoconf, automake, libtool.
5+
6+
set -ex
7+
8+
SCRIPT_PATH="$(cd "$(dirname "$0")" && pwd)"
9+
BASE_PATH=$(cd "${SCRIPT_PATH}/.." && pwd)
10+
cd "${BASE_PATH}"
11+
12+
mkdir -p "${BASE_PATH}/build/macos"
13+
rm -rf "${BASE_PATH}/build/macos/*"
14+
cp -r "${BASE_PATH}/deps" "${BASE_PATH}/build/macos/deps"
15+
mkdir -p "${BASE_PATH}/build/macos/dist"
16+
17+
LIB_PATH=${BASE_PATH}/build/macos/deps \
18+
PREFIX=${BASE_PATH}/build/macos/dist \
19+
CROSS_COMPILER=cc \
20+
CROSS_COMPILE=aarch64-apple-darwin \
21+
NPROC=8 \
22+
./deps/build_libs.sh

0 commit comments

Comments
 (0)