static-php-cli/assets/en_develop_system-build-tools.md.DK4AaCy_.js

69 lines
28 KiB
JavaScript
Raw Normal View History

import{_ as i,c as a,o as e,af as n}from"./chunks/framework.PeLcR_tw.js";const d=JSON.parse('{"title":"Compilation Tools","description":"","frontmatter":{},"headers":[],"relativePath":"en/develop/system-build-tools.md","filePath":"en/develop/system-build-tools.md"}'),t={name:"en/develop/system-build-tools.md"};function l(o,s,p,h,c,r){return e(),a("div",null,s[0]||(s[0]=[n(`<h1 id="compilation-tools" tabindex="-1">Compilation Tools <a class="header-anchor" href="#compilation-tools" aria-label="Permalink to “Compilation Tools”"></a></h1><p>static-php-cli uses many system compilation tools when building static PHP. These tools mainly include:</p><ul><li><code>autoconf</code>: used to generate <code>configure</code> scripts.</li><li><code>make</code>: used to execute <code>Makefile</code>.</li><li><code>cmake</code>: used to execute <code>CMakeLists.txt</code>.</li><li><code>pkg-config</code>: Used to find the installation path of dependent libraries.</li><li><code>gcc</code>: used to compile C/C++ projects under Linux.</li><li><code>clang</code>: used to compile C/C++ projects under macOS.</li></ul><p>For Linux and macOS operating systems, these tools can usually be installed through the package manager, which is written in the doctor module. Theoretically we can also compile and download these tools manually, but this will increase the complexity of compilation, so we do not recommend this.</p><h2 id="linux-compilation-tools" tabindex="-1">Linux Compilation Tools <a class="header-anchor" href="#linux-compilation-tools" aria-label="Permalink to “Linux Compilation Tools”"></a></h2><p>For Linux systems, different distributions have different installation methods for compilation tools. And for static compilation, the package management of some distributions cannot install libraries and tools for pure static compilation. Therefore, for the Linux platform and its different distributions, we currently provide a variety of compilation environment preparations.</p><h3 id="glibc-environment" tabindex="-1">Glibc Environment <a class="header-anchor" href="#glibc-environment" aria-label="Permalink to “Glibc Environment”"></a></h3><p>The glibc environment refers to the underlying <code>libc</code> library of the system (that is, the C standard library that all programs written in C language are dynamically linked to) uses <code>glibc</code>, which is the default environment for most distributions. For example: Ubuntu, Debian, CentOS, RHEL, openSUSE, Arch Linux, etc.</p><p>In the glibc environment, the package management and compiler we use point to glibc by default, and glibc cannot be statically linked well. One of the reasons it cannot be statically linked is that its network library <code>nss</code> cannot be compiled statically.</p><p>For the glibc environment, in static-php-cli and spc in 2.0-RC8 and later, you can choose two ways to build static PHP:</p><ol><li>Use Docker to build, you can use <code>bin/spc-alpine-docker</code> to build, it will build an Alpine Linux docker image.</li><li>Use <code>bin/spc doctor --auto-fix</code> to install the <code>musl-wrapper</code> and <code>musl-cross-make</code> packages, and then build directly. (<a href="https://github.com/crazywhalecc/static-php-cli/blob/main/src/SPC/doctor/item/LinuxMuslCheck.php" target="_blank" rel="noreferrer">Related source code</a>)</li></ol><p>Generally speaking, the build results in these two environments are consistent, and you can choose according to actual needs.</p><p>In the doctor module, static-php-cli will first detect the current Linux distribution. If the current distribution is a glibc environment, you will be prompted to install the musl-wrapper and musl-cross-make packages.</p><p>The process of installing <code>musl-wrapper</code> in the glibc environment is as follows:</p><ol><li>Download the specific version of <a href="https://musl.libc.org/releases/" target="_blank" rel="noreferrer">musl-wrapper source code</a> from the musl official website.</li><li>Use <code>gcc</code> installed from the package management to compile the m
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">FLAG = -g0 -Os -Wno-error</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">ifneq</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> (</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">$(</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">NATIVE</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">)</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,)</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">COMMON_CONFIG += CC=&quot;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">$(</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">HOST</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">)</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">-gcc </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">\${</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">STAT</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">}</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&quot; CXX=&quot;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">$(</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">HOST</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">)</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">-g++ </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">\${</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">STAT</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">}</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&quot;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">else</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">COMMON_CONFIG += CC=&quot;gcc </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">\${</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">STAT</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">}</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&quot; CXX=&quot;g++ </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">\${</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">STAT</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">}</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&quot;</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">endif</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">COMMON_CONFIG += CFLAGS=&quot;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">\${</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">FLAG</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">}</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&quot; CXXFLAGS=&quot;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">\${</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">FLAG</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">}</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&quot; LDFLAGS=&quot;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">\${</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">STAT</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">}</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">BINUTILS_CONFIG += --enable-gold=yes --enable-gprofng=no</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">GCC_CONFIG += --enable-static-pie --disable-cet --enable-default-pie </span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">#--enable-default-pie</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">CONFIG_SUB_REV = 888c8e3d5f7b</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">GCC_VER = 13.2.0</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">BINUTILS_VER = 2.40</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">MUSL_VER = 1.2.4</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">GMP_VER = 6.2.1</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">MPC_VER = 1.2.1</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">MPFR_VER = 4.2.0</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">LINUX_VER = 6.1.36</span></span></code></pre></div><p>And also you need to add <code>gcc-13.2.0.tar.xz.sha1</code> file, contents here:</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e;" tabindex="0" dir="ltr"><code><span class="line"><span>5f95b6d042fb37d45c6cbebfc91decfbc4fb493c gcc-13.2.0.tar.xz</span></span></code></pre></div><p>If you are using Docker to build, create a new <code>Dockerfile</code> file and write the following content:</p><div class="language-dockerfile"><button title="Copy Code" class="copy"></button><span class="lang">dockerfile</span><pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e;" tabindex="0" dir="ltr"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">FROM</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> alpine:edge</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">RUN</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> apk add --no-cache \\</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">gcc g++ git make curl perl \\</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">rsync patch wget libtool \\</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">texinfo autoconf automake \\</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">bison tar xz bzip2 zlib \\</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">file binutils flex \\</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">linux-headers libintl \\</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">gettext gettext-dev icu-libs pkgconf \\</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">pkgconfig icu-dev bash \\</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">ccache libarchive-tools zip</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">WORKDIR</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> /opt</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">RUN</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> git clone https://git.zv.io/toolchains/musl-cross-make.git</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">WORKDIR</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> /opt/musl-cross-make</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">COPY</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> config.mak /opt/musl-cross-make</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">COPY</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> gcc-13.2.0.tar.xz.sha1 /opt/musl-cross-make/hashes</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">RUN</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> make TARGET=x86_64-linux-musl -j || :</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">RUN</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> sed -i </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&#39;s/poison calloc/poison/g&#39;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> ./gcc-13.2.0/gcc/system.h</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">RUN</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> make TARGET=x86_64-linux-musl -j</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">RUN</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> make TARGET=x86_64-linux-musl install -j</span></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">RUN</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> tar cvzf x86_64-musl-toolchain.tgz output/*</span></span></code></pre></div><p>If you are using Alpine Linux in a non-Docker environment, you can directly execute the commands in the Dockerfile, for example:</p><div class="language-bash"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e;" tabindex="0" dir="ltr"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">apk</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> add</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --no-cache</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \\</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">gcc </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">g++</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> git</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> make</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> curl</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> perl</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \\</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">rsync </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">patch</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> wget</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> libtool</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \\</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">texinfo </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">autoconf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> automake</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \\</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">bison </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">tar</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> xz</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> bzip2</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> zlib</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \\</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">file </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">binutils</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> flex</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \\</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">linux-headers </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">libintl</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \\</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">gettext </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">gettext-dev</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> icu-libs</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> pkgconf</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \\</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">pkgconfig </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">icu-dev</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> bash</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> \\</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">ccache </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">libarchive-tools</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> zip</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">git</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> clone</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> https://git.zv.io/toolchains/musl-cross-make.git</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># Copy config.mak to the working directory of musl-cross-make.</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;"># You need to replace /path/to/config.mak with your config.mak file path.</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">cp</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /path/to/config.mak</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> musl-cross-make/</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">cp</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> /path/to/gcc-13.2.0.tar.xz.sha1</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> musl-cross-make/hashes</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">make</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> TARGET=x86_64-linux-musl</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -j</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> ||</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> :</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">sed</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -i</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &#39;s/poison calloc/poison/g&#39;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ./gcc-13.2.0/gcc/system.h</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">make</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> TARGET=x86_64-linux-musl</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -j</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">make</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> TARGET=x86_64-linux-musl</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -j</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">tar</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> cvzf</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> x86_64-musl-toolchain.tgz</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> output/</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">*</span></span></code></pre></div><div class="tip custom-block"><p class="custom-block-title custom-block-title-default">TIP</p><p>All the above scripts are suitable for x86_64 architecture Linux. If you need to build musl-cross-make for the ARM environment, just replace all <code>x86_64</code> above with <code>aarch64</code>.</p></div><p>This compilation process may fail due to insufficient memory, network problems, etc. You can try a few more times, or use a machine with larger memory to compile. If you encounter problems or you have better improvement solutions, go to <a href="https://github.com/crazywhalecc/static-php-cli-hosted/issues/1" target="_blank" rel="noreferrer">Discussion</a>.</p><h2 id="macos-environment" tabindex="-1">macOS Environment <a class="header-anchor" href="#macos-environment" aria-label="Permalink to macOS Environment"></a></h2><p>For macOS systems, the main compilation tool we use is <code>clang</code>, which is the default compiler for macOS systems and is also the compiler of Xcode.</p><p>Compiling under macOS mainly relies on Xcode or Xcode Command Line Tools. You can download Xcode from the App Store, or execute <code>xcode-select --install</code> in the terminal to install Xcode Command Line Tools.</p><p>In addition, in the <code>doctor</code> environment check module, static-php-cli will check whether Homebrew, compilation tools, etc. are installed on the macOS system. If not, you will be prompted to install them. I will not go into details here.</p><h2 id="freebsd-environment" tabindex="-1">FreeBSD Environment <a class="header-anchor" href="#freebsd-environment" aria-label="Permalink to FreeBSD Environment"></a></h2><p>FreeBSD is also a Unix system, and its compilation tools are similar to macOS. You can directly use the package management <code>pkg</code> to install <code>clang</code> and other compilation tools through the <code>doctor</code> command.</p><h2 id="pkg-config-compilation-nix-only" tabindex="-1">pkg-config Compilation (*nix only) <a class="header-anchor" href="#pkg-config-compilation-nix-only" aria-label="Permalink to pkg-config Compilation (*nix only)"></a></h2><p>If you observe the compilation log when using static-php-cli to build static PHP, you will find that no matter what is compiled, <code>pkg-config</code> will be compiled first. This is because <code>pkg-config</code> is a library used to find dependencies. In earlier versions of static-php-cli, we directly used the <code>pkg-config</code> tool installed by package management, but this would cause some problems, such as:</p><ul><li>Even if <code>PKG_CONFIG_PATH</code> is specified, <code>pkg-config</code> will try to find dependent packages from the system path.</li><li>Since <code>pkg-config</code> will look for dependent packages from the system path, if a dependent package with the same name exists in the system, compilation may fail.</li></ul><p>In order to avoid the above problems, we compile <code>pkg-config</code> into <code>buildroot/bin</code> in user mode and use it. We use parameters such as <code>--without-sysroot</code> to avoid looking for dependent packages from the system path.</p>`,50)]))}const m=i(t,[["render",l]]);export{d as __pageData,m as default};