Skip to content

Commit

Permalink
Merge pull request #39 from algbio/update-macos-build
Browse files Browse the repository at this point in the history
Fix macOS precompiled binaries build
  • Loading branch information
jnalanko authored Jun 12, 2024
2 parents e7a8062 + 6e95e73 commit 8a02a56
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion deploy/macOS/arm64-toolchain_GNU.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR X86)
set(CMAKE_SYSTEM_PROCESSOR ARM64)

set(TOOLCHAIN_NAME aarch64-apple-darwin22)
set(COMPILER_PATH "/gcc/bin")
Expand Down
20 changes: 14 additions & 6 deletions deploy/macOS/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,13 @@ if [ "$ARCH" = "x86-64" ]; then
export CXX="x86_64-apple-darwin22-g++"

## Setup ggcat-cpp-api cargo config files for cross compilation
sed "s/cargo build/RUSTFLAGS='-L \/osxcross\/SDK\/MacOSX13.0.sdk\/usr\/lib' cargo build --target x86_64-apple-darwin/g" ../ggcat/crates/capi/ggcat-cpp-api/Makefile | sed 's/target\/release/target\/x86_64-apple-darwin\/release/g' | sed 's/fPIE/fPIE -march=x86-64 -mtune=generic -m64 -fPIC/g' | sed 's/ar cr/\/gcc\/bin\/x86_64-apple-darwin22-gcc-ar cr/g' > Makefile.tmp
sed "s/cargo build/RUSTFLAGS='-L \/osxcross\/SDK\/MacOSX13.0.sdk\/usr\/lib' cargo build --target x86_64-apple-darwin/g" ../ggcat/crates/capi/ggcat-cpp-api/Makefile | sed 's/target\/release/target\/x86_64-apple-darwin\/release/g' | sed 's/fPIE/fPIE -march=x86-64 -mtune=generic -m64 -fPIC -static-libstdc++ -static-libgcc/g' | sed 's/ar cr/\/gcc\/bin\/x86_64-apple-darwin22-gcc-ar cr/g' > Makefile.tmp
mv Makefile.tmp ../ggcat/crates/capi/ggcat-cpp-api/Makefile

## Prevent KMC from linking statically
sed 's/-static-libgcc//g' ../SBWT/KMC/CMakeLists.txt | sed 's/-static-libstdc++//g' | sed 's/-static//g' > CMakeLists.txt.tmp
mv CMakeLists.txt.tmp ../SBWT/KMC/CMakeLists.txt

## Prevent sdsl-lite from building with native instructions
sed 's/-march=native/-march=x86-64/g' ../SBWT/sdsl-lite/CMakeLists.txt > CMakeLists.txt.tmp
mv CMakeLists.txt.tmp ../SBWT/sdsl-lite/CMakeLists.txt
Expand All @@ -63,8 +67,8 @@ if [ "$ARCH" = "x86-64" ]; then

# compile x86_64
cmake -DCMAKE_TOOLCHAIN_FILE="/io/$ARCH-toolchain_GNU.cmake" \
-DCMAKE_C_FLAGS="-march=$ARCH -mtune=generic -m64 -fPIC -fPIE" \
-DCMAKE_CXX_FLAGS="-march=$ARCH -mtune=generic -m64 -fPIC -fPIE" \
-DCMAKE_C_FLAGS="-march=$ARCH -mtune=generic -m64 -fPIC -fPIE -static-libstdc++ -static-libgcc" \
-DCMAKE_CXX_FLAGS="-march=$ARCH -mtune=generic -m64 -fPIC -fPIE -static-libstdc++ -static-libgcc" \
-DROARING_DISABLE_NATIVE=ON \
-DBZIP2_LIBRARIES="/osxcross/SDK/MacOSX13.0.sdk/usr/lib/libbz2.tbd" -DBZIP2_INCLUDE_DIR="/osxcross/SDK/MacOSX13.0.sdk/usr/include" \
-DZLIB="/osxcross/SDK/MacOSX13.0.sdk/usr/lib/libz.tbd" -DZLIB_INCLUDE_DIR="/osxcross/SDK/MacOSX13.0.sdk/usr/include" \
Expand All @@ -90,18 +94,22 @@ elif [ "$ARCH" = "arm64" ]; then
mv Makefile.tmp ../SBWT/KMC/Makefile
mv CMakeLists.txt.tmp ../SBWT/KMC/CMakeLists.txt

## Prevent KMC from linking statically
sed 's/-static-libgcc//g' ../SBWT/KMC/CMakeLists.txt | sed 's/-static-libstdc++//g' | sed 's/-static//g' > CMakeLists.txt.tmp
mv CMakeLists.txt.tmp ../SBWT/KMC/CMakeLists.txt

## Prevent sdsl-lite from building with native instructions
sed 's/-msse4.2[[:space:]]*-march=native/-march=armv8-a/g' ../SBWT/sdsl-lite/CMakeLists.txt > CMakeLists.txt.tmp
mv CMakeLists.txt.tmp ../SBWT/sdsl-lite/CMakeLists.txt

## Setup ggcat-cpp-api cargo config files for cross compilation
sed "s/cargo build/RUSTFLAGS='-L \/osxcross\/SDK\/MacOSX13.0.sdk\/usr\/lib' cargo build --target aarch64-apple-darwin/g" ../ggcat/crates/capi/ggcat-cpp-api/Makefile | sed 's/target\/release/target\/aarch64-apple-darwin\/release/g' | sed 's/fPIE/fPIE -march=armv8-a -mtune=generic -m64 -fPIC/g' | sed 's/ar cr/\/gcc\/bin\/aarch64-apple-darwin22-gcc-ar cr/g' > Makefile.tmp
sed "s/cargo build/RUSTFLAGS='-L \/osxcross\/SDK\/MacOSX13.0.sdk\/usr\/lib' cargo build --target aarch64-apple-darwin/g" ../ggcat/crates/capi/ggcat-cpp-api/Makefile | sed 's/target\/release/target\/aarch64-apple-darwin\/release/g' | sed 's/fPIE/fPIE -march=armv8-a -mtune=generic -m64 -fPIC -static-libstdc++ -static-libgcc/g' | sed 's/ar cr/\/gcc\/bin\/aarch64-apple-darwin22-gcc-ar cr/g' > Makefile.tmp
mv Makefile.tmp ../ggcat/crates/capi/ggcat-cpp-api/Makefile

# compile aarch64
cmake -DCMAKE_TOOLCHAIN_FILE="/io/$ARCH-toolchain_GNU.cmake" \
-DCMAKE_C_FLAGS="-march=armv8-a -mtune=generic -m64 -fPIC -fPIE" \
-DCMAKE_CXX_FLAGS="-march=armv8-a -mtune=generic -m64 -fPIC -fPIE" \
-DCMAKE_C_FLAGS="-march=armv8-a -mtune=generic -m64 -fPIC -fPIE -static-libstdc++ -static-libgcc" \
-DCMAKE_CXX_FLAGS="-march=armv8-a -mtune=generic -m64 -fPIC -fPIE -static-libstdc++ -static-libgcc" \
-DAPPLE=1 \
-DCMAKE_SYSTEM_PROCESSOR="arm64" \
-DROARING_DISABLE_NATIVE=ON \
Expand Down
4 changes: 0 additions & 4 deletions deploy/macOS/compile_in_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,10 @@ fi

set -ux

cp ../$2-toolchain_GNU.cmake ./

docker run \
-v `pwd`:/io \
--rm \
-it \
ghcr.io/shepherdjerred/macos-cross-compiler:latest \
/bin/bash /io/build.sh $1 $2

rm $2-toolchain_GNU.cmake

0 comments on commit 8a02a56

Please sign in to comment.