Skip to content

Commit

Permalink
only run necessary musl install steps
Browse files Browse the repository at this point in the history
  • Loading branch information
DubbleClick committed Oct 2, 2023
1 parent 5f08375 commit 6b99ba0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/SPC/builder/linux/LinuxBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public function buildFpm(string $extra_libs, string $use_lld): void
public function buildEmbed(string $extra_libs, 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' => $extra_libs,
'EXTRA_LDFLAGS_PROGRAM' => "{$use_lld} -all-static",
]);
Expand Down
20 changes: 13 additions & 7 deletions src/SPC/doctor/item/LinuxMuslCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@ public function fixMusl(): bool
'url' => 'https://github.com/richfelker/musl-cross-make',
'rev' => 'master',
];
$arch = arch2gnu(php_uname('m')) === 'x86_64' ? 'x86_64-linux-musl' : 'aarch64-linux-musl';
$cross_compile_lib = "/usr/local/musl/{$arch}/lib/libc.a";
$musl_wrapper_lib = sprintf('/lib/ld-musl-%s.so.1', php_uname('m'));
Downloader::downloadSource('musl-cross-make', $musl_cross_compile_source);
Downloader::downloadSource('musl-1.2.4', $musl_source);
FileSystem::extractSource('musl-1.2.4', DOWNLOAD_PATH . '/musl-1.2.4.tar.gz');
$arch = arch2gnu(php_uname('m')) === 'x86_64' ? 'x86_64-linux-musl' : 'aarch64-linux-musl';
$install_musl_wrapper_cmd = 'cd ' . DOWNLOAD_PATH . '/musl-cross-make && \
make install TARGET=' . $arch . ' OUTPUT=/usr/local/musl -j';
make install TARGET=' . $arch . ' OUTPUT=/usr/local/musl CFLAGS="-fPIE" -j';
$musl_install = 'cd ' . SOURCE_PATH . '/musl-1.2.4 && \
./configure --enable-wrapper=gcc && \
make -j && make install';
Expand All @@ -68,17 +70,21 @@ public function fixMusl(): bool
};
$fix_path = 'if [[ ! "$PATH" =~ (^|:)"/usr/local/musl/bin"(:|$) ]]; then echo "export PATH=/usr/local/musl/bin:$PATH" >> ~/.bash_profile
fi && \
source ~/.bash_profile';
export PATH=/usr/local/musl/bin:$PATH';
$prefix = '';
if (get_current_user() !== 'root') {
$prefix = 'sudo ';
logger()->warning('Current user is not root, using sudo for running command');
}
try {
shell(true)
->exec($prefix . $musl_install_cmd)
->exec($install_musl_wrapper_cmd)
->exec($prefix . $fix_path);
if (!file_exists($musl_wrapper_lib)) {
shell(true)->exec($prefix . $musl_install_cmd);
}
if (!file_exists($cross_compile_lib)) {
shell(true)->exec($prefix . $install_musl_wrapper_cmd);
}

shell(true)->exec($prefix . $fix_path);
return true;
} catch (RuntimeException) {
return false;
Expand Down

0 comments on commit 6b99ba0

Please sign in to comment.