feat(dfss): 支持 macOS 兼容(x86_64 + arm64) - #164
Merged
Merged
Conversation
- linux_release.sh/build_libs.sh 新增 darwin 构建目标,Mac 本机按当前芯片
生成 dfss-cpp-darwin-{x86_64,arm64},依赖 zlib/mbedtls/libssh2 静态编译
- Makefile 兼容 Darwin strip(-x)、main.cpp 修复 clang 下 filesystem 包含
并为 macOS 提供 _NSGetExecutablePath 获取可执行路径
- dfss pip 包架构识别支持 darwin-x86_64/darwin-arm64 二进制选择
- readme/release.sh 同步 darwin 支持说明
适用于 Intel Mac (x86_64) 与 Apple Silicon (arm64),需 Mac 本机构建
(darwin 交叉编译需要 macOS SDK,非 macOS 主机拦截并报错)
Co-Authored-By: Claude <noreply@anthropic.com>
- build_libs.sh 的 build_target 清理区分 Darwin(免 sudo,避免交互式密码挂死) - getExecutablePath macOS 分支补 realpath(),符号链接行为与 Linux 一致 - darwin 构建显式 -mmacosx-version-min=10.15(std::filesystem/clock_gettime 依赖) Co-Authored-By: Claude <noreply@anthropic.com>
GitHub Actions 官方 macOS 托管 runner(macos-15-intel x86_64 + macos-15 arm64) 上构建 darwin 目标并冒烟运行 --no_json --list,产物上传 artifact
CI 从仓库根调用 bash source/pdfss_cpp/linux_release.sh darwin lib 时, pushd libs/pushd src 等相对路径基于调用者目录解析失败;现基于脚本所在 目录 cd,对既有"在脚本目录运行"流程行为不变
独立行赋值只作用于 shell 变量,make 收不到链接参数,导致 macOS 链接 缺 force_load 静态库与 -lpthread 而报 symbol(s) not found
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述
为 dfss 子项目(
source/pdfss_cpp)增加 macOS 兼容,覆盖 Intel Mac (x86_64) 与 Apple Silicon (arm64) 两种架构。由于 Linux 上交叉编译 darwin 需要 macOS SDK(受许可限制无法在构建镜像内预置),采取 Mac 本机原生编译 方案:脚本新增
darwin构建目标,在 Mac 上按当前芯片产出对应架构二进制,与现有linux_*/win_*体系并列。改动清单
src/main.cpp<filesystem>头包含条件(!defined(__clang__)导致 macOS clang 下漏 include、无法编译);②getExecutablePath()新增__APPLE__分支(_NSGetExecutablePath,Linux 的/proc/self/exe在 macOS 不存在)src/Makefile-x(GNU--strip-debug --strip-unneeded不被 macOS strip 支持)linux_release.shdarwin分支:-Wl,-force_load静态链接 zlib/mbedtls/libssh2,产物dfss-cpp-darwin-$(uname -m);非 macOS 主机直接报错拦截;readlink -f兼容libs/build_libs.shdarwin分支:zlib/mbedtls/cmake + libssh2/configure 构建静态库(与 host 分支一致的参数);sysctl取核数(macOS 无 nproc);免 sudo(避免交互式密码卡住);readlink -f兼容dfss_pip/dfss/__main__.pyget_architecture()识别darwin-x86_64/darwin-arm64并选择对应二进制release.sh/readme.mddarwin;文档补充 macOS 构建说明、支持架构、编译器版本构建方式(在 Mac 上)
./linux_release.sh darwin lib # 按当前 Mac 芯片生成 dfss-cpp-darwin-<x86_64|arm64>验证情况
--list正常)main.cpp在 clang 下 fs-only 编译通过;以-D__APPLE__+ stubmach-o/dyld.h模拟 macOS 分支编译通过get_architecture()9 个用例单测通过(含 darwin 两种架构与既有平台回归)bash -n语法检查通过build_libs.sh的 build_target 清理区分 Darwin(原无条件sudo rm会让 macOS 构建触发交互式 sudo);并采纳 realpath 解析可执行路径、-mmacosx-version-min=10.15、免交互 sudo 三项建议./linux_release.sh darwin lib做最终确认已知限制
pthread_cancel不生效(SDK 有声明可编译,但 libpthread 不真正终止线程),多服务器测速时会等待各线程自然超时而非立即取消,兜底选快逻辑仍正确,仅耗时略增