From 1a7e7b4b0d829ec3cc4741577724226257623935 Mon Sep 17 00:00:00 2001 From: stantheman0128 Date: Wed, 23 Sep 2026 02:42:09 +0800 Subject: [PATCH 1/4] fix: choose make job count without nproc macOS does not ship nproc, so the clib build command failed before make started. sysctl and getconf are already on this system. Co-authored-by: Cursor --- src/Builder.php | 4 ++-- tests/make-jobs-darwin.test.sh | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 tests/make-jobs-darwin.test.sh diff --git a/src/Builder.php b/src/Builder.php index 7fa2e7b..4e8aa0c 100644 --- a/src/Builder.php +++ b/src/Builder.php @@ -61,9 +61,9 @@ public function build(): string throw BuildException::cmakeFailed($cmakeExitCode); } - // Run make (single invocation; exit code only) + // macOS has no nproc. sysctl is the Darwin count; getconf covers the rest. $makeCmd = sprintf( - 'cd %s && make -j$(nproc)', + 'cd %s && make -j"$(sysctl -n hw.ncpu 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1)"', escapeshellarg($buildPath) ); diff --git a/tests/make-jobs-darwin.test.sh b/tests/make-jobs-darwin.test.sh new file mode 100644 index 0000000..a91eaf8 --- /dev/null +++ b/tests/make-jobs-darwin.test.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# Builder.php must not ask make for $(nproc). macOS does not ship nproc. +set -euo pipefail +root=$(cd "$(dirname "$0")/.." && pwd) +builder="$root/src/Builder.php" + +if grep -q 'nproc' "$builder"; then + echo "Builder.php still calls nproc" >&2 + exit 1 +fi + +work=$(mktemp -d) +set +e +nproc >"$work/red.out" 2>"$work/red.err" +red=$? +set -e +if [ "$red" -eq 0 ]; then + echo "nproc unexpectedly succeeded" >&2 + exit 1 +fi +if ! grep -q "command not found" "$work/red.err"; then + echo "expected nproc command not found" >&2 + cat "$work/red.err" >&2 + exit 1 +fi + +jobs=$(sysctl -n hw.ncpu 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1) +printf '%s\n' "$jobs" | grep -Eq '^[1-9][0-9]*$' +echo "make jobs darwin ok (nproc exit $red, jobs $jobs)" +rm -rf "$work" From 43c5929aef8d41d797f54a0208702658c90e292a Mon Sep 17 00:00:00 2001 From: stantheman0128 Date: Wed, 23 Sep 2026 02:42:31 +0800 Subject: [PATCH 2/4] test: match the nproc command substitution, not the word in a comment The Darwin job-count check was failing on its own explanation. Co-authored-by: Cursor --- src/Builder.php | 2 +- tests/make-jobs-darwin.test.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Builder.php b/src/Builder.php index 4e8aa0c..814fabd 100644 --- a/src/Builder.php +++ b/src/Builder.php @@ -61,7 +61,7 @@ public function build(): string throw BuildException::cmakeFailed($cmakeExitCode); } - // macOS has no nproc. sysctl is the Darwin count; getconf covers the rest. + // macOS has no GNU nproc binary. sysctl is the Darwin count; getconf covers the rest. $makeCmd = sprintf( 'cd %s && make -j"$(sysctl -n hw.ncpu 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1)"', escapeshellarg($buildPath) diff --git a/tests/make-jobs-darwin.test.sh b/tests/make-jobs-darwin.test.sh index a91eaf8..4513b5d 100644 --- a/tests/make-jobs-darwin.test.sh +++ b/tests/make-jobs-darwin.test.sh @@ -4,7 +4,7 @@ set -euo pipefail root=$(cd "$(dirname "$0")/.." && pwd) builder="$root/src/Builder.php" -if grep -q 'nproc' "$builder"; then +if grep -q '$(nproc)' "$builder"; then echo "Builder.php still calls nproc" >&2 exit 1 fi From f60a4c472fa833aedade3664ad3ca9630ba6d681 Mon Sep 17 00:00:00 2001 From: stantheman0128 Date: Fri, 2 Oct 2026 15:58:12 +0800 Subject: [PATCH 3/4] docs: note the macOS make job count under Unreleased --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1619144..383ea13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 `bin/kb-lint.php` and `bin/README.md`. - The committed `vendor/` placeholder and the stray `php-ext/configure~` autoconf backup. +### Fixed + +- Building the C library on macOS no longer calls `nproc`. `make -j` uses + `sysctl -n hw.ncpu`, then `getconf _NPROCESSORS_ONLN`, then 1 (#95). + ## [0.5.2] - 2026-08-26 v0.5.1 has no binaries behind it: every extension build failed, so `Create From e79a315706d50fda25ab57c0323746e1eb0f4d8e Mon Sep 17 00:00:00 2001 From: stantheman0128 Date: Sat, 3 Oct 2026 22:08:23 +0800 Subject: [PATCH 4/4] test: keep the nproc search literal for shellcheck --- tests/make-jobs-darwin.test.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/make-jobs-darwin.test.sh b/tests/make-jobs-darwin.test.sh index 4513b5d..b3c2c7e 100644 --- a/tests/make-jobs-darwin.test.sh +++ b/tests/make-jobs-darwin.test.sh @@ -4,6 +4,8 @@ set -euo pipefail root=$(cd "$(dirname "$0")/.." && pwd) builder="$root/src/Builder.php" +# The single quotes are the point: this is a source search, not a command. +# shellcheck disable=SC2016 if grep -q '$(nproc)' "$builder"; then echo "Builder.php still calls nproc" >&2 exit 1