diff --git a/.github/workflows/linux-aarch64.yml b/.github/workflows/linux-aarch64.yml index c8245a3d33..f6f0c52fab 100644 --- a/.github/workflows/linux-aarch64.yml +++ b/.github/workflows/linux-aarch64.yml @@ -95,7 +95,7 @@ jobs: mkdir -p bin/ mkdir -p runtime/ test -f runtime/php && rm -f runtime/php - if [ ! -f runtime/php/php ] ; then + if [ ! -f runtime/php/pie ] ; then bash setup-php-runtime.sh fi bash sapi/download-box/download-box-get-archive-from-server.sh @@ -114,6 +114,8 @@ jobs: alias php="php -d curl.cainfo=/work/runtime/php/cacert.pem -d openssl.cafile=/work/runtime/php/cacert.pem" sh sapi/quickstart/linux/alpine-init.sh + git config --global --add safe.directory /work + composer install --no-interaction --no-autoloader --no-scripts --profile --no-dev composer dump-autoload --optimize --profile --no-dev diff --git a/.github/workflows/linux-glibc.yml b/.github/workflows/linux-glibc.yml new file mode 100644 index 0000000000..3580cfe5a6 --- /dev/null +++ b/.github/workflows/linux-glibc.yml @@ -0,0 +1,150 @@ +name: build-swoole-cli-linux-glibc-x86_64 + +on: [ push, pull_request ] + +jobs: + linux-glibc: + if: ${{ !contains(github.event.head_commit.message, '--filter=') || contains(github.event.head_commit.message, '[linux-glibc]') }} + strategy: + fail-fast: false + matrix: + os: [ ubuntu-22.04, ubuntu-22.04-arm ] + name: linux-glibc-${{ matrix.os }} + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + - name: Show Environment Info + run: | + echo $PATH + env + docker info + id -u + id -g + who + cat /etc/os-release + hostnamectl + uname -s + uname -m + uname -r + + cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c + cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l + cat /proc/cpuinfo | grep "cpu cores" | uniq + cat /proc/cpuinfo| grep "processor"| wc -l + lscpu + + export IPV6=$(ip -6 address show | grep inet6 | awk '{print $2}' | cut -d'/' -f1 | sed -n '2p') + export IPV4=$(ip -4 address show | grep inet | grep -v 127.0.0 | awk '{print $2}' | cut -d'/' -f1 | sed -n '1p') + echo $IPV4 + echo $IPV6 + echo "X_IPV6=${IPV6}" >> $GITHUB_ENV + echo "X_IPV4=${IPV4}" >> $GITHUB_ENV + + - name: Prepare Build Environment + run: | + git submodule update --init + + sudo mkdir -p /usr/local/swoole-cli + uid=$(id -u) && gid=$(id -g) && sudo chown -R ${uid}:${gid} /usr/local/swoole-cli + + mkdir -p ${{ github.workspace }}/var/build-github-action-container/ + + - name: Cache PHP Runtime + uses: actions/cache@v4 + id: php-runtime-cache-x86_64 + with: + path: ${{ github.workspace }}/runtime + key: ${{ runner.os }}-x86_64-php-runtime + + - name: Cache PHP Vendor + uses: actions/cache@v4 + id: php-vendor-cache-x86_64 + with: + path: ${{ github.workspace }}/vendor + key: ${{ runner.os }}-x86_64-php-vendor + + - name: Cache Dependency Source Code Tarball + uses: actions/cache@v4 + id: pool-cache + with: + path: ${{ github.workspace }}/pool/ + key: source-code-tarball-pool + + - name: Cache all-library + uses: actions/cache@v4 + id: all-library-cache-x86_64 + with: + path: /usr/local/swoole-cli + key: ${{ github.head_ref || github.ref_name }}-${{ runner.os }}-x86_64-all-library + + - name: Prepare Runtime and Libraries and Extensions + run: | + set -x + mkdir -p pool/lib + mkdir -p pool/ext + mkdir -p bin/ + mkdir -p runtime/ + test -f runtime/php && rm -f runtime/php + if [ ! -f runtime/php/pie ] ; then + bash setup-php-runtime.sh + fi + bash sapi/download-box/download-box-get-archive-from-server.sh + ls -A pool/lib/ + ls -A /usr/local/swoole-cli/ + + - name: Build + run: | + set -eux + uname -m + composer install --no-interaction --no-autoloader --no-scripts --profile + composer dump-autoload --optimize --profile + + php prepare.php --with-libavif --without-docker + + sudo apt update + bash ./sapi/scripts/install-deps-on-ubuntu.sh + bash ./ext/swoole/scripts/install-deps-on-ubuntu.sh + bash ./sapi/scripts/build-swoole-cli-with-linux-gcc.sh + + ./bin/swoole-cli -v + ./bin/swoole-cli -m + ./bin/swoole-cli --ri curl + ./bin/swoole-cli --ri gd + ./bin/swoole-cli --ri imagick + ./bin/swoole-cli --ri swoole + { ldd ./bin/swoole-cli ; } || { echo $? ; } ; + file ./bin/swoole-cli + + - name: Make nfpm package + run: | + ARCH=$(uname -m) + if [ "$ARCH" = "aarch64" ]; then + NFPM_ARCH="arm64" + else + NFPM_ARCH="amd64" + fi + wget https://github.com/goreleaser/nfpm/releases/download/v2.43.4/nfpm_2.43.4_${NFPM_ARCH}.deb + sudo dpkg -i nfpm_2.43.4_${NFPM_ARCH}.deb + strip ./bin/swoole-cli + ./make.sh nfpm-pkg + ls -ls ./*.deb + ls -ls ./*.rpm + + - name: upload artifacts to cloud object storage + if: ${{ (github.repository == 'swoole/swoole-cli') && (startsWith(github.ref, 'refs/tags/')) }} + env: + OSS_SECRET_ID: ${{ secrets.QCLOUD_OSS_SECRET_ID }} + OSS_SECRET_KEY: ${{ secrets.QCLOUD_OSS_SECRET_KEY }} + OSS_BUCKET: ${{ vars.QCLOUD_OSS_BUCKET }} + OSS_REGION: ${{ vars.QCLOUD_OSS_REGION }} + run: | + ARCH=$(uname -m) + if [ "$ARCH" = "aarch64" ]; then + FILE_ARCH="arm64" + else + FILE_ARCH="x64" + fi + SWOOLE_VERSION=$(awk 'NR==1{ print $1 }' "sapi/SWOOLE-VERSION.conf") + OS="linux" + bash sapi/scripts/tencent-cloud-object-storage.sh --upload-file ${{ github.workspace }}/swoole-cli-"${SWOOLE_VERSION}-${OS}-${FILE_ARCH}"-glibc.deb + bash sapi/scripts/tencent-cloud-object-storage.sh --upload-file ${{ github.workspace }}/swoole-cli-"${SWOOLE_VERSION}-${OS}-${FILE_ARCH}"-glibc.rpm diff --git a/.github/workflows/linux-x86_64.yml b/.github/workflows/linux-x86_64.yml index 5933b37576..223dfc9c60 100644 --- a/.github/workflows/linux-x86_64.yml +++ b/.github/workflows/linux-x86_64.yml @@ -114,7 +114,7 @@ jobs: mkdir -p bin/ mkdir -p runtime/ test -f runtime/php && rm -f runtime/php - if [ ! -f runtime/php/php ] ; then + if [ ! -f runtime/php/pie ] ; then bash setup-php-runtime.sh fi @@ -139,6 +139,8 @@ jobs: alias php="php -d curl.cainfo=/work/runtime/php/cacert.pem -d openssl.cafile=/work/runtime/php/cacert.pem" sh sapi/quickstart/linux/alpine-init.sh + git config --global --add safe.directory /work + composer install --no-interaction --no-autoloader --no-scripts --profile --no-dev composer dump-autoload --optimize --profile --no-dev diff --git a/.github/workflows/macos-aarch64.yml b/.github/workflows/macos-aarch64.yml index b569925b90..e63c267f22 100644 --- a/.github/workflows/macos-aarch64.yml +++ b/.github/workflows/macos-aarch64.yml @@ -90,7 +90,7 @@ jobs: mkdir -p bin/ mkdir -p runtime/ test -f runtime/php && rm -f runtime/php - if [ ! -f runtime/php/php ] ; then + if [ ! -f runtime/php/pie ] ; then bash setup-php-runtime.sh fi bash sapi/download-box/download-box-get-archive-from-server.sh diff --git a/.github/workflows/macos-x86_64.yml b/.github/workflows/macos-x86_64.yml index c097a85c52..fc163e4dd7 100644 --- a/.github/workflows/macos-x86_64.yml +++ b/.github/workflows/macos-x86_64.yml @@ -91,7 +91,7 @@ jobs: mkdir -p bin/ mkdir -p runtime/ test -f runtime/php && rm -f runtime/php - if [ ! -f runtime/php/php ] ; then + if [ ! -f runtime/php/pie ] ; then bash setup-php-runtime.sh fi bash sapi/download-box/download-box-get-archive-from-server.sh diff --git a/.github/workflows/windows-msys2.yml b/.github/workflows/windows-msys2.yml index 40305b65d5..5b8116bdae 100644 --- a/.github/workflows/windows-msys2.yml +++ b/.github/workflows/windows-msys2.yml @@ -6,7 +6,7 @@ on: jobs: windows-msys2: - if: 0 + if: 1 runs-on: windows-2022 steps: - name: Show Environment Info @@ -31,15 +31,6 @@ jobs: git config --global --add safe.directory ${{ github.workspace }} - uses: actions/checkout@v4 - - name: Cache msys2 packages - id: cache-msys2 - uses: actions/cache@v4 - env: - cache-name: cache-msys2-packages - with: - path: C:\msys2-packages - key: "${{ runner.os }}-build-${{ env.cache-name }}" - - name: Cache pool id: cache-msys2-pool uses: actions/cache@v4 @@ -56,7 +47,8 @@ jobs: - name: prepare build environment shell: msys2 {0} run: | - bash ./sapi/quickstart/windows/msys2-build/install-msys2.sh + bash sapi/quickstart/windows/msys2-build/install-msys2.sh + bash sapi/download-box/download-box-get-archive-from-server.sh - name: install deps lib with source code shell: msys2 {0} @@ -117,3 +109,26 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: files: ${{ env.APP_NAME }}-${{ env.APP_VERSION }}-msys2-x64.zip + + + upload-to-cloud-object-storage: + if: 1 + runs-on: ubuntu-latest + needs: windows-msys2 + steps: + - name: Prepare Run Environment + run: + sudo apt install -y curl + - uses: actions/checkout@v4 + - uses: actions/download-artifact@v4 + - name: upload artifacts to cloud object storage + if: ${{ (github.repository == 'swoole/swoole-cli') && (startsWith(github.ref, 'refs/tags/')) }} + env: + OSS_SECRET_ID: ${{ secrets.QCLOUD_OSS_SECRET_ID }} + OSS_SECRET_KEY: ${{ secrets.QCLOUD_OSS_SECRET_KEY }} + OSS_BUCKET: ${{ vars.QCLOUD_OSS_BUCKET }} + OSS_REGION: ${{ vars.QCLOUD_OSS_REGION }} + run: | + FILE_NAME=$(ls -d swoole-cli-v*-msys2-x64) + FILE="${{ github.workspace }}/${FILE_NAME}/${FILE_NAME}.zip" + bash sapi/scripts/tencent-cloud-object-storage.sh --upload-file ${FILE} diff --git a/.gitignore b/.gitignore index a14360d621..0ab27e377a 100644 --- a/.gitignore +++ b/.gitignore @@ -315,6 +315,7 @@ tmp-php.ini /ext/ds /ext/xlswriter /ext/uuid +/ext/phpy /.phpunit.result.cache /samples/sfx/*.phar .php-cs-fixer.cache @@ -334,8 +335,6 @@ php.ini sapi/webUI/deploy.sh sapi/webUI/public/data/ Makefile.backup -ldflags.log -cppflags.log libs.log ext/apcu/ ext/ssh2/ @@ -348,3 +347,7 @@ php-fpm-* !/runtime/.gitkeep /APP_NAME /APP_VERSION +*.deb +*.rpm +nfpm-pkg.yaml +!/var/.gitkeep diff --git a/bin/.gitkeep b/bin/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/prepare.php b/prepare.php index de2a48a12b..405bbe0467 100755 --- a/prepare.php +++ b/prepare.php @@ -35,18 +35,23 @@ // Sync code from php-src $p->setPhpSrcDir($p->getWorkDir() . '/var/php-' . BUILD_PHP_VERSION); +/* +// Download swoole-src +if (!is_dir(__DIR__ . '/ext/swoole')) { + //shell_exec(__DIR__ . '/sapi/scripts/download-swoole-src-archive.sh'); +} +*/ + // Compile directly on the host machine, not in the docker container -if ($p->getInputOption('without-docker') || ($p->isMacos())) { +if ($p->getInputOption('without-docker') || ($p->isMacos()) || ($p->isLinux() && (!is_file('/.dockerenv')))) { $p->setWorkDir(__DIR__); $p->setBuildDir(__DIR__ . '/thirdparty'); } - if ($p->getInputOption('with-override-default-enabled-ext')) { $p->setExtEnabled([]); } - if ($p->getInputOption('with-global-prefix')) { $p->setGlobalPrefix($p->getInputOption('with-global-prefix')); } @@ -93,7 +98,12 @@ if ($p->isMacos()) { //$p->setExtraLdflags('-undefined dynamic_lookup'); $p->setExtraLdflags(''); - $homebrew_prefix = trim(shell_exec('brew --prefix')); + exec("brew --prefix 2>&1", $output, $result_code); + if ($result_code == 0) { + $homebrew_prefix = trim(implode(' ', $output)); + } else { + $homebrew_prefix = ""; + } $p->withBinPath($homebrew_prefix . '/opt/flex/bin') ->withBinPath($homebrew_prefix . '/opt/bison/bin') ->withBinPath($homebrew_prefix . '/opt/libtool/bin') diff --git a/sapi/SWOOLE-VERSION.conf b/sapi/SWOOLE-VERSION.conf index 035fbdc6e7..4871c222ec 100644 --- a/sapi/SWOOLE-VERSION.conf +++ b/sapi/SWOOLE-VERSION.conf @@ -1 +1 @@ -v6.1.1 +v6.1.6 diff --git a/sapi/quickstart/windows/msys2-build/install-msys2.sh b/sapi/quickstart/windows/msys2-build/install-msys2.sh index 05715d057b..29f66d2146 100644 --- a/sapi/quickstart/windows/msys2-build/install-msys2.sh +++ b/sapi/quickstart/windows/msys2-build/install-msys2.sh @@ -71,6 +71,7 @@ pacman -S --needed --noconfirm icu-devel pacman -S --needed --noconfirm gettext-devel pacman -S --needed --noconfirm libintl pacman -S --needed --noconfirm flex +pacman -S --needed --noconfirm nasm yasm : <<'COMMENT' # 不存在的包 diff --git a/sapi/scripts/build-swoole-cli-with-linux-gcc.sh b/sapi/scripts/build-swoole-cli-with-linux-gcc.sh index a5155870f6..e26ac414a1 100755 --- a/sapi/scripts/build-swoole-cli-with-linux-gcc.sh +++ b/sapi/scripts/build-swoole-cli-with-linux-gcc.sh @@ -1,4 +1,9 @@ -./configure --prefix=/usr --disable-all \ +if [ ! -f ./configure ]; then + ./buildconf --force +fi + +./configure --prefix=/usr/local/swoole-cli \ + --disable-all \ --enable-zts \ --without-pcre-jit \ --with-openssl --enable-openssl \ @@ -30,18 +35,22 @@ --enable-exif \ --with-sodium \ --enable-xml --enable-simplexml --enable-xmlreader --enable-xmlwriter --enable-dom --with-libxml \ - --enable-gd --with-jpeg --with-freetype \ - --enable-swoole --enable-sockets --enable-mysqlnd --enable-swoole-curl --enable-cares \ + --enable-gd --with-jpeg --with-freetype --with-avif \ + --enable-swoole \ + --enable-swoole-curl \ + --enable-cares \ --enable-swoole-pgsql \ --enable-swoole-sqlite \ + --with-swoole-odbc=unixODBC,/usr \ --enable-swoole-thread \ + --enable-swoole-stdext \ --enable-brotli \ --enable-zstd \ - --enable-swoole-stdext \ --enable-redis \ --with-imagick \ --with-yaml \ --with-readline \ + --enable-phpy --with-python-config=python3-config \ --enable-opcache -make -j "$(nproc)" \ No newline at end of file +make -j "$(nproc)" diff --git a/sapi/scripts/copy-depend-libs.php b/sapi/scripts/copy-depend-libs.php new file mode 100644 index 0000000000..a1d7a8703f --- /dev/null +++ b/sapi/scripts/copy-depend-libs.php @@ -0,0 +1,99 @@ + (typical ldd output) + if (preg_match('/^\s*.*\s+=>\s+(\/.*)\s+\(0x[0-9a-f]+\)$/', $line, $matches)) { + $libPath = trim($matches[1]); + if (file_exists($libPath)) { + $dependencies[] = $libPath; + } + } + // Match lines without => (statically linked or direct paths) + elseif (preg_match('/^\s+(\/.*)\s+\(0x[0-9a-f]+\)$/', $line, $matches)) { + $libPath = trim($matches[1]); + if (file_exists($libPath)) { + $dependencies[] = $libPath; + } + } +} + +// Remove duplicates +$dependencies = array_unique($dependencies); + +// Filter out ignored libraries +$filteredDependencies = []; +foreach ($dependencies as $libPath) { + $fileName = basename($libPath); + foreach ($ignoredLibraries as $ignoredLib) { + if (strpos($fileName, $ignoredLib) !== false) { + echo "Skipping system library: $fileName\n"; + continue 2; + } + } + $filteredDependencies[] = $libPath; +} + +echo "Found " . count($filteredDependencies) . " dependencies (excluding system libraries)\n"; + +// Copy each dependency to target directory +$successCount = 0; +foreach ($filteredDependencies as $libPath) { + $fileName = basename($libPath); + $targetPath = "$targetDir/$fileName"; + + echo "Copying $libPath to $targetPath... "; + + if (copy($libPath, $targetPath)) { + echo "SUCCESS\n"; + $successCount++; + } else { + echo "FAILED\n"; + } +} + +echo "Successfully copied $successCount out of " . count($filteredDependencies) . " dependencies\n"; diff --git a/sapi/scripts/download-swoole-src-archive.sh b/sapi/scripts/download-swoole-src-archive.sh new file mode 100755 index 0000000000..9818ba63e7 --- /dev/null +++ b/sapi/scripts/download-swoole-src-archive.sh @@ -0,0 +1,48 @@ +__DIR__=$( + cd "$(dirname "$0")" || exit + pwd +) + +WORKDIR=$( + cd "${__DIR__}"/../../ || exit + pwd +) + +ORIGIN_SWOOLE_VERSION=$(awk 'NR==1{ print $1 }' "sapi/SWOOLE-VERSION.conf") +SWOOLE_VERSION=$(echo "${ORIGIN_SWOOLE_VERSION}" | sed 's/[^a-zA-Z0-9]/_/g') +CURRENT_SWOOLE_VERSION='' + +cd "${WORKDIR}" || exit + +TGZ_FILE="${WORKDIR}/pool/ext/swoole-${ORIGIN_SWOOLE_VERSION}.tgz" +SWOOLE_DIR="${WORKDIR}/ext/swoole/" + +if [ -f "ext/swoole/CMakeLists.txt" ] ;then + CURRENT_SWOOLE_VERSION=$(grep 'set(SWOOLE_VERSION' ext/swoole/CMakeLists.txt | awk '{ print $2 }' | sed 's/)//') + if [[ "${CURRENT_SWOOLE_VERSION}" =~ "-dev" ]]; then + echo 'swoole version master' + if [ -n "${GITHUB_ACTION}" ]; then + test -f "$TGZ_FILE" && rm -f "$TGZ_FILE" + CURRENT_SWOOLE_VERSION='' + fi + fi +fi + +if [ "${SWOOLE_VERSION}" != "${CURRENT_SWOOLE_VERSION}" ] ;then + if [ ! -f "$TGZ_FILE" ] ;then + echo "downloading swoole-${ORIGIN_SWOOLE_VERSION}.tgz" + test -d /tmp/swoole && rm -rf /tmp/swoole + git clone -b "${ORIGIN_SWOOLE_VERSION}" https://github.com/swoole/swoole-src.git /tmp/swoole + status=$? + if [[ $status -ne 0 ]]; then { echo $status ; exit 1 ; } fi + cd /tmp/swoole || exit + rm -rf /tmp/swoole/.git/ + tar -czvf "$TGZ_FILE" . + fi + + if [ ! -d "$SWOOLE_DIR" ] ;then + echo "unpacking swoole-${ORIGIN_SWOOLE_VERSION}.tgz" + mkdir -p "${SWOOLE_DIR}" + tar --strip-components=1 -C "${SWOOLE_DIR}" -xf "$TGZ_FILE" + fi +fi diff --git a/sapi/scripts/install-deps-on-ubuntu.sh b/sapi/scripts/install-deps-on-ubuntu.sh new file mode 100755 index 0000000000..75af25e7b2 --- /dev/null +++ b/sapi/scripts/install-deps-on-ubuntu.sh @@ -0,0 +1,38 @@ +# build tools +sudo apt install gcc g++ make autoconf libtool pkg-config re2c + +# libraries +sudo apt install libyaml-dev \ + libssl-dev \ + libxml2-dev \ + libmagic-dev \ + libpng-dev \ + libjpeg-dev \ + libfreetype-dev \ + libc-ares-dev \ + libpcre2-dev \ + libsodium-dev \ + libcurl4-openssl-dev \ + libmariadb-dev \ + libaio-dev \ + zlib1g \ + mime-support \ + tzdata \ + ucf \ + libargon2-dev \ + libsqlite3-dev \ + libbrotli-dev \ + libpq-dev \ + unixodbc-dev \ + firebird-dev \ + libzstd-dev \ + libssh-dev \ + liburing-dev \ + libedit-dev \ + libreadline-dev \ + libmagic-dev \ + libonig-dev \ + libxslt-dev \ + libzip-dev \ + libavif-dev \ + libpython3-dev diff --git a/sapi/scripts/msys2/config-ext.sh b/sapi/scripts/msys2/config-ext.sh index ab28e2628a..ec7d94380a 100644 --- a/sapi/scripts/msys2/config-ext.sh +++ b/sapi/scripts/msys2/config-ext.sh @@ -75,9 +75,11 @@ download_and_extract "yaml" ${YAML_VERSION} download_and_extract "imagick" ${IMAGICK_VERSION} cd ${__PROJECT__}/pool/ext +set +u if [ -n "${GITHUB_ACTION}" ]; then test -f ${__PROJECT__}/pool/ext/swoole-${SWOOLE_VERSION}.tgz && rm -f ${__PROJECT__}/pool/ext/swoole-${SWOOLE_VERSION}.tgz fi +set -u if [ ! -f swoole-${SWOOLE_VERSION}.tgz ]; then test -d ${WORK_TEMP_DIR}/swoole && rm -rf ${WORK_TEMP_DIR}/swoole git clone -b ${SWOOLE_VERSION} https://github.com/swoole/swoole-src.git ${WORK_TEMP_DIR}/swoole diff --git a/sapi/scripts/msys2/config.sh b/sapi/scripts/msys2/config.sh index 33acb69fb2..39bdeda756 100644 --- a/sapi/scripts/msys2/config.sh +++ b/sapi/scripts/msys2/config.sh @@ -94,7 +94,9 @@ test -f Makefile && make clean --enable-mbstring \ --with-pgsql \ --enable-intl \ - ${OPTIONS} + ${OPTIONS} \ + --enable-gd --with-jpeg --with-freetype --with-webp --with-avif \ + --with-imagick # --enable-intl \ # --with-sodium \ diff --git a/sapi/scripts/msys2/install-deps-lib.sh b/sapi/scripts/msys2/install-deps-lib.sh index ac12e3ac7e..918a3c395d 100644 --- a/sapi/scripts/msys2/install-deps-lib.sh +++ b/sapi/scripts/msys2/install-deps-lib.sh @@ -14,3 +14,14 @@ bash install-libzip.sh bash install-libsodium.sh bash install-liboniguruma.sh bash install-libpq.sh +bash install-libgif.sh +bash install-libpng.sh +bash install-freetype.sh +bash install-libjpeg.sh +bash install-libwebp.sh +bash install-libyuv.sh +bash install-libaom.sh +bash install-libgav1.sh +bash install-libavif.sh +bash install-imagemagick.sh + diff --git a/sapi/scripts/msys2/install-freetype.sh b/sapi/scripts/msys2/install-freetype.sh new file mode 100644 index 0000000000..e744bd4ab1 --- /dev/null +++ b/sapi/scripts/msys2/install-freetype.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env bash + +set -exu +__DIR__=$( + cd "$(dirname "$0")" + pwd +) +__PROJECT__=$( + cd ${__DIR__}/../../../ + pwd +) +cd ${__PROJECT__} +mkdir -p pool/lib/ +WORK_TEMP_DIR=${__PROJECT__}/var/msys2-build/ +mkdir -p ${WORK_TEMP_DIR} + +VERSION=2.13.2 + +download() { + curl -fSLo ${__PROJECT__}/pool/lib/freetype-${VERSION}.tar.gz https://github.com/freetype/freetype/archive/refs/tags/VER-2-13-2.tar.gz +} + +build() { + + cd ${WORK_TEMP_DIR} + mkdir -p freetype-${VERSION} + tar --strip-components=1 -xvf ${__PROJECT__}/pool/lib/freetype-${VERSION}.tar.gz -C freetype-${VERSION} + cd freetype-${VERSION} + + mkdir -p build + cd build + + cmake -S .. -B . \ + -DCMAKE_INSTALL_PREFIX=/usr \ + -DCMAKE_BUILD_TYPE=Release \ + -DBUILD_SHARED_LIBS=ON \ + -DFT_REQUIRE_ZLIB=TRUE \ + -DFT_REQUIRE_BZIP2=TRUE \ + -DFT_REQUIRE_BROTLI=TRUE \ + -DFT_REQUIRE_PNG=TRUE \ + -DFT_DISABLE_HARFBUZZ=TRUE \ + -DCMAKE_POLICY_VERSION_MINIMUM=3.5 + + make -j $(nproc) + make install + +} + +cd ${__PROJECT__} +test -f ${__PROJECT__}/pool/lib/freetype-${VERSION}.tar.gz || download + +build diff --git a/sapi/scripts/msys2/install-imagemagick.sh b/sapi/scripts/msys2/install-imagemagick.sh new file mode 100644 index 0000000000..cf23d78f04 --- /dev/null +++ b/sapi/scripts/msys2/install-imagemagick.sh @@ -0,0 +1,88 @@ +#!/usr/bin/env bash + +set -exu +__DIR__=$( + cd "$(dirname "$0")" + pwd +) +__PROJECT__=$( + cd ${__DIR__}/../../../ + pwd +) +cd ${__PROJECT__} +mkdir -p pool/lib/ +WORK_TEMP_DIR=${__PROJECT__}/var/msys2-build/ +mkdir -p ${WORK_TEMP_DIR} + +VERSION=7.1.2-8 + +download() { + curl -fSLo ${__PROJECT__}/pool/lib/ImageMagick-v${VERSION}.tar.gz https://github.com/ImageMagick/ImageMagick/archive/refs/tags/7.1.2-8.tar.gz +} + +build() { + + cd ${WORK_TEMP_DIR} + mkdir -p ImageMagick-v${VERSION} + tar --strip-components=1 -xvf ${__PROJECT__}/pool/lib/ImageMagick-v${VERSION}.tar.gz -C ImageMagick-v${VERSION} + cd ImageMagick-v${VERSION} + + ./configure \ + --prefix=/usr/ \ + --enable-shared=yes \ + --enable-static=no \ + --with-pic \ + --with-zip \ + --with-zlib \ + --with-lzma \ + --with-zstd \ + --with-jpeg \ + --with-png \ + --with-webp \ + --with-xml \ + --with-freetype \ + --with-heic \ + --with-raw \ + --with-tiff \ + --with-lcms \ + --enable-zero-configuration \ + --enable-bounds-checking \ + --enable-hdri \ + --disable-dependency-tracking \ + --without-perl \ + --disable-docs \ + --disable-opencl \ + --disable-openmp \ + --without-djvu \ + --without-rsvg \ + --without-fontconfig \ + --without-jbig \ + --without-jxl \ + --without-openjp2 \ + --without-lqr \ + --without-openexr \ + --without-pango \ + --without-x \ + --without-modules \ + --with-magick-plus-plus \ + --without-utilities \ + --without-gvc \ + --without-autotrace \ + --without-dps \ + --without-fftw \ + --without-flif \ + --without-fpx \ + --without-gslib \ + --without-perl \ + --without-raqm \ + --without-wmf + + make -j $(nproc) + make install + +} + +cd ${__PROJECT__} +test -f ${__PROJECT__}/pool/lib/ImageMagick-v${VERSION}.tar.gz || download + +build diff --git a/sapi/scripts/msys2/install-libaom.sh b/sapi/scripts/msys2/install-libaom.sh new file mode 100644 index 0000000000..549adfe0ad --- /dev/null +++ b/sapi/scripts/msys2/install-libaom.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash + +set -exu +__DIR__=$( + cd "$(dirname "$0")" + pwd +) +__PROJECT__=$( + cd ${__DIR__}/../../../ + pwd +) +cd ${__PROJECT__} +mkdir -p pool/lib/ +WORK_TEMP_DIR=${__PROJECT__}/var/msys2-build/ +mkdir -p ${WORK_TEMP_DIR} + +VERSION=v3.10.0 + +download() { + curl -fSLo ${__PROJECT__}/pool/lib/libaom-${VERSION}.tar.gz https://aomedia.googlesource.com/aom/+archive/c2fe6bf370f7c14fbaf12884b76244a3cfd7c5fc.tar.gz +} + +build() { + + cd ${WORK_TEMP_DIR} + mkdir -p libaom-${VERSION} + tar -xvf ${__PROJECT__}/pool/lib/libaom-${VERSION}.tar.gz -C libaom-${VERSION} + cd libaom-${VERSION} + + mkdir -p build_dir + cd build_dir + cmake -S .. -B . \ + -DCMAKE_INSTALL_PREFIX=/usr/ \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_C_STANDARD=11 \ + -DBUILD_SHARED_LIBS=OFF \ + -DBUILD_STATIC_LIBS=ON \ + -DENABLE_DOCS=OFF \ + -DENABLE_EXAMPLES=OFF \ + -DENABLE_TESTS=OFF \ + -DENABLE_TOOLS=ON + + make -j $(nproc) + make install + +} + +cd ${__PROJECT__} +test -f ${__PROJECT__}/pool/lib/libaom-${VERSION}.tar.gz || download + +build diff --git a/sapi/scripts/msys2/install-libavif.sh b/sapi/scripts/msys2/install-libavif.sh index eac0fa1fb9..e4244e7b9c 100644 --- a/sapi/scripts/msys2/install-libavif.sh +++ b/sapi/scripts/msys2/install-libavif.sh @@ -45,8 +45,7 @@ build() { -DENABLE_ZSTD=ON \ -DBUILD_REGRESS=OFF \ -DBUILD_OSSFUZZ=OFF \ - -DCMAKE_VERBOSE_MAKEFILE=ON \ - -DCMAKE_PREFIX_PATH="/usr/local/;/usr/" + -DCMAKE_VERBOSE_MAKEFILE=ON make -j $(nproc) diff --git a/sapi/scripts/msys2/install-libgav1.sh b/sapi/scripts/msys2/install-libgav1.sh new file mode 100644 index 0000000000..3ccce2ed9e --- /dev/null +++ b/sapi/scripts/msys2/install-libgav1.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash + +set -exu +__DIR__=$( + cd "$(dirname "$0")" + pwd +) +__PROJECT__=$( + cd ${__DIR__}/../../../ + pwd +) +cd ${__PROJECT__} +mkdir -p pool/lib/ +WORK_TEMP_DIR=${__PROJECT__}/var/msys2-build/ +mkdir -p ${WORK_TEMP_DIR} + +VERSION=v0.19.0 + +download() { + curl -fSLo ${__PROJECT__}/pool/lib/libgav1-${VERSION}.tar.gz https://chromium.googlesource.com/codecs/libgav1/+archive/e386d8f1fb983200972d159b9be47fd5d0776708.tar.gz +} + +build() { + + cd ${WORK_TEMP_DIR} + mkdir -p libgav1-${VERSION} + tar -xvf ${__PROJECT__}/pool/lib/libgav1-${VERSION}.tar.gz -C libgav1-${VERSION} + cd libgav1-${VERSION} + + mkdir -p build + cd build + cmake -G "Unix Makefiles" -S .. -B . \ + -DCMAKE_INSTALL_PREFIX=/usr/ \ + -DCMAKE_BUILD_TYPE=Release \ + -DBUILD_SHARED_LIBS=ON \ + -DBUILD_STATIC_LIBS=OFF \ + -DLIBGAV1_ENABLE_TESTS=OFF \ + -DLIBGAV1_ENABLE_EXAMPLES=OFF \ + -DLIBGAV1_THREADPOOL_USE_STD_MUTEX=1 + + make -j $(nproc) + make install + +} + +cd ${__PROJECT__} +test -f ${__PROJECT__}/pool/lib/libgav1-${VERSION}.tar.gz || download + +build diff --git a/sapi/scripts/msys2/install-libgif.sh b/sapi/scripts/msys2/install-libgif.sh new file mode 100644 index 0000000000..97d5b81aa9 --- /dev/null +++ b/sapi/scripts/msys2/install-libgif.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +set -exu +__DIR__=$( + cd "$(dirname "$0")" + pwd +) +__PROJECT__=$( + cd ${__DIR__}/../../../ + pwd +) +cd ${__PROJECT__} +mkdir -p pool/lib/ +WORK_TEMP_DIR=${__PROJECT__}/var/msys2-build/ +mkdir -p ${WORK_TEMP_DIR} + +VERSION=5.2.1 + +download() { + curl -fSLo ${__PROJECT__}/pool/lib/giflib-${VERSION}.tar.gz https://sourceforge.net/projects/giflib/files/giflib-${VERSION}.tar.gz +} + +build() { + + cd ${WORK_TEMP_DIR} + mkdir -p giflib-${VERSION} + tar --strip-components=1 -xvf ${__PROJECT__}/pool/lib/giflib-${VERSION}.tar.gz -C giflib-${VERSION} + cd giflib-${VERSION} + make -j $(nproc) libgif.so + # make install + cp -f libgif.so /usr/lib/libgif.so + cp -f gif_lib.h /usr/include/gif_lib.h +} + +cd ${__PROJECT__} +test -f ${__PROJECT__}/pool/lib/giflib-${VERSION}.tar.gz || download + +build diff --git a/sapi/scripts/msys2/install-libjpeg.sh b/sapi/scripts/msys2/install-libjpeg.sh new file mode 100644 index 0000000000..8292e35766 --- /dev/null +++ b/sapi/scripts/msys2/install-libjpeg.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash + +set -exu +__DIR__=$( + cd "$(dirname "$0")" + pwd +) +__PROJECT__=$( + cd ${__DIR__}/../../../ + pwd +) +cd ${__PROJECT__} +mkdir -p pool/lib/ +WORK_TEMP_DIR=${__PROJECT__}/var/msys2-build/ +mkdir -p ${WORK_TEMP_DIR} + +VERSION=3.1.2 + +download() { + # document https://github.com/libjpeg-turbo/libjpeg-turbo/ + curl -fSLo ${__PROJECT__}/pool/lib/libjpeg-${VERSION}.tar.gz https://github.com/libjpeg-turbo/libjpeg-turbo/archive/refs/tags/${VERSION}.tar.gz +} + +build() { + + cd ${WORK_TEMP_DIR} + mkdir -p libjpeg-${VERSION} + tar --strip-components=1 -xvf ${__PROJECT__}/pool/lib/libjpeg-${VERSION}.tar.gz -C libjpeg-${VERSION} + cd libjpeg-${VERSION} + + mkdir -p build + cd build + + cmake -G"Unix Makefiles" -S .. -B . \ + -DCMAKE_INSTALL_PREFIX=/usr/ \ + -DCMAKE_INSTALL_LIBDIR=/usr/lib \ + -DCMAKE_INSTALL_INCLUDEDIR=/usr/include \ + -DCMAKE_BUILD_TYPE=Release \ + -DBUILD_SHARED_LIBS=ON \ + -DBUILD_STATIC_LIBS=OFF + + + make -j $(nproc) + make install + +} + +cd ${__PROJECT__} +test -f ${__PROJECT__}/pool/lib/libjpeg-${VERSION}.tar.gz || download + +build diff --git a/sapi/scripts/msys2/install-libpng.sh b/sapi/scripts/msys2/install-libpng.sh new file mode 100644 index 0000000000..e2010f4957 --- /dev/null +++ b/sapi/scripts/msys2/install-libpng.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash + +set -exu +__DIR__=$( + cd "$(dirname "$0")" + pwd +) +__PROJECT__=$( + cd ${__DIR__}/../../../ + pwd +) +cd ${__PROJECT__} +mkdir -p pool/lib/ +WORK_TEMP_DIR=${__PROJECT__}/var/msys2-build/ +mkdir -p ${WORK_TEMP_DIR} + +VERSION=1.6.43 + +download() { + curl -fSLo ${__PROJECT__}/pool/lib/libpng-${VERSION}.tar.gz https://sourceforge.net/projects/libpng/files/libpng16/1.6.43/libpng-1.6.43.tar.gz +} + +build() { + + cd ${WORK_TEMP_DIR} + mkdir -p libpng-${VERSION} + tar --strip-components=1 -xvf ${__PROJECT__}/pool/lib/libpng-${VERSION}.tar.gz -C libpng-${VERSION} + cd libpng-${VERSION} + + mkdir -p build + cd build + cmake -S .. -B . \ + -DCMAKE_INSTALL_PREFIX=/usr \ + -DPNG_SHARED=ON \ + -DPNG_TESTS=OFF + + make -j $(nproc) + make install + +} + +cd ${__PROJECT__} +test -f ${__PROJECT__}/pool/lib/libpng-${VERSION}.tar.gz || download + +build diff --git a/sapi/scripts/msys2/install-libwebp.sh b/sapi/scripts/msys2/install-libwebp.sh new file mode 100644 index 0000000000..55bfd36b43 --- /dev/null +++ b/sapi/scripts/msys2/install-libwebp.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash + +set -exu +__DIR__=$( + cd "$(dirname "$0")" + pwd +) +__PROJECT__=$( + cd ${__DIR__}/../../../ + pwd +) +cd ${__PROJECT__} +mkdir -p pool/lib/ +WORK_TEMP_DIR=${__PROJECT__}/var/msys2-build/ +mkdir -p ${WORK_TEMP_DIR} + +VERSION=1.3.2 + +download() { + curl -fSLo ${__PROJECT__}/pool/lib/libwebp-${VERSION}.tar.gz https://github.com/webmproject/libwebp/archive/refs/tags/v1.3.2.tar.gz +} + +build() { + + cd ${WORK_TEMP_DIR} + mkdir -p libwebp-${VERSION} + tar --strip-components=1 -xvf ${__PROJECT__}/pool/lib/libwebp-${VERSION}.tar.gz -C libwebp-${VERSION} + cd libwebp-${VERSION} + + ./autogen.sh + ./configure \ + --prefix=/usr/ \ + --enable-shared=yes \ + --enable-everything \ + --disable-tiff + + make -j $(nproc) + make install + +} + +cd ${__PROJECT__} +test -f ${__PROJECT__}/pool/lib/libwebp-${VERSION}.tar.gz || download + +build diff --git a/sapi/scripts/msys2/install-libyuv.sh b/sapi/scripts/msys2/install-libyuv.sh index dedca02791..a672af1b82 100644 --- a/sapi/scripts/msys2/install-libyuv.sh +++ b/sapi/scripts/msys2/install-libyuv.sh @@ -17,7 +17,6 @@ mkdir -p ${WORK_TEMP_DIR} VERSION=068c9f2f643ce59eeb3001d61374bf44a2abd825 download() { - # document https://github.com/AOMediaCodec/libavif/ curl -fSLo ${__PROJECT__}/pool/lib/libyuv-${VERSION}.tar.gz https://chromium.googlesource.com/libyuv/libyuv/+archive/${VERSION}.tar.gz } diff --git a/sapi/scripts/tencent-cloud-object-storage.sh b/sapi/scripts/tencent-cloud-object-storage.sh index 723d930860..e4e00eba52 100644 --- a/sapi/scripts/tencent-cloud-object-storage.sh +++ b/sapi/scripts/tencent-cloud-object-storage.sh @@ -136,18 +136,17 @@ if [ "${UPLOAD_TYPE}" == 'all' ]; then SWOOLE_VERSION=$(echo ${SWOOLE_CLI_VERSION} | awk -F '.' '{ printf "%s.%s.%s" ,$1,$2,$3 }') cd ${__PROJECT__}/var/artifact-hash/${SWOOLE_CLI_VERSION} { - ${COSCLI} cp --forbid-overwrite --fail-output-path ${__PROJECT__}/var/tencent-cloud-object-storage/upload.log swoole-cli-${SWOOLE_VERSION}-cygwin-x64.zip ${COS_BUCKET_FOLDER} - ${COSCLI} cp --forbid-overwrite --fail-output-path ${__PROJECT__}/var/tencent-cloud-object-storage/upload.log swoole-cli-${SWOOLE_VERSION}-linux-arm64.tar.xz ${COS_BUCKET_FOLDER} - ${COSCLI} cp --forbid-overwrite --fail-output-path ${__PROJECT__}/var/tencent-cloud-object-storage/upload.log swoole-cli-${SWOOLE_VERSION}-linux-x64.tar.xz ${COS_BUCKET_FOLDER} - ${COSCLI} cp --forbid-overwrite --fail-output-path ${__PROJECT__}/var/tencent-cloud-object-storage/upload.log swoole-cli-${SWOOLE_VERSION}-macos-arm64.tar.xz ${COS_BUCKET_FOLDER} - ${COSCLI} cp --forbid-overwrite --fail-output-path ${__PROJECT__}/var/tencent-cloud-object-storage/upload.log swoole-cli-${SWOOLE_VERSION}-macos-x64.tar.xz ${COS_BUCKET_FOLDER} + ${COSCLI} cp --forbid-overwrite swoole-cli-${SWOOLE_VERSION}-cygwin-x64.zip ${COS_BUCKET_FOLDER} + ${COSCLI} cp --forbid-overwrite swoole-cli-${SWOOLE_VERSION}-linux-arm64.tar.xz ${COS_BUCKET_FOLDER} + ${COSCLI} cp --forbid-overwrite swoole-cli-${SWOOLE_VERSION}-linux-x64.tar.xz ${COS_BUCKET_FOLDER} + ${COSCLI} cp --forbid-overwrite swoole-cli-${SWOOLE_VERSION}-macos-arm64.tar.xz ${COS_BUCKET_FOLDER} + ${COSCLI} cp --forbid-overwrite swoole-cli-${SWOOLE_VERSION}-macos-x64.tar.xz ${COS_BUCKET_FOLDER} status=$? } || { status=$? } if [[ $status -ne 0 ]]; then echo $status - cat ${__PROJECT__}/var/tencent-cloud-object-storage/upload.log exit 1 fi cd ${__PROJECT__} @@ -155,11 +154,10 @@ if [ "${UPLOAD_TYPE}" == 'all' ]; then fi if [ "${UPLOAD_TYPE}" == 'single' ]; then - ${COSCLI} cp --fail-output-path ${__PROJECT__}/var/tencent-cloud-object-storage/upload.log ${UPLOAD_FILE} ${COS_BUCKET_FOLDER} + ${COSCLI} cp ${UPLOAD_FILE} ${COS_BUCKET_FOLDER} status=$? if [[ $status -ne 0 ]]; then echo $status - cat ${__PROJECT__}/var/tencent-cloud-object-storage/upload.log exit 1 fi exit 0 @@ -172,7 +170,6 @@ if [ "${UPLOAD_TYPE}" == 'show' ]; then status=$? if [[ $status -ne 0 ]]; then echo $status - cat ${__PROJECT__}/var/tencent-cloud-object-storage/coscli.log exit 1 fi exit 0 diff --git a/sapi/src/Extension.php b/sapi/src/Extension.php index fc9d681898..c056cc3f8b 100644 --- a/sapi/src/Extension.php +++ b/sapi/src/Extension.php @@ -7,6 +7,9 @@ class Extension extends Project public string $options = ''; public string $peclVersion = ''; + public string $pieVersion = ''; + public string $pieName = ''; + public array $dependentExtensions = []; public function withOptions(string $options): static @@ -26,4 +29,17 @@ public function withDependentExtensions(string ...$extensions): static $this->dependentExtensions += $extensions; return $this; } + + public function withPieVersion(string $pieVersion): static + { + $this->pieVersion = $pieVersion; + return $this; + } + + public function withPieName(string $pieName): static + { + $this->pieName = $pieName; + return $this; + } + } diff --git a/sapi/src/Preprocessor.php b/sapi/src/Preprocessor.php index 57406526aa..164fdb2ecc 100644 --- a/sapi/src/Preprocessor.php +++ b/sapi/src/Preprocessor.php @@ -45,6 +45,7 @@ class Preprocessor protected string $libraryDir; protected string $extensionDir; protected array $pkgConfigPaths = []; + protected array $nfpmDepends = []; protected string $phpSrcDir; protected string $dockerVersion = 'latest'; /** @@ -163,6 +164,19 @@ public function getSystemArch(): string } } + public function getDebArch(): string + { + $uname = posix_uname(); + switch ($uname['machine']) { + case 'x86_64': + return 'amd64'; + case 'aarch64': + return 'arm64'; + default: + return $uname['machine']; + } + } + public function getImageTag(): string { $arch = $this->getSystemArch(); @@ -244,6 +258,11 @@ public function getBuildDir(): string return $this->buildDir; } + public function getSwooleVersion(): string + { + return trim(file_get_contents($this->rootDir . '/sapi/SWOOLE-VERSION.conf')); + } + public function getWorkDir(): string { return $this->workDir; @@ -419,8 +438,10 @@ public function doNotInstallLibrary(): void * @param string $httpProxyConfig * @return void */ - protected function downloadFile(string $url, string $file, ?object $project = null, string $httpProxyConfig = ''): void + protected function downloadFile(?object $project = null, string $httpProxyConfig = ''): void { + $url = $project->url; + $file = $project->path; $retry_number = DOWNLOAD_FILE_RETRY_NUMBE; $wait_retry = DOWNLOAD_FILE_WAIT_RETRY; $connect_timeout = DOWNLOAD_FILE_CONNECTION_TIMEOUT; @@ -435,48 +456,83 @@ protected function downloadFile(string $url, string $file, ?object $project = nu echo PHP_EOL; echo `$cmd`; echo PHP_EOL; - if (is_file($file) && (filesize($file) == 0)) { - unlink($file); - } - // 下载失败 - if (!is_file($file) or filesize($file) == 0) { - throw new Exception("Downloading file[" . basename($file) . "] from url[$url] failed"); - } - // 下载文件的 hash 不一致 - if (!$this->skipHashVerify and $project->enableHashVerify) { - if (!$project->hashVerify($file)) { - throw new Exception("The {$project->hashAlgo} of downloaded file[$file] is inconsistent with the configuration"); - } - } } /** - * @param string $file - * @param string $downloadScript + * @param object $project + * @param string $httpProxyConfig + * @return void + */ + public function downloadFileWithPie(?object $project = null, string $httpProxyConfig): void + { + $pieName = $project->pieName; + $pieVersion = $project->pieVersion; + $file = $project->file; + $path = $project->path; + + $workdir = $this->getWorkDir(); + $cmd = << \${TEMP_FILE} 2>&1 +cat \${TEMP_FILE} +SOURCE_CODE_DIR=\$(cat \${TEMP_FILE} | grep 'source to: ' | awk -F 'source to: ' '{ print $2 }') +rm -f \${TEMP_FILE} +echo "{$pieName}:{$pieVersion} source code: \${SOURCE_CODE_DIR}" +pie info {$pieName}:{$pieVersion}; +cd \${SOURCE_CODE_DIR} +tar -czf "{$workdir}/var/ext/{$file}" . +cp -f {$workdir}/var/ext/{$file} {$path} +cd {$workdir} +EOF; + echo $cmd; + echo PHP_EOL; + echo '------------RUNNING START-------------'; + echo PHP_EOL; + echo `$cmd`; + echo '------------RUNNING END-------------'; + echo PHP_EOL; + } + + /** * @param object|null $project + * @param string $httpProxyConfig * @return void */ - protected function downloadFileWithScript(string $file, string $downloadScript, object $project = null): void + protected function downloadFileWithScript(?object $project = null, string $httpProxyConfig): void { + + if (!empty($project->downloadScript) && !empty($project->downloadDirName)) { + $workDir = $this->getRootDir(); + $cacheDir = '${__DIR__}/var/tmp/' . $project->name; + $downloadScript = <<downloadScript} + cd {$project->downloadDirName} + test -f {$project->path} || tar -zcf {$project->path} ./ + cd {$workDir} + +EOF; + + } else { + throw new Exception( + "[Extension] withDownloadScript() require \$downloadDirName and \$downloadScript " + ); + } + echo PHP_EOL; echo $downloadScript; echo PHP_EOL; echo `$downloadScript`; echo PHP_EOL; - - if (is_file($file) && (filesize($file) == 0)) { - unlink($file); - } - // 下载失败 - if (!is_file($file) or filesize($file) == 0) { - throw new Exception("Downloading file[" . basename($file) . "] failed"); - } - // 下载文件的 hash 不一致 - if ($project->enableHashVerify) { - if (!$project->hashVerify($file)) { - throw new Exception("The {$project->hashAlgo} of downloaded file[$file] is inconsistent with the configuration"); - } - } } /** @@ -485,8 +541,14 @@ protected function downloadFileWithScript(string $file, string $downloadScript, */ public function addLibrary(Library $lib): void { - - if ($lib->enableDownloadScript || !empty($lib->url)) { + $downloadType = ""; //curl , download_script + if ($lib->enableDownloadScript) { + $downloadType = "download_script"; + } + if (!empty($lib->url)) { + $downloadType = "curl"; + } + if (!empty($downloadType)) { if (empty($lib->file)) { if ($lib->enableDownloadScript) { $lib->file = $lib->name . '.tar.gz'; @@ -499,6 +561,7 @@ public function addLibrary(Library $lib): void if ($lib->enableDownloadWithOriginURL === false) { $lib->url = $this->getInputOption('with-download-mirror-url') . '/lib/' . $lib->file; $lib->enableDownloadWithMirrorURL = true; + $downloadType = "curl"; } } @@ -530,36 +593,26 @@ public function addLibrary(Library $lib): void if (!$lib->enableHttpProxy) { $httpProxyConfig = ''; } - if ($lib->enableDownloadScript && !$lib->enableDownloadWithMirrorURL) { - if (!empty($lib->downloadScript) && !empty($lib->downloadDirName)) { - $workDir = $this->getRootDir(); - $cacheDir = '${__DIR__}/var/tmp/lib/' . $lib->name; - $lib->downloadScript = <<downloadScript} - cd {$lib->downloadDirName} - test -f {$lib->path} || tar -zcf {$lib->path} ./ - cd {$workDir} - -EOF; - - $this->downloadFileWithScript( - $lib->path, - $lib->downloadScript, - $lib - ); - } else { - throw new Exception( - "[Library] withDownloadScript() require \$downloadDirName and \$downloadScript " - ); - } + if ($downloadType == "download_script") { + $this->downloadFileWithScript($lib, $httpProxyConfig); } else { echo "[Library] {$lib->file} not found, downloading: " . $lib->url . PHP_EOL; - $this->downloadFile($lib->url, $lib->path, $lib, $httpProxyConfig); + $this->downloadFile($lib, $httpProxyConfig); + } + + $file = $lib->path; + if (is_file($file) && (filesize($file) == 0)) { + unlink($file); + } + // 下载失败 + if (!is_file($file) or filesize($file) == 0) { + throw new Exception("Downloading file [" . basename($file) . "] failed"); + } + // 下载文件的 hash 不一致 + if (!$this->skipHashVerify and $lib->enableHashVerify) { + if (!$lib->hashVerify($file)) { + throw new Exception("The {$lib->hashAlgo} of downloaded file[$file] is inconsistent with the configuration"); + } } } @@ -573,7 +626,7 @@ public function addLibrary(Library $lib): void } } else { throw new Exception( - "[Library] require url OR downloadscript " + "[Library] require url OR download_script " ); } if (!empty($lib->pkgConfig)) { @@ -609,48 +662,69 @@ public function addLibrary(Library $lib): void public function addExtension(Extension $ext): void { - if (!empty($ext->peclVersion) || $ext->enableDownloadScript || !empty($ext->url)) { + $extensionVersion = ""; + $downloadType = ""; //pecl , pie , curl , download_script + + if ( + !empty($ext->peclVersion) || + $ext->enableDownloadScript || + !empty($ext->url) || + !empty($ext->pieVersion) + ) { + if (!empty($ext->peclVersion)) { + $extensionVersion = $ext->peclVersion; + $downloadType = "pecl"; + $ext->file = $ext->name . '-' . $extensionVersion . '.tgz'; + $ext->url = "https://pecl.php.net/get/{$ext->file}"; + } + if (!empty($ext->pieVersion)) { + $extensionVersion = $ext->pieVersion; + $downloadType = "pie"; + $ext->file = $ext->name . '-' . $extensionVersion . '.tgz'; + $ext->url = ''; + } + if (!empty($ext->url)) { + $downloadType = "curl"; if (empty($ext->file)) { $ext->file = $ext->name . '.tgz'; } } - if (!empty($ext->peclVersion)) { - $ext->file = $ext->name . '-' . $ext->peclVersion . '.tgz'; - $ext->url = "https://pecl.php.net/get/{$ext->file}"; - } if ($ext->enableDownloadScript) { + $downloadType = "download_script"; if (empty($ext->file)) { $ext->file = $ext->name . '.tgz'; } $ext->url = ''; } + $ext->path = $this->extensionDir . '/' . $ext->file; if (!empty($this->getInputOption('with-download-mirror-url'))) { if ($ext->enableDownloadWithOriginURL === false) { $ext->url = $this->getInputOption('with-download-mirror-url') . '/ext/' . $ext->file; $ext->enableDownloadWithMirrorURL = true; + $downloadType = "curl"; } } - if (!$this->skipHashVerify and $ext->enableHashVerify) { - // 检查文件的 hash,若不一致删除后重新下载 - $ext->hashVerify($ext->path); - } - - //文件内容为空,重新下载 - if (file_exists($ext->path) && (filesize($ext->path) == 0)) { - unlink($ext->path); + if (file_exists($ext->path)) { + if (!$this->skipHashVerify and $ext->enableHashVerify) { + // 检查文件的 hash,若不一致删除后重新下载 + $ext->hashVerify($ext->path); + } + //文件内容为空,重新下载 + if ((filesize($ext->path) == 0)) { + unlink($ext->path); + } + //不使用缓存包,拉取最新源码包 + if ($ext->enableLatestTarball) { + unlink($ext->path); + } } - //不使用缓存包,拉取最新源码包 - if (file_exists($ext->path) && $ext->enableLatestTarball) { - unlink($ext->path); - } - $skip_download = ($this->getInputOption('skip-download')); - if (!$skip_download) { + if (!$this->getInputOption('skip-download')) { if (!file_exists($ext->path)) { $httpProxyConfig = $this->getProxyConfig(); if ($ext->enableGitProxy) { @@ -659,37 +733,39 @@ public function addExtension(Extension $ext): void if (!$ext->enableHttpProxy) { $httpProxyConfig = ''; } - if ($ext->enableDownloadScript && !$ext->enableDownloadWithMirrorURL) { - if (!empty($ext->downloadScript) && !empty($ext->downloadDirName)) { - $workDir = $this->getRootDir(); - $cacheDir = '${__DIR__}/var/tmp/ext/' . $ext->name; - $ext->downloadScript = <<downloadScript} - cd {$ext->downloadDirName} - test -f {$ext->path} || tar -zcf {$ext->path} ./ - cd {$workDir} - -EOF; + switch ($downloadType) { ////pecl , pie , curl , script + case "pecl" : + case "curl" : + echo "[Extension] {$ext->file} not found, downloading: " . $ext->url . PHP_EOL; + $this->downloadFile($ext, $httpProxyConfig); + break; + case "pie" : + echo "[Extension] {$ext->file} not found, download with pie.phar " . $ext->homePage . PHP_EOL; + $this->downloadFileWithPie($ext, $httpProxyConfig); + break; + case "download_script" : + $this->downloadFileWithScript($ext, $httpProxyConfig); + break; + default: + break; + } - $this->downloadFileWithScript( - $ext->path, - $ext->downloadScript, - $ext - ); - } else { - throw new Exception( - "[Extension] withDownloadScript() require \$downloadDirName and \$downloadScript " - ); + $file = $ext->path; + if (is_file($file) && (filesize($file) == 0)) { + unlink($file); + } + // 下载失败 + if (!is_file($file) or filesize($file) == 0) { + throw new Exception("Downloading file[" . basename($file) . "] failed"); + } + // 下载文件的 hash 不一致 + if (!$this->skipHashVerify and $ext->enableHashVerify) { + if (!$ext->hashVerify($file)) { + throw new Exception("The {$ext->hashAlgo} of downloaded file[$file] is inconsistent with the configuration"); } - } else { - echo "[Extension] {$ext->file} not found, downloading: " . $ext->url . PHP_EOL; - $this->downloadFile($ext->url, $ext->path, $ext, $httpProxyConfig); } + } else { + echo "[Extension] file cached: " . $ext->file . PHP_EOL; } $dst_dir = "{$this->rootDir}/ext/{$ext->name}"; @@ -707,9 +783,10 @@ public function addExtension(Extension $ext): void echo PHP_EOL; } - if (($ext->enableLatestTarball || !$ext->enableBuildCached) + if ( + ($ext->enableLatestTarball || !$ext->enableBuildCached) && - (!empty($ext->peclVersion) || $ext->enableDownloadScript || !empty($ext->url)) + (!empty($downloadType)) ) { $this->deleteDirectoryIfExists($dst_dir); } @@ -1172,6 +1249,7 @@ public function execute(): void $this->mkdirIfNotExists($this->rootDir . '/bin'); $this->generateFile(__DIR__ . '/template/license.php', $this->rootDir . '/bin/LICENSE'); $this->generateFile(__DIR__ . '/template/credits.php', $this->rootDir . '/bin/credits.html'); + $this->generateFile(__DIR__ . '/template/nfpm-yaml.php', $this->rootDir . '/nfpm-pkg.yaml'); copy($this->rootDir . '/sapi/scripts/pack-sfx.php', $this->rootDir . '/bin/pack-sfx.php'); diff --git a/sapi/src/builder/extension/swoole.php b/sapi/src/builder/extension/swoole.php index eee0cd7192..4c2b711277 100644 --- a/sapi/src/builder/extension/swoole.php +++ b/sapi/src/builder/extension/swoole.php @@ -52,12 +52,16 @@ $p->withExportVariable('URING_LIBS', '$(pkg-config --libs --static liburing)'); } - - $p->addExtension((new Extension('swoole')) + $p->addExtension( + (new Extension('swoole')) ->withHomePage('https://github.com/swoole/swoole-src') ->withLicense('https://github.com/swoole/swoole-src/blob/master/LICENSE', Extension::LICENSE_APACHE2) ->withManual('https://wiki.swoole.com/#/') - ->withFile($file) + //->withAutoUpdateFile() + //->withFile($file) + //->withPeclVersion('6.1.6') + //->withPieName('swoole/swoole') + //->withPieVersion('v6.1.6') ->withDownloadScript( 'swoole-src', <<withOptions(implode(' ', $options)) ->withBuildCached(false) ->withDependentLibraries(...$dependentLibraries) - ->withDependentExtensions(...$dependentExtensions)); + ->withDependentExtensions(...$dependentExtensions) + ); if ($p->isMacos()) { # 测试 macos 专有特性 @@ -95,8 +100,8 @@ $p->withExportVariable('ZSTD_LIBS', '$(pkg-config --libs --static libzstd)'); $p->withExportVariable('SWOOLE_ODBC_LIBS', '$(pkg-config --libs-only-L --libs-only-l --static odbc odbccr odbcinst readline ncursesw ) ' . " -L{$libiconv_prefix}/lib -liconv "); - - + // Download swoole-src + # shell_exec(__DIR__ . '/sapi/scripts/download-swoole-src-archive.sh'); /* $p->withBeforeConfigureScript('swoole', function () use ($p) { $workDir = $p->getWorkDir(); @@ -135,4 +140,5 @@ return $shell; }); */ + }; diff --git a/sapi/src/builder/nfpm/deb-depends.php b/sapi/src/builder/nfpm/deb-depends.php new file mode 100644 index 0000000000..f73f961a86 --- /dev/null +++ b/sapi/src/builder/nfpm/deb-depends.php @@ -0,0 +1,43 @@ + '>=2.35', + "libgcc-s1" => '>= 3.0', + "libstdc++6" => '>= 11', + "libyaml-0-2" => '', + "libssl3" => '', + "libxml2" => '', + "libmagickcore-6.q16-6" => '', + "libmagickcore-6.q16-6-extra" => '', + "libmagickcore-6.q16hdri-6" => '', + "libmagickcore-6.q16hdri-6-extra" => '', + "libmagickwand-6.q16-6" => '', + "libmagickwand-6.q16hdri-6" => '', + "libpng16-16" => '', + "libjpeg8" => '', + "libjpeg-turbo8" => '', + "libfreetype6" => '', + "libc-ares2" => '', + "libpcre2-8-0" => '', + "libsodium23" => '', + "libcurl4" => '', + "libmariadb3" => '', + "libaio1" => '', + "zlib1g" => '', + "mime-support" => '', + "tzdata" => '', + "ucf" => '', + "libargon2-1" => '', + "libsqlite3-0" => '', + "libbrotli1" => '', + "libpq5" => '', + "unixodbc" => '', + "firebird3.0-common" => '', + "libzstd1" => '', + "libssh2-1" => '', + "liburing2" => '', + "libedit2" => '', + "libmagic1" => '', + 'libonig5' => '', + 'libxslt1.1' => '', + 'libzip4' => '', +]; diff --git a/sapi/src/template/deb-pkg.php b/sapi/src/template/deb-pkg.php new file mode 100644 index 0000000000..96cbbb2d86 --- /dev/null +++ b/sapi/src/template/deb-pkg.php @@ -0,0 +1,19 @@ +name: "swoole-cli" +arch: "getDebArch()?>" +platform: "getOsType()?>" +version: "getSwooleVersion()?>" +section: "default" +priority: "extra" +maintainer: "service " +description: | + SWOOLE-CLI is a php binary distribution composed swoole & php-core & cli & fpm and mostly of common extensions +homepage: "https://github.com/swoole/swoole-cli" + +depends: +nfpmDepends['deb'] as $pkg => $version) : ?> + - () + + +contents: + - src: "bin/swoole-cli" + dst: "/usr/local/bin/swoole-cli" diff --git a/sapi/src/template/make.php b/sapi/src/template/make.php index 293ad1b529..fead7787f1 100755 --- a/sapi/src/template/make.php +++ b/sapi/src/template/make.php @@ -15,7 +15,10 @@ PREPARE_ARGS="getPrepareArgs())?>" export LOGICAL_PROCESSORS=logicalProcessors). PHP_EOL ?> export CMAKE_BUILD_PARALLEL_LEVEL=maxJob. PHP_EOL ?> - +isMacos()) :?> +# 兼容 最低 macOS 版本 +export MACOSX_DEPLOYMENT_TARGET=12.0 + export CC=cCompiler . PHP_EOL ?> export CXX=cppCompiler . PHP_EOL ?> export LD=lld . PHP_EOL ?> @@ -392,6 +395,23 @@ exit 0 } +make_swoole_cli_with_linux_gcc() { + if [ ! -f bin/swoole-cli ] ;then + ./buildconf --force + ./sapi/scripts/build-swoole-cli-with-linux-gcc.sh + fi +} + +make_nfpm_pkg() { + make_swoole_cli_with_linux_gcc + ./bin/swoole-cli sapi/scripts/copy-depend-libs.php + patchelf --force-rpath --set-rpath '/usr/local/swoole-cli/lib' bin/swoole-cli + NFPM_PKG_FILENAME=swoole-cli-getSwooleVersion()?>-linux-getSystemArch()?>-glibc + nfpm pkg --config nfpm-pkg.yaml --target "${NFPM_PKG_FILENAME}.rpm" + nfpm pkg --config nfpm-pkg.yaml --target "${NFPM_PKG_FILENAME}.deb" + return 0 +} + help() { echo "./make.sh docker-build [ china | ustc | tuna ]" echo "./make.sh docker-bash" @@ -415,6 +435,7 @@ echo "./make.sh list-swoole-branch" echo "./make.sh switch-swoole-branch" echo "./make.sh [library-name]" + echo "./make.sh nfpm-pkg" echo "./make.sh clean-[library-name]" echo "./make.sh clean-[library-name]-cached" echo "./make.sh clean" @@ -551,6 +572,8 @@ echo "name ?>" exit 0 +elif [ "$1" = "nfpm-pkg" ] ;then + make_nfpm_pkg elif [ "$1" = "clean" ] ;then make_clean exit 0 diff --git a/sapi/src/template/nfpm-yaml.php b/sapi/src/template/nfpm-yaml.php new file mode 100644 index 0000000000..430f68e3a1 --- /dev/null +++ b/sapi/src/template/nfpm-yaml.php @@ -0,0 +1,24 @@ +name: "swoole-cli" +arch: "getDebArch()?>" +platform: "getOsType()?>" +version: "getSwooleVersion()?>" +section: "default" +priority: "extra" +maintainer: "service " +description: | + SWOOLE-CLI is a php binary distribution composed swoole & php-core & cli & fpm and mostly of common extensions +homepage: "https://github.com/swoole/swoole-cli" + +overrides: + deb: + depends: + - libc6 (>=2.35) + rpm: + depends: + - glibc >= 2.35 + +contents: + - src: "bin/swoole-cli" + dst: "/usr/local/bin/swoole-cli" + - src: "runtime/libs/" + dst: "/usr/local/swoole-cli/lib/" diff --git a/setup-php-runtime.sh b/setup-php-runtime.sh index e3244f3424..f2b3e212f6 100644 --- a/setup-php-runtime.sh +++ b/setup-php-runtime.sh @@ -51,7 +51,7 @@ esac APP_VERSION='v5.1.3' APP_NAME='swoole-cli' VERSION='v5.1.3.0' -PIE_VERSION="1.2.1" +PIE_VERSION="1.3.5" # 查看pie最新版本 https://github.com/php/pie/releases/latest cd ${__PROJECT__} diff --git a/var/.gitkeep b/var/.gitkeep new file mode 100644 index 0000000000..e69de29bb2