Skip to content
This repository has been archived by the owner on Nov 29, 2023. It is now read-only.

Commit

Permalink
Add build CI for macos
Browse files Browse the repository at this point in the history
  • Loading branch information
olomix committed Oct 31, 2023
1 parent 905e4b3 commit f3289b2
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 5 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,35 @@ jobs:
run: |
if [[ ! -d "depends/gmp/package_ios_arm64" ]]; then ./build_gmp.sh ios; fi
if [[ ! -d "depends/gmp/package_iphone_simulator" ]]; then ./build_gmp.sh ios_simulator; fi
if [[ ! -d "depends/gmp/package_macos" ]]; then ./build_gmp.sh macos; fi
mkdir build_prover_ios && cd build_prover_ios
cmake .. -GXcode -DTARGET_PLATFORM=IOS -DCMAKE_INSTALL_PREFIX=../package_ios
xcodebuild -destination 'generic/platform=iOS' -scheme rapidsnarkStatic -project rapidsnark.xcodeproj -configuration Release
cp ../depends/gmp/package_ios_arm64/lib/libgmp.a src/Release-iphoneos
cd ../
mkdir build_prover_ios_simulator && cd build_prover_ios_simulator
cmake .. -GXcode -DTARGET_PLATFORM=IOS -DCMAKE_INSTALL_PREFIX=../package_ios_simulator -DUSE_ASM=NO
xcodebuild -destination 'generic/platform=iOS Simulator' -scheme rapidsnarkStatic -project rapidsnark.xcodeproj
cp ../depends/gmp/package_iphone_simulator/lib/libgmp.a src/Debug-iphonesimulator
cd ../
mkdir build_prover_macos_arm64 && cd build_prover_macos_arm64
cmake .. -GXcode -DTARGET_PLATFORM=macos_arm64 -DCMAKE_INSTALL_PREFIX=../package_macos_arm64
xcodebuild -project rapidsnark.xcodeproj -scheme rapidsnarkStatic -configuration Release -arch arm64 -arch arm64e
cd ../
mkdir build_prover_macos_x86_64 && cd build_prover_macos_x86_64
cmake .. -GXcode -DTARGET_PLATFORM=macos_x86_64 -DCMAKE_INSTALL_PREFIX=../package_macos_x86_64
xcodebuild -project rapidsnark.xcodeproj -scheme rapidsnarkStatic -configuration Release -arch x86_64
cd ../
mkdir -p package_macos/lib package_macos/include
cp src/prover.h ./depends/gmp/package_macos/include/gmp.h ./package_macos/include/
cp depends/gmp/package_macos/lib/libgmp.a ./package_macos/lib/
lipo ./build_prover_macos_x86_64/src/Release/libfq.a ./build_prover_macos_arm64/src/Release/libfq.a -create -output "./package_macos/lib/libfq.a"
lipo ./build_prover_macos_x86_64/src/Release/libfr.a ./build_prover_macos_arm64/src/Release/libfr.a -create -output "./package_macos/lib/libfr.a"
lipo ./build_prover_macos_x86_64/src/Release/librapidsnark.a ./build_prover_macos_arm64/src/Release/librapidsnark.a -create -output "./package_macos/lib/librapidsnark.a"
- name: upload iOS artifacts
uses: actions/upload-artifact@v3
Expand All @@ -108,3 +128,11 @@ jobs:
path: |
build_prover_ios_simulator/src/Debug-iphonesimulator
if-no-files-found: error

- name: upload macOS artifacts
uses: actions/upload-artifact@v3
with:
name: macOS
path: |
package_macos
if-no-files-found: error
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ make -j4 && make install
```sh
git submodule init
git submodule update
./build_gmp.sh host_noasm
./build_gmp.sh macos
mkdir build_prover && cd build_prover
cmake .. -DTARGET_PLATFORM=arm64_host -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../package
make -j4 && make install
Expand Down
2 changes: 1 addition & 1 deletion build/fq.asm
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ Fq_longNeg:
Fq_longErr:
push rdi
mov rdi, 0
call Fq_fail WRT ..plt
call Fq_fail
pop rdi
mov rsp, rbp
pop rdx
Expand Down
2 changes: 1 addition & 1 deletion build/fr.asm
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ Fr_longNeg:
Fr_longErr:
push rdi
mov rdi, 0
call Fr_fail WRT ..plt
call Fr_fail
pop rdi
mov rsp, rbp
pop rdx
Expand Down
57 changes: 56 additions & 1 deletion build_gmp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ usage()
echo " aarch64: build for Linux aarch64"
echo " ios: build for iOS arm64"
echo " ios_simulator: build for iPhone Simulator for arm64/x86_64 (fat binary)"
echo " macos: build for maxOS for arm64/x86_64 (fat binary)"
echo " host: build for this host"
echo " host_noasm: build for this host without asm optimizations (e.g. needed for macOS)"

Expand Down Expand Up @@ -241,7 +242,7 @@ build_ios_simulator()
for ARCH in "arm64" "x86_64"; do
case "$ARCH" in
"arm64" )
echo "Building for iPhone Simulator ARM64"
echo "Building for iPhone Simulator arm64"
ARCH_FLAGS="-arch arm64 -arch arm64e"
;;
"x86_64" )
Expand Down Expand Up @@ -282,6 +283,55 @@ build_ios_simulator()
echo "Wrote universal fat library for iPhone Simulator arm64/x86_64 to ${GMP_DIR}/package_iphone_simulator/lib/libgmp.a"
}

build_macos_fat()
{
libs=()
for ARCH in "arm64" "x86_64"; do
case "$ARCH" in
"arm64" )
echo "Building for macOS arm64"
ARCH_FLAGS="-arch arm64 -arch arm64e"
;;
"x86_64" )
echo "Building for macOS x86_64"
ARCH_FLAGS="-arch x86_64"
;;
* )
echo "Incorrect arch"
exit 1
esac

BUILD_DIR="build_macos_${ARCH}"
PACKAGE_DIR="$GMP_DIR/package_macos_${ARCH}"
libs+=("${PACKAGE_DIR}/lib/libgmp.a")

if [ -d "$PACKAGE_DIR" ]; then
echo "macOS ${ARCH} package is built already. See $PACKAGE_DIR. Skip building this ARCH."
continue
fi

rm -rf "$BUILD_DIR"
mkdir "$BUILD_DIR"
cd "$BUILD_DIR"

../configure --prefix="${PACKAGE_DIR}" \
CC="$(xcrun --sdk macosx --find clang)" \
CFLAGS="-O3 -isysroot $(xcrun --sdk macosx --show-sdk-path) ${ARCH_FLAGS} -fvisibility=hidden -mmacos-version-min=14.0" \
LDFLAGS="" \
--host ${ARCH}-apple-darwin --disable-assembly --enable-static --disable-shared --with-pic &&
make -j${NPROC} &&
make install

cd ..
done

mkdir -p "${GMP_DIR}/package_macos/lib"
lipo ${libs[@]} -create -output "${GMP_DIR}/package_macos/lib/libgmp.a"
mkdir -p "${GMP_DIR}/package_macos/include"
cp "${GMP_DIR}/package_macos_arm64/include/gmp.h" "${GMP_DIR}/package_macos/include/"
echo "Wrote universal fat library for macOS arm64/x86_64 to ${GMP_DIR}/package_macos/lib/libgmp.a"
}

if [ $# -ne 1 ]; then
usage
fi
Expand All @@ -308,6 +358,11 @@ case "$TARGET_PLATFORM" in
build_ios_simulator
;;

"macos" )
echo "Building fat library for macOS"
build_macos_fat
;;

"android" )
echo "Building for android"
build_android
Expand Down
11 changes: 11 additions & 0 deletions cmake/platform.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,18 @@ elseif(TARGET_PLATFORM MATCHES "arm64_host")
set(GMP_PREFIX ${GMP_ROOT}/package)
set(ARCH arm64)

elseif(TARGET_PLATFORM MATCHES "macos_x86_64")

set(GMP_PREFIX ${GMP_ROOT}/package_macos_arm64)
set(ARCH x86_64)

elseif(TARGET_PLATFORM MATCHES "macos_arm64")

set(GMP_PREFIX ${GMP_ROOT}/package_macos_x86_64)
set(ARCH arm64)

else()

set(GMP_PREFIX ${GMP_ROOT}/package)
set(ARCH x86_64)

Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ endif()
if(USE_ASM AND ARCH MATCHES "x86_64")

if (CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin")
set(NASM_FLAGS "-fmacho64 --prefix _")
set(NASM_FLAGS -fmacho64 --prefix _)
else()
set(NASM_FLAGS -felf64)
endif()
Expand Down

0 comments on commit f3289b2

Please sign in to comment.