From a4b1571bf1b037f18d434524e6ebae1ca3d292bf Mon Sep 17 00:00:00 2001 From: "peng.li24" <734991033@qq.com> Date: Sat, 12 Sep 2026 18:50:40 +0800 Subject: [PATCH 1/5] =?UTF-8?q?ci:=20=E5=A2=9E=E5=8A=A0=20macOS=20?= =?UTF-8?q?=E6=9E=84=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit macos-latest 上源码构建依赖 blockmalloc v0.1.4 + slotsboxmalloc v0.1.5 (macOS 无预编译 ABI),再构建本仓并跑 ctest(KVSPACE_BUILD_TESTS=ON)。 Co-Authored-By: Claude Code --- .github/workflows/ci-macos.yml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/workflows/ci-macos.yml diff --git a/.github/workflows/ci-macos.yml b/.github/workflows/ci-macos.yml new file mode 100644 index 0000000..2916cc2 --- /dev/null +++ b/.github/workflows/ci-macos.yml @@ -0,0 +1,28 @@ +name: ci-macos +on: [push, pull_request] +jobs: + build: + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + - name: 构建依赖 blockmalloc(macOS 无预编译 ABI,从源码装) + run: | + git clone --depth 1 --branch v0.1.4 https://github.com/array2d/blockmalloc.git /tmp/blockmalloc + cmake -S /tmp/blockmalloc -B /tmp/blockmalloc/build \ + -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local + cmake --build /tmp/blockmalloc/build -j + sudo cmake --install /tmp/blockmalloc/build + - name: 构建依赖 slotsboxmalloc(同上,从源码装) + run: | + git clone --depth 1 --branch v0.1.5 https://github.com/array2d/slotsboxmalloc.git /tmp/slotsboxmalloc + cmake -S /tmp/slotsboxmalloc -B /tmp/slotsboxmalloc/build \ + -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local + cmake --build /tmp/slotsboxmalloc/build -j + sudo cmake --install /tmp/slotsboxmalloc/build + - name: 构建 + run: | + cmake -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local \ + -DKVSPACE_BUILD_TESTS=ON + cmake --build build -j + - name: 测试 + run: cd build && ctest --output-on-failure From 39787573833ca9fe61d4c5cc5ee11b51f5c1c23a Mon Sep 17 00:00:00 2001 From: "peng.li24" <734991033@qq.com> Date: Sat, 12 Sep 2026 18:58:30 +0800 Subject: [PATCH 2/5] =?UTF-8?q?ci:=20macOS=20=E4=BE=9D=E8=B5=96=20slotsbox?= =?UTF-8?q?malloc=20=E8=B7=9F=20main?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit v0.1.5 tag 不含 macOS 的 _POSIX_C_SOURCE 修复,改为 clone main; 待 slotsboxmalloc 发含修复的新 tag 后再改回固定版本。 Co-Authored-By: Claude Code --- .github/workflows/ci-macos.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci-macos.yml b/.github/workflows/ci-macos.yml index 2916cc2..2b94afc 100644 --- a/.github/workflows/ci-macos.yml +++ b/.github/workflows/ci-macos.yml @@ -14,7 +14,8 @@ jobs: sudo cmake --install /tmp/blockmalloc/build - name: 构建依赖 slotsboxmalloc(同上,从源码装) run: | - git clone --depth 1 --branch v0.1.5 https://github.com/array2d/slotsboxmalloc.git /tmp/slotsboxmalloc + # 跟 main:v0.1.5 尚不含 macOS 的 _POSIX_C_SOURCE 修复(待其发新 tag 后改回固定版本) + git clone --depth 1 https://github.com/array2d/slotsboxmalloc.git /tmp/slotsboxmalloc cmake -S /tmp/slotsboxmalloc -B /tmp/slotsboxmalloc/build \ -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local cmake --build /tmp/slotsboxmalloc/build -j From 1c10d6a0aa36419037512e1b6375054a024620db Mon Sep 17 00:00:00 2001 From: "peng.li24" <734991033@qq.com> Date: Sat, 12 Sep 2026 19:03:29 +0800 Subject: [PATCH 3/5] =?UTF-8?q?macos:=20fallocate=20=E6=9D=A1=E4=BB=B6?= =?UTF-8?q?=E7=BC=96=E8=AF=91=20+=20feature=20macro=20=E6=8F=90=E5=8D=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - kvspace.c: fallocate + FALLOC_FL_PUNCH_HOLE 是 Linux 专有,用 #if defined(__linux__) 包住;macOS 跳过(仅磁盘空间回收优化) - durable_abi.c: _POSIX_C_SOURCE 199309L→200809L(macOS 才暴露 C99 的 snprintf),并加 _DARWIN_C_SOURCE 暴露 usleep 等 Darwin API Linux 行为不变(本地 cmake 构建 + 3 个 test 目标通过)。 Co-Authored-By: Claude Code --- src/durable_abi.c | 7 ++++++- src/kvspace.c | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/durable_abi.c b/src/durable_abi.c index ed25863..84f2611 100644 --- a/src/durable_abi.c +++ b/src/durable_abi.c @@ -2,7 +2,12 @@ * 让 kvlang 的 Rust layout 零改动对接 kvspace-c 的 SHM。内部复用 kvspaceShm* 与 * kvspaceXvalue*。 */ -#define _POSIX_C_SOURCE 199309L +/* macOS 需 _DARWIN_C_SOURCE 才暴露 usleep 等完整 Darwin API;_POSIX_C_SOURCE ≥200112 + * 才在 macOS 暴露 C99 的 snprintf(Linux 走 glibc 的 _DEFAULT_SOURCE)。 */ +#if defined(__APPLE__) +#define _DARWIN_C_SOURCE +#endif +#define _POSIX_C_SOURCE 200809L #define _DEFAULT_SOURCE #include "kvspace_shm.h" diff --git a/src/kvspace.c b/src/kvspace.c index 151ae71..942e107 100644 --- a/src/kvspace.c +++ b/src/kvspace.c @@ -306,6 +306,8 @@ static uint64_t kv_sbo_alloc(kvspace_t *kv, size_t n) { /* Punch before free: once freed, another process may reuse the range. */ static void kv_sbo_free(kvspace_t *kv, uint64_t off) { +#if defined(__linux__) + /* Linux 用 fallocate PUNCH_HOLE 归还磁盘块;macOS 无该 API(仅空间回收优化),跳过。 */ uint64_t sz = sbo_allocated_size(kv->sbo_meta, off); if (sz >= SBO_PUNCH_MIN) { uint64_t pg = (uint64_t)sysconf(_SC_PAGESIZE); @@ -315,6 +317,7 @@ static void kv_sbo_free(kvspace_t *kv, uint64_t off) { FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, (off_t)a, (off_t)(b - a)); } +#endif sbo_free(kv->sbo_meta, off); } From b4c550c6dfa5ac425b0ce25c55a3255c5c1dc02f Mon Sep 17 00:00:00 2001 From: "peng.li24" <734991033@qq.com> Date: Sat, 12 Sep 2026 19:04:49 +0800 Subject: [PATCH 4/5] =?UTF-8?q?macos:=20test=5Fshm=5Fresize=20=E7=9A=84=20?= =?UTF-8?q?punch=20=E6=8E=A2=E6=B5=8B=E6=9D=A1=E4=BB=B6=E7=BC=96=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fallocate PUNCH_HOLE 为 Linux 专有;macOS 直接返回"不支持"。 Co-Authored-By: Claude Code --- tests/test_shm_resize.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/test_shm_resize.c b/tests/test_shm_resize.c index 57f14b9..b566ec2 100644 --- a/tests/test_shm_resize.c +++ b/tests/test_shm_resize.c @@ -250,6 +250,10 @@ static void t_cross_process(const char *dir) { } static int punch_supported(const char *dir) { +#if !defined(__linux__) + (void)dir; + return 0; /* macOS 无 fallocate PUNCH_HOLE */ +#else char p[600]; snprintf(p, sizeof p, "%s/punch-probe", dir); int fd = open(p, O_RDWR | O_CREAT | O_TRUNC, 0644); @@ -261,6 +265,7 @@ static int punch_supported(const char *dir) { close(fd); unlink(p); return ok; +#endif } static void t_punch(const char *dir) { From 180785bab3e3019623932a3c09b8c125c2bd377c Mon Sep 17 00:00:00 2001 From: "peng.li24" <734991033@qq.com> Date: Sat, 12 Sep 2026 19:06:07 +0800 Subject: [PATCH 5/5] =?UTF-8?q?ci(macos):=20=E6=B5=8B=E8=AF=95=E8=A1=A5=20?= =?UTF-8?q?DYLD=5FFALLBACK=5FLIBRARY=5FPATH?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit macOS 无 ldconfig,dyld 不自动搜 /usr/local/lib,测试可执行找不到 libblockmalloc.1.dylib。运行时补 fallback 路径。 Co-Authored-By: Claude Code --- .github/workflows/ci-macos.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci-macos.yml b/.github/workflows/ci-macos.yml index 2b94afc..a551409 100644 --- a/.github/workflows/ci-macos.yml +++ b/.github/workflows/ci-macos.yml @@ -26,4 +26,7 @@ jobs: -DKVSPACE_BUILD_TESTS=ON cmake --build build -j - name: 测试 + env: + # macOS 无 ldconfig,dyld 不会自动搜 /usr/local/lib + DYLD_FALLBACK_LIBRARY_PATH: /usr/local/lib run: cd build && ctest --output-on-failure