mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-03 06:45:39 +08:00
Compare commits
43 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5d2bd93bd7 | ||
|
|
4ba92b08ca | ||
|
|
11076b1355 | ||
|
|
71770a0a5f | ||
|
|
98d3766fe8 | ||
|
|
1fdb6b439e | ||
|
|
3136d6edc1 | ||
|
|
3e84becf77 | ||
|
|
1632c25223 | ||
|
|
e6c308c242 | ||
|
|
3fcb7ebf03 | ||
|
|
7416b8079b | ||
|
|
bde18054e5 | ||
|
|
954f8f4ddc | ||
|
|
0fee628842 | ||
|
|
69e6d82e83 | ||
|
|
e1e6270d86 | ||
|
|
30af182aff | ||
|
|
3ecc603770 | ||
|
|
15c2935d48 | ||
|
|
7a8e0a7e67 | ||
|
|
d98d6aeffb | ||
|
|
aaa4510f25 | ||
|
|
b14894fab7 | ||
|
|
1a87ce4194 | ||
|
|
6b96feb538 | ||
|
|
21dbb8af46 | ||
|
|
4d227ca7ef | ||
|
|
3a2683bb0c | ||
|
|
bd8f91d466 | ||
|
|
254844b5ec | ||
|
|
4cb1764439 | ||
|
|
847535721c | ||
|
|
e3c542d9df | ||
|
|
b4ed4ea956 | ||
|
|
99aadd3e73 | ||
|
|
c77dc1af6c | ||
|
|
9fd56987ef | ||
|
|
1e494a2213 | ||
|
|
da6d9ffb4b | ||
|
|
d3a001d808 | ||
|
|
d445668d9f | ||
|
|
32f14e16c8 |
32
.github/workflows/build-linux-arm.yml
vendored
32
.github/workflows/build-linux-arm.yml
vendored
@@ -45,14 +45,30 @@ jobs:
|
||||
name: build ${{ inputs.version }} on ${{ inputs.operating-system }}
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
# Cache composer dependencies
|
||||
- id: cache-composer-deps
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: vendor
|
||||
key: composer-dependencies
|
||||
|
||||
# If there's no Composer cache, install dependencies
|
||||
- if: steps.cache-composer-deps.outputs.cache-hit != 'true'
|
||||
run: composer update --no-dev --classmap-authoritative
|
||||
|
||||
- name: Generate hashed key for download cache
|
||||
run: |
|
||||
INPUT_HASH=$(echo "${{ runner.os }}-${{ inputs.version }}-${{ inputs.extensions }}" | sha256sum | awk '{print $1}')
|
||||
echo "INPUT_HASH=${INPUT_HASH}" >> $GITHUB_ENV
|
||||
|
||||
# Cache downloaded source
|
||||
- id: cache-download
|
||||
uses: actions/cache@v3
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: downloads
|
||||
key: php-${{ inputs.version }}-dependencies-${{ inputs.extensions }}
|
||||
key: php-${{ env.INPUT_HASH }}
|
||||
|
||||
# With or without debug
|
||||
- if: inputs.debug == true
|
||||
@@ -75,31 +91,31 @@ jobs:
|
||||
|
||||
# Upload cli executable
|
||||
- if: ${{ inputs.build-cli == true }}
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: php-${{ inputs.version }}-linux-${{ inputs.operating-system }}
|
||||
path: buildroot/bin/php
|
||||
|
||||
# Upload micro self-extracted executable
|
||||
- if: ${{ inputs.build-micro == true }}
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: micro-${{ inputs.version }}-linux-${{ inputs.operating-system }}
|
||||
path: buildroot/bin/micro.sfx
|
||||
|
||||
# Upload fpm executable
|
||||
- if: ${{ inputs.build-fpm == true }}
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: php-fpm-${{ inputs.version }}-linux-${{ inputs.operating-system }}
|
||||
path: buildroot/bin/php-fpm
|
||||
|
||||
# Upload extensions metadata
|
||||
- uses: actions/upload-artifact@v3
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: license-files
|
||||
path: buildroot/license/
|
||||
- uses: actions/upload-artifact@v3
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: build-meta
|
||||
path: |
|
||||
|
||||
23
.github/workflows/build-linux-x86_64.yml
vendored
23
.github/workflows/build-linux-x86_64.yml
vendored
@@ -39,11 +39,11 @@ jobs:
|
||||
name: build ${{ inputs.version }} on Linux x86_64
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
# Cache composer dependencies
|
||||
- id: cache-composer-deps
|
||||
uses: actions/cache@v3
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: vendor
|
||||
key: composer-dependencies
|
||||
@@ -52,12 +52,17 @@ jobs:
|
||||
- if: steps.cache-composer-deps.outputs.cache-hit != 'true'
|
||||
run: composer update --no-dev --classmap-authoritative
|
||||
|
||||
- name: Generate hashed key for download cache
|
||||
run: |
|
||||
INPUT_HASH=$(echo "${{ runner.os }}-${{ inputs.version }}-${{ inputs.extensions }}" | sha256sum | awk '{print $1}')
|
||||
echo "INPUT_HASH=${INPUT_HASH}" >> $GITHUB_ENV
|
||||
|
||||
# Cache downloaded source
|
||||
- id: cache-download
|
||||
uses: actions/cache@v3
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: downloads
|
||||
key: php-${{ inputs.version }}-dependencies-${{ inputs.extensions }}
|
||||
key: php-${{ env.INPUT_HASH }}
|
||||
|
||||
# With or without debug
|
||||
- if: inputs.debug == true
|
||||
@@ -80,31 +85,31 @@ jobs:
|
||||
|
||||
# Upload cli executable
|
||||
- if: ${{ inputs.build-cli == true }}
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: php-${{ inputs.version }}-${{ env.SPC_BUILD_OS }}
|
||||
path: buildroot/bin/php
|
||||
|
||||
# Upload micro self-extracted executable
|
||||
- if: ${{ inputs.build-micro == true }}
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: micro-${{ inputs.version }}-${{ env.SPC_BUILD_OS }}
|
||||
path: buildroot/bin/micro.sfx
|
||||
|
||||
# Upload fpm executable
|
||||
- if: ${{ inputs.build-fpm == true }}
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: php-fpm-${{ inputs.version }}-${{ env.SPC_BUILD_OS }}
|
||||
path: buildroot/bin/php-fpm
|
||||
|
||||
# Upload extensions metadata
|
||||
- uses: actions/upload-artifact@v3
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: license-files
|
||||
path: buildroot/license/
|
||||
- uses: actions/upload-artifact@v3
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: build-meta
|
||||
path: |
|
||||
|
||||
23
.github/workflows/build-macos-aarch64.yml
vendored
23
.github/workflows/build-macos-aarch64.yml
vendored
@@ -39,7 +39,7 @@ jobs:
|
||||
name: build ${{ inputs.version }} on macOS arm64
|
||||
runs-on: macos-14
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
# Install macOS missing packages and mark os suffix
|
||||
- run: |
|
||||
@@ -58,7 +58,7 @@ jobs:
|
||||
|
||||
# Cache composer dependencies
|
||||
- id: cache-composer-deps
|
||||
uses: actions/cache@v3
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: vendor
|
||||
key: composer-dependencies
|
||||
@@ -67,12 +67,17 @@ jobs:
|
||||
- if: steps.cache-composer-deps.outputs.cache-hit != 'true'
|
||||
run: composer update --no-dev --classmap-authoritative
|
||||
|
||||
- name: Generate hashed key for download cache
|
||||
run: |
|
||||
INPUT_HASH=$(echo "${{ runner.os }}-${{ inputs.version }}-${{ inputs.extensions }}" | sha256sum | awk '{print $1}')
|
||||
echo "INPUT_HASH=${INPUT_HASH}" >> $GITHUB_ENV
|
||||
|
||||
# Cache downloaded source
|
||||
- id: cache-download
|
||||
uses: actions/cache@v3
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: downloads
|
||||
key: php-${{ inputs.version }}-dependencies-${{ inputs.extensions }}
|
||||
key: php-${{ env.INPUT_HASH }}
|
||||
|
||||
# With or without debug
|
||||
- if: inputs.debug == true
|
||||
@@ -95,31 +100,31 @@ jobs:
|
||||
|
||||
# Upload cli executable
|
||||
- if: ${{ inputs.build-cli == true }}
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: php-${{ inputs.version }}-${{ env.SPC_BUILD_OS }}
|
||||
path: buildroot/bin/php
|
||||
|
||||
# Upload micro self-extracted executable
|
||||
- if: ${{ inputs.build-micro == true }}
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: micro-${{ inputs.version }}-${{ env.SPC_BUILD_OS }}
|
||||
path: buildroot/bin/micro.sfx
|
||||
|
||||
# Upload fpm executable
|
||||
- if: ${{ inputs.build-fpm == true }}
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: php-fpm-${{ inputs.version }}-${{ env.SPC_BUILD_OS }}
|
||||
path: buildroot/bin/php-fpm
|
||||
|
||||
# Upload extensions metadata
|
||||
- uses: actions/upload-artifact@v3
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: license-files
|
||||
path: buildroot/license/
|
||||
- uses: actions/upload-artifact@v3
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: build-meta
|
||||
path: |
|
||||
|
||||
33
.github/workflows/build-macos-x86_64.yml
vendored
33
.github/workflows/build-macos-x86_64.yml
vendored
@@ -37,18 +37,26 @@ env:
|
||||
jobs:
|
||||
build:
|
||||
name: build ${{ inputs.version }} on macOS x86_64
|
||||
runs-on: macos-latest
|
||||
runs-on: macos-13
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
# Install macOS missing packages and mark os suffix
|
||||
- run: |
|
||||
brew install automake gzip
|
||||
echo "SPC_BUILD_OS=macos" >> $GITHUB_ENV
|
||||
|
||||
- name: "Setup PHP"
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: 8.1
|
||||
tools: pecl, composer
|
||||
extensions: curl, openssl, mbstring, tokenizer
|
||||
ini-values: memory_limit=-1
|
||||
|
||||
# Cache composer dependencies
|
||||
- id: cache-composer-deps
|
||||
uses: actions/cache@v3
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: vendor
|
||||
key: composer-dependencies
|
||||
@@ -57,12 +65,17 @@ jobs:
|
||||
- if: steps.cache-composer-deps.outputs.cache-hit != 'true'
|
||||
run: composer update --no-dev --classmap-authoritative
|
||||
|
||||
- name: Generate hashed key for download cache
|
||||
run: |
|
||||
INPUT_HASH=$(echo "${{ runner.os }}-${{ inputs.version }}-${{ inputs.extensions }}" | sha256sum | awk '{print $1}')
|
||||
echo "INPUT_HASH=${INPUT_HASH}" >> $GITHUB_ENV
|
||||
|
||||
# Cache downloaded source
|
||||
- id: cache-download
|
||||
uses: actions/cache@v3
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: downloads
|
||||
key: php-${{ inputs.version }}-dependencies-${{ inputs.extensions }}
|
||||
key: php-${{ env.INPUT_HASH }}
|
||||
|
||||
# With or without debug
|
||||
- if: inputs.debug == true
|
||||
@@ -85,31 +98,31 @@ jobs:
|
||||
|
||||
# Upload cli executable
|
||||
- if: ${{ inputs.build-cli == true }}
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: php-${{ inputs.version }}-${{ env.SPC_BUILD_OS }}
|
||||
path: buildroot/bin/php
|
||||
|
||||
# Upload micro self-extracted executable
|
||||
- if: ${{ inputs.build-micro == true }}
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: micro-${{ inputs.version }}-${{ env.SPC_BUILD_OS }}
|
||||
path: buildroot/bin/micro.sfx
|
||||
|
||||
# Upload fpm executable
|
||||
- if: ${{ inputs.build-fpm == true }}
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: php-fpm-${{ inputs.version }}-${{ env.SPC_BUILD_OS }}
|
||||
path: buildroot/bin/php-fpm
|
||||
|
||||
# Upload extensions metadata
|
||||
- uses: actions/upload-artifact@v3
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: license-files
|
||||
path: buildroot/license/
|
||||
- uses: actions/upload-artifact@v3
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: build-meta
|
||||
path: |
|
||||
|
||||
108
.github/workflows/build-windows-x86_64.yml
vendored
Normal file
108
.github/workflows/build-windows-x86_64.yml
vendored
Normal file
@@ -0,0 +1,108 @@
|
||||
name: CI on x86_64 Windows
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
version:
|
||||
required: true
|
||||
description: php version to compile
|
||||
default: '8.2'
|
||||
type: choice
|
||||
options:
|
||||
- '8.3'
|
||||
- '8.2'
|
||||
- '8.1'
|
||||
- '8.0'
|
||||
- '7.4'
|
||||
build-cli:
|
||||
description: build cli binary
|
||||
default: true
|
||||
type: boolean
|
||||
build-micro:
|
||||
description: build phpmicro binary
|
||||
type: boolean
|
||||
extensions:
|
||||
description: extensions to compile (comma separated)
|
||||
required: true
|
||||
type: string
|
||||
debug:
|
||||
type: boolean
|
||||
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: build ${{ inputs.version }} on Windows x86_64
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
# Cache composer dependencies
|
||||
- id: cache-composer-deps
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: vendor
|
||||
key: composer-dependencies
|
||||
|
||||
# If there's no Composer cache, install dependencies
|
||||
- if: steps.cache-composer-deps.outputs.cache-hit != 'true'
|
||||
run: composer update --no-dev --classmap-authoritative
|
||||
|
||||
- name: Generate hashed key for download cache
|
||||
shell: bash
|
||||
run: |
|
||||
INPUT_HASH=$(echo "${{ runner.os }}-${{ inputs.version }}-${{ inputs.extensions }}" | sha256sum | awk '{print $1}')
|
||||
echo "INPUT_HASH=${INPUT_HASH}" >> "$GITHUB_ENV"
|
||||
|
||||
# Cache downloaded source
|
||||
- id: cache-download
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: downloads
|
||||
key: php-${{ env.INPUT_HASH }}
|
||||
|
||||
# With or without debug
|
||||
- if: inputs.debug == true
|
||||
run: echo "SPC_BUILD_DEBUG=--debug" >> $env:GITHUB_ENV
|
||||
|
||||
# With target select: cli, micro or both
|
||||
- if: ${{ inputs.build-cli == true }}
|
||||
run: echo "SPC_BUILD_CLI=--build-cli" >> $env:GITHUB_ENV
|
||||
- if: ${{ inputs.build-micro == true }}
|
||||
run: echo "SPC_BUILD_MICRO=--build-micro" >> $env:GITHUB_ENV
|
||||
|
||||
- run: ./bin/spc doctor
|
||||
|
||||
# If there's no dependencies cache, fetch sources, with or without debug
|
||||
- if: steps.cache-download.outputs.cache-hit != 'true'
|
||||
run: ./bin/spc download --with-php="${{ inputs.version }}" --for-extensions="${{ inputs.extensions }}" ${{ env.SPC_BUILD_DEBUG }}
|
||||
|
||||
# Run build command
|
||||
- run: ./bin/spc build "${{ inputs.extensions }}" ${{ env.SPC_BUILD_DEBUG }} ${{ env.SPC_BUILD_CLI }} ${{ env.SPC_BUILD_MICRO }} ${{ env.SPC_BUILD_FPM }}
|
||||
|
||||
# Upload cli executable
|
||||
- if: ${{ inputs.build-cli == true }}
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: php-${{ inputs.version }}
|
||||
path: buildroot/bin/php.exe
|
||||
|
||||
# Upload micro self-extracted executable
|
||||
- if: ${{ inputs.build-micro == true }}
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: micro-${{ inputs.version }}
|
||||
path: buildroot/bin/micro.sfx
|
||||
|
||||
# Upload extensions metadata
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: license-files
|
||||
path: buildroot/license/
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: build-meta
|
||||
path: |
|
||||
buildroot/build-extensions.json
|
||||
buildroot/build-libraries.json
|
||||
13
.github/workflows/release-build.yml
vendored
13
.github/workflows/release-build.yml
vendored
@@ -11,13 +11,13 @@ on:
|
||||
jobs:
|
||||
build-release-artifacts:
|
||||
name: "Build SPC Binary"
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: macos-14
|
||||
strategy:
|
||||
matrix:
|
||||
php-version:
|
||||
- "8.2"
|
||||
micro-version:
|
||||
- "8.2.16"
|
||||
- "8.2.18"
|
||||
operating-system:
|
||||
- "linux-x86_64"
|
||||
- "macos-x86_64"
|
||||
@@ -45,7 +45,7 @@ jobs:
|
||||
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: "Cache Composer dependencies"
|
||||
uses: "actions/cache@v3"
|
||||
uses: "actions/cache@v4"
|
||||
with:
|
||||
path: "${{ steps.composer-cache.outputs.dir }}"
|
||||
key: "php-${{ matrix.php-version }}-locked-composer-${{ hashFiles('**/composer.lock') }}"
|
||||
@@ -76,6 +76,9 @@ jobs:
|
||||
else
|
||||
chmod +x spc
|
||||
fi
|
||||
if [ "${{ matrix.operating-system }}" = "macos-aarch64" ] || [ "${{ matrix.operating-system }}" = "macos-x86_64" ]; then
|
||||
sudo xattr -cr ./spc
|
||||
fi
|
||||
|
||||
- name: "Archive Executable"
|
||||
run: |
|
||||
@@ -83,7 +86,7 @@ jobs:
|
||||
tar -czf spc-${{ matrix.operating-system }}.tar.gz spc
|
||||
echo "filename=spc-${{ matrix.operating-system }}.tar.gz" >> $GITHUB_ENV
|
||||
echo "OS=${{ matrix.operating-system }}" >> $GITHUB_ENV
|
||||
if [ "${{ matrix.operating-system }}" == "linux-x86_64" ]; then
|
||||
if [ "${{ matrix.operating-system }}" == "macos-aarch64" ]; then
|
||||
./spc dev:extensions
|
||||
fi
|
||||
else
|
||||
@@ -119,7 +122,7 @@ jobs:
|
||||
TARGET: ${{ secrets.DEPLOY_SERVER_TARGET_SPC_NIGHTLY }}
|
||||
|
||||
- name: "Upload Artifact"
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
path: spc${{ env.SUFFIX }}
|
||||
name: spc-${{ matrix.operating-system }}${{ env.SUFFIX }}
|
||||
|
||||
14
.github/workflows/tests.yml
vendored
14
.github/workflows/tests.yml
vendored
@@ -48,7 +48,7 @@ jobs:
|
||||
|
||||
- name: "Cache Composer packages"
|
||||
id: composer-cache
|
||||
uses: actions/cache@v3
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: vendor
|
||||
key: ${{ runner.os }}-phpstan-${{ hashFiles('**/composer.lock') }}
|
||||
@@ -86,7 +86,7 @@ jobs:
|
||||
|
||||
- name: "Cache Composer packages"
|
||||
id: composer-cache
|
||||
uses: actions/cache@v3
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: vendor
|
||||
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
|
||||
@@ -113,7 +113,7 @@ jobs:
|
||||
- "8.3"
|
||||
os:
|
||||
- ubuntu-latest
|
||||
- macos-latest
|
||||
- macos-13
|
||||
- windows-latest
|
||||
- macos-14
|
||||
fail-fast: false
|
||||
@@ -136,9 +136,9 @@ jobs:
|
||||
echo "GITHUB_TOKEN=${{ secrets.TEST_GH_TOKEN }}" >> $GITHUB_ENV
|
||||
fi
|
||||
|
||||
- name: "Cache Composer packages"
|
||||
- name: "Cache composer packages"
|
||||
id: composer-cache
|
||||
uses: actions/cache@v3
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: vendor
|
||||
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
|
||||
@@ -165,7 +165,7 @@ jobs:
|
||||
max_attempts: 3
|
||||
retry_on: error
|
||||
command: |
|
||||
bin/spc download --for-extensions="$(php src/globals/test-extensions.php extensions)" --for-libs="$(php src/globals/test-extensions.php libs)" --with-php=${{ matrix.php }} --ignore-cache-sources=php-src --debug
|
||||
bin/spc download --for-extensions="$(php src/globals/test-extensions.php extensions)" --for-libs="$(php src/globals/test-extensions.php libs)" --with-php=${{ matrix.php }} --ignore-cache-sources=php-src --debug --retry=3
|
||||
|
||||
- name: "Run Build Tests (build)"
|
||||
run: bin/spc build "$(php src/globals/test-extensions.php extensions)" $(php src/globals/test-extensions.php libs_cmd) --build-cli --build-micro --build-fpm --debug
|
||||
run: bin/spc build "$(php src/globals/test-extensions.php extensions)" $(php src/globals/test-extensions.php zts) --with-libs="$(php src/globals/test-extensions.php libs)" --build-cli --build-micro --build-fpm --debug
|
||||
|
||||
11
README-zh.md
11
README-zh.md
@@ -43,9 +43,12 @@ static-php-cli(简称 `spc`)有许多特性:
|
||||
|
||||
如果你不想自行编译 PHP,可以从本项目现有的示例 Action 下载 Artifact,也可以从自托管的服务器下载。
|
||||
|
||||
- [扩展组合 - common](https://dl.static-php.dev/static-php-cli/common/):common 组合包含了约 [30+](https://dl.static-php.dev/static-php-cli/common/README.txt) 个常用扩展,体积为 22MB 左右。
|
||||
- [扩展组合 - bulk](https://dl.static-php.dev/static-php-cli/bulk/):bulk 组合包含了 [50+](https://dl.static-php.dev/static-php-cli/bulk/README.txt) 个扩展,体积为 70MB 左右。
|
||||
- [扩展组合 - minimal](https://dl.static-php.dev/static-php-cli/minimal/):minimal 组合包含了 [5](https://dl.static-php.dev/static-php-cli/minimal/README.txt) 个扩展,体积为 6MB 左右。
|
||||
- [扩展组合 - common](https://dl.static-php.dev/static-php-cli/common/):common 组合包含了约 [30+](https://dl.static-php.dev/static-php-cli/common/README.txt) 个常用扩展,体积为 7.5MB 左右。
|
||||
- [扩展组合 - bulk](https://dl.static-php.dev/static-php-cli/bulk/):bulk 组合包含了 [50+](https://dl.static-php.dev/static-php-cli/bulk/README.txt) 个扩展,体积为 25MB 左右。
|
||||
- [扩展组合 - minimal](https://dl.static-php.dev/static-php-cli/minimal/):minimal 组合包含了 [5](https://dl.static-php.dev/static-php-cli/minimal/README.txt) 个扩展,体积为 3MB 左右。
|
||||
|
||||
> Linux 和 Windows 默认启用了 UPX 压缩,可减小 30~50% 的 PHP 二进制体积。
|
||||
> macOS 当前不支持 UPX,所以上述预编译的 macOS 版本体积可能较大。
|
||||
|
||||
对于 Windows 系统,目前支持的扩展较少,故仅提供 SPC 自身运行的最小扩展组合的 `cli` 和 `micro`:[扩展组合 - spc-min](https://dl.static-php.dev/static-php-cli/windows/spc-min/)。
|
||||
|
||||
@@ -66,7 +69,7 @@ static-php-cli(简称 `spc`)有许多特性:
|
||||
|---------|----------------------|----------------------|
|
||||
| macOS | :octocat: :computer: | :octocat: :computer: |
|
||||
| Linux | :octocat: :computer: | :octocat: :computer: |
|
||||
| Windows | :computer: | |
|
||||
| Windows | :octocat: :computer: | |
|
||||
| FreeBSD | :computer: | :computer: |
|
||||
|
||||
当前支持编译的 PHP 版本:
|
||||
|
||||
11
README.md
11
README.md
@@ -49,9 +49,12 @@ If you don't want to build or want to test first, you can download example pre-c
|
||||
Below are several precompiled static-php binaries with different extension combinations,
|
||||
which can be downloaded directly according to your needs.
|
||||
|
||||
- [Extension-Combination - common](https://dl.static-php.dev/static-php-cli/common/): `common` contains about [30+](https://dl.static-php.dev/static-php-cli/common/README.txt) commonly used extensions, and the size is about 22MB.
|
||||
- [Extension-Combination - bulk](https://dl.static-php.dev/static-php-cli/bulk/): `bulk` contains [50+](https://dl.static-php.dev/static-php-cli/bulk/README.txt) extensions and is about 70MB in size.
|
||||
- [Extension-Combination - minimal](https://dl.static-php.dev/static-php-cli/minimal/): `minimal` contains [5](https://dl.static-php.dev/static-php-cli/minimal/README.txt) extensions and is about 6MB in size.
|
||||
- [Extension-Combination - common](https://dl.static-php.dev/static-php-cli/common/): `common` contains about [30+](https://dl.static-php.dev/static-php-cli/common/README.txt) commonly used extensions, and the size is about 7.5MB.
|
||||
- [Extension-Combination - bulk](https://dl.static-php.dev/static-php-cli/bulk/): `bulk` contains [50+](https://dl.static-php.dev/static-php-cli/bulk/README.txt) extensions and is about 25MB in size.
|
||||
- [Extension-Combination - minimal](https://dl.static-php.dev/static-php-cli/minimal/): `minimal` contains [5](https://dl.static-php.dev/static-php-cli/minimal/README.txt) extensions and is about 3MB in size.
|
||||
|
||||
> Linux and Windows supports UPX compression for binaries, which can reduce the size of the binary by 30% to 50%.
|
||||
> macOS does not support UPX compression, so the size of the pre-built binaries for mac is larger.
|
||||
|
||||
For Windows systems, there are currently fewer extensions supported,
|
||||
so only `cli` and `micro` that run the minimum extension combination of SPC itself are provided: [Extension-Combination - spc-min](https://dl.static-php.dev/static-php-cli/windows/spc-min/).
|
||||
@@ -74,7 +77,7 @@ Here is the supported OS and arch, where :octocat: represents support for GitHub
|
||||
|---------|----------------------|----------------------|
|
||||
| macOS | :octocat: :computer: | :octocat: :computer: |
|
||||
| Linux | :octocat: :computer: | :octocat: :computer: |
|
||||
| Windows | :computer: | |
|
||||
| Windows | :octocat: :computer: | |
|
||||
| FreeBSD | :computer: | :computer: |
|
||||
|
||||
Currently supported PHP versions for compilation:
|
||||
|
||||
1
box.json
1
box.json
@@ -4,6 +4,7 @@
|
||||
"blacklist": [
|
||||
".github"
|
||||
],
|
||||
"compression": "GZ",
|
||||
"directories": [
|
||||
"config",
|
||||
"src",
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
"zhamao/logger": "^1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"captainhook/captainhook": "^5.10",
|
||||
"captainhook/plugin-composer": "^5.3",
|
||||
"captainhook/captainhook-phar": "^5.23",
|
||||
"captainhook/hook-installer": "^1.0",
|
||||
"friendsofphp/php-cs-fixer": "^3.25",
|
||||
"humbug/box": "^4.5",
|
||||
"nunomaduro/collision": "^7.8",
|
||||
@@ -50,7 +50,9 @@
|
||||
"config": {
|
||||
"allow-plugins": {
|
||||
"phpstan/extension-installer": true,
|
||||
"captainhook/plugin-composer": true
|
||||
"captainhook/hook-installer": true,
|
||||
"captainhook/plugin-composer": true,
|
||||
"captainhook/captainhook-phar": true
|
||||
},
|
||||
"optimize-autoloader": true,
|
||||
"sort-packages": true
|
||||
|
||||
1688
composer.lock
generated
1688
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -43,7 +43,10 @@
|
||||
},
|
||||
"dba": {
|
||||
"type": "builtin",
|
||||
"arg-type-windows": "with"
|
||||
"arg-type": "custom",
|
||||
"lib-suggests": [
|
||||
"qdbm"
|
||||
]
|
||||
},
|
||||
"dom": {
|
||||
"type": "builtin",
|
||||
@@ -57,6 +60,10 @@
|
||||
"xml"
|
||||
]
|
||||
},
|
||||
"ds": {
|
||||
"type": "external",
|
||||
"source": "ext-ds"
|
||||
},
|
||||
"event": {
|
||||
"type": "external",
|
||||
"source": "ext-event",
|
||||
@@ -166,7 +173,7 @@
|
||||
"lib-depends": [
|
||||
"imap"
|
||||
],
|
||||
"lib-suggests": [
|
||||
"ext-suggests": [
|
||||
"openssl"
|
||||
]
|
||||
},
|
||||
@@ -273,6 +280,14 @@
|
||||
"zlib"
|
||||
]
|
||||
},
|
||||
"parallel": {
|
||||
"type": "external",
|
||||
"source": "parallel",
|
||||
"arg-type-windows": "with",
|
||||
"lib-depends-windows": [
|
||||
"pthreads4w"
|
||||
]
|
||||
},
|
||||
"password-argon2": {
|
||||
"type": "builtin",
|
||||
"arg-type": "with-prefix",
|
||||
@@ -378,6 +393,11 @@
|
||||
"shmop": {
|
||||
"type": "builtin"
|
||||
},
|
||||
"simdjson": {
|
||||
"type": "external",
|
||||
"source": "ext-simdjson",
|
||||
"cpp-extension": true
|
||||
},
|
||||
"simplexml": {
|
||||
"type": "builtin",
|
||||
"arg-type": "custom",
|
||||
@@ -614,6 +634,14 @@
|
||||
"dom"
|
||||
]
|
||||
},
|
||||
"yac": {
|
||||
"type": "external",
|
||||
"source": "yac",
|
||||
"arg-type-unix": "custom",
|
||||
"ext-depends-unix": [
|
||||
"igbinary"
|
||||
]
|
||||
},
|
||||
"yaml": {
|
||||
"type": "external",
|
||||
"source": "yaml",
|
||||
|
||||
@@ -353,6 +353,9 @@
|
||||
"source": "libuuid",
|
||||
"static-libs-unix": [
|
||||
"libuuid.a"
|
||||
],
|
||||
"headers": [
|
||||
"uuid/uuid.h"
|
||||
]
|
||||
},
|
||||
"libuv": {
|
||||
@@ -525,6 +528,24 @@
|
||||
"zstd"
|
||||
]
|
||||
},
|
||||
"pthreads4w": {
|
||||
"source": "pthreads4w",
|
||||
"static-libs-windows": [
|
||||
"libpthreadVC3.lib"
|
||||
]
|
||||
},
|
||||
"qdbm": {
|
||||
"source": "qdbm",
|
||||
"static-libs-unix": [
|
||||
"libqdbm.a"
|
||||
],
|
||||
"static-libs-windows": [
|
||||
"qdbm_a.lib"
|
||||
],
|
||||
"headers-windows": [
|
||||
"depot.h"
|
||||
]
|
||||
},
|
||||
"readline": {
|
||||
"source": "readline",
|
||||
"static-libs-unix": [
|
||||
|
||||
@@ -52,6 +52,16 @@
|
||||
"path": "COPYING"
|
||||
}
|
||||
},
|
||||
"ext-ds": {
|
||||
"type": "url",
|
||||
"url": "https://pecl.php.net/get/ds",
|
||||
"path": "php-src/ext/ds",
|
||||
"filename": "ds.tgz",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
}
|
||||
},
|
||||
"ext-event": {
|
||||
"type": "url",
|
||||
"url": "https://bitbucket.org/osmanov/pecl-event/get/3.0.8.tar.gz",
|
||||
@@ -90,6 +100,16 @@
|
||||
"path": "LICENSE"
|
||||
}
|
||||
},
|
||||
"ext-simdjson": {
|
||||
"type": "url",
|
||||
"url": "https://pecl.php.net/get/simdjson",
|
||||
"path": "php-src/ext/simdjson",
|
||||
"filename": "simdjson.tgz",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
}
|
||||
},
|
||||
"ext-snappy": {
|
||||
"type": "git",
|
||||
"path": "php-src/ext/snappy",
|
||||
@@ -365,7 +385,7 @@
|
||||
},
|
||||
"libuuid": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/cloudbase/libuuid.git",
|
||||
"url": "https://github.com/static-php/libuuid.git",
|
||||
"rev": "master",
|
||||
"license": {
|
||||
"type": "file",
|
||||
@@ -495,6 +515,16 @@
|
||||
"path": "LICENSE.txt"
|
||||
}
|
||||
},
|
||||
"parallel": {
|
||||
"type": "url",
|
||||
"url": "https://pecl.php.net/get/parallel",
|
||||
"path": "php-src/ext/parallel",
|
||||
"filename": "parallel.tgz",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
}
|
||||
},
|
||||
"pdo_sqlsrv": {
|
||||
"type": "url",
|
||||
"url": "https://pecl.php.net/get/pdo_sqlsrv",
|
||||
@@ -531,6 +561,24 @@
|
||||
"path": "LICENSE"
|
||||
}
|
||||
},
|
||||
"pthreads4w": {
|
||||
"type": "git",
|
||||
"rev": "master",
|
||||
"url": "https://git.code.sf.net/p/pthreads4w/code",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
}
|
||||
},
|
||||
"qdbm": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/static-php/qdbm.git",
|
||||
"rev": "main",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "COPYING"
|
||||
}
|
||||
},
|
||||
"rar": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/static-php/php-rar.git",
|
||||
@@ -646,14 +694,23 @@
|
||||
}
|
||||
},
|
||||
"xz": {
|
||||
"type": "ghrel",
|
||||
"repo": "tukaani-project/xz",
|
||||
"match": "xz-.+\\.tar\\.gz",
|
||||
"type": "url",
|
||||
"url": "https://fossies.org/linux/misc/xz-5.4.6.tar.xz",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "COPYING"
|
||||
}
|
||||
},
|
||||
"yac": {
|
||||
"type": "url",
|
||||
"url": "https://pecl.php.net/get/yac",
|
||||
"path": "php-src/ext/yac",
|
||||
"filename": "yac.tgz",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
}
|
||||
},
|
||||
"yaml": {
|
||||
"type": "git",
|
||||
"path": "php-src/ext/yaml",
|
||||
|
||||
@@ -16,16 +16,15 @@ use SPC\command\DumpLicenseCommand;
|
||||
use SPC\command\ExtractCommand;
|
||||
use SPC\command\InstallPkgCommand;
|
||||
use SPC\command\MicroCombineCommand;
|
||||
use SPC\command\SwitchPhpVersionCommand;
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Command\HelpCommand;
|
||||
use Symfony\Component\Console\Command\ListCommand;
|
||||
|
||||
/**
|
||||
* static-php-cli console app entry
|
||||
*/
|
||||
final class ConsoleApplication extends Application
|
||||
{
|
||||
public const VERSION = '2.1.5';
|
||||
public const VERSION = '2.2.1';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -33,6 +32,7 @@ final class ConsoleApplication extends Application
|
||||
|
||||
$this->addCommands(
|
||||
[
|
||||
// Common commands
|
||||
new BuildCliCommand(),
|
||||
new BuildLibsCommand(),
|
||||
new DoctorCommand(),
|
||||
@@ -42,6 +42,7 @@ final class ConsoleApplication extends Application
|
||||
new DumpLicenseCommand(),
|
||||
new ExtractCommand(),
|
||||
new MicroCombineCommand(),
|
||||
new SwitchPhpVersionCommand(),
|
||||
|
||||
// Dev commands
|
||||
new AllExtCommand(),
|
||||
@@ -50,9 +51,4 @@ final class ConsoleApplication extends Application
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
protected function getDefaultCommands(): array
|
||||
{
|
||||
return [new HelpCommand(), new ListCommand()];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ abstract class BuilderBase
|
||||
protected string $patch_point = '';
|
||||
|
||||
/**
|
||||
* Build libraries
|
||||
* Convert libraries to class
|
||||
*
|
||||
* @param array<string> $sorted_libraries Libraries to build (if not empty, must sort first)
|
||||
* @throws FileSystemException
|
||||
@@ -41,7 +41,27 @@ abstract class BuilderBase
|
||||
* @throws WrongUsageException
|
||||
* @internal
|
||||
*/
|
||||
abstract public function buildLibs(array $sorted_libraries);
|
||||
abstract public function proveLibs(array $sorted_libraries);
|
||||
|
||||
/**
|
||||
* Build libraries
|
||||
*
|
||||
* @throws FileSystemException
|
||||
* @throws RuntimeException
|
||||
* @throws WrongUsageException
|
||||
*/
|
||||
public function buildLibs(): void
|
||||
{
|
||||
// build all libs
|
||||
foreach ($this->libs as $lib) {
|
||||
match ($lib->tryBuild($this->getOption('rebuild', false))) {
|
||||
BUILD_STATUS_OK => logger()->info('lib [' . $lib::NAME . '] build success'),
|
||||
BUILD_STATUS_ALREADY => logger()->notice('lib [' . $lib::NAME . '] already built'),
|
||||
BUILD_STATUS_FAILED => logger()->error('lib [' . $lib::NAME . '] build failed'),
|
||||
default => logger()->warning('lib [' . $lib::NAME . '] build status unknown'),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add library to build.
|
||||
@@ -335,6 +355,19 @@ abstract class BuilderBase
|
||||
return $this->patch_point;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate libs and exts can be compiled successfully in current environment
|
||||
*/
|
||||
public function validateLibsAndExts(): void
|
||||
{
|
||||
foreach ($this->libs as $lib) {
|
||||
$lib->validate();
|
||||
}
|
||||
foreach ($this->exts as $ext) {
|
||||
$ext->validate();
|
||||
}
|
||||
}
|
||||
|
||||
public function emitPatchPoint(string $point_name): void
|
||||
{
|
||||
$this->patch_point = $point_name;
|
||||
|
||||
@@ -223,6 +223,11 @@ class Extension
|
||||
}
|
||||
}
|
||||
|
||||
public function validate(): void
|
||||
{
|
||||
// do nothing, just throw wrong usage exception if not valid
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
|
||||
@@ -177,6 +177,11 @@ abstract class LibraryBase
|
||||
return false;
|
||||
}
|
||||
|
||||
public function validate(): void
|
||||
{
|
||||
// do nothing, just throw wrong usage exception if not valid
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current builder object.
|
||||
*/
|
||||
@@ -206,4 +211,9 @@ abstract class LibraryBase
|
||||
}
|
||||
logger()->debug('enabling ' . static::NAME . " without {$name}");
|
||||
}
|
||||
|
||||
protected function getSnakeCaseName(): string
|
||||
{
|
||||
return str_replace('-', '_', static::NAME);
|
||||
}
|
||||
}
|
||||
|
||||
24
src/SPC/builder/extension/dba.php
Normal file
24
src/SPC/builder/extension/dba.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\extension;
|
||||
|
||||
use SPC\builder\Extension;
|
||||
use SPC\util\CustomExt;
|
||||
|
||||
#[CustomExt('dba')]
|
||||
class dba extends Extension
|
||||
{
|
||||
public function getUnixConfigureArg(): string
|
||||
{
|
||||
$qdbm = $this->builder->getLib('qdbm') ? (' --with-qdbm=' . BUILD_ROOT_PATH) : '';
|
||||
return '--enable-dba' . $qdbm;
|
||||
}
|
||||
|
||||
public function getWindowsConfigureArg(): string
|
||||
{
|
||||
$qdbm = $this->builder->getLib('qdbm') ? ' --with-qdbm' : '';
|
||||
return '--with-dba' . $qdbm;
|
||||
}
|
||||
}
|
||||
@@ -14,11 +14,11 @@ class imagick extends Extension
|
||||
public function patchBeforeMake(): bool
|
||||
{
|
||||
// imagick may call omp_pause_all which requires -lgomp
|
||||
$extra_libs = $this->builder->getOption('extra-libs', '');
|
||||
$extra_libs = getenv('SPC_EXTRA_LIBS') ?: '';
|
||||
if ($this->builder instanceof LinuxBuilder) {
|
||||
$extra_libs .= ' -lgomp ';
|
||||
$extra_libs .= (empty($extra_libs) ? '' : ' ') . '-lgomp ';
|
||||
}
|
||||
$this->builder->setOption('extra-libs', $extra_libs);
|
||||
f_putenv('SPC_EXTRA_LIBS=' . $extra_libs);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,11 +14,15 @@ class imap extends Extension
|
||||
/**
|
||||
* @throws WrongUsageException
|
||||
*/
|
||||
public function getUnixConfigureArg(): string
|
||||
public function validate(): void
|
||||
{
|
||||
if ($this->builder->getOption('enable-zts')) {
|
||||
throw new WrongUsageException('ext-imap is not thread safe, do not build it with ZTS builds');
|
||||
}
|
||||
}
|
||||
|
||||
public function getUnixConfigureArg(): string
|
||||
{
|
||||
$arg = '--with-imap=' . BUILD_ROOT_PATH;
|
||||
if ($this->builder->getLib('openssl') !== null) {
|
||||
$arg .= ' --with-imap-ssl=' . BUILD_ROOT_PATH;
|
||||
|
||||
26
src/SPC/builder/extension/intl.php
Normal file
26
src/SPC/builder/extension/intl.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\extension;
|
||||
|
||||
use SPC\builder\Extension;
|
||||
use SPC\store\FileSystem;
|
||||
use SPC\util\CustomExt;
|
||||
|
||||
#[CustomExt('intl')]
|
||||
class intl extends Extension
|
||||
{
|
||||
public function patchBeforeBuildconf(): bool
|
||||
{
|
||||
// TODO: remove the following line when https://github.com/php/php-src/pull/14002 will be released
|
||||
FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/ext/intl/config.m4', 'PHP_CXX_COMPILE_STDCXX(11', 'PHP_CXX_COMPILE_STDCXX(17');
|
||||
// Also need to use clang++ -std=c++17 to force override the default C++ standard
|
||||
if (is_string($env = getenv('CXX')) && !str_contains($env, 'std=c++17')) {
|
||||
f_putenv('CXX=' . $env . ' -std=c++17');
|
||||
} else {
|
||||
f_putenv('CXX=clang++ -std=c++17');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -16,11 +16,15 @@ class opcache extends Extension
|
||||
* @throws WrongUsageException
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function getUnixConfigureArg(): string
|
||||
public function validate(): void
|
||||
{
|
||||
if ($this->builder->getPHPVersionID() < 80000) {
|
||||
if ($this->builder->getPHPVersionID() < 80000 && getenv('SPC_SKIP_PHP_VERSION_CHECK') !== 'yes') {
|
||||
throw new WrongUsageException('Statically compiled PHP with Zend Opcache only available for PHP >= 8.0 !');
|
||||
}
|
||||
}
|
||||
|
||||
public function getUnixConfigureArg(): string
|
||||
{
|
||||
return '--enable-opcache';
|
||||
}
|
||||
|
||||
|
||||
20
src/SPC/builder/extension/parallel.php
Normal file
20
src/SPC/builder/extension/parallel.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\extension;
|
||||
|
||||
use SPC\builder\Extension;
|
||||
use SPC\exception\WrongUsageException;
|
||||
use SPC\util\CustomExt;
|
||||
|
||||
#[CustomExt('parallel')]
|
||||
class parallel extends Extension
|
||||
{
|
||||
public function validate(): void
|
||||
{
|
||||
if (!$this->builder->getOption('enable-zts')) {
|
||||
throw new WrongUsageException('ext-parallel must be built with ZTS builds. Use "--enable-zts" option!');
|
||||
}
|
||||
}
|
||||
}
|
||||
19
src/SPC/builder/extension/protobuf.php
Normal file
19
src/SPC/builder/extension/protobuf.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\extension;
|
||||
|
||||
use SPC\builder\Extension;
|
||||
use SPC\util\CustomExt;
|
||||
|
||||
#[CustomExt('protobuf')]
|
||||
class protobuf extends Extension
|
||||
{
|
||||
public function validate(): void
|
||||
{
|
||||
if ($this->builder->getPHPVersionID() < 80000 && getenv('SPC_SKIP_PHP_VERSION_CHECK') !== 'yes') {
|
||||
throw new \RuntimeException('The latest protobuf extension requires PHP 8.0 or later');
|
||||
}
|
||||
}
|
||||
}
|
||||
34
src/SPC/builder/extension/simdjson.php
Normal file
34
src/SPC/builder/extension/simdjson.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\extension;
|
||||
|
||||
use SPC\builder\Extension;
|
||||
use SPC\store\FileSystem;
|
||||
use SPC\util\CustomExt;
|
||||
|
||||
#[CustomExt('simdjson')]
|
||||
class simdjson extends Extension
|
||||
{
|
||||
public function patchBeforeBuildconf(): bool
|
||||
{
|
||||
$php_ver = $this->builder->getPHPVersionID();
|
||||
FileSystem::replaceFileRegex(
|
||||
SOURCE_PATH . '/php-src/ext/simdjson/config.m4',
|
||||
'/php_version=(`.*`)$/m',
|
||||
'php_version=' . strval($php_ver)
|
||||
);
|
||||
FileSystem::replaceFileStr(
|
||||
SOURCE_PATH . '/php-src/ext/simdjson/config.m4',
|
||||
'if test -z "$PHP_CONFIG"; then',
|
||||
'if false; then'
|
||||
);
|
||||
FileSystem::replaceFileStr(
|
||||
SOURCE_PATH . '/php-src/ext/simdjson/config.w32',
|
||||
"'yes',",
|
||||
'PHP_SIMDJSON_SHARED,'
|
||||
);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -17,12 +17,16 @@ class swoole_hook_pgsql extends Extension
|
||||
return 'swoole';
|
||||
}
|
||||
|
||||
public function getUnixConfigureArg(): string
|
||||
public function validate(): void
|
||||
{
|
||||
// pdo_pgsql need to be disabled
|
||||
if ($this->builder->getExt('pdo_pgsql') !== null) {
|
||||
throw new WrongUsageException('swoole-hook-pgsql provides pdo_pgsql, if you enable pgsql hook for swoole, you must remove pdo_pgsql extension.');
|
||||
}
|
||||
}
|
||||
|
||||
public function getUnixConfigureArg(): string
|
||||
{
|
||||
// enable swoole pgsql hook
|
||||
return '--enable-swoole-pgsql';
|
||||
}
|
||||
|
||||
@@ -17,12 +17,16 @@ class swoole_hook_sqlite extends Extension
|
||||
return 'swoole';
|
||||
}
|
||||
|
||||
public function getUnixConfigureArg(): string
|
||||
public function validate(): void
|
||||
{
|
||||
// pdo_pgsql need to be disabled
|
||||
if ($this->builder->getExt('pdo_sqlite') !== null) {
|
||||
throw new WrongUsageException('swoole-hook-sqlite provides pdo_sqlite, if you enable sqlite hook for swoole, you must remove pdo_sqlite extension.');
|
||||
}
|
||||
}
|
||||
|
||||
public function getUnixConfigureArg(): string
|
||||
{
|
||||
// enable swoole pgsql hook
|
||||
return '--enable-swoole-sqlite';
|
||||
}
|
||||
|
||||
@@ -11,6 +11,13 @@ use SPC\util\CustomExt;
|
||||
#[CustomExt('swow')]
|
||||
class swow extends Extension
|
||||
{
|
||||
public function validate(): void
|
||||
{
|
||||
if ($this->builder->getPHPVersionID() < 80000 && getenv('SPC_SKIP_PHP_VERSION_CHECK') !== 'yes') {
|
||||
throw new RuntimeException('The latest swow extension requires PHP 8.0 or later');
|
||||
}
|
||||
}
|
||||
|
||||
public function getUnixConfigureArg(): string
|
||||
{
|
||||
$arg = '--enable-swow';
|
||||
|
||||
26
src/SPC/builder/extension/yac.php
Normal file
26
src/SPC/builder/extension/yac.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\extension;
|
||||
|
||||
use SPC\builder\Extension;
|
||||
use SPC\store\FileSystem;
|
||||
use SPC\util\CustomExt;
|
||||
|
||||
#[CustomExt('yac')]
|
||||
class yac extends Extension
|
||||
{
|
||||
public function patchBeforeBuildconf(): bool
|
||||
{
|
||||
FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/ext/yac/storage/allocator/yac_allocator.h', 'defined(HAVE_SHM_MMAP_ANON)', 'defined(YAC_ALLOCATOR_H)');
|
||||
FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/ext/yac/serializer/igbinary.c', '#ifdef YAC_ENABLE_IGBINARY', '#if 1');
|
||||
FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/ext/yac/serializer/json.c', '#if YAC_ENABLE_JSON', '#if 1');
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getUnixConfigureArg(): string
|
||||
{
|
||||
return '--enable-yac --enable-igbinary --enable-json';
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ class BSDBuilder extends UnixBuilderBase
|
||||
// ---------- set necessary options ----------
|
||||
// set C Compiler (default: clang)
|
||||
f_putenv('CC=' . $this->getOption('cc', 'clang'));
|
||||
// set C++ Composer (default: clang++)
|
||||
// set C++ Compiler (default: clang++)
|
||||
f_putenv('CXX=' . $this->getOption('cxx', 'clang++'));
|
||||
// set PATH
|
||||
f_putenv('PATH=' . BUILD_ROOT_PATH . '/bin:' . getenv('PATH'));
|
||||
@@ -86,7 +86,8 @@ class BSDBuilder extends UnixBuilderBase
|
||||
SourcePatcher::patchBeforeConfigure($this);
|
||||
|
||||
$json_74 = $this->getPHPVersionID() < 80000 ? '--enable-json ' : '';
|
||||
$zts = $this->getOption('enable-zts', false) ? '--enable-zts --disable-zend-signals ' : '';
|
||||
$zts_enable = $this->getPHPVersionID() < 80000 ? '--enable-maintainer-zts --disable-zend-signals' : '--enable-zts --disable-zend-signals';
|
||||
$zts = $this->getOption('enable-zts', false) ? $zts_enable : '';
|
||||
|
||||
$enableCli = ($build_target & BUILD_TARGET_CLI) === BUILD_TARGET_CLI;
|
||||
$enableFpm = ($build_target & BUILD_TARGET_FPM) === BUILD_TARGET_FPM;
|
||||
|
||||
@@ -11,68 +11,43 @@ use SPC\exception\RuntimeException;
|
||||
use SPC\exception\WrongUsageException;
|
||||
use SPC\store\FileSystem;
|
||||
use SPC\store\SourcePatcher;
|
||||
use SPC\util\GlobalEnvManager;
|
||||
|
||||
class LinuxBuilder extends UnixBuilderBase
|
||||
{
|
||||
/** @var array Tune cflags */
|
||||
public array $tune_c_flags;
|
||||
|
||||
/** @var bool Micro patch phar flag */
|
||||
private bool $phar_patched = false;
|
||||
|
||||
/**
|
||||
* @throws FileSystemException
|
||||
* @throws RuntimeException
|
||||
* @throws WrongUsageException
|
||||
*/
|
||||
public function __construct(array $options = [])
|
||||
{
|
||||
$this->options = $options;
|
||||
|
||||
// ---------- set necessary options ----------
|
||||
// set C/C++ compilers (default: alpine: gcc, others: musl-cross-make)
|
||||
if (SystemUtil::isMuslDist()) {
|
||||
f_putenv("CC={$this->getOption('cc', 'gcc')}");
|
||||
f_putenv("CXX={$this->getOption('cxx', 'g++')}");
|
||||
f_putenv("AR={$this->getOption('ar', 'ar')}");
|
||||
f_putenv("LD={$this->getOption('ld', 'ld.gold')}");
|
||||
} else {
|
||||
$arch = arch2gnu(php_uname('m'));
|
||||
f_putenv("CC={$this->getOption('cc', "{$arch}-linux-musl-gcc")}");
|
||||
f_putenv("CXX={$this->getOption('cxx', "{$arch}-linux-musl-g++")}");
|
||||
f_putenv("AR={$this->getOption('ar', "{$arch}-linux-musl-ar")}");
|
||||
f_putenv("LD={$this->getOption('ld', 'ld.gold')}");
|
||||
f_putenv("PATH=/usr/local/musl/bin:/usr/local/musl/{$arch}-linux-musl/bin:" . BUILD_ROOT_PATH . '/bin:' . getenv('PATH'));
|
||||
// check musl-cross make installed if we use musl-cross-make
|
||||
$arch = arch2gnu(php_uname('m'));
|
||||
|
||||
// set library path, some libraries need it. (We cannot use `putenv` here, because cmake will be confused)
|
||||
$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");
|
||||
// set library path, some libraries need it. (We cannot use `putenv` here, because cmake will be confused)
|
||||
$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");
|
||||
|
||||
// check musl-cross make installed if we use musl-cross-make
|
||||
if (str_ends_with(getenv('CC'), 'linux-musl-gcc') && !file_exists("/usr/local/musl/bin/{$arch}-linux-musl-gcc")) {
|
||||
throw new WrongUsageException('musl-cross-make not installed, please install it first. (You can use `doctor` command to install it)');
|
||||
}
|
||||
GlobalEnvManager::init($this);
|
||||
|
||||
if (str_ends_with(getenv('CC'), 'linux-musl-gcc') && !file_exists("/usr/local/musl/bin/{$arch}-linux-musl-gcc")) {
|
||||
throw new WrongUsageException('musl-cross-make not installed, please install it first. (You can use `doctor` command to install it)');
|
||||
}
|
||||
|
||||
// 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')));
|
||||
|
||||
// concurrency
|
||||
$this->concurrency = SystemUtil::getCpuCount();
|
||||
$this->concurrency = intval(getenv('SPC_CONCURRENCY'));
|
||||
// cflags
|
||||
$this->arch_c_flags = SystemUtil::getArchCFlags(getenv('CC'), $this->getOption('arch'));
|
||||
$this->arch_cxx_flags = SystemUtil::getArchCFlags(getenv('CXX'), $this->getOption('arch'));
|
||||
$this->tune_c_flags = SystemUtil::checkCCFlags(SystemUtil::getTuneCFlags($this->getOption('arch')), getenv('CC'));
|
||||
$this->arch_c_flags = getenv('SPC_DEFAULT_C_FLAGS');
|
||||
$this->arch_cxx_flags = getenv('SPC_DEFAULT_CXX_FLAGS');
|
||||
// cmake toolchain
|
||||
$this->cmake_toolchain_file = SystemUtil::makeCmakeToolchainFile(
|
||||
'Linux',
|
||||
$this->getOption('arch'),
|
||||
$arch,
|
||||
$this->arch_c_flags,
|
||||
getenv('CC'),
|
||||
getenv('CXX'),
|
||||
@@ -117,6 +92,9 @@ class LinuxBuilder extends UnixBuilderBase
|
||||
}
|
||||
|
||||
/**
|
||||
* Build PHP from source.
|
||||
*
|
||||
* @param int $build_target Build target, use `BUILD_TARGET_*` constants
|
||||
* @throws RuntimeException
|
||||
* @throws FileSystemException
|
||||
* @throws WrongUsageException
|
||||
@@ -124,8 +102,8 @@ class LinuxBuilder extends UnixBuilderBase
|
||||
public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
|
||||
{
|
||||
// ---------- Update extra-libs ----------
|
||||
$extra_libs = $this->getOption('extra-libs', '');
|
||||
// non-bloat linking
|
||||
$extra_libs = getenv('SPC_EXTRA_LIBS') ?: '';
|
||||
// bloat means force-load all static libraries, even if they are not used
|
||||
if (!$this->getOption('bloat', false)) {
|
||||
$extra_libs .= (empty($extra_libs) ? '' : ' ') . implode(' ', $this->getAllStaticLibFiles());
|
||||
} else {
|
||||
@@ -133,21 +111,13 @@ class LinuxBuilder extends UnixBuilderBase
|
||||
}
|
||||
// add libstdc++, some extensions or libraries need it
|
||||
$extra_libs .= (empty($extra_libs) ? '' : ' ') . ($this->hasCpp() ? '-lstdc++ ' : '');
|
||||
$this->setOption('extra-libs', $extra_libs);
|
||||
f_putenv('SPC_EXTRA_LIBS=' . $extra_libs);
|
||||
$cflags = $this->arch_c_flags;
|
||||
|
||||
// prepare build php envs
|
||||
$envs_build_php = SystemUtil::makeEnvVarString([
|
||||
'CFLAGS' => $cflags,
|
||||
'CPPFLAGS' => '-I' . BUILD_INCLUDE_PATH,
|
||||
'LDFLAGS' => '-L' . BUILD_LIB_PATH,
|
||||
'LIBS' => '-ldl -lpthread',
|
||||
]);
|
||||
|
||||
$this->emitPatchPoint('before-php-buildconf');
|
||||
SourcePatcher::patchBeforeBuildconf($this);
|
||||
|
||||
shell()->cd(SOURCE_PATH . '/php-src')->exec('./buildconf --force');
|
||||
shell()->cd(SOURCE_PATH . '/php-src')->exec(getenv('SPC_CMD_PREFIX_PHP_BUILDCONF'));
|
||||
|
||||
$this->emitPatchPoint('before-php-configure');
|
||||
SourcePatcher::patchBeforeConfigure($this);
|
||||
@@ -164,47 +134,31 @@ class LinuxBuilder extends UnixBuilderBase
|
||||
}
|
||||
$disable_jit = $this->getOption('disable-opcache-jit', false) ? '--disable-opcache-jit ' : '';
|
||||
|
||||
$enableCli = ($build_target & BUILD_TARGET_CLI) === BUILD_TARGET_CLI;
|
||||
$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;
|
||||
$enable_cli = ($build_target & BUILD_TARGET_CLI) === BUILD_TARGET_CLI;
|
||||
$enable_fpm = ($build_target & BUILD_TARGET_FPM) === BUILD_TARGET_FPM;
|
||||
$enable_micro = ($build_target & BUILD_TARGET_MICRO) === BUILD_TARGET_MICRO;
|
||||
$enable_embed = ($build_target & BUILD_TARGET_EMBED) === BUILD_TARGET_EMBED;
|
||||
|
||||
// upx pack and strip for micro
|
||||
if ($this->getOption('with-upx-pack', false)) {
|
||||
FileSystem::replaceFileRegex(
|
||||
SOURCE_PATH . '/php-src/sapi/micro/Makefile.frag',
|
||||
'/POST_MICRO_BUILD_COMMANDS=.*/',
|
||||
'POST_MICRO_BUILD_COMMANDS=\$(STRIP) \$(MICRO_STRIP_FLAGS) \$(SAPI_MICRO_PATH) && ' . $this->getOption('upx-exec') . ' --best \$(SAPI_MICRO_PATH)',
|
||||
);
|
||||
} elseif (!$this->getOption('no-strip', false)) {
|
||||
FileSystem::replaceFileRegex(
|
||||
SOURCE_PATH . '/php-src/sapi/micro/Makefile.frag',
|
||||
'/POST_MICRO_BUILD_COMMANDS=.*/',
|
||||
'POST_MICRO_BUILD_COMMANDS=\$(STRIP) \$(MICRO_STRIP_FLAGS) \$(SAPI_MICRO_PATH)',
|
||||
);
|
||||
} else {
|
||||
FileSystem::replaceFileRegex(
|
||||
SOURCE_PATH . '/php-src/sapi/micro/Makefile.frag',
|
||||
'/POST_MICRO_BUILD_COMMANDS=.*/',
|
||||
'POST_MICRO_BUILD_COMMANDS=true',
|
||||
);
|
||||
// prepare build php envs
|
||||
$envs_build_php = SystemUtil::makeEnvVarString([
|
||||
'CFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS'),
|
||||
'CPPFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_CPPFLAGS'),
|
||||
'LDFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_LDFLAGS'),
|
||||
'LIBS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_LIBS'),
|
||||
]);
|
||||
|
||||
// process micro upx patch if micro sapi enabled
|
||||
if ($enable_micro) {
|
||||
$this->processMicroUPX();
|
||||
}
|
||||
|
||||
shell()->cd(SOURCE_PATH . '/php-src')
|
||||
->exec(
|
||||
"{$this->getOption('ld_library_path')} " .
|
||||
'./configure ' .
|
||||
'--prefix= ' .
|
||||
'--with-valgrind=no ' .
|
||||
'--enable-shared=no ' .
|
||||
'--enable-static=yes ' .
|
||||
'--disable-all ' .
|
||||
'--disable-cgi ' .
|
||||
'--disable-phpdbg ' .
|
||||
($enableCli ? '--enable-cli ' : '--disable-cli ') .
|
||||
($enableFpm ? '--enable-fpm ' : '--disable-fpm ') .
|
||||
($enableEmbed ? '--enable-embed=static ' : '--disable-embed ') .
|
||||
($enableMicro ? '--enable-micro=all-static ' : '--disable-micro ') .
|
||||
getenv('SPC_CMD_PREFIX_PHP_CONFIGURE') . ' ' .
|
||||
($enable_cli ? '--enable-cli ' : '--disable-cli ') .
|
||||
($enable_fpm ? '--enable-fpm ' : '--disable-fpm ') .
|
||||
($enable_embed ? '--enable-embed=static ' : '--disable-embed ') .
|
||||
($enable_micro ? '--enable-micro=all-static ' : '--disable-micro ') .
|
||||
$disable_jit .
|
||||
$json_74 .
|
||||
$zts .
|
||||
@@ -218,21 +172,21 @@ class LinuxBuilder extends UnixBuilderBase
|
||||
|
||||
$this->cleanMake();
|
||||
|
||||
if ($enableCli) {
|
||||
if ($enable_cli) {
|
||||
logger()->info('building cli');
|
||||
$this->buildCli();
|
||||
}
|
||||
if ($enableFpm) {
|
||||
if ($enable_fpm) {
|
||||
logger()->info('building fpm');
|
||||
$this->buildFpm();
|
||||
}
|
||||
if ($enableMicro) {
|
||||
if ($enable_micro) {
|
||||
logger()->info('building micro');
|
||||
$this->buildMicro();
|
||||
}
|
||||
if ($enableEmbed) {
|
||||
if ($enable_embed) {
|
||||
logger()->info('building embed');
|
||||
if ($enableMicro) {
|
||||
if ($enable_micro) {
|
||||
FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/Makefile', 'OVERALL_TARGET =', 'OVERALL_TARGET = libphp.la');
|
||||
}
|
||||
$this->buildEmbed();
|
||||
@@ -252,15 +206,15 @@ class LinuxBuilder extends UnixBuilderBase
|
||||
*/
|
||||
protected function buildCli(): void
|
||||
{
|
||||
$vars = SystemUtil::makeEnvVarString($this->getBuildVars());
|
||||
$vars = SystemUtil::makeEnvVarString($this->getMakeExtraVars());
|
||||
shell()->cd(SOURCE_PATH . '/php-src')
|
||||
->exec('sed -i "s|//lib|/lib|g" Makefile')
|
||||
->exec("make -j{$this->concurrency} {$vars} cli");
|
||||
->exec("\$SPC_CMD_PREFIX_PHP_MAKE {$vars} cli");
|
||||
|
||||
if ($this->getOption('with-upx-pack')) {
|
||||
shell()->cd(SOURCE_PATH . '/php-src/sapi/cli')
|
||||
->exec('strip --strip-all php')
|
||||
->exec($this->getOption('upx-exec') . ' --best php');
|
||||
->exec(getenv('UPX_EXEC') . ' --best php');
|
||||
} elseif (!$this->getOption('no-strip', false)) {
|
||||
shell()->cd(SOURCE_PATH . '/php-src/sapi/cli')->exec('strip --strip-all php');
|
||||
}
|
||||
@@ -285,12 +239,16 @@ class LinuxBuilder extends UnixBuilderBase
|
||||
SourcePatcher::patchMicro(['phar']);
|
||||
}
|
||||
|
||||
$vars = SystemUtil::makeEnvVarString($this->getBuildVars([
|
||||
'EXTRA_CFLAGS' => $this->getOption('with-micro-fake-cli', false) ? ' -DPHP_MICRO_FAKE_CLI' : '',
|
||||
]));
|
||||
$enable_fake_cli = $this->getOption('with-micro-fake-cli', false) ? ' -DPHP_MICRO_FAKE_CLI' : '';
|
||||
$vars = $this->getMakeExtraVars();
|
||||
|
||||
// patch fake cli for micro
|
||||
$vars['EXTRA_CFLAGS'] .= $enable_fake_cli;
|
||||
$vars = SystemUtil::makeEnvVarString($vars);
|
||||
|
||||
shell()->cd(SOURCE_PATH . '/php-src')
|
||||
->exec('sed -i "s|//lib|/lib|g" Makefile')
|
||||
->exec("make -j{$this->concurrency} {$vars} micro");
|
||||
->exec("\$SPC_CMD_PREFIX_PHP_MAKE {$vars} micro");
|
||||
|
||||
$this->deployBinary(BUILD_TARGET_MICRO);
|
||||
|
||||
@@ -307,15 +265,15 @@ class LinuxBuilder extends UnixBuilderBase
|
||||
*/
|
||||
protected function buildFpm(): void
|
||||
{
|
||||
$vars = SystemUtil::makeEnvVarString($this->getBuildVars());
|
||||
$vars = SystemUtil::makeEnvVarString($this->getMakeExtraVars());
|
||||
shell()->cd(SOURCE_PATH . '/php-src')
|
||||
->exec('sed -i "s|//lib|/lib|g" Makefile')
|
||||
->exec("make -j{$this->concurrency} {$vars} fpm");
|
||||
->exec("\$SPC_CMD_PREFIX_PHP_MAKE {$vars} fpm");
|
||||
|
||||
if ($this->getOption('with-upx-pack')) {
|
||||
shell()->cd(SOURCE_PATH . '/php-src/sapi/fpm')
|
||||
->exec('strip --strip-all php-fpm')
|
||||
->exec($this->getOption('upx-exec') . ' --best php-fpm');
|
||||
->exec(getenv('UPX_EXEC') . ' --best php-fpm');
|
||||
} elseif (!$this->getOption('no-strip', false)) {
|
||||
shell()->cd(SOURCE_PATH . '/php-src/sapi/fpm')->exec('strip --strip-all php-fpm');
|
||||
}
|
||||
@@ -329,29 +287,63 @@ class LinuxBuilder extends UnixBuilderBase
|
||||
*/
|
||||
protected function buildEmbed(): void
|
||||
{
|
||||
$vars = SystemUtil::makeEnvVarString($this->getBuildVars());
|
||||
$vars = SystemUtil::makeEnvVarString($this->getMakeExtraVars());
|
||||
|
||||
shell()
|
||||
->cd(SOURCE_PATH . '/php-src')
|
||||
shell()->cd(SOURCE_PATH . '/php-src')
|
||||
->exec('sed -i "s|//lib|/lib|g" Makefile')
|
||||
->exec('make INSTALL_ROOT=' . BUILD_ROOT_PATH . " -j{$this->concurrency} {$vars} install");
|
||||
->exec(getenv('SPC_CMD_PREFIX_PHP_MAKE') . ' INSTALL_ROOT=' . BUILD_ROOT_PATH . " {$vars} install");
|
||||
}
|
||||
|
||||
private function getBuildVars($input = []): array
|
||||
private function getMakeExtraVars(): array
|
||||
{
|
||||
$use_lld = '';
|
||||
if (str_ends_with(getenv('CC'), 'clang') && SystemUtil::findCommand('lld')) {
|
||||
$use_lld = '-Xcompiler -fuse-ld=lld';
|
||||
}
|
||||
$optimization = $this->getOption('no-strip', false) ? '-g -O0' : '-g0 -Os';
|
||||
$cflags = isset($input['EXTRA_CFLAGS']) && $input['EXTRA_CFLAGS'] ? " {$input['EXTRA_CFLAGS']}" : '';
|
||||
$libs = isset($input['EXTRA_LIBS']) && $input['EXTRA_LIBS'] ? " {$input['EXTRA_LIBS']}" : '';
|
||||
$ldflags = isset($input['EXTRA_LDFLAGS_PROGRAM']) && $input['EXTRA_LDFLAGS_PROGRAM'] ? " {$input['EXTRA_LDFLAGS_PROGRAM']}" : '';
|
||||
$tune_c_flags = implode(' ', array_map(fn ($x) => "-Xcompiler {$x}", $this->tune_c_flags));
|
||||
return [
|
||||
'EXTRA_CFLAGS' => "{$optimization} -fno-ident -fPIE {$tune_c_flags}{$cflags}",
|
||||
'EXTRA_LIBS' => "{$this->getOption('extra-libs', '')} {$libs}",
|
||||
'EXTRA_LDFLAGS_PROGRAM' => "{$use_lld} -all-static{$ldflags}",
|
||||
'EXTRA_CFLAGS' => getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS'),
|
||||
'EXTRA_LIBS' => getenv('SPC_EXTRA_LIBS') . ' ' . getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS'),
|
||||
'EXTRA_LDFLAGS_PROGRAM' => getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply option --no-strip and --with-upx-pack for micro sapi.
|
||||
*
|
||||
* @throws FileSystemException
|
||||
*/
|
||||
private function processMicroUPX(): void
|
||||
{
|
||||
// upx pack and strip for micro
|
||||
// but always restore Makefile.frag.bak first
|
||||
if (file_exists(SOURCE_PATH . '/php-src/sapi/micro/Makefile.frag.bak')) {
|
||||
copy(SOURCE_PATH . '/php-src/sapi/micro/Makefile.frag.bak', SOURCE_PATH . '/php-src/sapi/micro/Makefile.frag');
|
||||
}
|
||||
if ($this->getOption('with-upx-pack', false)) {
|
||||
// judge $(MAKE) micro_2s_objs SFX_FILESIZE=`$(STAT_SIZE) $(SAPI_MICRO_PATH)` count
|
||||
// if 2, replace src/globals/extra/micro-triple-Makefile.frag file content
|
||||
if (substr_count(FileSystem::readFile(SOURCE_PATH . '/php-src/sapi/micro/Makefile.frag'), '$(MAKE) micro_2s_objs SFX_FILESIZE=`$(STAT_SIZE) $(SAPI_MICRO_PATH)`') === 2) {
|
||||
// bak first
|
||||
copy(SOURCE_PATH . '/php-src/sapi/micro/Makefile.frag', SOURCE_PATH . '/php-src/sapi/micro/Makefile.frag.bak');
|
||||
// replace Makefile.frag content
|
||||
FileSystem::writeFile(SOURCE_PATH . '/php-src/sapi/micro/Makefile.frag', FileSystem::readFile(ROOT_DIR . '/src/globals/extra/micro-triple-Makefile.frag'));
|
||||
}
|
||||
// with upx pack always need strip
|
||||
FileSystem::replaceFileRegex(
|
||||
SOURCE_PATH . '/php-src/sapi/micro/Makefile.frag',
|
||||
'/POST_MICRO_BUILD_COMMANDS=.*/',
|
||||
'POST_MICRO_BUILD_COMMANDS=\$(STRIP) \$(MICRO_STRIP_FLAGS) \$(SAPI_MICRO_PATH) && ' . getenv('UPX_EXEC') . ' --best \$(SAPI_MICRO_PATH)',
|
||||
);
|
||||
} elseif (!$this->getOption('no-strip', false)) {
|
||||
// not-no-strip means strip (default behavior)
|
||||
FileSystem::replaceFileRegex(
|
||||
SOURCE_PATH . '/php-src/sapi/micro/Makefile.frag',
|
||||
'/POST_MICRO_BUILD_COMMANDS=.*/',
|
||||
'POST_MICRO_BUILD_COMMANDS=\$(STRIP) \$(MICRO_STRIP_FLAGS) \$(SAPI_MICRO_PATH)',
|
||||
);
|
||||
} else {
|
||||
// just no strip
|
||||
FileSystem::replaceFileRegex(
|
||||
SOURCE_PATH . '/php-src/sapi/micro/Makefile.frag',
|
||||
'/POST_MICRO_BUILD_COMMANDS=.*/',
|
||||
'POST_MICRO_BUILD_COMMANDS=true',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,6 +220,8 @@ class SystemUtil
|
||||
'redhat',
|
||||
// alpine
|
||||
'alpine',
|
||||
// arch
|
||||
'arch', 'manjaro',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ class icu extends LinuxLibraryBase
|
||||
protected function build(): void
|
||||
{
|
||||
$cppflags = 'CPPFLAGS="-DU_CHARSET_IS_UTF8=1 -DU_USING_ICU_NAMESPACE=1 -DU_STATIC_IMPLEMENTATION=1"';
|
||||
$cxxflags = 'CXXFLAGS="-std=c++11"';
|
||||
$cxxflags = 'CXXFLAGS="-std=c++17"';
|
||||
$ldflags = 'LDFLAGS="-static"';
|
||||
shell()->cd($this->source_dir . '/source')
|
||||
->exec(
|
||||
|
||||
@@ -24,6 +24,7 @@ use SPC\builder\linux\SystemUtil;
|
||||
use SPC\exception\FileSystemException;
|
||||
use SPC\exception\RuntimeException;
|
||||
use SPC\exception\WrongUsageException;
|
||||
use SPC\store\FileSystem;
|
||||
|
||||
class openssl extends LinuxLibraryBase
|
||||
{
|
||||
@@ -41,8 +42,7 @@ class openssl extends LinuxLibraryBase
|
||||
$extra = '';
|
||||
$ex_lib = '-ldl -pthread';
|
||||
|
||||
$env = "CFLAGS='{$this->builder->arch_c_flags}'";
|
||||
$env .= " CC='" . getenv('CC') . ' -static -idirafter ' . BUILD_INCLUDE_PATH .
|
||||
$env = "CC='" . getenv('CC') . ' -static -idirafter ' . BUILD_INCLUDE_PATH .
|
||||
' -idirafter /usr/include/ ' .
|
||||
' -idirafter /usr/include/' . $this->builder->getOption('arch') . '-linux-gnu/ ' .
|
||||
"' ";
|
||||
@@ -63,7 +63,8 @@ class openssl extends LinuxLibraryBase
|
||||
$clang_postfix = SystemUtil::getCCType(getenv('CC')) === 'clang' ? '-clang' : '';
|
||||
|
||||
shell()->cd($this->source_dir)
|
||||
->exec(
|
||||
->setEnv(['CFLAGS' => $this->getLibExtraCFlags() ?: $this->builder->arch_c_flags, 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()])
|
||||
->execWithEnv(
|
||||
"{$env} ./Configure no-shared {$extra} " .
|
||||
'--prefix=/ ' .
|
||||
'--libdir=lib ' .
|
||||
@@ -73,8 +74,18 @@ class openssl extends LinuxLibraryBase
|
||||
"linux-{$this->builder->getOption('arch')}{$clang_postfix}"
|
||||
)
|
||||
->exec('make clean')
|
||||
->exec("make -j{$this->builder->concurrency} CNF_EX_LIBS=\"{$ex_lib}\"")
|
||||
->execWithEnv("make -j{$this->builder->concurrency} CNF_EX_LIBS=\"{$ex_lib}\"")
|
||||
->exec("make install_sw DESTDIR={$destdir}");
|
||||
$this->patchPkgconfPrefix(['libssl.pc', 'openssl.pc', 'libcrypto.pc']);
|
||||
// patch for openssl 3.3.0+
|
||||
if (!str_contains($file = FileSystem::readFile(BUILD_LIB_PATH . '/pkgconfig/libssl.pc'), 'prefix=')) {
|
||||
FileSystem::writeFile(BUILD_LIB_PATH . '/pkgconfig/libssl.pc', 'prefix=' . BUILD_ROOT_PATH . "\n" . $file);
|
||||
}
|
||||
if (!str_contains($file = FileSystem::readFile(BUILD_LIB_PATH . '/pkgconfig/openssl.pc'), 'prefix=')) {
|
||||
FileSystem::writeFile(BUILD_LIB_PATH . '/pkgconfig/openssl.pc', 'prefix=' . BUILD_ROOT_PATH . "\n" . $file);
|
||||
}
|
||||
if (!str_contains($file = FileSystem::readFile(BUILD_LIB_PATH . '/pkgconfig/libcrypto.pc'), 'prefix=')) {
|
||||
FileSystem::writeFile(BUILD_LIB_PATH . '/pkgconfig/libcrypto.pc', 'prefix=' . BUILD_ROOT_PATH . "\n" . $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
12
src/SPC/builder/linux/library/qdbm.php
Normal file
12
src/SPC/builder/linux/library/qdbm.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\linux\library;
|
||||
|
||||
class qdbm extends LinuxLibraryBase
|
||||
{
|
||||
use \SPC\builder\unix\library\qdbm;
|
||||
|
||||
public const NAME = 'qdbm';
|
||||
}
|
||||
@@ -11,6 +11,7 @@ use SPC\exception\RuntimeException;
|
||||
use SPC\exception\WrongUsageException;
|
||||
use SPC\store\FileSystem;
|
||||
use SPC\store\SourcePatcher;
|
||||
use SPC\util\GlobalEnvManager;
|
||||
|
||||
class MacOSBuilder extends UnixBuilderBase
|
||||
{
|
||||
@@ -26,28 +27,15 @@ class MacOSBuilder extends UnixBuilderBase
|
||||
{
|
||||
$this->options = $options;
|
||||
|
||||
// ---------- set necessary options ----------
|
||||
// set C Compiler (default: clang)
|
||||
f_putenv('CC=' . $this->getOption('cc', 'clang'));
|
||||
// set C++ Composer (default: 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/');
|
||||
// apply global environment variables
|
||||
GlobalEnvManager::init($this);
|
||||
|
||||
// set arch (default: current)
|
||||
$this->setOptionIfNotExist('arch', php_uname('m'));
|
||||
$this->setOptionIfNotExist('gnu-arch', arch2gnu($this->getOption('arch')));
|
||||
|
||||
// ---------- set necessary compile environments ----------
|
||||
// ---------- set necessary compile vars ----------
|
||||
// concurrency
|
||||
$this->concurrency = SystemUtil::getCpuCount();
|
||||
$this->concurrency = intval(getenv('SPC_CONCURRENCY'));
|
||||
// cflags
|
||||
$this->arch_c_flags = SystemUtil::getArchCFlags($this->getOption('arch'));
|
||||
$this->arch_cxx_flags = SystemUtil::getArchCFlags($this->getOption('arch'));
|
||||
$this->arch_c_flags = getenv('SPC_DEFAULT_C_FLAGS');
|
||||
$this->arch_cxx_flags = getenv('SPC_DEFAULT_CXX_FLAGS');
|
||||
// cmake toolchain
|
||||
$this->cmake_toolchain_file = SystemUtil::makeCmakeToolchainFile('Darwin', $this->getOption('arch'), $this->arch_c_flags);
|
||||
|
||||
@@ -123,24 +111,25 @@ class MacOSBuilder extends UnixBuilderBase
|
||||
*/
|
||||
public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
|
||||
{
|
||||
$extra_libs = getenv('SPC_EXTRA_LIBS') ?: '';
|
||||
// ---------- Update extra-libs ----------
|
||||
$extra_libs = $this->getOption('extra-libs', '');
|
||||
// add macOS frameworks
|
||||
$extra_libs .= (empty($extra_libs) ? '' : ' ') . $this->getFrameworks(true);
|
||||
// add libc++, some extensions or libraries need it (C++ cannot be linked statically)
|
||||
$extra_libs .= (empty($extra_libs) ? '' : ' ') . ($this->hasCpp() ? '-lc++ ' : '');
|
||||
// bloat means force-load all static libraries, even if they are not used
|
||||
if (!$this->getOption('bloat', false)) {
|
||||
$extra_libs .= (empty($extra_libs) ? '' : ' ') . implode(' ', $this->getAllStaticLibFiles());
|
||||
} else {
|
||||
logger()->info('bloat linking');
|
||||
$extra_libs .= (empty($extra_libs) ? '' : ' ') . implode(' ', array_map(fn ($x) => "-Wl,-force_load,{$x}", array_filter($this->getAllStaticLibFiles())));
|
||||
}
|
||||
$this->setOption('extra-libs', $extra_libs);
|
||||
f_putenv('SPC_EXTRA_LIBS=' . $extra_libs);
|
||||
|
||||
$this->emitPatchPoint('before-php-buildconf');
|
||||
SourcePatcher::patchBeforeBuildconf($this);
|
||||
|
||||
shell()->cd(SOURCE_PATH . '/php-src')->exec('./buildconf --force');
|
||||
shell()->cd(SOURCE_PATH . '/php-src')->exec(getenv('SPC_CMD_PREFIX_PHP_BUILDCONF'));
|
||||
|
||||
$this->emitPatchPoint('before-php-configure');
|
||||
SourcePatcher::patchBeforeConfigure($this);
|
||||
@@ -155,9 +144,9 @@ class MacOSBuilder extends UnixBuilderBase
|
||||
|
||||
// prepare build php envs
|
||||
$envs_build_php = SystemUtil::makeEnvVarString([
|
||||
'CFLAGS' => " {$this->arch_c_flags} -Werror=unknown-warning-option ",
|
||||
'CPPFLAGS' => '-I' . BUILD_INCLUDE_PATH,
|
||||
'LDFLAGS' => '-L' . BUILD_LIB_PATH,
|
||||
'CFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS'),
|
||||
'CPPFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_CPPFLAGS'),
|
||||
'LDFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_LDFLAGS'),
|
||||
]);
|
||||
|
||||
if ($this->getLib('postgresql')) {
|
||||
@@ -170,14 +159,7 @@ class MacOSBuilder extends UnixBuilderBase
|
||||
|
||||
shell()->cd(SOURCE_PATH . '/php-src')
|
||||
->exec(
|
||||
'./configure ' .
|
||||
'--prefix= ' .
|
||||
'--with-valgrind=no ' . // Not detect memory leak
|
||||
'--enable-shared=no ' .
|
||||
'--enable-static=yes ' .
|
||||
'--disable-all ' .
|
||||
'--disable-cgi ' .
|
||||
'--disable-phpdbg ' .
|
||||
getenv('SPC_CMD_PREFIX_PHP_CONFIGURE') . ' ' .
|
||||
($enableCli ? '--enable-cli ' : '--disable-cli ') .
|
||||
($enableFpm ? '--enable-fpm ' : '--disable-fpm ') .
|
||||
($enableEmbed ? '--enable-embed=static ' : '--disable-embed ') .
|
||||
@@ -227,10 +209,10 @@ class MacOSBuilder extends UnixBuilderBase
|
||||
*/
|
||||
protected function buildCli(): void
|
||||
{
|
||||
$vars = SystemUtil::makeEnvVarString($this->getBuildVars());
|
||||
$vars = SystemUtil::makeEnvVarString($this->getMakeExtraVars());
|
||||
|
||||
$shell = shell()->cd(SOURCE_PATH . '/php-src');
|
||||
$shell->exec("make -j{$this->concurrency} {$vars} cli");
|
||||
$shell->exec("\$SPC_CMD_PREFIX_PHP_MAKE {$vars} cli");
|
||||
if (!$this->getOption('no-strip', false)) {
|
||||
$shell->exec('dsymutil -f sapi/cli/php')->exec('strip sapi/cli/php');
|
||||
}
|
||||
@@ -255,18 +237,17 @@ class MacOSBuilder extends UnixBuilderBase
|
||||
}
|
||||
|
||||
$enable_fake_cli = $this->getOption('with-micro-fake-cli', false) ? ' -DPHP_MICRO_FAKE_CLI' : '';
|
||||
$vars = [
|
||||
// with debug information, optimize for size, remove identifiers, patch fake cli for micro
|
||||
'EXTRA_CFLAGS' => '-g -Os -fno-ident' . $enable_fake_cli,
|
||||
];
|
||||
$vars = $this->getBuildVars($vars);
|
||||
$vars = $this->getMakeExtraVars();
|
||||
|
||||
// patch fake cli for micro
|
||||
$vars['EXTRA_CFLAGS'] .= $enable_fake_cli;
|
||||
if (!$this->getOption('no-strip', false)) {
|
||||
$vars['STRIP'] = 'dsymutil -f ';
|
||||
}
|
||||
$vars = SystemUtil::makeEnvVarString($vars);
|
||||
|
||||
shell()->cd(SOURCE_PATH . '/php-src')
|
||||
->exec("make -j{$this->concurrency} {$vars} micro");
|
||||
shell()->cd(SOURCE_PATH . '/php-src')->exec(getenv('SPC_CMD_PREFIX_PHP_MAKE') . " {$vars} micro");
|
||||
|
||||
$this->deployBinary(BUILD_TARGET_MICRO);
|
||||
|
||||
if ($this->phar_patched) {
|
||||
@@ -282,10 +263,10 @@ class MacOSBuilder extends UnixBuilderBase
|
||||
*/
|
||||
protected function buildFpm(): void
|
||||
{
|
||||
$vars = SystemUtil::makeEnvVarString($this->getBuildVars());
|
||||
$vars = SystemUtil::makeEnvVarString($this->getMakeExtraVars());
|
||||
|
||||
$shell = shell()->cd(SOURCE_PATH . '/php-src');
|
||||
$shell->exec("make -j{$this->concurrency} {$vars} fpm");
|
||||
$shell->exec(getenv('SPC_CMD_PREFIX_PHP_MAKE') . " {$vars} fpm");
|
||||
if (!$this->getOption('no-strip', false)) {
|
||||
$shell->exec('dsymutil -f sapi/fpm/php-fpm')->exec('strip sapi/fpm/php-fpm');
|
||||
}
|
||||
@@ -299,11 +280,10 @@ class MacOSBuilder extends UnixBuilderBase
|
||||
*/
|
||||
protected function buildEmbed(): void
|
||||
{
|
||||
$vars = SystemUtil::makeEnvVarString($this->getBuildVars());
|
||||
$vars = SystemUtil::makeEnvVarString($this->getMakeExtraVars());
|
||||
|
||||
shell()
|
||||
->cd(SOURCE_PATH . '/php-src')
|
||||
->exec('make INSTALL_ROOT=' . BUILD_ROOT_PATH . " -j{$this->concurrency} {$vars} install")
|
||||
shell()->cd(SOURCE_PATH . '/php-src')
|
||||
->exec(getenv('SPC_CMD_PREFIX_PHP_MAKE') . ' INSTALL_ROOT=' . BUILD_ROOT_PATH . " {$vars} install")
|
||||
// Workaround for https://github.com/php/php-src/issues/12082
|
||||
->exec('rm -Rf ' . BUILD_ROOT_PATH . '/lib/php-o')
|
||||
->exec('mkdir ' . BUILD_ROOT_PATH . '/lib/php-o')
|
||||
@@ -314,14 +294,11 @@ class MacOSBuilder extends UnixBuilderBase
|
||||
->exec('rm -Rf ' . BUILD_ROOT_PATH . '/lib/php-o');
|
||||
}
|
||||
|
||||
private function getBuildVars($input = []): array
|
||||
private function getMakeExtraVars(): array
|
||||
{
|
||||
$optimization = $this->getOption('no-strip', false) ? '-g -O0' : '-g0 -Os';
|
||||
$cflags = isset($input['EXTRA_CFLAGS']) && $input['EXTRA_CFLAGS'] ? " {$input['EXTRA_CFLAGS']}" : '';
|
||||
$libs = isset($input['EXTRA_LIBS']) && $input['EXTRA_LIBS'] ? " {$input['EXTRA_LIBS']}" : '';
|
||||
return [
|
||||
'EXTRA_CFLAGS' => "{$optimization} {$cflags} " . $this->getOption('x-extra-cflags'),
|
||||
'EXTRA_LIBS' => "{$this->getOption('extra-libs')} -lresolv {$libs} " . $this->getOption('x-extra-libs'),
|
||||
'EXTRA_CFLAGS' => getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS'),
|
||||
'EXTRA_LIBS' => getenv('SPC_EXTRA_LIBS') . ' ' . getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ class libpng extends MacOSLibraryBase
|
||||
*/
|
||||
protected function build(): void
|
||||
{
|
||||
$optimizations = match ($this->builder->getOption('arch')) {
|
||||
$optimizations = match (php_uname('m')) {
|
||||
'x86_64' => '--enable-intel-sse ',
|
||||
'arm64' => '--enable-arm-neon ',
|
||||
default => '',
|
||||
@@ -45,7 +45,7 @@ class libpng extends MacOSLibraryBase
|
||||
->exec('chmod +x ./install-sh')
|
||||
->exec(
|
||||
'./configure ' .
|
||||
"--host={$this->builder->getOption('gnu-arch')}-apple-darwin " .
|
||||
'--host=' . arch2gnu(php_uname('m')) . '-apple-darwin ' .
|
||||
'--disable-shared ' .
|
||||
'--enable-static ' .
|
||||
'--enable-hardware-optimizations ' .
|
||||
|
||||
@@ -23,6 +23,7 @@ namespace SPC\builder\macos\library;
|
||||
use SPC\exception\FileSystemException;
|
||||
use SPC\exception\RuntimeException;
|
||||
use SPC\exception\WrongUsageException;
|
||||
use SPC\store\FileSystem;
|
||||
|
||||
class openssl extends MacOSLibraryBase
|
||||
{
|
||||
@@ -47,6 +48,7 @@ class openssl extends MacOSLibraryBase
|
||||
}
|
||||
|
||||
shell()->cd($this->source_dir)
|
||||
->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()])
|
||||
->exec(
|
||||
"./Configure no-shared {$extra} " .
|
||||
'--prefix=/ ' . // use prefix=/
|
||||
@@ -55,8 +57,18 @@ class openssl extends MacOSLibraryBase
|
||||
"darwin64-{$this->builder->getOption('arch')}-cc"
|
||||
)
|
||||
->exec('make clean')
|
||||
->exec("make -j{$this->builder->concurrency} CNF_EX_LIBS=\"{$ex_lib}\"")
|
||||
->execWithEnv("make -j{$this->builder->concurrency} CNF_EX_LIBS=\"{$ex_lib}\"")
|
||||
->exec("make install_sw DESTDIR={$destdir}");
|
||||
$this->patchPkgconfPrefix(['libssl.pc', 'openssl.pc', 'libcrypto.pc']);
|
||||
// patch for openssl 3.3.0+
|
||||
if (!str_contains($file = FileSystem::readFile(BUILD_LIB_PATH . '/pkgconfig/libssl.pc'), 'prefix=')) {
|
||||
FileSystem::writeFile(BUILD_LIB_PATH . '/pkgconfig/libssl.pc', 'prefix=' . BUILD_ROOT_PATH . "\n" . $file);
|
||||
}
|
||||
if (!str_contains($file = FileSystem::readFile(BUILD_LIB_PATH . '/pkgconfig/openssl.pc'), 'prefix=')) {
|
||||
FileSystem::writeFile(BUILD_LIB_PATH . '/pkgconfig/openssl.pc', 'prefix=' . BUILD_ROOT_PATH . "\n" . $file);
|
||||
}
|
||||
if (!str_contains($file = FileSystem::readFile(BUILD_LIB_PATH . '/pkgconfig/libcrypto.pc'), 'prefix=')) {
|
||||
FileSystem::writeFile(BUILD_LIB_PATH . '/pkgconfig/libcrypto.pc', 'prefix=' . BUILD_ROOT_PATH . "\n" . $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
12
src/SPC/builder/macos/library/qdbm.php
Normal file
12
src/SPC/builder/macos/library/qdbm.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\macos\library;
|
||||
|
||||
class qdbm extends MacOSLibraryBase
|
||||
{
|
||||
use \SPC\builder\unix\library\qdbm;
|
||||
|
||||
public const NAME = 'qdbm';
|
||||
}
|
||||
@@ -1,20 +1,4 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright (c) 2022 Yun Dou <dixyes@gmail.com>
|
||||
*
|
||||
* lwmbs is licensed under Mulan PSL v2. You can use this
|
||||
* software according to the terms and conditions of the
|
||||
* Mulan PSL v2. You may obtain a copy of Mulan PSL v2 at:
|
||||
*
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
||||
* INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ trait UnixLibraryTrait
|
||||
* @throws RuntimeException
|
||||
* @throws WrongUsageException
|
||||
*/
|
||||
public function makeAutoconfEnv(string $prefix = null): string
|
||||
public function makeAutoconfEnv(?string $prefix = null): string
|
||||
{
|
||||
if ($prefix === null) {
|
||||
$prefix = str_replace('-', '_', strtoupper(static::NAME));
|
||||
@@ -99,4 +99,19 @@ trait UnixLibraryTrait
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getLibExtraCFlags(): string
|
||||
{
|
||||
return getenv($this->getSnakeCaseName() . '_CFLAGS') ?: '';
|
||||
}
|
||||
|
||||
public function getLibExtraLdFlags(): string
|
||||
{
|
||||
return getenv($this->getSnakeCaseName() . '_LDFLAGS') ?: '';
|
||||
}
|
||||
|
||||
public function getLibExtraLibs(): string
|
||||
{
|
||||
return getenv($this->getSnakeCaseName() . '_LIBS') ?: '';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ abstract class UnixBuilderBase extends BuilderBase
|
||||
return $extra;
|
||||
}
|
||||
|
||||
public function buildLibs(array $sorted_libraries): void
|
||||
public function proveLibs(array $sorted_libraries): void
|
||||
{
|
||||
// search all supported libs
|
||||
$support_lib_list = [];
|
||||
@@ -137,16 +137,6 @@ abstract class UnixBuilderBase extends BuilderBase
|
||||
SourceManager::initSource(libs: $sorted_libraries);
|
||||
|
||||
$this->emitPatchPoint('after-libs-extract');
|
||||
|
||||
// build all libs
|
||||
foreach ($this->libs as $lib) {
|
||||
match ($lib->tryBuild($this->getOption('rebuild', false))) {
|
||||
BUILD_STATUS_OK => logger()->info('lib [' . $lib::NAME . '] build success'),
|
||||
BUILD_STATUS_ALREADY => logger()->notice('lib [' . $lib::NAME . '] already built'),
|
||||
BUILD_STATUS_FAILED => logger()->error('lib [' . $lib::NAME . '] build failed'),
|
||||
default => logger()->warning('lib [' . $lib::NAME . '] build status unknown'),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,14 +18,15 @@ trait brotli
|
||||
{
|
||||
FileSystem::resetDir($this->source_dir . '/build-dir');
|
||||
shell()->cd($this->source_dir . '/build-dir')
|
||||
->exec(
|
||||
->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()])
|
||||
->execWithEnv(
|
||||
'cmake ' .
|
||||
"{$this->builder->makeCmakeArgs()} " .
|
||||
'-DBUILD_SHARED_LIBS=OFF ' .
|
||||
'..'
|
||||
)
|
||||
->exec("cmake --build . -j {$this->builder->concurrency}")
|
||||
->exec('make install DESTDIR=' . BUILD_ROOT_PATH);
|
||||
->execWithEnv("cmake --build . -j {$this->builder->concurrency}")
|
||||
->execWithEnv('make install DESTDIR=' . BUILD_ROOT_PATH);
|
||||
$this->patchPkgconfPrefix(['libbrotlicommon.pc', 'libbrotlidec.pc', 'libbrotlienc.pc']);
|
||||
shell()->cd(BUILD_ROOT_PATH . '/lib')->exec('ln -sf libbrotlicommon.a libbrotli.a');
|
||||
foreach (FileSystem::scanDirFiles(BUILD_ROOT_PATH . '/lib/', false, true) as $filename) {
|
||||
|
||||
@@ -9,8 +9,9 @@ trait bzip2
|
||||
protected function build(): void
|
||||
{
|
||||
shell()->cd($this->source_dir)
|
||||
->exec("make PREFIX='" . BUILD_ROOT_PATH . "' clean")
|
||||
->exec("make -j{$this->builder->concurrency} {$this->builder->getEnvString()} PREFIX='" . BUILD_ROOT_PATH . "' libbz2.a")
|
||||
->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()])
|
||||
->execWithEnv("make PREFIX='" . BUILD_ROOT_PATH . "' clean")
|
||||
->execWithEnv("make -j{$this->builder->concurrency} {$this->builder->getEnvString()} PREFIX='" . BUILD_ROOT_PATH . "' libbz2.a")
|
||||
->exec('cp libbz2.a ' . BUILD_LIB_PATH)
|
||||
->exec('cp bzlib.h ' . BUILD_INCLUDE_PATH);
|
||||
}
|
||||
|
||||
@@ -51,10 +51,11 @@ trait curl
|
||||
FileSystem::resetDir($this->source_dir . '/build');
|
||||
// compile!
|
||||
shell()->cd($this->source_dir . '/build')
|
||||
->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()])
|
||||
->exec('sed -i.save s@\${CMAKE_C_IMPLICIT_LINK_LIBRARIES}@@ ../CMakeLists.txt')
|
||||
->exec("cmake {$this->builder->makeCmakeArgs()} -DBUILD_SHARED_LIBS=OFF -DBUILD_CURL_EXE=OFF -DBUILD_LIBCURL_DOCS=OFF {$extra} ..")
|
||||
->exec("make -j{$this->builder->concurrency}")
|
||||
->exec('make install DESTDIR=' . BUILD_ROOT_PATH);
|
||||
->execWithEnv("cmake {$this->builder->makeCmakeArgs()} -DBUILD_SHARED_LIBS=OFF -DBUILD_CURL_EXE=OFF -DBUILD_LIBCURL_DOCS=OFF {$extra} ..")
|
||||
->execWithEnv("make -j{$this->builder->concurrency}")
|
||||
->execWithEnv('make install DESTDIR=' . BUILD_ROOT_PATH);
|
||||
// patch pkgconf
|
||||
$this->patchPkgconfPrefix(['libcurl.pc']);
|
||||
shell()->cd(BUILD_LIB_PATH . '/cmake/CURL/')
|
||||
|
||||
@@ -26,15 +26,16 @@ trait freetype
|
||||
$suggested .= ' ';
|
||||
|
||||
shell()->cd($this->source_dir)
|
||||
->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()])
|
||||
->exec('sh autogen.sh')
|
||||
->exec(
|
||||
->execWithEnv(
|
||||
'./configure ' .
|
||||
'--enable-static --disable-shared --without-harfbuzz --prefix= ' .
|
||||
$suggested
|
||||
)
|
||||
->exec('make clean')
|
||||
->exec("make -j{$this->builder->concurrency}")
|
||||
->exec('make install DESTDIR=' . BUILD_ROOT_PATH);
|
||||
->execWithEnv('make clean')
|
||||
->execWithEnv("make -j{$this->builder->concurrency}")
|
||||
->execWithEnv('make install DESTDIR=' . BUILD_ROOT_PATH);
|
||||
$this->patchPkgconfPrefix(['freetype2.pc']);
|
||||
FileSystem::replaceFileStr(
|
||||
BUILD_ROOT_PATH . '/lib/pkgconfig/freetype2.pc',
|
||||
|
||||
@@ -11,7 +11,8 @@ trait gettext
|
||||
$extra = $this->builder->getLib('ncurses') ? ('--with-libncurses-prefix=' . BUILD_ROOT_PATH . ' ') : '';
|
||||
$extra .= $this->builder->getLib('libxml2') ? ('--with-libxml2-prefix=' . BUILD_ROOT_PATH . ' ') : '';
|
||||
shell()->cd($this->source_dir)
|
||||
->exec(
|
||||
->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()])
|
||||
->execWithEnv(
|
||||
'./configure ' .
|
||||
'--enable-static ' .
|
||||
'--disable-shared ' .
|
||||
@@ -21,8 +22,8 @@ trait gettext
|
||||
'--with-libiconv-prefix=' . BUILD_ROOT_PATH . ' ' .
|
||||
'--prefix=' . BUILD_ROOT_PATH
|
||||
)
|
||||
->exec('make clean')
|
||||
->exec("make -j{$this->builder->concurrency}")
|
||||
->exec('make install');
|
||||
->execWithEnv('make clean')
|
||||
->execWithEnv("make -j{$this->builder->concurrency}")
|
||||
->execWithEnv('make install');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,13 +16,14 @@ trait gmp
|
||||
protected function build(): void
|
||||
{
|
||||
shell()->cd($this->source_dir)
|
||||
->exec(
|
||||
->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()])
|
||||
->execWithEnv(
|
||||
'./configure ' .
|
||||
'--enable-static --disable-shared ' .
|
||||
'--prefix='
|
||||
)
|
||||
->exec('make clean')
|
||||
->exec("make -j{$this->builder->concurrency}")
|
||||
->execWithEnv('make clean')
|
||||
->execWithEnv("make -j{$this->builder->concurrency}")
|
||||
->exec('make install DESTDIR=' . BUILD_ROOT_PATH);
|
||||
$this->patchPkgconfPrefix(['gmp.pc']);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ trait imagemagick
|
||||
protected function build(): void
|
||||
{
|
||||
// TODO: imagemagick build with bzip2 failed with bugs, we need to fix it in the future
|
||||
$extra = '--without-jxl --without-x --disable-openmp --without-bzlib ';
|
||||
$extra = '--without-jxl --without-x --enable-openmp --without-bzlib ';
|
||||
$required_libs = '';
|
||||
$optional_libs = [
|
||||
'libzip' => 'zip',
|
||||
@@ -39,15 +39,18 @@ trait imagemagick
|
||||
}
|
||||
}
|
||||
|
||||
$ldflags = $this instanceof LinuxLibraryBase ? ('LDFLAGS="-static" ') : '';
|
||||
$ldflags = $this instanceof LinuxLibraryBase ? ('-static') : '';
|
||||
|
||||
// libxml iconv patch
|
||||
$required_libs .= $this instanceof MacOSLibraryBase ? (' -liconv') : '';
|
||||
$required_libs .= $this instanceof MacOSLibraryBase ? ('-liconv') : '';
|
||||
shell()->cd($this->source_dir)
|
||||
->exec(
|
||||
'PKG_CONFIG="$PKG_CONFIG --static" ' .
|
||||
$ldflags .
|
||||
"LIBS='{$required_libs}' " .
|
||||
->setEnv([
|
||||
'CFLAGS' => $this->getLibExtraCFlags(),
|
||||
'LDFLAGS' => $this->getLibExtraLdFlags() ?: $ldflags,
|
||||
'LIBS' => $this->getLibExtraLibs() ?: $required_libs,
|
||||
'PKG_CONFIG' => '$PKG_CONFIG --static',
|
||||
])
|
||||
->execWithEnv(
|
||||
'./configure ' .
|
||||
'--enable-static --disable-shared ' .
|
||||
$extra .
|
||||
|
||||
@@ -25,9 +25,15 @@ trait ldap
|
||||
$alt .= $this->builder->getLib('libsodium') ? '--with-argon2=libsodium ' : '--enable-argon2=no ';
|
||||
f_putenv('PKG_CONFIG=' . BUILD_ROOT_PATH . '/bin/pkg-config');
|
||||
f_putenv('PKG_CONFIG_PATH=' . BUILD_LIB_PATH . '/pkgconfig');
|
||||
$ldflags = '-L' . BUILD_LIB_PATH;
|
||||
shell()->cd($this->source_dir)
|
||||
->exec(
|
||||
$this->builder->makeAutoconfFlags(AUTOCONF_LDFLAGS | AUTOCONF_CPPFLAGS) .
|
||||
->setEnv([
|
||||
'CFLAGS' => $this->getLibExtraCFlags(),
|
||||
'LDFLAGS' => $this->getLibExtraLdFlags() ?: $ldflags,
|
||||
'LIBS' => $this->getLibExtraLibs(),
|
||||
])
|
||||
->execWithEnv(
|
||||
$this->builder->makeAutoconfFlags(AUTOCONF_CPPFLAGS) .
|
||||
' ./configure ' .
|
||||
'--enable-static ' .
|
||||
'--disable-shared ' .
|
||||
|
||||
@@ -11,9 +11,10 @@ trait libargon2
|
||||
protected function build()
|
||||
{
|
||||
shell()->cd($this->source_dir)
|
||||
->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()])
|
||||
->exec("make PREFIX='' clean")
|
||||
->exec("make -j{$this->builder->concurrency} PREFIX=''")
|
||||
->exec("make install PREFIX='' DESTDIR=" . BUILD_ROOT_PATH);
|
||||
->execWithEnv("make -j{$this->builder->concurrency} PREFIX=''")
|
||||
->execWithEnv("make install PREFIX='' DESTDIR=" . BUILD_ROOT_PATH);
|
||||
|
||||
$this->patchPkgconfPrefix(['libargon2.pc']);
|
||||
|
||||
|
||||
@@ -22,9 +22,10 @@ trait libavif
|
||||
FileSystem::resetDir($this->source_dir . '/build');
|
||||
// Start build
|
||||
shell()->cd($this->source_dir . '/build')
|
||||
->exec("cmake {$this->builder->makeCmakeArgs()} -DBUILD_SHARED_LIBS=OFF ..")
|
||||
->exec("cmake --build . -j {$this->builder->concurrency}")
|
||||
->exec('make install DESTDIR=' . BUILD_ROOT_PATH);
|
||||
->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()])
|
||||
->execWithEnv("cmake {$this->builder->makeCmakeArgs()} -DBUILD_SHARED_LIBS=OFF ..")
|
||||
->execWithEnv("cmake --build . -j {$this->builder->concurrency}")
|
||||
->execWithEnv('make install DESTDIR=' . BUILD_ROOT_PATH);
|
||||
// patch pkgconfig
|
||||
$this->patchPkgconfPrefix(['libavif.pc']);
|
||||
$this->cleanLaFiles();
|
||||
|
||||
@@ -14,8 +14,9 @@ trait libcares
|
||||
protected function build(): void
|
||||
{
|
||||
shell()->cd($this->source_dir)
|
||||
->exec('./configure --prefix=' . BUILD_ROOT_PATH . ' --enable-static --disable-shared --disable-tests')
|
||||
->exec("make -j {$this->builder->concurrency}")
|
||||
->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()])
|
||||
->execWithEnv('./configure --prefix=' . BUILD_ROOT_PATH . ' --enable-static --disable-shared --disable-tests')
|
||||
->execWithEnv("make -j {$this->builder->concurrency}")
|
||||
->exec('make install');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,8 @@ trait libevent
|
||||
FileSystem::resetDir($this->source_dir . '/build');
|
||||
// Start build
|
||||
shell()->cd($this->source_dir . '/build')
|
||||
->exec(
|
||||
->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()])
|
||||
->execWithEnv(
|
||||
'cmake ' .
|
||||
'-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' ' .
|
||||
"-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " .
|
||||
@@ -33,7 +34,7 @@ trait libevent
|
||||
'-DEVENT__DISABLE_SAMPLES=ON ' .
|
||||
'..'
|
||||
)
|
||||
->exec("cmake --build . -j {$this->builder->concurrency}")
|
||||
->execWithEnv("cmake --build . -j {$this->builder->concurrency}")
|
||||
->exec('make install');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,29 +10,37 @@ use SPC\store\FileSystem;
|
||||
|
||||
trait libuuid
|
||||
{
|
||||
public function patchBeforeBuild(): bool
|
||||
{
|
||||
FileSystem::replaceFileStr($this->source_dir . '/configure', '-${am__api_version}', '');
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws FileSystemException
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
protected function build(): void
|
||||
{
|
||||
shell()->cd($this->source_dir)
|
||||
->exec('chmod +x configure')
|
||||
->exec('chmod +x install-sh')
|
||||
FileSystem::resetDir($this->source_dir . '/build');
|
||||
shell()->cd($this->source_dir . '/build')
|
||||
->exec(
|
||||
'./configure ' .
|
||||
'--enable-static --disable-shared ' .
|
||||
'--prefix='
|
||||
'cmake ' .
|
||||
"{$this->builder->makeCmakeArgs()} " .
|
||||
'..'
|
||||
)
|
||||
->exec('make clean')
|
||||
->exec("make -j{$this->builder->concurrency}")
|
||||
->exec('make install DESTDIR=' . BUILD_ROOT_PATH);
|
||||
$this->patchPkgconfPrefix(['uuid.pc']);
|
||||
->exec("cmake --build . -j {$this->builder->concurrency}");
|
||||
copy($this->source_dir . '/build/libuuid.a', BUILD_LIB_PATH . '/libuuid.a');
|
||||
FileSystem::createDir(BUILD_INCLUDE_PATH . '/uuid');
|
||||
copy($this->source_dir . '/uuid.h', BUILD_INCLUDE_PATH . '/uuid/uuid.h');
|
||||
$pc = FileSystem::readFile($this->source_dir . '/uuid.pc.in');
|
||||
$pc = str_replace([
|
||||
'@prefix@',
|
||||
'@exec_prefix@',
|
||||
'@libdir@',
|
||||
'@includedir@',
|
||||
'@LIBUUID_VERSION@',
|
||||
], [
|
||||
BUILD_ROOT_PATH,
|
||||
'${prefix}',
|
||||
'${prefix}/lib',
|
||||
'${prefix}/include',
|
||||
'1.0.3',
|
||||
], $pc);
|
||||
FileSystem::writeFile(BUILD_LIB_PATH . '/pkgconfig/uuid.pc', $pc);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ trait ncurses
|
||||
'--with-curses-h ' .
|
||||
'--enable-pc-files ' .
|
||||
'--enable-echo ' .
|
||||
// '--enable-widec ' .
|
||||
'--disable-widec ' .
|
||||
'--with-normal ' .
|
||||
'--with-ticlib ' .
|
||||
'--without-tests ' .
|
||||
|
||||
@@ -8,15 +8,12 @@ trait pkgconfig
|
||||
{
|
||||
protected function build(): void
|
||||
{
|
||||
$macos_env = "CFLAGS='{$this->builder->arch_c_flags} -Wimplicit-function-declaration' ";
|
||||
$linux_env = 'LDFLAGS=--static ';
|
||||
$cflags = PHP_OS_FAMILY !== 'Linux' ? "{$this->builder->arch_c_flags} -Wimplicit-function-declaration -Wno-int-conversion" : '';
|
||||
$ldflags = PHP_OS_FAMILY !== 'Linux' ? '' : '--static';
|
||||
|
||||
shell()->cd($this->source_dir)
|
||||
->exec(
|
||||
match (PHP_OS_FAMILY) {
|
||||
'Darwin' => $macos_env,
|
||||
default => $linux_env,
|
||||
} .
|
||||
->setEnv(['CFLAGS' => $this->getLibExtraCFlags() ?: $cflags, 'LDFLAGS' => $this->getLibExtraLdFlags() ?: $ldflags, 'LIBS' => $this->getLibExtraLibs()])
|
||||
->execWithEnv(
|
||||
'./configure ' .
|
||||
'--disable-shared ' .
|
||||
'--enable-static ' .
|
||||
@@ -30,8 +27,8 @@ trait pkgconfig
|
||||
'--without-pc-path'
|
||||
)
|
||||
->exec('make clean')
|
||||
->exec("make -j{$this->builder->concurrency}")
|
||||
->exec('make install-exec');
|
||||
->execWithEnv("make -j{$this->builder->concurrency}")
|
||||
->execWithEnv('make install-exec');
|
||||
shell()->exec('strip ' . BUILD_ROOT_PATH . '/bin/pkg-config');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,26 +27,31 @@ trait postgresql
|
||||
'libxslt' => 'libxslt',
|
||||
'icu' => 'icu-i18n',
|
||||
];
|
||||
$error_exec_cnt = 0;
|
||||
|
||||
foreach ($optional_packages as $lib => $pkg) {
|
||||
if ($this->getBuilder()->getLib($lib)) {
|
||||
$packages .= ' ' . $pkg;
|
||||
$output = shell()->execWithResult("pkg-config --static {$pkg}");
|
||||
$error_exec_cnt += $output[0] === 0 ? 0 : 1;
|
||||
logger()->info(var_export($output[1], true));
|
||||
}
|
||||
}
|
||||
|
||||
$output = shell()->execWithResult("pkg-config --cflags-only-I --static {$packages}");
|
||||
$error_exec_cnt += $output[0] === 0 ? 0 : 1;
|
||||
if (!empty($output[1][0])) {
|
||||
$cppflags = $output[1][0];
|
||||
$envs .= " CPPFLAGS=\"{$cppflags}\"";
|
||||
}
|
||||
$output = shell()->execWithResult("pkg-config --libs-only-L --static {$packages}");
|
||||
$error_exec_cnt += $output[0] === 0 ? 0 : 1;
|
||||
if (!empty($output[1][0])) {
|
||||
$ldflags = $output[1][0];
|
||||
$envs .= $this instanceof MacOSLibraryBase ? " LDFLAGS=\"{$ldflags}\" " : " LDFLAGS=\"{$ldflags} -static\" ";
|
||||
}
|
||||
$output = shell()->execWithResult("pkg-config --libs-only-l --static {$packages}");
|
||||
$error_exec_cnt += $output[0] === 0 ? 0 : 1;
|
||||
if (!empty($output[1][0])) {
|
||||
$libs = $output[1][0];
|
||||
$libcpp = '';
|
||||
@@ -55,6 +60,9 @@ trait postgresql
|
||||
}
|
||||
$envs .= " LIBS=\"{$libs}{$libcpp}\" ";
|
||||
}
|
||||
if ($error_exec_cnt > 0) {
|
||||
throw new RuntimeException('Failed to get pkg-config information!');
|
||||
}
|
||||
|
||||
FileSystem::resetDir($this->source_dir . '/build');
|
||||
|
||||
|
||||
33
src/SPC/builder/unix/library/qdbm.php
Normal file
33
src/SPC/builder/unix/library/qdbm.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\unix\library;
|
||||
|
||||
use SPC\builder\macos\library\MacOSLibraryBase;
|
||||
use SPC\exception\FileSystemException;
|
||||
use SPC\exception\RuntimeException;
|
||||
use SPC\store\FileSystem;
|
||||
|
||||
trait qdbm
|
||||
{
|
||||
/**
|
||||
* @throws FileSystemException
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
protected function build(): void
|
||||
{
|
||||
shell()->cd($this->source_dir)
|
||||
->exec(
|
||||
'./configure ' .
|
||||
'--enable-static --disable-shared ' .
|
||||
'--prefix='
|
||||
)
|
||||
->exec('make clean');
|
||||
FileSystem::replaceFileRegex($this->source_dir . '/Makefile', '/MYLIBS = libqdbm.a.*/m', 'MYLIBS = libqdbm.a');
|
||||
shell()->cd($this->source_dir)
|
||||
->exec("make -j{$this->builder->concurrency}" . ($this instanceof MacOSLibraryBase ? ' mac' : ''))
|
||||
->exec('make install DESTDIR=' . BUILD_ROOT_PATH);
|
||||
$this->patchPkgconfPrefix(['qdbm.pc']);
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,6 @@ trait xz
|
||||
'./configure ' .
|
||||
'--enable-static ' .
|
||||
'--disable-shared ' .
|
||||
"--host={$this->builder->getOption('gnu-arch')}-unknown-linux " .
|
||||
'--disable-scripts ' .
|
||||
'--disable-doc ' .
|
||||
'--with-libiconv ' .
|
||||
|
||||
@@ -13,6 +13,7 @@ use SPC\store\FileSystem;
|
||||
use SPC\store\SourceManager;
|
||||
use SPC\store\SourcePatcher;
|
||||
use SPC\util\DependencyUtil;
|
||||
use SPC\util\GlobalEnvManager;
|
||||
|
||||
class WindowsBuilder extends BuilderBase
|
||||
{
|
||||
@@ -33,6 +34,8 @@ class WindowsBuilder extends BuilderBase
|
||||
{
|
||||
$this->options = $options;
|
||||
|
||||
GlobalEnvManager::init($this);
|
||||
|
||||
// ---------- set necessary options ----------
|
||||
// set sdk (require visual studio 16 or 17)
|
||||
$vs = SystemUtil::findVisualStudio()['version'];
|
||||
@@ -42,10 +45,13 @@ class WindowsBuilder extends BuilderBase
|
||||
$this->zts = $this->getOption('enable-zts', false);
|
||||
|
||||
// set concurrency
|
||||
$this->concurrency = SystemUtil::getCpuCount();
|
||||
$this->concurrency = intval(getenv('SPC_CONCURRENCY'));
|
||||
|
||||
// make cmake toolchain
|
||||
$this->cmake_toolchain_file = SystemUtil::makeCmakeToolchainFile();
|
||||
|
||||
f_mkdir(BUILD_INCLUDE_PATH, recursive: true);
|
||||
f_mkdir(BUILD_LIB_PATH, recursive: true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,9 +62,10 @@ class WindowsBuilder extends BuilderBase
|
||||
public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
|
||||
{
|
||||
// ---------- Update extra-libs ----------
|
||||
$extra_libs = $this->getOption('extra-libs', '');
|
||||
$extra_libs = getenv('SPC_EXTRA_LIBS') ?: '';
|
||||
$extra_libs .= (empty($extra_libs) ? '' : ' ') . implode(' ', $this->getAllStaticLibFiles());
|
||||
$this->setOption('extra-libs', $extra_libs);
|
||||
f_putenv('SPC_EXTRA_LIBS=' . $extra_libs);
|
||||
|
||||
$enableCli = ($build_target & BUILD_TARGET_CLI) === BUILD_TARGET_CLI;
|
||||
$enableFpm = ($build_target & BUILD_TARGET_FPM) === BUILD_TARGET_FPM;
|
||||
$enableMicro = ($build_target & BUILD_TARGET_MICRO) === BUILD_TARGET_MICRO;
|
||||
@@ -77,7 +84,7 @@ class WindowsBuilder extends BuilderBase
|
||||
if ($this->getOption('with-upx-pack', false)) {
|
||||
if (!file_exists($makefile . '.originfile')) {
|
||||
copy($makefile, $makefile . '.originfile');
|
||||
FileSystem::replaceFileStr($makefile, '$(MICRO_SFX):', "_MICRO_UPX = {$this->getOption('upx-exec')} --best $(MICRO_SFX)\n$(MICRO_SFX):");
|
||||
FileSystem::replaceFileStr($makefile, '$(MICRO_SFX):', '_MICRO_UPX = ' . getenv('UPX_EXEC') . " --best $(MICRO_SFX)\n$(MICRO_SFX):");
|
||||
FileSystem::replaceFileStr($makefile, '@$(_MICRO_MT)', "@$(_MICRO_MT)\n\t@$(_MICRO_UPX)");
|
||||
}
|
||||
} elseif (file_exists($makefile . '.originfile')) {
|
||||
@@ -198,7 +205,7 @@ class WindowsBuilder extends BuilderBase
|
||||
$this->deployBinary(BUILD_TARGET_MICRO);
|
||||
}
|
||||
|
||||
public function buildLibs(array $sorted_libraries): void
|
||||
public function proveLibs(array $sorted_libraries): void
|
||||
{
|
||||
// search all supported libs
|
||||
$support_lib_list = [];
|
||||
@@ -235,16 +242,6 @@ class WindowsBuilder extends BuilderBase
|
||||
|
||||
// extract sources
|
||||
SourceManager::initSource(libs: $sorted_libraries);
|
||||
|
||||
// build all libs
|
||||
foreach ($this->libs as $lib) {
|
||||
match ($lib->tryBuild($this->getOption('rebuild', false))) {
|
||||
BUILD_STATUS_OK => logger()->info('lib [' . $lib::NAME . '] build success'),
|
||||
BUILD_STATUS_ALREADY => logger()->notice('lib [' . $lib::NAME . '] already built'),
|
||||
BUILD_STATUS_FAILED => logger()->error('lib [' . $lib::NAME . '] build failed'),
|
||||
default => logger()->warning('lib [' . $lib::NAME . '] build status unknown'),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -264,6 +261,12 @@ class WindowsBuilder extends BuilderBase
|
||||
*/
|
||||
public function sanityCheck(mixed $build_target): void
|
||||
{
|
||||
// remove all .dll from `buildroot/bin/`
|
||||
logger()->debug('Removing all .dll files from buildroot/bin/');
|
||||
$dlls = glob(BUILD_BIN_PATH . '\*.dll');
|
||||
foreach ($dlls as $dll) {
|
||||
@unlink($dll);
|
||||
}
|
||||
// sanity check for php-cli
|
||||
if (($build_target & BUILD_TARGET_CLI) === BUILD_TARGET_CLI) {
|
||||
logger()->info('running cli sanity check');
|
||||
@@ -319,7 +322,7 @@ class WindowsBuilder extends BuilderBase
|
||||
|
||||
// with-upx-pack for cli
|
||||
if ($this->getOption('with-upx-pack', false) && $type === BUILD_TARGET_CLI) {
|
||||
cmd()->exec($this->getOption('upx-exec') . ' --best ' . escapeshellarg($src));
|
||||
cmd()->exec(getenv('UPX_EXEC') . ' --best ' . escapeshellarg($src));
|
||||
}
|
||||
|
||||
logger()->info('Deploying ' . $this->getBuildTypeName($type) . ' file');
|
||||
|
||||
@@ -25,6 +25,8 @@ class nghttp2 extends WindowsLibraryBase
|
||||
'-DCMAKE_BUILD_TYPE=Release ' .
|
||||
'-DENABLE_SHARED_LIB=OFF ' .
|
||||
'-DENABLE_STATIC_LIB=ON ' .
|
||||
'-DBUILD_STATIC_LIBS=ON ' .
|
||||
'-DBUILD_SHARED_LIBS=OFF ' .
|
||||
'-DENABLE_STATIC_CRT=ON ' .
|
||||
'-DENABLE_LIB_ONLY=ON ' .
|
||||
'-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' '
|
||||
|
||||
29
src/SPC/builder/windows/library/pthreads4w.php
Normal file
29
src/SPC/builder/windows/library/pthreads4w.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\windows\library;
|
||||
|
||||
class pthreads4w extends WindowsLibraryBase
|
||||
{
|
||||
public const NAME = 'pthreads4w';
|
||||
|
||||
protected function build(): void
|
||||
{
|
||||
cmd()->cd($this->source_dir)
|
||||
->execWithWrapper(
|
||||
$this->builder->makeSimpleWrapper(
|
||||
'nmake /E /nologo /f Makefile ' .
|
||||
'DESTROOT=' . BUILD_ROOT_PATH . ' ' .
|
||||
'XCFLAGS="/MT" ' . // no dll
|
||||
'EHFLAGS="/I. /DHAVE_CONFIG_H /Os /Ob2 /D__PTW32_STATIC_LIB /D__PTW32_BUILD_INLINED"'
|
||||
),
|
||||
'pthreadVC3.inlined_static_stamp'
|
||||
);
|
||||
copy($this->source_dir . '\libpthreadVC3.lib', BUILD_LIB_PATH . '\libpthreadVC3.lib');
|
||||
copy($this->source_dir . '\_ptw32.h', BUILD_INCLUDE_PATH . '\_ptw32.h');
|
||||
copy($this->source_dir . '\pthread.h', BUILD_INCLUDE_PATH . '\pthread.h');
|
||||
copy($this->source_dir . '\sched.h', BUILD_INCLUDE_PATH . '\sched.h');
|
||||
copy($this->source_dir . '\semaphore.h', BUILD_INCLUDE_PATH . '\semaphore.h');
|
||||
}
|
||||
}
|
||||
24
src/SPC/builder/windows/library/qdbm.php
Normal file
24
src/SPC/builder/windows/library/qdbm.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\windows\library;
|
||||
|
||||
use SPC\store\FileSystem;
|
||||
|
||||
class qdbm extends WindowsLibraryBase
|
||||
{
|
||||
public const NAME = 'qdbm';
|
||||
|
||||
protected function build(): void
|
||||
{
|
||||
cmd()->cd($this->source_dir)
|
||||
->execWithWrapper(
|
||||
$this->builder->makeSimpleWrapper('nmake'),
|
||||
'/f VCMakefile'
|
||||
);
|
||||
copy($this->source_dir . '\qdbm_a.lib', BUILD_LIB_PATH . '\qdbm_a.lib');
|
||||
copy($this->source_dir . '\depot.h', BUILD_INCLUDE_PATH . '\depot.h');
|
||||
// FileSystem::copyDir($this->source_dir . '\include\curl', BUILD_INCLUDE_PATH . '\curl');
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ abstract class BaseCommand extends Command
|
||||
|
||||
protected OutputInterface $output;
|
||||
|
||||
public function __construct(string $name = null)
|
||||
public function __construct(?string $name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
$this->addOption('debug', null, null, 'Enable debug mode');
|
||||
@@ -132,4 +132,14 @@ abstract class BaseCommand extends Command
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function logWithResult(bool $result, string $success_msg, string $fail_msg): int
|
||||
{
|
||||
if ($result) {
|
||||
logger()->info($success_msg);
|
||||
return static::SUCCESS;
|
||||
}
|
||||
logger()->error($fail_msg);
|
||||
return static::FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,13 +10,14 @@ use SPC\exception\WrongUsageException;
|
||||
use SPC\store\FileSystem;
|
||||
use SPC\store\SourcePatcher;
|
||||
use SPC\util\DependencyUtil;
|
||||
use SPC\util\GlobalEnvManager;
|
||||
use SPC\util\LicenseDumper;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use ZM\Logger\ConsoleColor;
|
||||
|
||||
#[AsCommand('build', 'build PHP')]
|
||||
#[AsCommand('build', 'build PHP', ['build:php'])]
|
||||
class BuildCliCommand extends BuildCommand
|
||||
{
|
||||
public function configure(): void
|
||||
@@ -92,6 +93,9 @@ class BuildCliCommand extends BuildCommand
|
||||
if ($this->getOption('no-strip')) {
|
||||
logger()->warning('--with-upx-pack conflicts with --no-strip, --no-strip won\'t work!');
|
||||
}
|
||||
if (($rule & BUILD_TARGET_MICRO) === BUILD_TARGET_MICRO) {
|
||||
logger()->warning('Some cases micro.sfx cannot be packed via UPX due to dynamic size bug, be aware!');
|
||||
}
|
||||
}
|
||||
try {
|
||||
// create builder
|
||||
@@ -117,7 +121,6 @@ class BuildCliCommand extends BuildCommand
|
||||
}
|
||||
if ($this->input->getOption('with-upx-pack') && in_array(PHP_OS_FAMILY, ['Linux', 'Windows'])) {
|
||||
$indent_texts['UPX Pack'] = 'enabled';
|
||||
$builder->setOption('upx-exec', FileSystem::convertPath(PKG_ROOT_PATH . '/bin/upx' . $suffix));
|
||||
}
|
||||
try {
|
||||
$ver = $builder->getPHPVersion();
|
||||
@@ -131,18 +134,25 @@ class BuildCliCommand extends BuildCommand
|
||||
if (!empty($not_included)) {
|
||||
$indent_texts['Extra Exts (' . count($not_included) . ')'] = implode(', ', $not_included);
|
||||
}
|
||||
$this->printFormatInfo($this->getDefinedEnvs(), true);
|
||||
$this->printFormatInfo($indent_texts);
|
||||
|
||||
logger()->notice('Build will start after 2s ...');
|
||||
sleep(2);
|
||||
|
||||
// compile libraries
|
||||
$builder->proveLibs($libraries);
|
||||
// check extensions
|
||||
$builder->proveExts($extensions);
|
||||
// validate libs and exts
|
||||
$builder->validateLibsAndExts();
|
||||
// build libraries
|
||||
$builder->buildLibs();
|
||||
|
||||
if ($this->input->getOption('with-clean')) {
|
||||
logger()->info('Cleaning source dir...');
|
||||
FileSystem::removeDir(SOURCE_PATH);
|
||||
}
|
||||
// compile libraries
|
||||
$builder->buildLibs($libraries);
|
||||
// check extensions
|
||||
$builder->proveExts($extensions);
|
||||
|
||||
// Process -I option
|
||||
$custom_ini = [];
|
||||
@@ -226,7 +236,18 @@ class BuildCliCommand extends BuildCommand
|
||||
return $rule;
|
||||
}
|
||||
|
||||
private function printFormatInfo(array $indent_texts): void
|
||||
private function getDefinedEnvs(): array
|
||||
{
|
||||
$envs = GlobalEnvManager::getInitializedEnv();
|
||||
$final = [];
|
||||
foreach ($envs as $env) {
|
||||
$exp = explode('=', $env, 2);
|
||||
$final['Init var [' . $exp[0] . ']'] = $exp[1];
|
||||
}
|
||||
return $final;
|
||||
}
|
||||
|
||||
private function printFormatInfo(array $indent_texts, bool $debug = false): void
|
||||
{
|
||||
// calculate space count for every line
|
||||
$maxlen = 0;
|
||||
@@ -236,14 +257,14 @@ class BuildCliCommand extends BuildCommand
|
||||
foreach ($indent_texts as $k => $v) {
|
||||
if (is_string($v)) {
|
||||
/* @phpstan-ignore-next-line */
|
||||
logger()->info($k . ': ' . str_pad('', $maxlen - strlen($k)) . ConsoleColor::yellow($v));
|
||||
logger()->{$debug ? 'debug' : 'info'}($k . ': ' . str_pad('', $maxlen - strlen($k)) . ConsoleColor::yellow($v));
|
||||
} elseif (is_array($v) && !is_assoc_array($v)) {
|
||||
$first = array_shift($v);
|
||||
/* @phpstan-ignore-next-line */
|
||||
logger()->info($k . ': ' . str_pad('', $maxlen - strlen($k)) . ConsoleColor::yellow($first));
|
||||
logger()->{$debug ? 'debug' : 'info'}($k . ': ' . str_pad('', $maxlen - strlen($k)) . ConsoleColor::yellow($first));
|
||||
foreach ($v as $vs) {
|
||||
/* @phpstan-ignore-next-line */
|
||||
logger()->info(str_pad('', $maxlen + 2) . ConsoleColor::yellow($vs));
|
||||
logger()->{$debug ? 'debug' : 'info'}(str_pad('', $maxlen + 2) . ConsoleColor::yellow($vs));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
abstract class BuildCommand extends BaseCommand
|
||||
{
|
||||
public function __construct(string $name = null)
|
||||
public function __construct(?string $name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
|
||||
@@ -61,7 +61,11 @@ class BuildLibsCommand extends BuildCommand
|
||||
$builder->setLibsOnly();
|
||||
// 编译和检查库完整
|
||||
$libraries = DependencyUtil::getLibs($libraries);
|
||||
$builder->buildLibs($libraries);
|
||||
logger()->info('Building libraries: ' . implode(',', $libraries));
|
||||
sleep(2);
|
||||
$builder->proveLibs($libraries);
|
||||
$builder->validateLibsAndExts();
|
||||
$builder->buildLibs();
|
||||
|
||||
$time = round(microtime(true) - START_TIME, 3);
|
||||
logger()->info('Build libs complete, used ' . $time . ' s !');
|
||||
|
||||
@@ -57,8 +57,11 @@ class DumpLicenseCommand extends BaseCommand
|
||||
$libraries = DependencyUtil::getLibs($libraries);
|
||||
$dumper->addLibs($libraries);
|
||||
$dumper->dump($this->getOption('dump-dir'));
|
||||
$this->output->writeln('Dump target dir: ' . $this->getOption('dump-dir'));
|
||||
return static::SUCCESS;
|
||||
return $this->logWithResult(
|
||||
$dumper->dump($this->getOption('dump-dir')),
|
||||
'Dump target dir: ' . $this->getOption('dump-dir'),
|
||||
'Dump failed!'
|
||||
);
|
||||
}
|
||||
if ($this->getOption('for-sources') !== null) {
|
||||
$sources = array_map('trim', array_filter(explode(',', $this->getOption('for-sources'))));
|
||||
|
||||
67
src/SPC/command/SwitchPhpVersionCommand.php
Normal file
67
src/SPC/command/SwitchPhpVersionCommand.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\command;
|
||||
|
||||
use SPC\store\Config;
|
||||
use SPC\store\Downloader;
|
||||
use SPC\store\FileSystem;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
#[AsCommand('switch-php-version', description: 'Switch downloaded PHP version')]
|
||||
class SwitchPhpVersionCommand extends BaseCommand
|
||||
{
|
||||
public function configure()
|
||||
{
|
||||
$this->addArgument(
|
||||
'php-major-version',
|
||||
InputArgument::REQUIRED,
|
||||
'PHP major version (supported: 7.4, 8.0, 8.1, 8.2, 8.3)',
|
||||
null,
|
||||
fn () => ['7.4', '8.0', '8.1', '8.2', '8.3']
|
||||
);
|
||||
$this->no_motd = true;
|
||||
|
||||
$this->addOption('retry', 'R', InputOption::VALUE_REQUIRED, 'Set retry time when downloading failed (default: 0)', '0');
|
||||
}
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
$php_ver = $this->input->getArgument('php-major-version');
|
||||
if (!in_array($php_ver, ['7.4', '8.0', '8.1', '8.2', '8.3'])) {
|
||||
$this->output->writeln('<error>Invalid PHP major version ' . $php_ver . ' !</error>');
|
||||
return static::FAILURE;
|
||||
}
|
||||
|
||||
// detect if downloads/.lock.json exists
|
||||
$lock_file = DOWNLOAD_PATH . '/.lock.json';
|
||||
// parse php-src part of lock file
|
||||
$lock_data = json_decode(file_get_contents($lock_file), true);
|
||||
// get php-src downloaded file name
|
||||
$php_src = $lock_data['php-src'];
|
||||
$file = DOWNLOAD_PATH . '/' . ($php_src['filename'] ?? '.donot.delete.me');
|
||||
if (file_exists($file)) {
|
||||
$this->output->writeln('<info>Removing old PHP source...</info>');
|
||||
unlink($file);
|
||||
}
|
||||
|
||||
// Download new PHP source
|
||||
$this->output->writeln('<info>Downloading PHP source...</info>');
|
||||
define('SPC_BUILD_PHP_VERSION', $php_ver);
|
||||
|
||||
// retry
|
||||
$retry = intval($this->getOption('retry'));
|
||||
f_putenv('SPC_RETRY_TIME=' . $retry);
|
||||
|
||||
Downloader::downloadSource('php-src', Config::getSource('php-src'));
|
||||
|
||||
// Remove source/php-src dir
|
||||
FileSystem::removeDir(SOURCE_PATH . '/php-src');
|
||||
|
||||
$this->output->writeln('<info>Switched to PHP ' . $php_ver . ' successfully!</info>');
|
||||
return static::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -40,8 +40,13 @@ class LinuxToolCheckList
|
||||
'xz',
|
||||
];
|
||||
|
||||
public const TOOLS_ARCH = [
|
||||
'base-devel', 'cmake',
|
||||
];
|
||||
|
||||
private const PROVIDED_COMMAND = [
|
||||
'binutils-gold' => 'ld.gold',
|
||||
'base-devel' => 'automake',
|
||||
];
|
||||
|
||||
/** @noinspection PhpUnused */
|
||||
@@ -53,6 +58,7 @@ class LinuxToolCheckList
|
||||
$required = match ($distro['dist']) {
|
||||
'alpine' => self::TOOLS_ALPINE,
|
||||
'redhat' => self::TOOLS_RHEL,
|
||||
'arch' => self::TOOLS_ARCH,
|
||||
default => self::TOOLS_DEBIAN,
|
||||
};
|
||||
$missing = [];
|
||||
@@ -67,6 +73,7 @@ class LinuxToolCheckList
|
||||
'alpine',
|
||||
'redhat',
|
||||
'Deepin',
|
||||
'arch',
|
||||
'debian' => CheckResult::fail(implode(', ', $missing) . ' not installed on your system', 'install-linux-tools', [$distro, $missing]),
|
||||
default => CheckResult::fail(implode(', ', $missing) . ' not installed on your system'),
|
||||
};
|
||||
@@ -74,6 +81,22 @@ class LinuxToolCheckList
|
||||
return CheckResult::ok();
|
||||
}
|
||||
|
||||
#[AsCheckItem('if cmake version >= 3.18', limit_os: 'Linux')]
|
||||
public function checkCMakeVersion(): ?CheckResult
|
||||
{
|
||||
$check_cmd = 'cmake --version';
|
||||
$pattern = '/cmake version (.*)/m';
|
||||
$out = shell()->execWithResult($check_cmd, false)[1][0];
|
||||
if (preg_match($pattern, $out, $match)) {
|
||||
$ver = $match[1];
|
||||
if (version_compare($ver, '3.18.0') <= 0) {
|
||||
return CheckResult::fail('cmake version is too low (' . $ver . '), please update it manually!');
|
||||
}
|
||||
return CheckResult::ok($match[1]);
|
||||
}
|
||||
return CheckResult::fail('Failed to get cmake version');
|
||||
}
|
||||
|
||||
/** @noinspection PhpUnused */
|
||||
#[AsCheckItem('if necessary linux headers are installed', limit_os: 'Linux')]
|
||||
public function checkSystemOSPackages(): ?CheckResult
|
||||
@@ -98,6 +121,7 @@ class LinuxToolCheckList
|
||||
'ubuntu', 'debian', 'Deepin' => 'apt-get install -y',
|
||||
'alpine' => 'apk add',
|
||||
'redhat' => 'dnf install -y',
|
||||
'arch' => 'pacman -S --noconfirm',
|
||||
default => throw new RuntimeException('Current linux distro does not have an auto-install script for musl packages yet.'),
|
||||
};
|
||||
$prefix = '';
|
||||
|
||||
@@ -37,10 +37,12 @@ class MacOSToolCheckList
|
||||
#[AsCheckItem('if homebrew has installed', limit_os: 'Darwin', level: 998)]
|
||||
public function checkBrew(): ?CheckResult
|
||||
{
|
||||
// 检查 homebrew 是否已经安装
|
||||
if ($this->findCommand('brew') === null) {
|
||||
if (($path = $this->findCommand('brew')) === null) {
|
||||
return CheckResult::fail('Homebrew is not installed', 'brew');
|
||||
}
|
||||
if ($path !== '/opt/homebrew/bin/brew' && php_uname('m') === 'arm64') {
|
||||
return CheckResult::fail('Current homebrew (/usr/local/bin/homebrew) is not installed for M1 Mac, please re-install homebrew in /opt/homebrew/ !');
|
||||
}
|
||||
return CheckResult::ok();
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ class OSCheckList
|
||||
return CheckResult::fail('Current OS is not supported: ' . PHP_OS_FAMILY);
|
||||
}
|
||||
$distro = PHP_OS_FAMILY === 'Linux' ? (' ' . SystemUtil::getOSRelease()['dist']) : '';
|
||||
$known_distro = PHP_OS_FAMILY === 'Linux' && in_array(SystemUtil::getOSRelease()['dist'], SystemUtil::getSupportedDistros());
|
||||
$known_distro = PHP_OS_FAMILY !== 'Linux' || in_array(SystemUtil::getOSRelease()['dist'], SystemUtil::getSupportedDistros());
|
||||
return CheckResult::ok(PHP_OS_FAMILY . ' ' . php_uname('m') . $distro . ', supported' . ($known_distro ? '' : ' (but not tested on this distro)'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,12 +62,17 @@ class DependencyUtil
|
||||
|
||||
if ($include_suggested_libs) {
|
||||
foreach ($dep_list as $name => $obj) {
|
||||
$del_list = [];
|
||||
foreach ($obj['suggests'] as $id => $suggest) {
|
||||
if (!str_starts_with($suggest, 'ext@')) {
|
||||
$dep_list[$name]['depends'][] = $suggest;
|
||||
array_splice($dep_list[$name]['suggests'], $id, 1);
|
||||
$del_list[] = $id;
|
||||
}
|
||||
}
|
||||
foreach ($del_list as $id) {
|
||||
unset($dep_list[$name]['suggests'][$id]);
|
||||
}
|
||||
$dep_list[$name]['suggests'] = array_values($dep_list[$name]['suggests']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,12 +98,17 @@ class DependencyUtil
|
||||
if ($include_suggested_exts) {
|
||||
// check every deps suggests contains ext@
|
||||
foreach ($dep_list as $name => $obj) {
|
||||
$del_list = [];
|
||||
foreach ($obj['suggests'] as $id => $suggest) {
|
||||
if (str_starts_with($suggest, 'ext@')) {
|
||||
$dep_list[$name]['depends'][] = $suggest;
|
||||
array_splice($dep_list[$name]['suggests'], $id, 1);
|
||||
$del_list[] = $id;
|
||||
}
|
||||
}
|
||||
foreach ($del_list as $id) {
|
||||
unset($dep_list[$name]['suggests'][$id]);
|
||||
}
|
||||
$dep_list[$name]['suggests'] = array_values($dep_list[$name]['suggests']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,12 +116,17 @@ class DependencyUtil
|
||||
if ($include_suggested_libs) {
|
||||
// check every deps suggests
|
||||
foreach ($dep_list as $name => $obj) {
|
||||
$del_list = [];
|
||||
foreach ($obj['suggests'] as $id => $suggest) {
|
||||
if (!str_starts_with($suggest, 'ext@')) {
|
||||
$dep_list[$name]['depends'][] = $suggest;
|
||||
array_splice($dep_list[$name]['suggests'], $id, 1);
|
||||
$del_list[] = $id;
|
||||
}
|
||||
}
|
||||
foreach ($del_list as $id) {
|
||||
unset($dep_list[$name]['suggests'][$id]);
|
||||
}
|
||||
$dep_list[$name]['suggests'] = array_values($dep_list[$name]['suggests']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
189
src/SPC/util/GlobalEnvManager.php
Normal file
189
src/SPC/util/GlobalEnvManager.php
Normal file
@@ -0,0 +1,189 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\util;
|
||||
|
||||
use SPC\builder\BuilderBase;
|
||||
use SPC\builder\freebsd\SystemUtil as BSDSystemUtil;
|
||||
use SPC\builder\linux\SystemUtil as LinuxSystemUtil;
|
||||
use SPC\builder\macos\SystemUtil as MacOSSystemUtil;
|
||||
use SPC\builder\windows\SystemUtil as WindowsSystemUtil;
|
||||
use SPC\exception\RuntimeException;
|
||||
|
||||
/**
|
||||
* Environment variable manager
|
||||
*/
|
||||
class GlobalEnvManager
|
||||
{
|
||||
private static array $env_cache = [];
|
||||
|
||||
public static function getInitializedEnv(): array
|
||||
{
|
||||
return self::$env_cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the environment variables
|
||||
*
|
||||
* @param BuilderBase $builder Builder
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public static function init(BuilderBase $builder): void
|
||||
{
|
||||
// Init global env, build related path
|
||||
self::putenv('BUILD_ROOT_PATH=' . BUILD_ROOT_PATH);
|
||||
self::putenv('BUILD_INCLUDE_PATH=' . BUILD_INCLUDE_PATH);
|
||||
self::putenv('BUILD_LIB_PATH=' . BUILD_LIB_PATH);
|
||||
self::putenv('BUILD_BIN_PATH=' . BUILD_BIN_PATH);
|
||||
self::putenv('PKG_ROOT_PATH=' . PKG_ROOT_PATH);
|
||||
self::putenv('SOURCE_PATH=' . SOURCE_PATH);
|
||||
self::putenv('DOWNLOAD_PATH=' . DOWNLOAD_PATH);
|
||||
|
||||
// Init SPC env
|
||||
self::initIfNotExists('SPC_CONCURRENCY', match (PHP_OS_FAMILY) {
|
||||
'Windows' => (string) WindowsSystemUtil::getCpuCount(),
|
||||
'Darwin' => (string) MacOSSystemUtil::getCpuCount(),
|
||||
'Linux' => (string) LinuxSystemUtil::getCpuCount(),
|
||||
'BSD' => (string) BSDSystemUtil::getCpuCount(),
|
||||
default => '1',
|
||||
});
|
||||
|
||||
// Init system-specific env
|
||||
match (PHP_OS_FAMILY) {
|
||||
'Windows' => self::initWindowsEnv(),
|
||||
'Darwin' => self::initDarwinEnv($builder),
|
||||
'Linux' => self::initLinuxEnv($builder),
|
||||
'BSD' => 'TODO',
|
||||
default => logger()->warning('Unknown OS: ' . PHP_OS_FAMILY),
|
||||
};
|
||||
}
|
||||
|
||||
private static function initWindowsEnv(): void
|
||||
{
|
||||
// Windows need php-sdk binary tools
|
||||
self::initIfNotExists('PHP_SDK_PATH', WORKING_DIR . DIRECTORY_SEPARATOR . 'php-sdk-binary-tools');
|
||||
self::initIfNotExists('UPX_EXEC', PKG_ROOT_PATH . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . 'upx.exe');
|
||||
}
|
||||
|
||||
private static function initLinuxEnv(BuilderBase $builder): void
|
||||
{
|
||||
// Init C Compiler and C++ Compiler (alpine)
|
||||
if (LinuxSystemUtil::isMuslDist()) {
|
||||
self::initIfNotExists('CC', 'gcc');
|
||||
self::initIfNotExists('CXX', 'g++');
|
||||
self::initIfNotExists('AR', 'ar');
|
||||
self::initIfNotExists('LD', 'ld.gold');
|
||||
} else {
|
||||
$arch = arch2gnu(php_uname('m'));
|
||||
self::initIfNotExists('CC', "{$arch}-linux-musl-gcc");
|
||||
self::initIfNotExists('CXX', "{$arch}-linux-musl-g++");
|
||||
self::initIfNotExists('AR', "{$arch}-linux-musl-ar");
|
||||
self::initIfNotExists('LD', 'ld.gold');
|
||||
if (getenv('SPC_NO_MUSL_PATH') !== 'yes') {
|
||||
self::putenv("PATH=/usr/local/musl/bin:/usr/local/musl/{$arch}-linux-musl/bin:" . getenv('PATH'));
|
||||
}
|
||||
}
|
||||
|
||||
// Init arch-specific cflags
|
||||
self::initIfNotExists('SPC_DEFAULT_C_FLAGS', '');
|
||||
self::initIfNotExists('SPC_DEFAULT_CXX_FLAGS', '');
|
||||
self::initIfNotExists('SPC_EXTRA_LIBS', '');
|
||||
|
||||
// Init linux-only env
|
||||
self::initIfNotExists('UPX_EXEC', PKG_ROOT_PATH . '/bin/upx');
|
||||
self::initIfNotExists('GNU_ARCH', arch2gnu(php_uname('m')));
|
||||
|
||||
// optimization flags with different strip option
|
||||
$php_extra_cflags_optimize = $builder->getOption('no-strip') ? '-g -O0' : '-g -Os';
|
||||
// optimization flags with different c compiler
|
||||
$clang_use_lld = str_ends_with(getenv('CC'), 'clang') && LinuxSystemUtil::findCommand('lld') ? '-Xcompiler -fuse-ld=lld ' : '';
|
||||
|
||||
$init_spc_cmd_maps = [
|
||||
// Init default build command prefix
|
||||
'SPC_CMD_PREFIX_PHP_BUILDCONF' => './buildconf --force',
|
||||
'SPC_CMD_PREFIX_PHP_CONFIGURE' => $builder->getOption('ld_library_path') . ' ./configure --prefix= --with-valgrind=no --enable-shared=no --enable-static=yes --disable-all --disable-cgi --disable-phpdbg',
|
||||
'SPC_CMD_PREFIX_PHP_MAKE' => 'make -j' . getenv('SPC_CONCURRENCY'),
|
||||
// Init default build vars for build command
|
||||
'SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS' => getenv('SPC_DEFAULT_C_FLAGS'),
|
||||
'SPC_CMD_VAR_PHP_CONFIGURE_CPPFLAGS' => '-I' . BUILD_INCLUDE_PATH,
|
||||
'SPC_CMD_VAR_PHP_CONFIGURE_LDFLAGS' => '-L' . BUILD_LIB_PATH,
|
||||
'SPC_CMD_VAR_PHP_CONFIGURE_LIBS' => '-ldl -lpthread -lm',
|
||||
'SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS' => $php_extra_cflags_optimize . ' -fno-ident -fPIE',
|
||||
'SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS' => '',
|
||||
'SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM' => $clang_use_lld . '-all-static',
|
||||
];
|
||||
foreach ($init_spc_cmd_maps as $name => $value) {
|
||||
self::initIfNotExists($name, $value);
|
||||
}
|
||||
|
||||
self::initUnixEnv($builder);
|
||||
}
|
||||
|
||||
private static function initDarwinEnv(BuilderBase $builder): void
|
||||
{
|
||||
// Init C Compiler and C++ Compiler
|
||||
self::initIfNotExists('CC', 'clang');
|
||||
self::initIfNotExists('CXX', 'clang++');
|
||||
|
||||
// Init arch-specific cflags
|
||||
self::initIfNotExists('SPC_DEFAULT_C_FLAGS', match (php_uname('m')) {
|
||||
'arm64', 'aarch64' => '--target=arm64-apple-darwin',
|
||||
default => '--target=x86_64-apple-darwin',
|
||||
});
|
||||
// Init arch-specific cxxflags
|
||||
self::initIfNotExists('SPC_DEFAULT_CXX_FLAGS', match (php_uname('m')) {
|
||||
'arm64', 'aarch64' => '--target=arm64-apple-darwin',
|
||||
default => '--target=x86_64-apple-darwin',
|
||||
});
|
||||
|
||||
// Init extra libs (will be appended before `before-php-buildconf` event point)
|
||||
self::initIfNotExists('SPC_EXTRA_LIBS', '');
|
||||
|
||||
$init_spc_cmd_maps = [
|
||||
// Init default build command prefix
|
||||
'SPC_CMD_PREFIX_PHP_BUILDCONF' => './buildconf --force',
|
||||
'SPC_CMD_PREFIX_PHP_CONFIGURE' => './configure --prefix= --with-valgrind=no --enable-shared=no --enable-static=yes --disable-all --disable-cgi --disable-phpdbg',
|
||||
'SPC_CMD_PREFIX_PHP_MAKE' => 'make -j' . getenv('SPC_CONCURRENCY'),
|
||||
// Init default build vars for build command
|
||||
'SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS' => getenv('SPC_DEFAULT_C_FLAGS') . ' -Werror=unknown-warning-option',
|
||||
'SPC_CMD_VAR_PHP_CONFIGURE_CPPFLAGS' => '-I' . BUILD_INCLUDE_PATH,
|
||||
'SPC_CMD_VAR_PHP_CONFIGURE_LDFLAGS' => '-L' . BUILD_LIB_PATH,
|
||||
'SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS' => $builder->getOption('no-strip') ? '-g -O0' : '-g -Os',
|
||||
'SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS' => '-lresolv',
|
||||
];
|
||||
foreach ($init_spc_cmd_maps as $name => $value) {
|
||||
self::initIfNotExists($name, $value);
|
||||
}
|
||||
|
||||
self::initUnixEnv($builder);
|
||||
}
|
||||
|
||||
private static function initUnixEnv(BuilderBase $builder): void
|
||||
{
|
||||
self::putenv('PATH=' . BUILD_ROOT_PATH . '/bin:' . getenv('PATH'));
|
||||
self::putenv('PKG_CONFIG=' . BUILD_BIN_PATH . '/pkg-config');
|
||||
self::putenv('PKG_CONFIG_PATH=' . BUILD_ROOT_PATH . '/lib/pkgconfig');
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the environment variable if it does not exist
|
||||
*
|
||||
* @param string $name Environment variable name
|
||||
* @param string $value Environment variable value
|
||||
*/
|
||||
private static function initIfNotExists(string $name, string $value): void
|
||||
{
|
||||
if (($val = getenv($name)) === false) {
|
||||
self::putenv($name . '=' . $value);
|
||||
} else {
|
||||
logger()->debug("env [{$name}] existing: {$val}");
|
||||
}
|
||||
}
|
||||
|
||||
private static function putenv(string $val): void
|
||||
{
|
||||
f_putenv($val);
|
||||
self::$env_cache[] = $val;
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,9 @@ use SPC\exception\WrongUsageException;
|
||||
use SPC\store\Config;
|
||||
use SPC\store\FileSystem;
|
||||
|
||||
/**
|
||||
* License dumper, dump source license files to target directory
|
||||
*/
|
||||
class LicenseDumper
|
||||
{
|
||||
private array $exts = [];
|
||||
@@ -37,6 +40,10 @@ class LicenseDumper
|
||||
}
|
||||
|
||||
/**
|
||||
* Dump source licenses to target directory
|
||||
*
|
||||
* @param string $target_dir Target directory
|
||||
* @return bool Success or not
|
||||
* @throws WrongUsageException
|
||||
* @throws FileSystemException
|
||||
* @throws RuntimeException
|
||||
@@ -55,20 +62,29 @@ class LicenseDumper
|
||||
|
||||
$source_name = Config::getExt($ext, 'source');
|
||||
foreach ($this->getSourceLicenses($source_name) as $index => $license) {
|
||||
file_put_contents("{$target_dir}/ext_{$ext}_{$index}.txt", $license);
|
||||
$result = file_put_contents("{$target_dir}/ext_{$ext}_{$index}.txt", $license);
|
||||
if ($result === false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->libs as $lib) {
|
||||
$source_name = Config::getLib($lib, 'source');
|
||||
foreach ($this->getSourceLicenses($source_name) as $index => $license) {
|
||||
file_put_contents("{$target_dir}/lib_{$lib}_{$index}.txt", $license);
|
||||
$result = file_put_contents("{$target_dir}/lib_{$lib}_{$index}.txt", $license);
|
||||
if ($result === false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->sources as $source) {
|
||||
foreach ($this->getSourceLicenses($source) as $index => $license) {
|
||||
file_put_contents("{$target_dir}/src_{$source}_{$index}.txt", $license);
|
||||
$result = file_put_contents("{$target_dir}/src_{$source}_{$index}.txt", $license);
|
||||
if ($result === false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\util;
|
||||
|
||||
use SPC\exception\FileSystemException;
|
||||
use SPC\exception\RuntimeException;
|
||||
use SPC\store\FileSystem;
|
||||
|
||||
class Patcher
|
||||
{
|
||||
/**
|
||||
* @throws FileSystemException
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public static function patchLinuxConfigHeader(string $libc): void
|
||||
{
|
||||
switch ($libc) {
|
||||
case 'musl_wrapper':
|
||||
// bad checks
|
||||
FileSystem::replaceFileRegex(SOURCE_PATH . '/php-src/main/php_config.h', '/^#define HAVE_STRLCPY 1$/m', '');
|
||||
FileSystem::replaceFileRegex(SOURCE_PATH . '/php-src/main/php_config.h', '/^#define HAVE_STRLCAT 1$/m', '');
|
||||
// no break
|
||||
case 'musl':
|
||||
FileSystem::replaceFileRegex(SOURCE_PATH . '/php-src/main/php_config.h', '/^#define HAVE_FUNC_ATTRIBUTE_IFUNC 1$/m', '');
|
||||
break;
|
||||
case 'glibc':
|
||||
// avoid lcrypt dependency
|
||||
FileSystem::replaceFileRegex(SOURCE_PATH . '/php-src/main/php_config.h', '/^#define HAVE_CRYPT 1$/m', '');
|
||||
FileSystem::replaceFileRegex(SOURCE_PATH . '/php-src/main/php_config.h', '/^#define HAVE_CRYPT_R 1$/m', '');
|
||||
FileSystem::replaceFileRegex(SOURCE_PATH . '/php-src/main/php_config.h', '/^#define HAVE_CRYPT_H 1$/m', '');
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException('not implemented');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,9 @@ class UnixShell
|
||||
|
||||
private array $env = [];
|
||||
|
||||
/**
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function __construct(?bool $debug = null)
|
||||
{
|
||||
if (PHP_OS_FAMILY === 'Windows') {
|
||||
@@ -62,7 +65,12 @@ class UnixShell
|
||||
|
||||
public function setEnv(array $env): UnixShell
|
||||
{
|
||||
$this->env = array_merge($this->env, $env);
|
||||
foreach ($env as $k => $v) {
|
||||
if ($v === '') {
|
||||
continue;
|
||||
}
|
||||
$this->env[$k] = $v;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,9 @@ class WindowsCmd
|
||||
|
||||
private array $env = [];
|
||||
|
||||
/**
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function __construct(?bool $debug = null)
|
||||
{
|
||||
if (PHP_OS_FAMILY !== 'Windows') {
|
||||
|
||||
51
src/globals/extra/micro-triple-Makefile.frag
Normal file
51
src/globals/extra/micro-triple-Makefile.frag
Normal file
@@ -0,0 +1,51 @@
|
||||
|
||||
micro: $(SAPI_MICRO_PATH)
|
||||
|
||||
micro_2s_objs:
|
||||
rm $(MICRO_2STAGE_OBJS) || :
|
||||
$(MAKE) $(MICRO_2STAGE_OBJS)
|
||||
|
||||
EXTRA_MICRO_BUILD_COMMANDS=
|
||||
POST_MICRO_BUILD_COMMANDS=$(STRIP) $(MICRO_STRIP_FLAGS) $(SAPI_MICRO_PATH)
|
||||
|
||||
$(SAPI_MICRO_PATH): $(PHP_GLOBAL_OBJS) $(PHP_BINARY_OBJS) $(PHP_MICRO_OBJS)
|
||||
$(MAKE) micro_2s_objs SFX_FILESIZE=0xcafebabe
|
||||
$(BUILD_MICRO)
|
||||
$(EXTRA_MICRO_BUILD_COMMANDS)
|
||||
$(POST_MICRO_BUILD_COMMANDS)
|
||||
$(MAKE) micro_2s_objs SFX_FILESIZE=`$(STAT_SIZE) $(SAPI_MICRO_PATH)`
|
||||
$(BUILD_MICRO)
|
||||
$(EXTRA_MICRO_BUILD_COMMANDS)
|
||||
$(POST_MICRO_BUILD_COMMANDS)
|
||||
$(MAKE) micro_2s_objs SFX_FILESIZE=`$(STAT_SIZE) $(SAPI_MICRO_PATH)`
|
||||
$(BUILD_MICRO)
|
||||
$(EXTRA_MICRO_BUILD_COMMANDS)
|
||||
$(POST_MICRO_BUILD_COMMANDS)
|
||||
$(MAKE) micro_2s_objs SFX_FILESIZE=`$(STAT_SIZE) $(SAPI_MICRO_PATH)`
|
||||
$(BUILD_MICRO)
|
||||
$(EXTRA_MICRO_BUILD_COMMANDS)
|
||||
$(POST_MICRO_BUILD_COMMANDS)
|
||||
|
||||
MICRO_EXES = sapi/micro/tests/simpleecho.exe sapi/micro/tests/fakecmd.exe
|
||||
|
||||
$(MICRO_EXES): $(SAPI_MICRO_PATH)
|
||||
@binname=$@;\
|
||||
cat $(SAPI_MICRO_PATH) $${binname%.exe}.php > $@ || {\
|
||||
rm $@; \
|
||||
exit 1; \
|
||||
}
|
||||
@chmod 0755 $@
|
||||
|
||||
MICRO_FAKECMD=sapi/micro/tests/fakecmd.exe
|
||||
|
||||
micro_test: $(SAPI_MICRO_PATH) $(MICRO_EXES)
|
||||
@[ x"hello world" = "x`sapi/micro/tests/simpleecho.exe nonce world`" ] || {\
|
||||
echo sanity check for micro.sfx failed, the sfx generated may be corrupt. >&2 ;\
|
||||
exit 1;\
|
||||
}
|
||||
@SKIP_IO_CAPTURE_TESTS=yes \
|
||||
TEST_PHP_EXECUTABLE=$(MICRO_FAKECMD) \
|
||||
TEST_PHP_SRCDIR=$(top_srcdir) \
|
||||
CC="$(CC)" \
|
||||
$(MICRO_FAKECMD) -n $(PHP_TEST_SETTINGS) $(top_srcdir)/run-tests.php -n $(TESTS); \
|
||||
exit $$?;
|
||||
@@ -47,6 +47,13 @@ function arch2gnu(string $arch): string
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Match pattern function
|
||||
* Example: match_pattern('*.txt', 'test.txt') will return true.
|
||||
*
|
||||
* @param string $pattern Pattern string
|
||||
* @param string $subject Subject string
|
||||
*/
|
||||
function match_pattern(string $pattern, string $subject): bool
|
||||
{
|
||||
$pattern = str_replace(['\*', '\\\\.*'], ['.*', '\*'], preg_quote($pattern, '/'));
|
||||
@@ -54,6 +61,12 @@ function match_pattern(string $pattern, string $subject): bool
|
||||
return preg_match($pattern, $subject) === 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Quote a string with a quote character
|
||||
*
|
||||
* @param string $str String to quote
|
||||
* @param string $quote Quote character, default: `"`
|
||||
*/
|
||||
function quote(string $str, string $quote = '"'): string
|
||||
{
|
||||
return $quote . $str . $quote;
|
||||
@@ -61,7 +74,6 @@ function quote(string $str, string $quote = '"'): string
|
||||
|
||||
/**
|
||||
* Get Family name of current OS
|
||||
*
|
||||
* @throws WrongUsageException
|
||||
*/
|
||||
function osfamily2dir(): string
|
||||
@@ -76,6 +88,41 @@ function osfamily2dir(): string
|
||||
};
|
||||
}
|
||||
|
||||
function shell(?bool $debug = null): UnixShell
|
||||
{
|
||||
/* @noinspection PhpUnhandledExceptionInspection */
|
||||
return new UnixShell($debug);
|
||||
}
|
||||
|
||||
function cmd(?bool $debug = null): WindowsCmd
|
||||
{
|
||||
/* @noinspection PhpUnhandledExceptionInspection */
|
||||
return new WindowsCmd($debug);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current builder.
|
||||
*
|
||||
* @throws WrongUsageException
|
||||
*/
|
||||
function builder(): BuilderBase
|
||||
{
|
||||
return BuilderProvider::getBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current patch point.
|
||||
*
|
||||
* @throws WrongUsageException
|
||||
*/
|
||||
function patch_point(): string
|
||||
{
|
||||
return BuilderProvider::getBuilder()->getPatchPoint();
|
||||
}
|
||||
|
||||
// ------- function f_* part -------
|
||||
// f_ means standard function wrapper
|
||||
|
||||
/**
|
||||
* Execute the shell command, and the output will be directly printed in the terminal. If there is an error, an exception will be thrown
|
||||
*
|
||||
@@ -126,33 +173,3 @@ function f_putenv(string $env): bool
|
||||
logger()->debug('Setting env: ' . $env);
|
||||
return putenv($env);
|
||||
}
|
||||
|
||||
function shell(?bool $debug = null): UnixShell
|
||||
{
|
||||
return new UnixShell($debug);
|
||||
}
|
||||
|
||||
function cmd(?bool $debug = null): WindowsCmd
|
||||
{
|
||||
return new WindowsCmd($debug);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current builder.
|
||||
*
|
||||
* @throws WrongUsageException
|
||||
*/
|
||||
function builder(): BuilderBase
|
||||
{
|
||||
return BuilderProvider::getBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current patch point.
|
||||
*
|
||||
* @throws WrongUsageException
|
||||
*/
|
||||
function patch_point(): string
|
||||
{
|
||||
return BuilderProvider::getBuilder()->getPatchPoint();
|
||||
}
|
||||
|
||||
@@ -11,15 +11,17 @@ declare(strict_types=1);
|
||||
|
||||
// --------------------------------- edit area ---------------------------------
|
||||
|
||||
$zts = true;
|
||||
|
||||
// If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`).
|
||||
$extensions = match (PHP_OS_FAMILY) {
|
||||
'Linux', 'Darwin' => 'intl,pdo_sqlite,sqlite3,curl,openssl,tokenizer,bcmath,bz2,calendar,dba,ftp,iconv,mysqli,mbstring,mbregex,xml,simplexml,ctype,dom,pdo,filter,session,zlib,fileinfo,pdo_mysql,posix,sockets,shmop,sodium,sysvmsg,sysvsem,sysvshm,gd,zip,gmp,redis,xmlwriter,phar,exif,xmlreader,readline,pcntl,soap,imagick,ffi,password-argon2,pgsql,pdo_pgsql,imap,ldap,xsl',
|
||||
'Windows' => 'mbstring,pdo_sqlite,mbregex,ffi',
|
||||
'Linux', 'Darwin' => 'parallel',
|
||||
'Windows' => 'mbstring,pdo_sqlite,mbregex,parallel',
|
||||
};
|
||||
|
||||
// If you want to test lib-suggests feature with extension, add them below (comma separated, example `libwebp,libavif`).
|
||||
$with_libs = match (PHP_OS_FAMILY) {
|
||||
'Linux', 'Darwin' => 'nghttp2',
|
||||
'Linux', 'Darwin' => '',
|
||||
'Windows' => '',
|
||||
};
|
||||
|
||||
@@ -27,7 +29,7 @@ $with_libs = match (PHP_OS_FAMILY) {
|
||||
// You can use `common`, `bulk`, `minimal` or `none`.
|
||||
// note: combination is only available for *nix platform. Windows must use `none` combination
|
||||
$base_combination = match (PHP_OS_FAMILY) {
|
||||
'Linux', 'Darwin' => 'none',
|
||||
'Linux', 'Darwin' => 'minimal',
|
||||
'Windows' => 'none',
|
||||
};
|
||||
|
||||
@@ -62,7 +64,6 @@ $final_libs = trim($with_libs, $trim_value);
|
||||
|
||||
if (PHP_OS_FAMILY === 'Windows') {
|
||||
$final_extensions_cmd = '"' . $final_extensions . '"';
|
||||
$final_libs = $final_libs === '' ? '' : ('"' . $final_libs . '"');
|
||||
} else {
|
||||
$final_extensions_cmd = $final_extensions;
|
||||
}
|
||||
@@ -72,5 +73,6 @@ echo match ($argv[1]) {
|
||||
'libs' => $final_libs,
|
||||
'libs_cmd' => ($final_libs === '' ? '' : (' --with-libs=' . $final_libs)),
|
||||
'cmd' => $final_extensions_cmd . ($final_libs === '' ? '' : (' --with-libs=' . $final_libs)),
|
||||
'zts' => $zts ? '--enable-zts' : '',
|
||||
default => '',
|
||||
};
|
||||
|
||||
5
src/globals/tests/parallel.php
Normal file
5
src/globals/tests/parallel.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
assert(class_exists('\parallel\Runtime'));
|
||||
6
src/globals/tests/uuid.php
Normal file
6
src/globals/tests/uuid.php
Normal file
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
assert(function_exists('uuid_create'));
|
||||
assert(strlen(uuid_create(0)) === 36);
|
||||
Reference in New Issue
Block a user