Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux c++ support using musl-cross-make toolchains #231

Merged
merged 42 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
830f379
add --disable-opcache-jit option for alpine
DubbleClick Oct 16, 2023
46b0ecf
allow patching of extra_libs before make on linux too
DubbleClick Oct 16, 2023
658e8e7
use arch-linux-musl toolchains
DubbleClick Oct 16, 2023
64dfb57
don't add -liconv on linux (cannot find library when specified that w…
DubbleClick Oct 16, 2023
a7265bf
add -static linker flag to libicu compilation
DubbleClick Oct 16, 2023
a4dc177
install libxml2 and snappy into /lib instead of /lib64
DubbleClick Oct 16, 2023
a83a457
fix pgsql build on non-alpine
DubbleClick Oct 16, 2023
da1cbeb
introduce library_path and ld_library_path options to linuxbuilder (s…
DubbleClick Oct 16, 2023
0007043
fix imagemagick and postgresql builds with different libs
DubbleClick Oct 17, 2023
6dfd353
fix order of imagick libs
DubbleClick Oct 17, 2023
75b9d66
use ar and ld from musl-tools (uses gold-ld and can handle wrong lib …
DubbleClick Oct 17, 2023
ca1189b
use ld.gold (revert this if you think this doesn't add benefit)
DubbleClick Oct 19, 2023
b6409bd
optimize install musl wrapper and cross make function
crazywhalecc Oct 22, 2023
d56c060
remove `--enable-wrapper=gcc` for fix-musl
crazywhalecc Oct 22, 2023
6cc7e6c
add comment for hard-coded musl version
crazywhalecc Oct 22, 2023
5cfba6e
Merge branch 'main' into cplus
crazywhalecc Oct 22, 2023
8191444
refactor musl tool doctor
crazywhalecc Oct 22, 2023
99150e2
add putenv wrapper
crazywhalecc Oct 22, 2023
5934e5e
fix doctor phpunit test
crazywhalecc Oct 22, 2023
c84eb72
[mixed] refactor with putenv, fix imagemagick and c++ build
crazywhalecc Oct 22, 2023
8a70da6
change instanceof check
crazywhalecc Oct 22, 2023
9b9644f
simplify download error message
crazywhalecc Oct 23, 2023
8dcec73
let bzip2 use correct CC and AR
crazywhalecc Oct 23, 2023
c24dc8f
create helper method to pass environment variables to 'make'
DubbleClick Oct 24, 2023
e00908d
Merge remote-tracking branch 'DubbleClick/cplus' into cplus
crazywhalecc Oct 26, 2023
e84a246
add back required -lgomp for imagick extension
DubbleClick Oct 27, 2023
d40f2ca
simplify libpng compilation
DubbleClick Oct 27, 2023
2e47e8a
specify --with-openssl-dir in php ./configure
DubbleClick Oct 27, 2023
b4f9235
Merge branch 'main' into cplus
DubbleClick Oct 29, 2023
90b2e55
update sqlite version
crazywhalecc Oct 29, 2023
2768dc0
adjust doctor for os and linux musl check
crazywhalecc Oct 29, 2023
6b848da
disable musl-gcc wrapper
DubbleClick Oct 29, 2023
ed8837f
let postgresql use -lc++ in bsd and macos
crazywhalecc Oct 30, 2023
98b906d
Merge remote-tracking branch 'origin/main' into cplus
crazywhalecc Oct 30, 2023
e637cce
use prompts to ask
crazywhalecc Oct 30, 2023
aee040d
use prompts to show table
crazywhalecc Oct 30, 2023
e158cc5
update composer lock
crazywhalecc Oct 30, 2023
d5405ce
update to the release version
crazywhalecc Oct 30, 2023
bfc56cf
refactor build var generation
DubbleClick Oct 30, 2023
12cc422
merge main
DubbleClick Oct 30, 2023
8747266
make it rc8
DubbleClick Oct 30, 2023
0b37080
a good coding font is very important
crazywhalecc Oct 31, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions config/ext.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@
},
"intl": {
"type": "builtin",
"cpp-extension": true,
"lib-depends": [
"icu"
]
Expand Down Expand Up @@ -233,7 +232,7 @@
},
"openssl": {
"type": "builtin",
"arg-type": "with",
"arg-type": "custom",
"lib-depends": [
"openssl"
],
Expand Down
15 changes: 9 additions & 6 deletions config/lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
},
"icu": {
"source": "icu",
"cpp-library": true,
"static-libs-unix": [
"libicui18n.a",
"libicuio.a",
Expand All @@ -122,20 +123,20 @@
"source": "imagemagick",
"static-libs-unix": [
"libMagick++-7.Q16HDRI.a",
"libMagickCore-7.Q16HDRI.a",
"libMagickWand-7.Q16HDRI.a"
"libMagickWand-7.Q16HDRI.a",
"libMagickCore-7.Q16HDRI.a"
],
"lib-depends": [
"zlib",
"libpng",
"libjpeg",
"bzip2",
"libwebp",
"freetype"
],
"lib-suggests": [
"zstd",
"xz",
"bzip2",
"libzip",
"libxml2"
]
Expand Down Expand Up @@ -434,7 +435,10 @@
"readline"
],
"lib-suggests": [
"icu"
"icu",
"libxslt",
"ldap",
"zstd"
]
},
"pthreads4w": {
Expand Down Expand Up @@ -464,10 +468,9 @@
"libsnappy.a"
],
"headers-unix": [
"snappy.h",
"snappy-c.h",
"snappy-sinksource.h",
"snappy.h",
"snappy-stubs-internal.h",
"snappy-stubs-public.h"
],
"lib-depends": [
Expand Down
2 changes: 1 addition & 1 deletion config/source.json
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@
},
"sqlite": {
"type": "url",
"url": "https://www.sqlite.org/2023/sqlite-autoconf-3410100.tar.gz",
"url": "https://www.sqlite.org/2023/sqlite-autoconf-3430200.tar.gz",
"license": {
"type": "text",
"text": "The author disclaims copyright to this source code. In place of\na legal notice, here is a blessing:\n\n * May you do good and not evil.\n * May you find forgiveness for yourself and forgive others.\n * May you share freely, never taking more than you give."
Expand Down
32 changes: 30 additions & 2 deletions src/SPC/builder/BuilderBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@ public function getLib(string $name): ?LibraryBase
return $this->libs[$name] ?? null;
}

/**
* Get all library objects.
*
* @return LibraryBase[]
*/
public function getLibs(): array
{
return $this->libs;
}

/**
* Add extension to build.
*/
Expand Down Expand Up @@ -139,12 +149,12 @@ public function getExts(): array
}

/**
* Check if there is a cpp extension.
* Check if there is a cpp extensions or libraries.
*
* @throws FileSystemException
* @throws WrongUsageException
*/
public function hasCppExtension(): bool
public function hasCpp(): bool
{
// judge cpp-extension
$exts = array_keys($this->getExts());
Expand All @@ -153,6 +163,12 @@ public function hasCppExtension(): bool
return true;
}
}
$libs = array_keys($this->getLibs());
foreach ($libs as $lib) {
if (Config::getLib($lib, 'cpp-library', false) === true) {
return true;
}
}
return false;
}

Expand Down Expand Up @@ -303,6 +319,18 @@ public function setOption(string $key, mixed $value): void
$this->options[$key] = $value;
}

public function getEnvString(array $vars = ['cc', 'cxx', 'ar', 'ld']): string
{
$env = [];
foreach ($vars as $var) {
$var = strtoupper($var);
if (getenv($var) !== false) {
$env[] = "{$var}=" . getenv($var);
}
}
return implode(' ', $env);
}

/**
* Check if all libs are downloaded.
* If not, throw exception.
Expand Down
4 changes: 4 additions & 0 deletions src/SPC/builder/extension/iconv.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace SPC\builder\extension;

use SPC\builder\Extension;
use SPC\builder\macos\MacOSBuilder;
use SPC\util\CustomExt;

#[CustomExt('iconv')]
Expand All @@ -13,6 +14,9 @@ class iconv extends Extension
public function patchBeforeConfigure(): bool
{
// macOS need to link iconv dynamically, we add it to extra-libs
if (!$this->builder instanceof MacOSBuilder) {
return false;
}
$extra_libs = $this->builder->getOption('extra-libs', '');
if (!str_contains($extra_libs, '-liconv')) {
$extra_libs .= ' -liconv';
Expand Down
8 changes: 3 additions & 5 deletions src/SPC/builder/extension/imagick.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@
#[CustomExt('imagick')]
class imagick extends Extension
{
public function patchBeforeBuildconf(): bool
public function patchBeforeMake(): bool
{
// linux need to link library manually, we add it to extra-libs
// imagick may call omp_pause_all which requires -lgomp
$extra_libs = $this->builder->getOption('extra-libs', '');
if (!str_contains($extra_libs, 'libMagickCore')) {
$extra_libs .= ' /usr/lib/libMagick++-7.Q16HDRI.a /usr/lib/libMagickCore-7.Q16HDRI.a /usr/lib/libMagickWand-7.Q16HDRI.a';
}
$extra_libs .= ' -lgomp ';
$this->builder->setOption('extra-libs', $extra_libs);
return true;
}
Expand Down
5 changes: 5 additions & 0 deletions src/SPC/builder/extension/openssl.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ public function patchBeforeMake(): bool

return false;
}

public function getUnixConfigureArg(): string
{
return '--with-openssl=' . BUILD_ROOT_PATH . ' --with-openssl-dir=' . BUILD_ROOT_PATH;
}
}
37 changes: 20 additions & 17 deletions src/SPC/builder/freebsd/BSDBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,16 @@ public function __construct(array $options = [])

// ---------- set necessary options ----------
// set C Compiler (default: clang)
$this->setOptionIfNotExist('cc', 'clang');
f_putenv('CC=' . $this->getOption('cc', 'clang'));
// set C++ Composer (default: clang++)
$this->setOptionIfNotExist('cxx', 'clang++');
f_putenv('CXX=' . $this->getOption('cxx', 'clang++'));
// set PATH
f_putenv('PATH=' . BUILD_ROOT_PATH . '/bin:' . getenv('PATH'));
// set PKG_CONFIG
f_putenv('PKG_CONFIG=' . BUILD_ROOT_PATH . '/bin/pkg-config');
// set PKG_CONFIG_PATH
f_putenv('PKG_CONFIG_PATH=' . BUILD_LIB_PATH . '/pkgconfig/');

// set arch (default: current)
$this->setOptionIfNotExist('arch', php_uname('m'));
$this->setOptionIfNotExist('gnu-arch', arch2gnu($this->getOption('arch')));
Expand All @@ -46,16 +53,6 @@ public function __construct(array $options = [])
$this->arch_cxx_flags = SystemUtil::getArchCFlags($this->getOption('arch'));
// cmake toolchain
$this->cmake_toolchain_file = SystemUtil::makeCmakeToolchainFile('BSD', $this->getOption('arch'), $this->arch_c_flags);
// configure environment
$this->configure_env = SystemUtil::makeEnvVarString([
'PKG_CONFIG' => BUILD_ROOT_PATH . '/bin/pkg-config',
'PKG_CONFIG_PATH' => BUILD_LIB_PATH . '/pkgconfig/',
'CC' => $this->getOption('cc'),
'CXX' => $this->getOption('cxx'),
'CFLAGS' => "{$this->arch_c_flags} -Wimplicit-function-declaration -Os",
'LIBS' => '-ldl -lpthread',
'PATH' => BUILD_ROOT_PATH . '/bin:' . getenv('PATH'),
]);

// create pkgconfig and include dir (some libs cannot create them automatically)
f_mkdir(BUILD_LIB_PATH . '/pkgconfig', recursive: true);
Expand All @@ -75,7 +72,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
// ---------- Update extra-libs ----------
$extra_libs = $this->getOption('extra-libs', '');
// add libc++, some extensions or libraries need it (C++ cannot be linked statically)
$extra_libs .= (empty($extra_libs) ? '' : ' ') . ($this->hasCppExtension() ? '-lc++ ' : '');
$extra_libs .= (empty($extra_libs) ? '' : ' ') . ($this->hasCpp() ? '-lc++ ' : '');
if (!$this->getOption('bloat', false)) {
$extra_libs .= (empty($extra_libs) ? '' : ' ') . implode(' ', $this->getAllStaticLibFiles());
} else {
Expand Down Expand Up @@ -115,8 +112,7 @@ public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
($enableMicro ? '--enable-micro ' : '--disable-micro ') .
$json_74 .
$zts .
$this->makeExtensionArgs() . ' ' .
$this->configure_env
$this->makeExtensionArgs()
);

SourcePatcher::patchBeforeMake($this);
Expand Down Expand Up @@ -173,12 +169,14 @@ public function buildCli(): void
/**
* Build phpmicro sapi
*
* @throws FileSystemException|RuntimeException
* @throws FileSystemException
* @throws RuntimeException
* @throws WrongUsageException
*/
public function buildMicro(): void
{
if ($this->getPHPVersionID() < 80000) {
throw new RuntimeException('phpmicro only support PHP >= 8.0!');
throw new WrongUsageException('phpmicro only support PHP >= 8.0!');
}
if ($this->getExt('phar')) {
$this->phar_patched = true;
Expand Down Expand Up @@ -228,6 +226,11 @@ public function buildFpm(): void
$this->deployBinary(BUILD_TARGET_FPM);
}

/**
* Build embed sapi
*
* @throws RuntimeException
*/
public function buildEmbed(): void
{
$vars = SystemUtil::makeEnvVarString([
Expand Down
2 changes: 1 addition & 1 deletion src/SPC/builder/freebsd/library/openssl.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected function build(): void

shell()->cd($this->source_dir)
->exec(
"{$this->builder->configure_env} ./Configure no-shared {$extra} " .
"./Configure no-shared {$extra} " .
'--prefix=/ ' . // use prefix=/
"--libdir={$lib} " .
'--openssldir=/etc/ssl ' .
Expand Down
Loading