chore: macOS build scripts (#15936)

This commit is contained in:
Hao Guan
2026-03-07 19:08:15 +08:00
committed by GitHub
parent fd70de22fb
commit 4cb374fe61
6 changed files with 71 additions and 28 deletions

View File

@@ -10,3 +10,6 @@ end_of_line = lf
[*.json]
indent_size = 4
[*.makefile]
indent_style = tab

1
.gitignore vendored
View File

@@ -475,6 +475,7 @@ Thumbs.db
# build & install
build
install
install-*
# pnpm cache
.pnpm-store

View File

@@ -1,3 +1,5 @@
# This file is no longer used in the official build process,
# but is kept for reference and potential future use.
if (BUILD_XCFRAMEWORK)
set(XCFRAMEWORK_DIR "${CMAKE_BINARY_DIR}/xcframework")
file(MAKE_DIRECTORY ${XCFRAMEWORK_DIR})

View File

@@ -78,6 +78,8 @@ endif()
if(APPLE)
set_target_properties(MaaCore PROPERTIES INSTALL_RPATH "@loader_path/")
set_target_properties(MaaCore PROPERTIES BUILD_WITH_INSTALL_RPATH TRUE)
set_target_properties(MaaUtils PROPERTIES BUILD_WITH_INSTALL_RPATH TRUE)
elseif(UNIX)
set_target_properties(MaaCore PROPERTIES INSTALL_RPATH "$ORIGIN/")
endif()

View File

@@ -32,25 +32,6 @@ else
exit 1
fi
rm -rf build
mkdir build
for LIB_NAME in $(ls install-"${arch}" | grep .dylib); do
if [[ "${maa_debug}" -eq 1 ]]; then
mv install-"${arch}"/$LIB_NAME build/$LIB_NAME
else
lipo -create install-arm64/$LIB_NAME install-x86_64/$LIB_NAME -output build/$LIB_NAME
fi
done
cp build-"${arch}"/compile_commands.json build
make -f tools/xcframework.makefile MAA_DEBUG=${maa_debug} -j$(sysctl -n hw.ncpu) all
pushd build
xcodebuild -create-xcframework -library libMaaCore.dylib -headers ../include -output MaaCore.xcframework
xcodebuild -create-xcframework -library libMaaUtils.dylib -output MaaUtils.xcframework
xcodebuild -create-xcframework -library libfastdeploy_ppocr.dylib -output fastdeploy_ppocr.xcframework
xcodebuild -create-xcframework -library libonnxruntime.*.dylib -output ONNXRuntime.xcframework
xcodebuild -create-xcframework -library libopencv*.dylib -output OpenCV.xcframework
rm -rf *.dylib
popd
rm -rf install-arm64 install-x86_64
popd

View File

@@ -0,0 +1,54 @@
ARCH ?= $(shell uname -m)
MAA_DEBUG ?= 1
BUILD_DIR := build
XCFRAMEWORKS := $(BUILD_DIR)/MaaCore.xcframework \
$(BUILD_DIR)/MaaUtils.xcframework \
$(BUILD_DIR)/fastdeploy_ppocr.xcframework \
$(BUILD_DIR)/ONNXRuntime.xcframework \
$(BUILD_DIR)/OpenCV.xcframework
.PHONY: all clean
all: $(XCFRAMEWORKS) $(BUILD_DIR)/compile_commands.json
$(BUILD_DIR):
@mkdir -p $(BUILD_DIR)
$(BUILD_DIR)/compile_commands.json: build-$(ARCH)/compile_commands.json | $(BUILD_DIR)
@cp $< $@
ifeq ($(MAA_DEBUG), 0)
SRC_DIRS := install-arm64 install-x86_64
else
SRC_DIRS := install-$(ARCH)
endif
_get_and_check = $(if $(filter-out 1,$(words $(wildcard $(1)/$(2)))),\
$(error Ambiguous dylibs: $(wildcard $(1)/$(2))),\
$(wildcard $(1)/$(2)))
get_srcs = $(foreach dir,$(SRC_DIRS),$(call _get_and_check,$(dir),$(1)))
$(BUILD_DIR)/MaaCore.xcframework: $(call get_srcs,libMaaCore.dylib)
$(BUILD_DIR)/MaaUtils.xcframework: $(call get_srcs,libMaaUtils.dylib)
$(BUILD_DIR)/fastdeploy_ppocr.xcframework: $(call get_srcs,libfastdeploy_ppocr.dylib)
$(BUILD_DIR)/ONNXRuntime.xcframework: $(call get_srcs,libonnxruntime*.dylib)
$(BUILD_DIR)/OpenCV.xcframework: $(call get_srcs,libopencv*.dylib)
$(BUILD_DIR)/MaaCore.xcframework: EXTRA_ARGS := -headers include
$(XCFRAMEWORKS): | $(BUILD_DIR)
@rm -rf $@
@TMP_LIB="$(BUILD_DIR)/$$(basename "$<")"; \
if [ "$(MAA_DEBUG)" -eq 0 ]; then \
lipo -create $^ -output "$$TMP_LIB"; \
else \
cp "$<" "$$TMP_LIB"; \
fi; \
xcodebuild -create-xcframework -library "$$TMP_LIB" $(EXTRA_ARGS) -output $@; \
rm -f "$$TMP_LIB"
clean:
rm -rf $(BUILD_DIR)