Skip to content

Commit

Permalink
use ar and ld from musl-tools (uses gold-ld and can handle wrong lib …
Browse files Browse the repository at this point in the history
…order)
  • Loading branch information
DubbleClick committed Oct 17, 2023
1 parent 11152e2 commit 629c1ef
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/SPC/builder/linux/LinuxBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,16 @@ public function __construct(array $options = [])
if (SystemUtil::isMuslDist()) {
$this->setOptionIfNotExist('cc', 'gcc');
$this->setOptionIfNotExist('cxx', 'g++');
$this->setOptionIfNotExist('ar', 'ar');
$this->setOptionIfNotExist('ld', 'ld');
$this->setOptionIfNotExist('library_path', '');
$this->setOptionIfNotExist('ld_library_path', '');
} else {
$arch = arch2gnu(php_uname('m'));
$this->setOptionIfNotExist('cc', "{$arch}-linux-musl-gcc");
$this->setOptionIfNotExist('cxx', "{$arch}-linux-musl-g++");
$this->setOptionIfNotExist('ar', "{$arch}-linux-musl-ar");
$this->setOptionIfNotExist('ld', "{$arch}-linux-musl-ld");
$this->setOptionIfNotExist('library_path', "LIBRARY_PATH=/usr/local/musl/{$arch}-linux-musl/lib");
$this->setOptionIfNotExist('ld_library_path', "LD_LIBRARY_PATH=/usr/local/musl/{$arch}-linux-musl/lib");
}
Expand Down Expand Up @@ -79,6 +83,8 @@ public function __construct(array $options = [])
...$vars,
'CC' => $this->getOption('cc'),
'CXX' => $this->getOption('cxx'),
'AR' => $this->getOption('ar'),
'LD' => $this->getOption('ld'),
'PATH' => BUILD_ROOT_PATH . '/bin:' . getenv('PATH'),
]);
// cross-compiling is not supported yet
Expand Down Expand Up @@ -147,6 +153,8 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
$envs = $this->pkgconf_env . ' ' . SystemUtil::makeEnvVarString([
'CC' => $this->getOption('cc'),
'CXX' => $this->getOption('cxx'),
'AR' => $this->getOption('ar'),
'LD' => $this->getOption('ld'),
'CFLAGS' => $cflags,
'LIBS' => '-ldl -lpthread',
'PATH' => BUILD_ROOT_PATH . '/bin:' . getenv('PATH'),
Expand Down Expand Up @@ -174,7 +182,6 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
$enableFpm = ($build_target & BUILD_TARGET_FPM) === BUILD_TARGET_FPM;
$enableMicro = ($build_target & BUILD_TARGET_MICRO) === BUILD_TARGET_MICRO;
$enableEmbed = ($build_target & BUILD_TARGET_EMBED) === BUILD_TARGET_EMBED;
$arch = arch2gnu(php_uname('m'));

shell()->cd(SOURCE_PATH . '/php-src')
->exec(
Expand Down Expand Up @@ -237,7 +244,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
public function buildCli(string $use_lld): void
{
$vars = SystemUtil::makeEnvVarString([
'EXTRA_CFLAGS' => '-g -Os -fno-ident ' . implode(' ', array_map(fn ($x) => "-Xcompiler {$x}", $this->tune_c_flags)),
'EXTRA_CFLAGS' => '-g -Os -fno-ident -fPIE ' . implode(' ', array_map(fn ($x) => "-Xcompiler {$x}", $this->tune_c_flags)),
'EXTRA_LIBS' => $this->getOption('extra-libs', ''),
'EXTRA_LDFLAGS_PROGRAM' => "{$use_lld} -all-static",
]);
Expand Down Expand Up @@ -270,7 +277,7 @@ public function buildMicro(string $use_lld, string $cflags): void

$enable_fake_cli = $this->getOption('with-micro-fake-cli', false) ? ' -DPHP_MICRO_FAKE_CLI' : '';
$vars = SystemUtil::makeEnvVarString([
'EXTRA_CFLAGS' => '-g -Os -fno-ident ' . implode(' ', array_map(fn ($x) => "-Xcompiler {$x}", $this->tune_c_flags)) . $enable_fake_cli,
'EXTRA_CFLAGS' => '-g -Os -fno-ident -fPIE ' . implode(' ', array_map(fn ($x) => "-Xcompiler {$x}", $this->tune_c_flags)) . $enable_fake_cli,
'EXTRA_LIBS' => $this->getOption('extra-libs', ''),
'EXTRA_LDFLAGS_PROGRAM' => "{$cflags} {$use_lld} -all-static",
]);
Expand Down Expand Up @@ -298,7 +305,7 @@ public function buildMicro(string $use_lld, string $cflags): void
public function buildFpm(string $use_lld): void
{
$vars = SystemUtil::makeEnvVarString([
'EXTRA_CFLAGS' => '-g -Os -fno-ident ' . implode(' ', array_map(fn ($x) => "-Xcompiler {$x}", $this->tune_c_flags)),
'EXTRA_CFLAGS' => '-g -Os -fno-ident -fPIE ' . implode(' ', array_map(fn ($x) => "-Xcompiler {$x}", $this->tune_c_flags)),
'EXTRA_LIBS' => $this->getOption('extra-libs', ''),
'EXTRA_LDFLAGS_PROGRAM' => "{$use_lld} -all-static",
]);
Expand All @@ -317,7 +324,7 @@ public function buildFpm(string $use_lld): void
public function buildEmbed(string $use_lld): void
{
$vars = SystemUtil::makeEnvVarString([
'EXTRA_CFLAGS' => '-g -Os -fno-ident ' . implode(' ', array_map(fn ($x) => "-Xcompiler {$x}", $this->tune_c_flags)),
'EXTRA_CFLAGS' => '-g -Os -fno-ident -fPIE ' . implode(' ', array_map(fn ($x) => "-Xcompiler {$x}", $this->tune_c_flags)),
'EXTRA_LIBS' => $this->getOption('extra-libs', ''),
'EXTRA_LDFLAGS_PROGRAM' => "{$use_lld} -all-static",
]);
Expand Down

0 comments on commit 629c1ef

Please sign in to comment.