Skip to content

Commit 433043c

Browse files
committed
fix macOS
1 parent b38c7b2 commit 433043c

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

src/StaticPHP/Doctor/Item/LlvmToolsCheck.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,23 @@
77
use Package\Artifact\llvm_tools;
88
use StaticPHP\Attribute\Doctor\CheckItem;
99
use StaticPHP\Attribute\Doctor\FixItem;
10+
use StaticPHP\Attribute\Doctor\OptionalCheck;
11+
use StaticPHP\DI\ApplicationContext;
1012
use StaticPHP\Doctor\CheckResult;
1113
use StaticPHP\Package\PackageInstaller;
14+
use StaticPHP\Toolchain\Interface\ToolchainInterface;
15+
use StaticPHP\Toolchain\ZigToolchain;
1216

17+
#[OptionalCheck([self::class, 'optionalCheck'])]
1318
class LlvmToolsCheck
1419
{
20+
public static function optionalCheck(): bool
21+
{
22+
return ApplicationContext::get(ToolchainInterface::class) instanceof ZigToolchain;
23+
}
24+
1525
/** @noinspection PhpUnused */
16-
#[CheckItem('if llvm-tools (objcopy/strip/profdata) are built', limit_os: 'Linux', level: 798)]
26+
#[CheckItem('if llvm-tools (objcopy/strip/profdata) are built', level: 798)]
1727
public function checkLlvmTools(): CheckResult
1828
{
1929
$binDir = PKG_ROOT_PATH . '/llvm-tools/bin';

src/StaticPHP/Package/PackageBuilder.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
use StaticPHP\Exception\WrongUsageException;
1212
use StaticPHP\Runtime\Shell\Shell;
1313
use StaticPHP\Runtime\SystemTarget;
14+
use StaticPHP\Toolchain\Interface\ToolchainInterface;
15+
use StaticPHP\Toolchain\ZigToolchain;
1416
use StaticPHP\Util\FileSystem;
1517
use StaticPHP\Util\GlobalPathTrait;
1618
use StaticPHP\Util\InteractiveTerm;
@@ -178,7 +180,7 @@ public function extractDebugInfo(string $binary_path): string
178180
if (SystemTarget::getTargetOS() === 'Darwin') {
179181
shell()->exec("dsymutil -f {$binary_path} -o {$debug_file}");
180182
} elseif (SystemTarget::getTargetOS() === 'Linux') {
181-
$objcopy = getenv('OBJCOPY');
183+
$objcopy = getenv('OBJCOPY') ?: 'objcopy';
182184
if ($eu_strip = LinuxUtil::findCommand('eu-strip')) {
183185
shell()
184186
->exec("{$eu_strip} -f {$debug_file} {$binary_path}")
@@ -200,7 +202,9 @@ public function extractDebugInfo(string $binary_path): string
200202
*/
201203
public function stripBinary(string $binary_path): void
202204
{
203-
$strip = PKG_ROOT_PATH . '/llvm-tools/bin/llvm-strip';
205+
$strip = ApplicationContext::tryGet(ToolchainInterface::class) instanceof ZigToolchain
206+
? PKG_ROOT_PATH . '/llvm-tools/bin/llvm-strip'
207+
: 'strip';
204208
shell()->exec(match (SystemTarget::getTargetOS()) {
205209
'Darwin' => "{$strip} -S {$binary_path}",
206210
'Linux' => "{$strip} --strip-unneeded {$binary_path}",

src/StaticPHP/Toolchain/ClangNativeToolchain.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ public function afterInit(): void
3838
default => throw new EnvironmentException(__CLASS__ . ' is not supported on ' . PHP_OS_FAMILY . '.'),
3939
};
4040
}
41-
GlobalEnvManager::putenv('OBJCOPY=' . PKG_ROOT_PATH . '/llvm-tools/bin/llvm-objcopy');
4241
}
4342

4443
public function getCompilerInfo(): ?string

0 commit comments

Comments
 (0)