diff --git a/phpunit/src/Build/NativeBuildConfigurationTest.php b/phpunit/src/Build/NativeBuildConfigurationTest.php index adf730a7..e2f0d5ca 100644 --- a/phpunit/src/Build/NativeBuildConfigurationTest.php +++ b/phpunit/src/Build/NativeBuildConfigurationTest.php @@ -115,6 +115,25 @@ final class NativeBuildConfigurationTest extends TestCase } } + public function testAppleNanoKeepsDarwinSdkTypesVisibleUnderPosixProfile(): void + { + foreach ([new Macos(), new Ios()] as $platform) { + $compiler = $this->newCompiler($platform); + $compiler->enableNanoForTest(); + $defines = $compiler->getCommonCompileOptionsForTest()['user_defines']; + + self::assertContains('_POSIX_C_SOURCE=200809L', $defines); + self::assertContains('_DARWIN_C_SOURCE=1', $defines); + } + + $compiler = $this->newCompiler(new Linux()); + $compiler->enableNanoForTest(); + self::assertNotContains( + '_DARWIN_C_SOURCE=1', + $compiler->getCommonCompileOptionsForTest()['user_defines'], + ); + } + public function testAndroidResolvesSelfContainedSdkAndSystemLibraries(): void { $phpxDir = $this->temporaryDirectory('phpx-android-host'); @@ -263,6 +282,11 @@ final class NativeBuildConfigurationTest extends TestCase { return $this->getCommonCompileCommandOptions()->toArray(); } + + public function enableNanoForTest(): void + { + $this->nanoMode = true; + } }; return $compiler->withPlatform($platform); diff --git a/src/Build/NativeCommandOptionsTrait.php b/src/Build/NativeCommandOptionsTrait.php index 05ffa9a6..15373b80 100644 --- a/src/Build/NativeCommandOptionsTrait.php +++ b/src/Build/NativeCommandOptionsTrait.php @@ -41,6 +41,12 @@ trait NativeCommandOptionsTrait 'PHPX_NANO=1', '_POSIX_C_SOURCE=200809L', ); + if ($this->isMacos() || $this->isIosTarget()) { + // A strict POSIX feature profile hides Darwin's BSD integer + // aliases (u_int/u_char/u_short), which are still used by + // public macOS and iOS SDK headers such as sys/sysctl.h. + $userDefines[] = '_DARWIN_C_SOURCE=1'; + } array_push($userDefines, ...$this->nanoRuntimeDefines); if ($this->isWasiTarget()) { $userDefines[] = 'ZEND_MM_ERROR=0'; diff --git a/src/Build/NativeSourceProjectBuilder.php b/src/Build/NativeSourceProjectBuilder.php index ff97bd55..b65a00c8 100644 --- a/src/Build/NativeSourceProjectBuilder.php +++ b/src/Build/NativeSourceProjectBuilder.php @@ -111,6 +111,7 @@ final class NativeSourceProjectBuilder '-DPHP_NANO=1', '-DPHPX_NANO=1', '-D_POSIX_C_SOURCE=200809L', + ...(PHP_OS_FAMILY === 'Darwin' ? ['-D_DARWIN_C_SOURCE=1'] : []), ...array_map( static fn(string $define): string => '-D' . $define, $composition['defines'],