Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### 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).
- The source-build installer copies the FFI library under the platform-specific name used
by the FFI resolver, so successful fallback builds can be found (#71).
- `BinaryDownloader::download()` no longer calls `curl_close()`, which is a no-op since PHP 8.0
Expand Down
4 changes: 2 additions & 2 deletions src/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ public function build(): string
throw BuildException::cmakeFailed($cmakeExitCode);
}

// Run make (single invocation; exit code only)
// macOS has no GNU nproc binary. 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)
);

Expand Down
32 changes: 32 additions & 0 deletions tests/make-jobs-darwin.test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/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"

# 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
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"
Loading