Skip to content

Commit

Permalink
Add experimental apple silicon support
Browse files Browse the repository at this point in the history
  • Loading branch information
gliwka committed May 4, 2021
1 parent 85b054b commit ad04930
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 18 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,21 @@ jobs:
include:
- os: windows-latest
shell: msys2 {0}
platform: windows-x86_64
- os: macos-latest
shell: bash
platform: macosx-x86_64
- os: macos-latest
shell: bash
platform: macosx-arm64
- os: ubuntu-latest
shell: bash
platform: linux-x86_64
env:
SIGN_KEY: ${{ secrets.SIGN_KEY }}
SIGN_KEY_PASS: ${{ secrets.SIGN_KEY_PASS }}
STAGING_REPO: ${{ needs.create-staging-repo.outputs.staging-repo }}
DETECTED_PLATFORM: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v2
- uses: msys2/setup-msys2@v2
Expand Down
45 changes: 29 additions & 16 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,22 @@ set -xeu
set -o pipefail

HYPERSCAN=5.4.0
VECTORSCAN=af8c6d375cba32a50a9e575de83807d96a0fb503

detect_platform() {
# use os-maven-plugin to detect platform
local platform=$(mvn help:evaluate -Dexpression=os.detected.classifier -q -DforceStdout)
# fix value for macos: plugin outputs osx, but JavaCPP needs it to be macosx
if [[ $platform == osx-* ]]
then
echo mac$platform
else
echo $platform
fi
# fix value for macosx: plugin outputs osx, but JavaCPP needs it to be macosx
local fixOsName=${platform/osx/macosx}
# fix value for arm64: plugin outputs aarch64, but JavaCPP needs it to be arm64
echo ${fixOsName/aarch_64/arm64}
}

export DETECTED_PLATFORM=$(detect_platform)
export DETECTED_PLATFORM=${DETECTED_PLATFORM:-$(detect_platform)}

cross_platform_nproc() {
case $DETECTED_PLATFORM in
macosx-x86_64) echo $(sysctl -n hw.logicalcpu) ;;
macosx-x86_64|macosx-arm64) echo $(sysctl -n hw.logicalcpu) ;;
linux-x86_64|windows-x86_64) echo $(nproc --all) ;;
*) echo Unsupported Platform: $DETECTED_PLATFORM >&2 ; exit -1 ;;
esac
Expand All @@ -32,7 +30,7 @@ cross_platform_check_sha() {
local sha=$1
local file=$2
case $DETECTED_PLATFORM in
macosx-x86_64) echo "$sha $file" | shasum -a 256 -c ;;
macosx-x86_64|macosx-arm64) echo "$sha $file" | shasum -a 256 -c ;;
linux-x86_64|windows-x86_64) echo "$sha $file" | sha256sum -c ;;
*) echo Unsupported Platform: $DETECTED_PLATFORM >&2 ; exit -1 ;;
esac
Expand All @@ -45,12 +43,22 @@ mkdir -p cppbuild/bin
mkdir -p cppbuild/include/hs
cd cppbuild

# -OJ doesn't work on old centos, so we have to be verbose
curl -L -o hyperscan-$HYPERSCAN.tar.gz https://github.com/intel/hyperscan/archive/v$HYPERSCAN.tar.gz
cross_platform_check_sha \
e51aba39af47e3901062852e5004d127fa7763b5dbbc16bcca4265243ffa106f \
hyperscan-$HYPERSCAN.tar.gz
tar -zxf hyperscan-$HYPERSCAN.tar.gz
# use own vectorscan fork with clang patches for apple silicon macs
if [ $DETECTED_PLATFORM = "macosx-arm64" ]
then
curl -L -o vectorscan-$VECTORSCAN.zip https://github.com/gliwka/vectorscan/archive/$VECTORSCAN.zip
cross_platform_check_sha \
5ba9b3766b92371324a83fc2fc47d5005bbed49bc6ba601e2e3ca679d74a150e \
vectorscan-$VECTORSCAN.zip
unzip vectorscan-$VECTORSCAN.zip
mv vectorscan-$VECTORSCAN hyperscan-$HYPERSCAN
else
curl -L -o hyperscan-$HYPERSCAN.tar.gz https://github.com/intel/hyperscan/archive/v$HYPERSCAN.tar.gz
cross_platform_check_sha \
e51aba39af47e3901062852e5004d127fa7763b5dbbc16bcca4265243ffa106f \
hyperscan-$HYPERSCAN.tar.gz
tar -zxf hyperscan-$HYPERSCAN.tar.gz
fi

curl -L -o boost_1_74_0.tar.gz https://dl.bintray.com/boostorg/release/1.74.0/source/boost_1_74_0.tar.gz
cross_platform_check_sha \
Expand Down Expand Up @@ -84,6 +92,11 @@ macosx-x86_64)
make -j $THREADS
make install/strip
;;
macosx-arm64)
CFLAGS="-target arm64-apple-macos11" cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="$(pwd)/.." -DCMAKE_INSTALL_LIBDIR="lib" -DARCH_OPT_FLAGS='-Wno-error' .
make -j $THREADS
make install/strip
;;
windows-x86_64)
unset TEMP TMP # temp is defined in uppercase by bash and lowercase by windows, which causes problems with cmake + msbuild
CXXFLAGS="/Wv:17" cmake -G "Visual Studio 16 2019" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="$(pwd)/.." -DCMAKE_INSTALL_LIBDIR="lib" -DARCH_OPT_FLAGS='' .
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<javacpp.version>1.5.4</javacpp.version>
<javacpp.version>1.5.5</javacpp.version>
</properties>
<distributionManagement>
<snapshotRepository>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/gliwka/hyperscan/jni/JavaCppPreset.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
value = {
@Platform(
define = "NO_JNI_DETACH_THREAD", //JNI callback on same thread
value = {"linux-x86_64", "macosx-x86_64", "windows-x86_64"},
value = {"linux-x86_64", "macosx-x86_64", "macosx-arm64", "windows-x86_64"},
compiler = "cpp11",
include = {"hs/hs_common.h", "hs/hs_compile.h", "hs/hs_runtime.h", "hs/hs.h"},
link = {"hs", "hs_runtime"}
Expand Down

0 comments on commit ad04930

Please sign in to comment.