fix(nano): expose Darwin SDK types on Apple targets

master
韩天峰 2 weeks ago
parent e0dcbc3166
commit 136b08fe72
  1. 24
      phpunit/src/Build/NativeBuildConfigurationTest.php
  2. 6
      src/Build/NativeCommandOptionsTrait.php
  3. 1
      src/Build/NativeSourceProjectBuilder.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 public function testAndroidResolvesSelfContainedSdkAndSystemLibraries(): void
{ {
$phpxDir = $this->temporaryDirectory('phpx-android-host'); $phpxDir = $this->temporaryDirectory('phpx-android-host');
@ -263,6 +282,11 @@ final class NativeBuildConfigurationTest extends TestCase
{ {
return $this->getCommonCompileCommandOptions()->toArray(); return $this->getCommonCompileCommandOptions()->toArray();
} }
public function enableNanoForTest(): void
{
$this->nanoMode = true;
}
}; };
return $compiler->withPlatform($platform); return $compiler->withPlatform($platform);

@ -41,6 +41,12 @@ trait NativeCommandOptionsTrait
'PHPX_NANO=1', 'PHPX_NANO=1',
'_POSIX_C_SOURCE=200809L', '_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); array_push($userDefines, ...$this->nanoRuntimeDefines);
if ($this->isWasiTarget()) { if ($this->isWasiTarget()) {
$userDefines[] = 'ZEND_MM_ERROR=0'; $userDefines[] = 'ZEND_MM_ERROR=0';

@ -111,6 +111,7 @@ final class NativeSourceProjectBuilder
'-DPHP_NANO=1', '-DPHP_NANO=1',
'-DPHPX_NANO=1', '-DPHPX_NANO=1',
'-D_POSIX_C_SOURCE=200809L', '-D_POSIX_C_SOURCE=200809L',
...(PHP_OS_FAMILY === 'Darwin' ? ['-D_DARWIN_C_SOURCE=1'] : []),
...array_map( ...array_map(
static fn(string $define): string => '-D' . $define, static fn(string $define): string => '-D' . $define,
$composition['defines'], $composition['defines'],

Loading…
Cancel
Save