Compare commits

...

53 Commits
2.1.1 ... 2.2.0

Author SHA1 Message Date
crazywhalecc
3fcb7ebf03 update spc binary php version 2024-05-06 14:25:24 +08:00
Jerry Ma
7416b8079b Fix dependency util suggest calculate bug (#441)
* fix dependency util suggest calculate bug

* fix dependency util suggest calculate bug
2024-05-06 14:23:32 +08:00
Jerry Ma
bde18054e5 Fix micro upx compress bug (#440)
* triple compression for micro with upx

* place debug info first
2024-05-06 14:12:40 +08:00
Jerry Ma
954f8f4ddc fix ncurses 6.5 build (#439) 2024-05-06 14:11:50 +08:00
Jerry Ma
0fee628842 Fix xz build on macOS and Linux (#438)
* fix xz build

* add xz tests
2024-05-06 12:55:38 +08:00
Jerry Ma
69e6d82e83 add linux env var: SPC_NO_MUSL_PATH (#437) 2024-05-06 12:32:43 +08:00
crazywhalecc
e1e6270d86 update README 2024-05-06 12:08:35 +08:00
Simon Hamp
30af182aff Windows build GitHub Action (#420)
* Create build-windows-x86_64.yml

* Update build-windows-x86_64.yml

* Fix CLI param

* Fix env writing in Powershell

* Run doctor first, per docs

* Fix file paths

* Generate an acceptable cache key

* Change shell

* Improve cache key generation

* Update upload-artifact action

* Update actions

* Attempt to fix cache key storage

* Remove FPM build option
2024-05-06 11:59:02 +08:00
Jerry Ma
3ecc603770 Fix ncurses pkg-config bug temporarily (#432)
* Fix ncurses pkg-config bug temporarily

* Add tests
2024-04-30 13:57:44 +08:00
Simon Hamp
15c2935d48 Update actions (#428)
* Update action versions

* Use same dependency cache key naming logic

Bring consistency across the whole pipeline
2024-04-29 21:24:47 +08:00
Simon Hamp
7a8e0a7e67 Fix Intel Mac build action (#427)
* Fix Intel Mac build action

* Use x64 build server

* Use macos-13 runner
2024-04-29 09:12:03 +08:00
Jerry Ma
d98d6aeffb Fix FreeBSD pkg-config linking issue (#426) 2024-04-26 16:03:03 +08:00
Jerry Ma
aaa4510f25 Fix linux imagick openmp linking issue (#424) 2024-04-26 11:00:33 +08:00
Jerry Ma
b14894fab7 Fix windows UPX_EXEC env var missing (#423) 2024-04-25 16:48:31 +08:00
Jerry Ma
1a87ce4194 Fix windows nghttp2 dynamic linking bug (#422)
* fix windows nghttp2 dynamic linking bug

* add tests for fixing windows nghttp2 dynamic linking bug
2024-04-25 15:55:08 +08:00
Kévin Dunglas
6b96feb538 fix: use C++ 17 compiler for ICU (#414)
* fix: use C++ 17 compiler for ICU

* wip

* hack CXX env var to force C++17

* test intl

* test intl

* add retry for CI test download

* patch

* separate intl with newer icu c++ patch

---------

Co-authored-by: crazywhalecc <jesse2061@outlook.com>
2024-04-22 15:58:08 +08:00
Jerry Ma
21dbb8af46 change SPC_CONCURRENCT order 2024-04-14 01:15:07 +08:00
crazywhalecc
4d227ca7ef fix macOS build libpng error with old option mode 2024-04-14 01:15:07 +08:00
crazywhalecc
3a2683bb0c fix LinuxBuilder with env manager 2024-04-14 01:15:07 +08:00
crazywhalecc
bd8f91d466 add env manager 2024-04-14 01:15:07 +08:00
crazywhalecc
254844b5ec add Archlinux doctor support 2024-04-13 16:30:15 +08:00
Jerry Ma
4cb1764439 Fix libuuid build source (#411)
* fix libuuid build source

* fix libuuid build source tests
2024-04-12 21:05:51 +08:00
crazywhalecc
847535721c add macOS brew arch check for doctor 2024-04-12 16:34:58 +08:00
Jerry Ma
e3c542d9df add qdbm for dba (#409)
* add qdbm for dba

* add windows support for dba-qdbm

* fix test scripts

* fix test scripts
2024-04-12 15:53:38 +08:00
Jerry Ma
b4ed4ea956 Add ext yac (#407)
* add ext yac

* enable yac for windows

* enable yac test for windows

* correct
2024-04-12 01:43:27 +08:00
Jerry Ma
99aadd3e73 fix openssl build with corrupted pkg-config file (#406)
* fix openssl build with corrupted pkg-config file

* add test

* fix linux openssl

* add exec exit error counter for postgresql
2024-04-12 00:49:15 +08:00
Jerry Ma
c77dc1af6c Add extension simdjson support (#402)
* add extension simdjson support

* add extension simdjson tests

* fix windows build for simdjson
2024-04-02 16:57:59 +08:00
Jerry Ma
9fd56987ef Add extension ds support (#401)
* add extension ds

* add ds tests
2024-04-02 15:54:28 +08:00
crazywhalecc
1e494a2213 bump version 2024-04-02 15:06:54 +08:00
Jerry Ma
da6d9ffb4b Cmake version check (#400)
* add cmake version checker for doctor

* fix linux distro checker message
2024-04-02 15:05:49 +08:00
Jerry Ma
d3a001d808 use old xz mirror, fix CVE-2024-3094 (#399)
* use old xz mirror, fix CVE-2024-3094

* add test
2024-04-02 11:31:29 +08:00
Jerry Ma
d445668d9f trigger tests and nightly builds 2024-03-31 15:36:38 +08:00
Jerry Ma
32f14e16c8 fix pkg-config build for macOS sonoma (#391)
* fix pkg-config build for macOS sonoma

* cs fix

* bump version to 2.1.6 [skip ci]
2024-03-20 21:50:05 +08:00
Jerry Ma
46984b6df1 Fix latest libsodium compatibility (#388)
* fix #384

* bypass password-argon2 micro sanity check

* ignore funding yaml schema [skip ci]

* test linux compatibility for libargon2 and libsodium

* update composer.json to prevent smart-aleck composer [skip ci]
2024-03-16 22:37:39 +08:00
Kévin Dunglas
96c3e6b935 fix: false postive with binutils-gold 2024-03-16 18:53:53 +08:00
Jerry Ma
8092f1e481 Update FUNDING.yml 2024-03-15 22:44:05 +08:00
crazywhalecc
632f904f30 fix install-pkg different arch cache bug 2024-03-15 14:27:51 +08:00
crazywhalecc
8358a985b3 fix retry for windows 2024-03-10 17:09:49 +08:00
crazywhalecc
e21b5676e7 add --retry for download command 2024-03-10 17:09:49 +08:00
crazywhalecc
94b3afe6bc add pdo_sqlsrv for macOS and Linux 2024-03-10 15:30:51 +08:00
crazywhalecc
e4d8e5e4d2 fix ncurses build command 2024-03-10 11:53:33 +08:00
crazywhalecc
88796bc017 update tests 2024-03-10 11:53:33 +08:00
crazywhalecc
e23daaa355 enhancement for download command 2024-03-10 11:53:33 +08:00
crazywhalecc
71017361b5 fix libxml2 build on RHEL/CentOS bug 2024-03-08 14:18:33 +08:00
crazywhalecc
d202de3f50 fix libxml2 build on RHEL/CentOS bug 2024-03-08 14:11:04 +08:00
Jerry Ma
03510073c6 Fix windows curl build (#368)
* fix curl on windows build needs nghttp2.dll bug

* add curl on windows tests

* cs fix

* fix curl headers

* exit powershell properly

* reproduce zend_mm_heap corrupted

* reproduce zend_mm_heap corrupted

* reproduce zend_mm_heap corrupted

* add for-libs option for download

* add for-libs option for download

* add for-libs option for download
2024-03-05 21:43:09 +08:00
Jerry Ma
8e58592a6e Fix swoole compile bug on Linux (#367)
* swoole ci test

* swoole ci test

* fix swoole (disable-thread-context)

* restore pgsql ver

* bump version to 2.1.4
2024-03-04 15:31:39 +08:00
Jerry Ma
96dd5ba87b Add amqp/librabbitmq support for linux, macos, windows (#366)
* add amqp/librabbitmq support for linux, macos, windows

* add test for amqp
2024-03-04 10:40:23 +08:00
Jerry Ma
d4c0290195 Fix libuuid random bug when make clean (#364)
* fix libuuid random bug when `make clean`

* test

* test [skip ci]
2024-03-01 21:27:51 +08:00
Jerry Ma
f5d1df5407 add uuid/libuuid for linux and macos (#363) 2024-03-01 20:10:48 +08:00
Jerry Ma
9664709f21 Add libtiff support (#361)
* add libtiff support

* fix command option not working on *nix

* fix test with libs ext test
2024-03-01 19:19:47 +08:00
Jerry Ma
b46655ecfe Add custom Windows micro logo support (#358)
* add custom windows micro logo option `--with-micro-logo`

* bump version 2.1.2
2024-02-29 15:35:02 +08:00
Jerry Ma
842e0add29 Add ffi support for windows x64 (#357)
* add ffi support for windows x64

* add ffi test
2024-02-29 15:34:06 +08:00
90 changed files with 1723 additions and 418 deletions

2
.github/FUNDING.yml vendored
View File

@@ -10,4 +10,6 @@ liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username otechie: # Replace with a single Otechie username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
# noinspection YAMLSchemaValidation
buy_me_a_coffee: crazywhalecc
custom: 'https://github.com/crazywhalecc/crazywhalecc/blob/master/FUNDING.md' # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] custom: 'https://github.com/crazywhalecc/crazywhalecc/blob/master/FUNDING.md' # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']

View File

@@ -45,14 +45,30 @@ jobs:
name: build ${{ inputs.version }} on ${{ inputs.operating-system }} name: build ${{ inputs.version }} on ${{ inputs.operating-system }}
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: 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 # Cache downloaded source
- id: cache-download - id: cache-download
uses: actions/cache@v3 uses: actions/cache@v4
with: with:
path: downloads path: downloads
key: php-${{ inputs.version }}-dependencies-${{ inputs.extensions }} key: php-${{ env.INPUT_HASH }}
# With or without debug # With or without debug
- if: inputs.debug == true - if: inputs.debug == true
@@ -75,31 +91,31 @@ jobs:
# Upload cli executable # Upload cli executable
- if: ${{ inputs.build-cli == true }} - if: ${{ inputs.build-cli == true }}
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v4
with: with:
name: php-${{ inputs.version }}-linux-${{ inputs.operating-system }} name: php-${{ inputs.version }}-linux-${{ inputs.operating-system }}
path: buildroot/bin/php path: buildroot/bin/php
# Upload micro self-extracted executable # Upload micro self-extracted executable
- if: ${{ inputs.build-micro == true }} - if: ${{ inputs.build-micro == true }}
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v4
with: with:
name: micro-${{ inputs.version }}-linux-${{ inputs.operating-system }} name: micro-${{ inputs.version }}-linux-${{ inputs.operating-system }}
path: buildroot/bin/micro.sfx path: buildroot/bin/micro.sfx
# Upload fpm executable # Upload fpm executable
- if: ${{ inputs.build-fpm == true }} - if: ${{ inputs.build-fpm == true }}
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v4
with: with:
name: php-fpm-${{ inputs.version }}-linux-${{ inputs.operating-system }} name: php-fpm-${{ inputs.version }}-linux-${{ inputs.operating-system }}
path: buildroot/bin/php-fpm path: buildroot/bin/php-fpm
# Upload extensions metadata # Upload extensions metadata
- uses: actions/upload-artifact@v3 - uses: actions/upload-artifact@v4
with: with:
name: license-files name: license-files
path: buildroot/license/ path: buildroot/license/
- uses: actions/upload-artifact@v3 - uses: actions/upload-artifact@v4
with: with:
name: build-meta name: build-meta
path: | path: |

View File

@@ -39,11 +39,11 @@ jobs:
name: build ${{ inputs.version }} on Linux x86_64 name: build ${{ inputs.version }} on Linux x86_64
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
# Cache composer dependencies # Cache composer dependencies
- id: cache-composer-deps - id: cache-composer-deps
uses: actions/cache@v3 uses: actions/cache@v4
with: with:
path: vendor path: vendor
key: composer-dependencies key: composer-dependencies
@@ -52,12 +52,17 @@ jobs:
- if: steps.cache-composer-deps.outputs.cache-hit != 'true' - if: steps.cache-composer-deps.outputs.cache-hit != 'true'
run: composer update --no-dev --classmap-authoritative 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 # Cache downloaded source
- id: cache-download - id: cache-download
uses: actions/cache@v3 uses: actions/cache@v4
with: with:
path: downloads path: downloads
key: php-${{ inputs.version }}-dependencies-${{ inputs.extensions }} key: php-${{ env.INPUT_HASH }}
# With or without debug # With or without debug
- if: inputs.debug == true - if: inputs.debug == true
@@ -80,31 +85,31 @@ jobs:
# Upload cli executable # Upload cli executable
- if: ${{ inputs.build-cli == true }} - if: ${{ inputs.build-cli == true }}
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v4
with: with:
name: php-${{ inputs.version }}-${{ env.SPC_BUILD_OS }} name: php-${{ inputs.version }}-${{ env.SPC_BUILD_OS }}
path: buildroot/bin/php path: buildroot/bin/php
# Upload micro self-extracted executable # Upload micro self-extracted executable
- if: ${{ inputs.build-micro == true }} - if: ${{ inputs.build-micro == true }}
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v4
with: with:
name: micro-${{ inputs.version }}-${{ env.SPC_BUILD_OS }} name: micro-${{ inputs.version }}-${{ env.SPC_BUILD_OS }}
path: buildroot/bin/micro.sfx path: buildroot/bin/micro.sfx
# Upload fpm executable # Upload fpm executable
- if: ${{ inputs.build-fpm == true }} - if: ${{ inputs.build-fpm == true }}
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v4
with: with:
name: php-fpm-${{ inputs.version }}-${{ env.SPC_BUILD_OS }} name: php-fpm-${{ inputs.version }}-${{ env.SPC_BUILD_OS }}
path: buildroot/bin/php-fpm path: buildroot/bin/php-fpm
# Upload extensions metadata # Upload extensions metadata
- uses: actions/upload-artifact@v3 - uses: actions/upload-artifact@v4
with: with:
name: license-files name: license-files
path: buildroot/license/ path: buildroot/license/
- uses: actions/upload-artifact@v3 - uses: actions/upload-artifact@v4
with: with:
name: build-meta name: build-meta
path: | path: |

View File

@@ -39,7 +39,7 @@ jobs:
name: build ${{ inputs.version }} on macOS arm64 name: build ${{ inputs.version }} on macOS arm64
runs-on: macos-14 runs-on: macos-14
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
# Install macOS missing packages and mark os suffix # Install macOS missing packages and mark os suffix
- run: | - run: |
@@ -58,7 +58,7 @@ jobs:
# Cache composer dependencies # Cache composer dependencies
- id: cache-composer-deps - id: cache-composer-deps
uses: actions/cache@v3 uses: actions/cache@v4
with: with:
path: vendor path: vendor
key: composer-dependencies key: composer-dependencies
@@ -67,12 +67,17 @@ jobs:
- if: steps.cache-composer-deps.outputs.cache-hit != 'true' - if: steps.cache-composer-deps.outputs.cache-hit != 'true'
run: composer update --no-dev --classmap-authoritative 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 # Cache downloaded source
- id: cache-download - id: cache-download
uses: actions/cache@v3 uses: actions/cache@v4
with: with:
path: downloads path: downloads
key: php-${{ inputs.version }}-dependencies-${{ inputs.extensions }} key: php-${{ env.INPUT_HASH }}
# With or without debug # With or without debug
- if: inputs.debug == true - if: inputs.debug == true
@@ -95,31 +100,31 @@ jobs:
# Upload cli executable # Upload cli executable
- if: ${{ inputs.build-cli == true }} - if: ${{ inputs.build-cli == true }}
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v4
with: with:
name: php-${{ inputs.version }}-${{ env.SPC_BUILD_OS }} name: php-${{ inputs.version }}-${{ env.SPC_BUILD_OS }}
path: buildroot/bin/php path: buildroot/bin/php
# Upload micro self-extracted executable # Upload micro self-extracted executable
- if: ${{ inputs.build-micro == true }} - if: ${{ inputs.build-micro == true }}
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v4
with: with:
name: micro-${{ inputs.version }}-${{ env.SPC_BUILD_OS }} name: micro-${{ inputs.version }}-${{ env.SPC_BUILD_OS }}
path: buildroot/bin/micro.sfx path: buildroot/bin/micro.sfx
# Upload fpm executable # Upload fpm executable
- if: ${{ inputs.build-fpm == true }} - if: ${{ inputs.build-fpm == true }}
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v4
with: with:
name: php-fpm-${{ inputs.version }}-${{ env.SPC_BUILD_OS }} name: php-fpm-${{ inputs.version }}-${{ env.SPC_BUILD_OS }}
path: buildroot/bin/php-fpm path: buildroot/bin/php-fpm
# Upload extensions metadata # Upload extensions metadata
- uses: actions/upload-artifact@v3 - uses: actions/upload-artifact@v4
with: with:
name: license-files name: license-files
path: buildroot/license/ path: buildroot/license/
- uses: actions/upload-artifact@v3 - uses: actions/upload-artifact@v4
with: with:
name: build-meta name: build-meta
path: | path: |

View File

@@ -37,18 +37,26 @@ env:
jobs: jobs:
build: build:
name: build ${{ inputs.version }} on macOS x86_64 name: build ${{ inputs.version }} on macOS x86_64
runs-on: macos-latest runs-on: macos-13
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
# Install macOS missing packages and mark os suffix # Install macOS missing packages and mark os suffix
- run: | - run: |
brew install automake gzip brew install automake gzip
echo "SPC_BUILD_OS=macos" >> $GITHUB_ENV 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 # Cache composer dependencies
- id: cache-composer-deps - id: cache-composer-deps
uses: actions/cache@v3 uses: actions/cache@v4
with: with:
path: vendor path: vendor
key: composer-dependencies key: composer-dependencies
@@ -57,12 +65,17 @@ jobs:
- if: steps.cache-composer-deps.outputs.cache-hit != 'true' - if: steps.cache-composer-deps.outputs.cache-hit != 'true'
run: composer update --no-dev --classmap-authoritative 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 # Cache downloaded source
- id: cache-download - id: cache-download
uses: actions/cache@v3 uses: actions/cache@v4
with: with:
path: downloads path: downloads
key: php-${{ inputs.version }}-dependencies-${{ inputs.extensions }} key: php-${{ env.INPUT_HASH }}
# With or without debug # With or without debug
- if: inputs.debug == true - if: inputs.debug == true
@@ -85,31 +98,31 @@ jobs:
# Upload cli executable # Upload cli executable
- if: ${{ inputs.build-cli == true }} - if: ${{ inputs.build-cli == true }}
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v4
with: with:
name: php-${{ inputs.version }}-${{ env.SPC_BUILD_OS }} name: php-${{ inputs.version }}-${{ env.SPC_BUILD_OS }}
path: buildroot/bin/php path: buildroot/bin/php
# Upload micro self-extracted executable # Upload micro self-extracted executable
- if: ${{ inputs.build-micro == true }} - if: ${{ inputs.build-micro == true }}
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v4
with: with:
name: micro-${{ inputs.version }}-${{ env.SPC_BUILD_OS }} name: micro-${{ inputs.version }}-${{ env.SPC_BUILD_OS }}
path: buildroot/bin/micro.sfx path: buildroot/bin/micro.sfx
# Upload fpm executable # Upload fpm executable
- if: ${{ inputs.build-fpm == true }} - if: ${{ inputs.build-fpm == true }}
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v4
with: with:
name: php-fpm-${{ inputs.version }}-${{ env.SPC_BUILD_OS }} name: php-fpm-${{ inputs.version }}-${{ env.SPC_BUILD_OS }}
path: buildroot/bin/php-fpm path: buildroot/bin/php-fpm
# Upload extensions metadata # Upload extensions metadata
- uses: actions/upload-artifact@v3 - uses: actions/upload-artifact@v4
with: with:
name: license-files name: license-files
path: buildroot/license/ path: buildroot/license/
- uses: actions/upload-artifact@v3 - uses: actions/upload-artifact@v4
with: with:
name: build-meta name: build-meta
path: | path: |

View 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

View File

@@ -17,7 +17,7 @@ jobs:
php-version: php-version:
- "8.2" - "8.2"
micro-version: micro-version:
- "8.2.16" - "8.2.18"
operating-system: operating-system:
- "linux-x86_64" - "linux-x86_64"
- "macos-x86_64" - "macos-x86_64"

View File

@@ -164,7 +164,8 @@ jobs:
timeout_minutes: 10 timeout_minutes: 10
max_attempts: 3 max_attempts: 3
retry_on: error retry_on: error
command: bin/spc download --for-extensions="$(php src/globals/test-extensions.php extensions)" --with-php=${{ matrix.php }} --debug 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 --retry=3
- name: "Run Build Tests (build)" - 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)" --with-libs="$(php src/globals/test-extensions.php libs)" --build-cli --build-micro --build-fpm --debug

View File

@@ -66,7 +66,7 @@ static-php-cli简称 `spc`)有许多特性:
|---------|----------------------|----------------------| |---------|----------------------|----------------------|
| macOS | :octocat: :computer: | :octocat: :computer: | | macOS | :octocat: :computer: | :octocat: :computer: |
| Linux | :octocat: :computer: | :octocat: :computer: | | Linux | :octocat: :computer: | :octocat: :computer: |
| Windows | :computer: | | | Windows | :octocat: :computer: | |
| FreeBSD | :computer: | :computer: | | FreeBSD | :computer: | :computer: |
当前支持编译的 PHP 版本: 当前支持编译的 PHP 版本:

View File

@@ -74,7 +74,7 @@ Here is the supported OS and arch, where :octocat: represents support for GitHub
|---------|----------------------|----------------------| |---------|----------------------|----------------------|
| macOS | :octocat: :computer: | :octocat: :computer: | | macOS | :octocat: :computer: | :octocat: :computer: |
| Linux | :octocat: :computer: | :octocat: :computer: | | Linux | :octocat: :computer: | :octocat: :computer: |
| Windows | :computer: | | | Windows | :octocat: :computer: | |
| FreeBSD | :computer: | :computer: | | FreeBSD | :computer: | :computer: |
Currently supported PHP versions for compilation: Currently supported PHP versions for compilation:

View File

@@ -9,3 +9,4 @@ if (-not(Test-Path $PHP_Exec)) {
} }
& "$PHP_Exec" ("bin/spc") @args & "$PHP_Exec" ("bin/spc") @args
exit $LASTEXITCODE

View File

@@ -54,5 +54,11 @@
}, },
"optimize-autoloader": true, "optimize-autoloader": true,
"sort-packages": true "sort-packages": true
} },
"funding": [
{
"type": "other",
"url": "https://github.com/crazywhalecc/crazywhalecc/blob/master/FUNDING.md"
}
]
} }

View File

@@ -1,4 +1,15 @@
{ {
"amqp": {
"type": "external",
"arg-type": "custom",
"source": "amqp",
"lib-depends": [
"librabbitmq"
],
"ext-depends-windows": [
"openssl"
]
},
"apcu": { "apcu": {
"type": "external", "type": "external",
"source": "apcu" "source": "apcu"
@@ -32,7 +43,10 @@
}, },
"dba": { "dba": {
"type": "builtin", "type": "builtin",
"arg-type-windows": "with" "arg-type": "custom",
"lib-suggests": [
"qdbm"
]
}, },
"dom": { "dom": {
"type": "builtin", "type": "builtin",
@@ -41,8 +55,15 @@
"lib-depends": [ "lib-depends": [
"libxml2", "libxml2",
"zlib" "zlib"
],
"ext-depends-windows": [
"xml"
] ]
}, },
"ds": {
"type": "external",
"source": "ext-ds"
},
"event": { "event": {
"type": "external", "type": "external",
"source": "ext-event", "source": "ext-event",
@@ -63,8 +84,11 @@
"ffi": { "ffi": {
"arg-type": "custom", "arg-type": "custom",
"type": "builtin", "type": "builtin",
"lib-depends": [ "lib-depends-unix": [
"libffi" "libffi"
],
"lib-depends-windows": [
"libffi-win"
] ]
}, },
"fileinfo": { "fileinfo": {
@@ -300,6 +324,15 @@
"sqlite" "sqlite"
] ]
}, },
"pdo_sqlsrv": {
"type": "external",
"source": "pdo_sqlsrv",
"arg-type": "with",
"ext-depends": [
"pdo",
"sqlsrv"
]
},
"pgsql": { "pgsql": {
"type": "builtin", "type": "builtin",
"arg-type": "with-prefix", "arg-type": "with-prefix",
@@ -352,6 +385,11 @@
"shmop": { "shmop": {
"type": "builtin" "type": "builtin"
}, },
"simdjson": {
"type": "external",
"source": "ext-simdjson",
"cpp-extension": true
},
"simplexml": { "simplexml": {
"type": "builtin", "type": "builtin",
"arg-type": "custom", "arg-type": "custom",
@@ -510,6 +548,14 @@
"tokenizer": { "tokenizer": {
"type": "builtin" "type": "builtin"
}, },
"uuid": {
"type": "external",
"source": "ext-uuid",
"arg-type": "with-prefix",
"lib-depends": [
"libuuid"
]
},
"uv": { "uv": {
"type": "external", "type": "external",
"source": "ext-uv", "source": "ext-uv",
@@ -580,6 +626,14 @@
"dom" "dom"
] ]
}, },
"yac": {
"type": "external",
"source": "yac",
"arg-type-unix": "custom",
"ext-depends-unix": [
"igbinary"
]
},
"yaml": { "yaml": {
"type": "external", "type": "external",
"source": "yaml", "source": "yaml",

View File

@@ -36,7 +36,7 @@
"libcurl.a" "libcurl.a"
], ],
"static-libs-windows": [ "static-libs-windows": [
"libcurl.lib" "libcurl_a.lib"
], ],
"headers": [ "headers": [
"curl" "curl"
@@ -147,7 +147,8 @@
"libpng", "libpng",
"libjpeg", "libjpeg",
"libwebp", "libwebp",
"freetype" "freetype",
"libtiff"
], ],
"lib-suggests": [ "lib-suggests": [
"zstd", "zstd",
@@ -233,6 +234,17 @@
"ffitarget.h" "ffitarget.h"
] ]
}, },
"libffi-win": {
"source": "libffi-win",
"static-libs-windows": [
"libffi.lib"
],
"headers-windows": [
"ffi.h",
"ffitarget.h",
"fficonfig.h"
]
},
"libiconv": { "libiconv": {
"source": "libiconv", "source": "libiconv",
"static-libs-unix": [ "static-libs-unix": [
@@ -293,6 +305,18 @@
"zlib" "zlib"
] ]
}, },
"librabbitmq": {
"source": "librabbitmq",
"static-libs-unix": [
"librabbitmq.a"
],
"static-libs-windows": [
"rabbitmq.4.lib"
],
"lib-depends": [
"openssl"
]
},
"libsodium": { "libsodium": {
"source": "libsodium", "source": "libsodium",
"static-libs-unix": [ "static-libs-unix": [
@@ -319,6 +343,21 @@
"zlib" "zlib"
] ]
}, },
"libtiff": {
"source": "libtiff",
"static-libs-unix": [
"libtiff.a"
]
},
"libuuid": {
"source": "libuuid",
"static-libs-unix": [
"libuuid.a"
],
"headers": [
"uuid/uuid.h"
]
},
"libuv": { "libuv": {
"source": "libuv", "source": "libuv",
"static-libs-unix": [ "static-libs-unix": [
@@ -489,6 +528,18 @@
"zstd" "zstd"
] ]
}, },
"qdbm": {
"source": "qdbm",
"static-libs-unix": [
"libqdbm.a"
],
"static-libs-windows": [
"qdbm_a.lib"
],
"headers-windows": [
"depot.h"
]
},
"readline": { "readline": {
"source": "readline", "source": "readline",
"static-libs-unix": [ "static-libs-unix": [

View File

@@ -6,6 +6,16 @@
"path": "LICENSE" "path": "LICENSE"
} }
}, },
"amqp": {
"type": "url",
"url": "https://pecl.php.net/get/amqp",
"path": "php-src/ext/amqp",
"filename": "amqp.tgz",
"license": {
"type": "file",
"path": "LICENSE"
}
},
"apcu": { "apcu": {
"type": "url", "type": "url",
"url": "https://pecl.php.net/get/APCu", "url": "https://pecl.php.net/get/APCu",
@@ -42,6 +52,16 @@
"path": "COPYING" "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": { "ext-event": {
"type": "url", "type": "url",
"url": "https://bitbucket.org/osmanov/pecl-event/get/3.0.8.tar.gz", "url": "https://bitbucket.org/osmanov/pecl-event/get/3.0.8.tar.gz",
@@ -80,6 +100,16 @@
"path": "LICENSE" "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": { "ext-snappy": {
"type": "git", "type": "git",
"path": "php-src/ext/snappy", "path": "php-src/ext/snappy",
@@ -100,6 +130,16 @@
"path": "LICENSE" "path": "LICENSE"
} }
}, },
"ext-uuid": {
"type": "url",
"url": "https://pecl.php.net/get/uuid",
"path": "php-src/ext/uuid",
"filename": "uuid.tgz",
"license": {
"type": "file",
"path": "LICENSE"
}
},
"ext-uv": { "ext-uv": {
"type": "url", "type": "url",
"url": "https://pecl.php.net/get/uv", "url": "https://pecl.php.net/get/uv",
@@ -204,7 +244,7 @@
"libargon2": { "libargon2": {
"type": "git", "type": "git",
"rev": "master", "rev": "master",
"url": "https://github.com/mpociot/phc-winner-argon2", "url": "https://github.com/static-php/phc-winner-argon2",
"license": { "license": {
"type": "file", "type": "file",
"path": "LICENSE" "path": "LICENSE"
@@ -245,6 +285,15 @@
"path": "LICENSE" "path": "LICENSE"
} }
}, },
"libffi-win": {
"type": "git",
"rev": "master",
"url": "https://github.com/static-php/libffi-win.git",
"license": {
"type": "file",
"path": "LICENSE"
}
},
"libiconv": { "libiconv": {
"type": "filelist", "type": "filelist",
"url": "https://ftp.gnu.org/gnu/libiconv/", "url": "https://ftp.gnu.org/gnu/libiconv/",
@@ -298,6 +347,15 @@
"path": "LICENSE" "path": "LICENSE"
} }
}, },
"librabbitmq": {
"type": "git",
"url": "https://github.com/alanxz/rabbitmq-c.git",
"rev": "master",
"license": {
"type": "file",
"path": "LICENSE"
}
},
"libsodium": { "libsodium": {
"type": "ghrel", "type": "ghrel",
"repo": "jedisct1/libsodium", "repo": "jedisct1/libsodium",
@@ -316,6 +374,24 @@
"path": "COPYING" "path": "COPYING"
} }
}, },
"libtiff": {
"type": "filelist",
"url": "https://download.osgeo.org/libtiff/",
"regex": "/href=\"(?<file>tiff-(?<version>[^\"]+)\\.tar\\.xz)\"/",
"license": {
"type": "file",
"path": "LICENSE.md"
}
},
"libuuid": {
"type": "git",
"url": "https://github.com/static-php/libuuid.git",
"rev": "master",
"license": {
"type": "file",
"path": "COPYING"
}
},
"libuv": { "libuv": {
"type": "ghtar", "type": "ghtar",
"repo": "libuv/libuv", "repo": "libuv/libuv",
@@ -439,6 +515,16 @@
"path": "LICENSE.txt" "path": "LICENSE.txt"
} }
}, },
"pdo_sqlsrv": {
"type": "url",
"url": "https://pecl.php.net/get/pdo_sqlsrv",
"path": "php-src/ext/pdo_sqlsrv",
"filename": "pdo_sqlsrv.tgz",
"license": {
"type": "file",
"path": "LICENSE"
}
},
"pkg-config": { "pkg-config": {
"type": "url", "type": "url",
"url": "https://dl.static-php.dev/static-php-cli/deps/pkg-config/pkg-config-0.29.2.tar.gz", "url": "https://dl.static-php.dev/static-php-cli/deps/pkg-config/pkg-config-0.29.2.tar.gz",
@@ -465,6 +551,15 @@
"path": "LICENSE" "path": "LICENSE"
} }
}, },
"qdbm": {
"type": "git",
"url": "https://github.com/static-php/qdbm.git",
"rev": "main",
"license": {
"type": "file",
"path": "COPYING"
}
},
"rar": { "rar": {
"type": "git", "type": "git",
"url": "https://github.com/static-php/php-rar.git", "url": "https://github.com/static-php/php-rar.git",
@@ -580,14 +675,23 @@
} }
}, },
"xz": { "xz": {
"type": "ghrel", "type": "url",
"repo": "tukaani-project/xz", "url": "https://fossies.org/linux/misc/xz-5.4.6.tar.xz",
"match": "xz-.+\\.tar\\.gz",
"license": { "license": {
"type": "file", "type": "file",
"path": "COPYING" "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": { "yaml": {
"type": "git", "type": "git",
"path": "php-src/ext/yaml", "path": "php-src/ext/yaml",

View File

@@ -25,7 +25,7 @@ use Symfony\Component\Console\Command\ListCommand;
*/ */
final class ConsoleApplication extends Application final class ConsoleApplication extends Application
{ {
public const VERSION = '2.1.1'; public const VERSION = '2.2.0';
public function __construct() public function __construct()
{ {
@@ -33,6 +33,7 @@ final class ConsoleApplication extends Application
$this->addCommands( $this->addCommands(
[ [
// Common commands
new BuildCliCommand(), new BuildCliCommand(),
new BuildLibsCommand(), new BuildLibsCommand(),
new DoctorCommand(), new DoctorCommand(),

View File

@@ -206,4 +206,9 @@ abstract class LibraryBase
} }
logger()->debug('enabling ' . static::NAME . " without {$name}"); logger()->debug('enabling ' . static::NAME . " without {$name}");
} }
protected function getSnakeCaseName(): string
{
return str_replace('-', '_', static::NAME);
}
} }

View File

@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
namespace SPC\builder\extension;
use SPC\builder\Extension;
use SPC\store\FileSystem;
use SPC\util\CustomExt;
#[CustomExt('amqp')]
class amqp extends Extension
{
public function patchBeforeMake(): bool
{
if (PHP_OS_FAMILY === 'Windows') {
FileSystem::replaceFileRegex(BUILD_INCLUDE_PATH . '\amqp.h', '/^#warning.*/m', '');
FileSystem::replaceFileRegex(BUILD_INCLUDE_PATH . '\amqp_framing.h', '/^#warning.*/m', '');
FileSystem::replaceFileRegex(BUILD_INCLUDE_PATH . '\amqp_ssl_socket.h', '/^#warning.*/m', '');
FileSystem::replaceFileRegex(BUILD_INCLUDE_PATH . '\amqp_tcp_socket.h', '/^#warning.*/m', '');
return true;
}
return false;
}
public function getUnixConfigureArg(): string
{
return '--with-amqp --with-librabbitmq-dir=' . BUILD_ROOT_PATH;
}
public function getWindowsConfigureArg(): string
{
return '--with-amqp';
}
}

View 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;
}
}

View File

@@ -14,4 +14,9 @@ class ffi extends Extension
{ {
return '--with-ffi --enable-zend-signals'; return '--with-ffi --enable-zend-signals';
} }
public function getWindowsConfigureArg(): string
{
return '--with-ffi';
}
} }

View File

@@ -14,11 +14,11 @@ class imagick extends Extension
public function patchBeforeMake(): bool public function patchBeforeMake(): bool
{ {
// imagick may call omp_pause_all which requires -lgomp // 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) { 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; return true;
} }

View 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;
}
}

View File

@@ -11,6 +11,11 @@ use SPC\util\CustomExt;
#[CustomExt('password-argon2')] #[CustomExt('password-argon2')]
class password_argon2 extends Extension class password_argon2 extends Extension
{ {
public function getDistName(): string
{
return '';
}
public function runCliCheckUnix(): void public function runCliCheckUnix(): void
{ {
[$ret] = shell()->execWithResult(BUILD_ROOT_PATH . '/bin/php -r "assert(defined(\'PASSWORD_ARGON2I\'));"'); [$ret] = shell()->execWithResult(BUILD_ROOT_PATH . '/bin/php -r "assert(defined(\'PASSWORD_ARGON2I\'));"');

View 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;
}
}

View File

@@ -15,8 +15,8 @@ class swoole extends Extension
// enable swoole // enable swoole
$arg = '--enable-swoole'; $arg = '--enable-swoole';
// commonly-used feature: coroutine-time, thread-context // commonly-used feature: coroutine-time, disable-thread-context
$arg .= ' --enable-swoole-coro-time --enable-thread-context'; $arg .= ' --enable-swoole-coro-time --disable-thread-context';
// required feature: curl, openssl (but curl hook is buggy for php 8.0) // required feature: curl, openssl (but curl hook is buggy for php 8.0)
$arg .= $this->builder->getPHPVersionID() >= 80100 ? ' --enable-swoole-curl' : ' --disable-swoole-curl'; $arg .= $this->builder->getPHPVersionID() >= 80100 ? ' --enable-swoole-curl' : ' --disable-swoole-curl';

View 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';
}
}

View File

@@ -11,68 +11,43 @@ use SPC\exception\RuntimeException;
use SPC\exception\WrongUsageException; use SPC\exception\WrongUsageException;
use SPC\store\FileSystem; use SPC\store\FileSystem;
use SPC\store\SourcePatcher; use SPC\store\SourcePatcher;
use SPC\util\GlobalEnvManager;
class LinuxBuilder extends UnixBuilderBase class LinuxBuilder extends UnixBuilderBase
{ {
/** @var array Tune cflags */
public array $tune_c_flags;
/** @var bool Micro patch phar flag */ /** @var bool Micro patch phar flag */
private bool $phar_patched = false; private bool $phar_patched = false;
/** /**
* @throws FileSystemException * @throws FileSystemException
* @throws RuntimeException
* @throws WrongUsageException * @throws WrongUsageException
*/ */
public function __construct(array $options = []) public function __construct(array $options = [])
{ {
$this->options = $options; $this->options = $options;
// ---------- set necessary options ---------- // check musl-cross make installed if we use musl-cross-make
// set C/C++ compilers (default: alpine: gcc, others: musl-cross-make) $arch = arch2gnu(php_uname('m'));
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'));
// set library path, some libraries need it. (We cannot use `putenv` here, because cmake will be confused) // 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('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"); $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 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)'); 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 // concurrency
$this->concurrency = SystemUtil::getCpuCount(); $this->concurrency = intval(getenv('SPC_CONCURRENCY'));
// cflags // cflags
$this->arch_c_flags = SystemUtil::getArchCFlags(getenv('CC'), $this->getOption('arch')); $this->arch_c_flags = getenv('SPC_DEFAULT_C_FLAGS');
$this->arch_cxx_flags = SystemUtil::getArchCFlags(getenv('CXX'), $this->getOption('arch')); $this->arch_cxx_flags = getenv('SPC_DEFAULT_CXX_FLAGS');
$this->tune_c_flags = SystemUtil::checkCCFlags(SystemUtil::getTuneCFlags($this->getOption('arch')), getenv('CC'));
// cmake toolchain // cmake toolchain
$this->cmake_toolchain_file = SystemUtil::makeCmakeToolchainFile( $this->cmake_toolchain_file = SystemUtil::makeCmakeToolchainFile(
'Linux', 'Linux',
$this->getOption('arch'), $arch,
$this->arch_c_flags, $this->arch_c_flags,
getenv('CC'), getenv('CC'),
getenv('CXX'), getenv('CXX'),
@@ -124,8 +99,8 @@ class LinuxBuilder extends UnixBuilderBase
public function buildPHP(int $build_target = BUILD_TARGET_NONE): void public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
{ {
// ---------- Update extra-libs ---------- // ---------- Update extra-libs ----------
$extra_libs = $this->getOption('extra-libs', ''); $extra_libs = getenv('SPC_EXTRA_LIBS') ?: '';
// non-bloat linking // bloat means force-load all static libraries, even if they are not used
if (!$this->getOption('bloat', false)) { if (!$this->getOption('bloat', false)) {
$extra_libs .= (empty($extra_libs) ? '' : ' ') . implode(' ', $this->getAllStaticLibFiles()); $extra_libs .= (empty($extra_libs) ? '' : ' ') . implode(' ', $this->getAllStaticLibFiles());
} else { } else {
@@ -133,21 +108,13 @@ class LinuxBuilder extends UnixBuilderBase
} }
// add libstdc++, some extensions or libraries need it // add libstdc++, some extensions or libraries need it
$extra_libs .= (empty($extra_libs) ? '' : ' ') . ($this->hasCpp() ? '-lstdc++ ' : ''); $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; $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'); $this->emitPatchPoint('before-php-buildconf');
SourcePatcher::patchBeforeBuildconf($this); 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'); $this->emitPatchPoint('before-php-configure');
SourcePatcher::patchBeforeConfigure($this); SourcePatcher::patchBeforeConfigure($this);
@@ -169,20 +136,43 @@ class LinuxBuilder extends UnixBuilderBase
$enableMicro = ($build_target & BUILD_TARGET_MICRO) === BUILD_TARGET_MICRO; $enableMicro = ($build_target & BUILD_TARGET_MICRO) === BUILD_TARGET_MICRO;
$enableEmbed = ($build_target & BUILD_TARGET_EMBED) === BUILD_TARGET_EMBED; $enableEmbed = ($build_target & BUILD_TARGET_EMBED) === BUILD_TARGET_EMBED;
// 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'),
]);
// upx pack and strip for micro // 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)) { 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( FileSystem::replaceFileRegex(
SOURCE_PATH . '/php-src/sapi/micro/Makefile.frag', SOURCE_PATH . '/php-src/sapi/micro/Makefile.frag',
'/POST_MICRO_BUILD_COMMANDS=.*/', '/POST_MICRO_BUILD_COMMANDS=.*/',
'POST_MICRO_BUILD_COMMANDS=\$(STRIP) \$(MICRO_STRIP_FLAGS) \$(SAPI_MICRO_PATH) && ' . $this->getOption('upx-exec') . ' --best \$(SAPI_MICRO_PATH)', 'POST_MICRO_BUILD_COMMANDS=\$(STRIP) \$(MICRO_STRIP_FLAGS) \$(SAPI_MICRO_PATH) && ' . getenv('UPX_EXEC') . ' --best \$(SAPI_MICRO_PATH)',
); );
} elseif (!$this->getOption('no-strip', false)) { } elseif (!$this->getOption('no-strip', false)) {
// not-no-strip means strip (default behavior)
FileSystem::replaceFileRegex( FileSystem::replaceFileRegex(
SOURCE_PATH . '/php-src/sapi/micro/Makefile.frag', SOURCE_PATH . '/php-src/sapi/micro/Makefile.frag',
'/POST_MICRO_BUILD_COMMANDS=.*/', '/POST_MICRO_BUILD_COMMANDS=.*/',
'POST_MICRO_BUILD_COMMANDS=\$(STRIP) \$(MICRO_STRIP_FLAGS) \$(SAPI_MICRO_PATH)', 'POST_MICRO_BUILD_COMMANDS=\$(STRIP) \$(MICRO_STRIP_FLAGS) \$(SAPI_MICRO_PATH)',
); );
} else { } else {
// just no strip
FileSystem::replaceFileRegex( FileSystem::replaceFileRegex(
SOURCE_PATH . '/php-src/sapi/micro/Makefile.frag', SOURCE_PATH . '/php-src/sapi/micro/Makefile.frag',
'/POST_MICRO_BUILD_COMMANDS=.*/', '/POST_MICRO_BUILD_COMMANDS=.*/',
@@ -192,15 +182,7 @@ class LinuxBuilder extends UnixBuilderBase
shell()->cd(SOURCE_PATH . '/php-src') shell()->cd(SOURCE_PATH . '/php-src')
->exec( ->exec(
"{$this->getOption('ld_library_path')} " . getenv('SPC_CMD_PREFIX_PHP_CONFIGURE') . ' ' .
'./configure ' .
'--prefix= ' .
'--with-valgrind=no ' .
'--enable-shared=no ' .
'--enable-static=yes ' .
'--disable-all ' .
'--disable-cgi ' .
'--disable-phpdbg ' .
($enableCli ? '--enable-cli ' : '--disable-cli ') . ($enableCli ? '--enable-cli ' : '--disable-cli ') .
($enableFpm ? '--enable-fpm ' : '--disable-fpm ') . ($enableFpm ? '--enable-fpm ' : '--disable-fpm ') .
($enableEmbed ? '--enable-embed=static ' : '--disable-embed ') . ($enableEmbed ? '--enable-embed=static ' : '--disable-embed ') .
@@ -252,15 +234,15 @@ class LinuxBuilder extends UnixBuilderBase
*/ */
protected function buildCli(): void protected function buildCli(): 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('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')) { if ($this->getOption('with-upx-pack')) {
shell()->cd(SOURCE_PATH . '/php-src/sapi/cli') shell()->cd(SOURCE_PATH . '/php-src/sapi/cli')
->exec('strip --strip-all php') ->exec('strip --strip-all php')
->exec($this->getOption('upx-exec') . ' --best php'); ->exec(getenv('UPX_EXEC') . ' --best php');
} elseif (!$this->getOption('no-strip', false)) { } elseif (!$this->getOption('no-strip', false)) {
shell()->cd(SOURCE_PATH . '/php-src/sapi/cli')->exec('strip --strip-all php'); shell()->cd(SOURCE_PATH . '/php-src/sapi/cli')->exec('strip --strip-all php');
} }
@@ -285,12 +267,16 @@ class LinuxBuilder extends UnixBuilderBase
SourcePatcher::patchMicro(['phar']); SourcePatcher::patchMicro(['phar']);
} }
$vars = SystemUtil::makeEnvVarString($this->getBuildVars([ $enable_fake_cli = $this->getOption('with-micro-fake-cli', false) ? ' -DPHP_MICRO_FAKE_CLI' : '';
'EXTRA_CFLAGS' => $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') shell()->cd(SOURCE_PATH . '/php-src')
->exec('sed -i "s|//lib|/lib|g" Makefile') ->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); $this->deployBinary(BUILD_TARGET_MICRO);
@@ -307,15 +293,15 @@ class LinuxBuilder extends UnixBuilderBase
*/ */
protected function buildFpm(): void protected function buildFpm(): 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('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')) { if ($this->getOption('with-upx-pack')) {
shell()->cd(SOURCE_PATH . '/php-src/sapi/fpm') shell()->cd(SOURCE_PATH . '/php-src/sapi/fpm')
->exec('strip --strip-all php-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)) { } elseif (!$this->getOption('no-strip', false)) {
shell()->cd(SOURCE_PATH . '/php-src/sapi/fpm')->exec('strip --strip-all php-fpm'); shell()->cd(SOURCE_PATH . '/php-src/sapi/fpm')->exec('strip --strip-all php-fpm');
} }
@@ -329,29 +315,19 @@ class LinuxBuilder extends UnixBuilderBase
*/ */
protected function buildEmbed(): void protected function buildEmbed(): void
{ {
$vars = SystemUtil::makeEnvVarString($this->getBuildVars()); $vars = SystemUtil::makeEnvVarString($this->getMakeExtraVars());
shell() shell()->cd(SOURCE_PATH . '/php-src')
->cd(SOURCE_PATH . '/php-src')
->exec('sed -i "s|//lib|/lib|g" Makefile') ->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 [ return [
'EXTRA_CFLAGS' => "{$optimization} -fno-ident -fPIE {$tune_c_flags}{$cflags}", 'EXTRA_CFLAGS' => getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS'),
'EXTRA_LIBS' => "{$this->getOption('extra-libs', '')} {$libs}", 'EXTRA_LIBS' => getenv('SPC_EXTRA_LIBS') . ' ' . getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS'),
'EXTRA_LDFLAGS_PROGRAM' => "{$use_lld} -all-static{$ldflags}", 'EXTRA_LDFLAGS_PROGRAM' => getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM'),
]; ];
} }
} }

View File

@@ -220,6 +220,8 @@ class SystemUtil
'redhat', 'redhat',
// alpine // alpine
'alpine', 'alpine',
// arch
'arch', 'manjaro',
]; ];
} }
} }

View File

@@ -11,7 +11,7 @@ class icu extends LinuxLibraryBase
protected function build(): void protected function build(): void
{ {
$cppflags = 'CPPFLAGS="-DU_CHARSET_IS_UTF8=1 -DU_USING_ICU_NAMESPACE=1 -DU_STATIC_IMPLEMENTATION=1"'; $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"'; $ldflags = 'LDFLAGS="-static"';
shell()->cd($this->source_dir . '/source') shell()->cd($this->source_dir . '/source')
->exec( ->exec(

View File

@@ -4,7 +4,6 @@ declare(strict_types=1);
namespace SPC\builder\linux\library; namespace SPC\builder\linux\library;
use SPC\exception\WrongUsageException;
use SPC\store\FileSystem; use SPC\store\FileSystem;
class libargon2 extends LinuxLibraryBase class libargon2 extends LinuxLibraryBase
@@ -15,10 +14,6 @@ class libargon2 extends LinuxLibraryBase
public function patchBeforeBuild(): bool public function patchBeforeBuild(): bool
{ {
// detect libsodium (The libargon2 conflicts with the libsodium library.)
if ($this->builder->getLib('libsodium') !== null) {
throw new WrongUsageException('libargon2 (required by password-argon2) conflicts with the libsodium library !');
}
FileSystem::replaceFileStr($this->source_dir . '/Makefile', 'LIBRARY_REL ?= lib/x86_64-linux-gnu', 'LIBRARY_REL ?= lib'); FileSystem::replaceFileStr($this->source_dir . '/Makefile', 'LIBRARY_REL ?= lib/x86_64-linux-gnu', 'LIBRARY_REL ?= lib');
return true; return true;
} }

View File

@@ -0,0 +1,12 @@
<?php
declare(strict_types=1);
namespace SPC\builder\linux\library;
class librabbitmq extends LinuxLibraryBase
{
use \SPC\builder\unix\library\librabbitmq;
public const NAME = 'librabbitmq';
}

View File

@@ -0,0 +1,12 @@
<?php
declare(strict_types=1);
namespace SPC\builder\linux\library;
class libtiff extends LinuxLibraryBase
{
use \SPC\builder\unix\library\libtiff;
public const NAME = 'libtiff';
}

View File

@@ -0,0 +1,12 @@
<?php
declare(strict_types=1);
namespace SPC\builder\linux\library;
class libuuid extends LinuxLibraryBase
{
use \SPC\builder\unix\library\libuuid;
public const NAME = 'libuuid';
}

View File

@@ -28,6 +28,7 @@ class libxml2 extends LinuxLibraryBase
'cmake ' . 'cmake ' .
'-DCMAKE_BUILD_TYPE=Release ' . '-DCMAKE_BUILD_TYPE=Release ' .
'-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' ' . '-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' ' .
'-DCMAKE_INSTALL_LIBDIR=' . BUILD_LIB_PATH . ' ' .
"-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " . "-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " .
'-DBUILD_SHARED_LIBS=OFF ' . '-DBUILD_SHARED_LIBS=OFF ' .
'-DIconv_IS_BUILT_IN=OFF ' . '-DIconv_IS_BUILT_IN=OFF ' .

View File

@@ -24,6 +24,7 @@ use SPC\builder\linux\SystemUtil;
use SPC\exception\FileSystemException; use SPC\exception\FileSystemException;
use SPC\exception\RuntimeException; use SPC\exception\RuntimeException;
use SPC\exception\WrongUsageException; use SPC\exception\WrongUsageException;
use SPC\store\FileSystem;
class openssl extends LinuxLibraryBase class openssl extends LinuxLibraryBase
{ {
@@ -41,8 +42,7 @@ class openssl extends LinuxLibraryBase
$extra = ''; $extra = '';
$ex_lib = '-ldl -pthread'; $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/ ' .
' -idirafter /usr/include/' . $this->builder->getOption('arch') . '-linux-gnu/ ' . ' -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' : ''; $clang_postfix = SystemUtil::getCCType(getenv('CC')) === 'clang' ? '-clang' : '';
shell()->cd($this->source_dir) 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} " . "{$env} ./Configure no-shared {$extra} " .
'--prefix=/ ' . '--prefix=/ ' .
'--libdir=lib ' . '--libdir=lib ' .
@@ -73,8 +74,18 @@ class openssl extends LinuxLibraryBase
"linux-{$this->builder->getOption('arch')}{$clang_postfix}" "linux-{$this->builder->getOption('arch')}{$clang_postfix}"
) )
->exec('make clean') ->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}"); ->exec("make install_sw DESTDIR={$destdir}");
$this->patchPkgconfPrefix(['libssl.pc', 'openssl.pc', 'libcrypto.pc']); $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);
}
} }
} }

View 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';
}

View File

@@ -11,6 +11,7 @@ use SPC\exception\RuntimeException;
use SPC\exception\WrongUsageException; use SPC\exception\WrongUsageException;
use SPC\store\FileSystem; use SPC\store\FileSystem;
use SPC\store\SourcePatcher; use SPC\store\SourcePatcher;
use SPC\util\GlobalEnvManager;
class MacOSBuilder extends UnixBuilderBase class MacOSBuilder extends UnixBuilderBase
{ {
@@ -26,28 +27,15 @@ class MacOSBuilder extends UnixBuilderBase
{ {
$this->options = $options; $this->options = $options;
// ---------- set necessary options ---------- // apply global environment variables
// set C Compiler (default: clang) GlobalEnvManager::init($this);
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/');
// set arch (default: current) // ---------- set necessary compile vars ----------
$this->setOptionIfNotExist('arch', php_uname('m'));
$this->setOptionIfNotExist('gnu-arch', arch2gnu($this->getOption('arch')));
// ---------- set necessary compile environments ----------
// concurrency // concurrency
$this->concurrency = SystemUtil::getCpuCount(); $this->concurrency = intval(getenv('SPC_CONCURRENCY'));
// cflags // cflags
$this->arch_c_flags = SystemUtil::getArchCFlags($this->getOption('arch')); $this->arch_c_flags = getenv('SPC_DEFAULT_C_FLAGS');
$this->arch_cxx_flags = SystemUtil::getArchCFlags($this->getOption('arch')); $this->arch_cxx_flags = getenv('SPC_DEFAULT_CXX_FLAGS');
// cmake toolchain // cmake toolchain
$this->cmake_toolchain_file = SystemUtil::makeCmakeToolchainFile('Darwin', $this->getOption('arch'), $this->arch_c_flags); $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 public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
{ {
$extra_libs = getenv('SPC_EXTRA_LIBS') ?: '';
// ---------- Update extra-libs ---------- // ---------- Update extra-libs ----------
$extra_libs = $this->getOption('extra-libs', '');
// add macOS frameworks // add macOS frameworks
$extra_libs .= (empty($extra_libs) ? '' : ' ') . $this->getFrameworks(true); $extra_libs .= (empty($extra_libs) ? '' : ' ') . $this->getFrameworks(true);
// add libc++, some extensions or libraries need it (C++ cannot be linked statically) // add libc++, some extensions or libraries need it (C++ cannot be linked statically)
$extra_libs .= (empty($extra_libs) ? '' : ' ') . ($this->hasCpp() ? '-lc++ ' : ''); $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)) { if (!$this->getOption('bloat', false)) {
$extra_libs .= (empty($extra_libs) ? '' : ' ') . implode(' ', $this->getAllStaticLibFiles()); $extra_libs .= (empty($extra_libs) ? '' : ' ') . implode(' ', $this->getAllStaticLibFiles());
} else { } else {
logger()->info('bloat linking'); logger()->info('bloat linking');
$extra_libs .= (empty($extra_libs) ? '' : ' ') . implode(' ', array_map(fn ($x) => "-Wl,-force_load,{$x}", array_filter($this->getAllStaticLibFiles()))); $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'); $this->emitPatchPoint('before-php-buildconf');
SourcePatcher::patchBeforeBuildconf($this); 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'); $this->emitPatchPoint('before-php-configure');
SourcePatcher::patchBeforeConfigure($this); SourcePatcher::patchBeforeConfigure($this);
@@ -155,9 +144,9 @@ class MacOSBuilder extends UnixBuilderBase
// prepare build php envs // prepare build php envs
$envs_build_php = SystemUtil::makeEnvVarString([ $envs_build_php = SystemUtil::makeEnvVarString([
'CFLAGS' => " {$this->arch_c_flags} -Werror=unknown-warning-option ", 'CFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS'),
'CPPFLAGS' => '-I' . BUILD_INCLUDE_PATH, 'CPPFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_CPPFLAGS'),
'LDFLAGS' => '-L' . BUILD_LIB_PATH, 'LDFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_LDFLAGS'),
]); ]);
if ($this->getLib('postgresql')) { if ($this->getLib('postgresql')) {
@@ -170,14 +159,7 @@ class MacOSBuilder extends UnixBuilderBase
shell()->cd(SOURCE_PATH . '/php-src') shell()->cd(SOURCE_PATH . '/php-src')
->exec( ->exec(
'./configure ' . getenv('SPC_CMD_PREFIX_PHP_CONFIGURE') . ' ' .
'--prefix= ' .
'--with-valgrind=no ' . // Not detect memory leak
'--enable-shared=no ' .
'--enable-static=yes ' .
'--disable-all ' .
'--disable-cgi ' .
'--disable-phpdbg ' .
($enableCli ? '--enable-cli ' : '--disable-cli ') . ($enableCli ? '--enable-cli ' : '--disable-cli ') .
($enableFpm ? '--enable-fpm ' : '--disable-fpm ') . ($enableFpm ? '--enable-fpm ' : '--disable-fpm ') .
($enableEmbed ? '--enable-embed=static ' : '--disable-embed ') . ($enableEmbed ? '--enable-embed=static ' : '--disable-embed ') .
@@ -227,10 +209,10 @@ class MacOSBuilder extends UnixBuilderBase
*/ */
protected function buildCli(): void protected function buildCli(): void
{ {
$vars = SystemUtil::makeEnvVarString($this->getBuildVars()); $vars = SystemUtil::makeEnvVarString($this->getMakeExtraVars());
$shell = shell()->cd(SOURCE_PATH . '/php-src'); $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)) { if (!$this->getOption('no-strip', false)) {
$shell->exec('dsymutil -f sapi/cli/php')->exec('strip sapi/cli/php'); $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' : ''; $enable_fake_cli = $this->getOption('with-micro-fake-cli', false) ? ' -DPHP_MICRO_FAKE_CLI' : '';
$vars = [ $vars = $this->getMakeExtraVars();
// with debug information, optimize for size, remove identifiers, patch fake cli for micro
'EXTRA_CFLAGS' => '-g -Os -fno-ident' . $enable_fake_cli, // patch fake cli for micro
]; $vars['EXTRA_CFLAGS'] .= $enable_fake_cli;
$vars = $this->getBuildVars($vars);
if (!$this->getOption('no-strip', false)) { if (!$this->getOption('no-strip', false)) {
$vars['STRIP'] = 'dsymutil -f '; $vars['STRIP'] = 'dsymutil -f ';
} }
$vars = SystemUtil::makeEnvVarString($vars); $vars = SystemUtil::makeEnvVarString($vars);
shell()->cd(SOURCE_PATH . '/php-src') shell()->cd(SOURCE_PATH . '/php-src')->exec(getenv('SPC_CMD_PREFIX_PHP_MAKE') . " {$vars} micro");
->exec("make -j{$this->concurrency} {$vars} micro");
$this->deployBinary(BUILD_TARGET_MICRO); $this->deployBinary(BUILD_TARGET_MICRO);
if ($this->phar_patched) { if ($this->phar_patched) {
@@ -282,10 +263,10 @@ class MacOSBuilder extends UnixBuilderBase
*/ */
protected function buildFpm(): void protected function buildFpm(): void
{ {
$vars = SystemUtil::makeEnvVarString($this->getBuildVars()); $vars = SystemUtil::makeEnvVarString($this->getMakeExtraVars());
$shell = shell()->cd(SOURCE_PATH . '/php-src'); $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)) { if (!$this->getOption('no-strip', false)) {
$shell->exec('dsymutil -f sapi/fpm/php-fpm')->exec('strip sapi/fpm/php-fpm'); $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 protected function buildEmbed(): void
{ {
$vars = SystemUtil::makeEnvVarString($this->getBuildVars()); $vars = SystemUtil::makeEnvVarString($this->getMakeExtraVars());
shell() shell()->cd(SOURCE_PATH . '/php-src')
->cd(SOURCE_PATH . '/php-src') ->exec(getenv('SPC_CMD_PREFIX_PHP_MAKE') . ' INSTALL_ROOT=' . BUILD_ROOT_PATH . " {$vars} install")
->exec('make INSTALL_ROOT=' . BUILD_ROOT_PATH . " -j{$this->concurrency} {$vars} install")
// Workaround for https://github.com/php/php-src/issues/12082 // Workaround for https://github.com/php/php-src/issues/12082
->exec('rm -Rf ' . BUILD_ROOT_PATH . '/lib/php-o') ->exec('rm -Rf ' . BUILD_ROOT_PATH . '/lib/php-o')
->exec('mkdir ' . 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'); ->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 [ return [
'EXTRA_CFLAGS' => "{$optimization} {$cflags} " . $this->getOption('x-extra-cflags'), 'EXTRA_CFLAGS' => getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS'),
'EXTRA_LIBS' => "{$this->getOption('extra-libs')} -lresolv {$libs} " . $this->getOption('x-extra-libs'), 'EXTRA_LIBS' => getenv('SPC_EXTRA_LIBS') . ' ' . getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS'),
]; ];
} }
} }

View File

@@ -35,7 +35,7 @@ class libpng extends MacOSLibraryBase
*/ */
protected function build(): void protected function build(): void
{ {
$optimizations = match ($this->builder->getOption('arch')) { $optimizations = match (php_uname('m')) {
'x86_64' => '--enable-intel-sse ', 'x86_64' => '--enable-intel-sse ',
'arm64' => '--enable-arm-neon ', 'arm64' => '--enable-arm-neon ',
default => '', default => '',
@@ -45,7 +45,7 @@ class libpng extends MacOSLibraryBase
->exec('chmod +x ./install-sh') ->exec('chmod +x ./install-sh')
->exec( ->exec(
'./configure ' . './configure ' .
"--host={$this->builder->getOption('gnu-arch')}-apple-darwin " . '--host=' . arch2gnu(php_uname('m')) . '-apple-darwin ' .
'--disable-shared ' . '--disable-shared ' .
'--enable-static ' . '--enable-static ' .
'--enable-hardware-optimizations ' . '--enable-hardware-optimizations ' .

View File

@@ -0,0 +1,12 @@
<?php
declare(strict_types=1);
namespace SPC\builder\macos\library;
class librabbitmq extends MacOSLibraryBase
{
use \SPC\builder\unix\library\librabbitmq;
public const NAME = 'librabbitmq';
}

View File

@@ -0,0 +1,12 @@
<?php
declare(strict_types=1);
namespace SPC\builder\macos\library;
class libtiff extends MacOSLibraryBase
{
use \SPC\builder\unix\library\libtiff;
public const NAME = 'libtiff';
}

View File

@@ -0,0 +1,12 @@
<?php
declare(strict_types=1);
namespace SPC\builder\macos\library;
class libuuid extends MacOSLibraryBase
{
use \SPC\builder\unix\library\libuuid;
public const NAME = 'libuuid';
}

View File

@@ -29,6 +29,7 @@ class libxml2 extends MacOSLibraryBase
// '--debug-find ' . // '--debug-find ' .
'-DCMAKE_BUILD_TYPE=Release ' . '-DCMAKE_BUILD_TYPE=Release ' .
'-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' ' . '-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' ' .
'-DCMAKE_INSTALL_LIBDIR=' . BUILD_LIB_PATH . ' ' .
"-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " . "-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " .
'-DBUILD_SHARED_LIBS=OFF ' . '-DBUILD_SHARED_LIBS=OFF ' .
'-DLIBXML2_WITH_ICONV=ON ' . '-DLIBXML2_WITH_ICONV=ON ' .

View File

@@ -23,6 +23,7 @@ namespace SPC\builder\macos\library;
use SPC\exception\FileSystemException; use SPC\exception\FileSystemException;
use SPC\exception\RuntimeException; use SPC\exception\RuntimeException;
use SPC\exception\WrongUsageException; use SPC\exception\WrongUsageException;
use SPC\store\FileSystem;
class openssl extends MacOSLibraryBase class openssl extends MacOSLibraryBase
{ {
@@ -47,6 +48,7 @@ class openssl extends MacOSLibraryBase
} }
shell()->cd($this->source_dir) shell()->cd($this->source_dir)
->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()])
->exec( ->exec(
"./Configure no-shared {$extra} " . "./Configure no-shared {$extra} " .
'--prefix=/ ' . // use prefix=/ '--prefix=/ ' . // use prefix=/
@@ -55,8 +57,18 @@ class openssl extends MacOSLibraryBase
"darwin64-{$this->builder->getOption('arch')}-cc" "darwin64-{$this->builder->getOption('arch')}-cc"
) )
->exec('make clean') ->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}"); ->exec("make install_sw DESTDIR={$destdir}");
$this->patchPkgconfPrefix(['libssl.pc', 'openssl.pc', 'libcrypto.pc']); $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);
}
} }
} }

View 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';
}

View File

@@ -1,20 +1,4 @@
<?php <?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); declare(strict_types=1);

View File

@@ -48,7 +48,7 @@ trait UnixLibraryTrait
* @throws RuntimeException * @throws RuntimeException
* @throws WrongUsageException * @throws WrongUsageException
*/ */
public function makeAutoconfEnv(string $prefix = null): string public function makeAutoconfEnv(?string $prefix = null): string
{ {
if ($prefix === null) { if ($prefix === null) {
$prefix = str_replace('-', '_', strtoupper(static::NAME)); $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') ?: '';
}
} }

View File

@@ -18,14 +18,15 @@ trait brotli
{ {
FileSystem::resetDir($this->source_dir . '/build-dir'); FileSystem::resetDir($this->source_dir . '/build-dir');
shell()->cd($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 ' . 'cmake ' .
"{$this->builder->makeCmakeArgs()} " . "{$this->builder->makeCmakeArgs()} " .
'-DBUILD_SHARED_LIBS=OFF ' . '-DBUILD_SHARED_LIBS=OFF ' .
'..' '..'
) )
->exec("cmake --build . -j {$this->builder->concurrency}") ->execWithEnv("cmake --build . -j {$this->builder->concurrency}")
->exec('make install DESTDIR=' . BUILD_ROOT_PATH); ->execWithEnv('make install DESTDIR=' . BUILD_ROOT_PATH);
$this->patchPkgconfPrefix(['libbrotlicommon.pc', 'libbrotlidec.pc', 'libbrotlienc.pc']); $this->patchPkgconfPrefix(['libbrotlicommon.pc', 'libbrotlidec.pc', 'libbrotlienc.pc']);
shell()->cd(BUILD_ROOT_PATH . '/lib')->exec('ln -sf libbrotlicommon.a libbrotli.a'); shell()->cd(BUILD_ROOT_PATH . '/lib')->exec('ln -sf libbrotlicommon.a libbrotli.a');
foreach (FileSystem::scanDirFiles(BUILD_ROOT_PATH . '/lib/', false, true) as $filename) { foreach (FileSystem::scanDirFiles(BUILD_ROOT_PATH . '/lib/', false, true) as $filename) {

View File

@@ -9,8 +9,9 @@ trait bzip2
protected function build(): void protected function build(): void
{ {
shell()->cd($this->source_dir) shell()->cd($this->source_dir)
->exec("make PREFIX='" . BUILD_ROOT_PATH . "' clean") ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()])
->exec("make -j{$this->builder->concurrency} {$this->builder->getEnvString()} PREFIX='" . BUILD_ROOT_PATH . "' libbz2.a") ->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 libbz2.a ' . BUILD_LIB_PATH)
->exec('cp bzlib.h ' . BUILD_INCLUDE_PATH); ->exec('cp bzlib.h ' . BUILD_INCLUDE_PATH);
} }

View File

@@ -51,10 +51,11 @@ trait curl
FileSystem::resetDir($this->source_dir . '/build'); FileSystem::resetDir($this->source_dir . '/build');
// compile // compile
shell()->cd($this->source_dir . '/build') 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('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} ..") ->execWithEnv("cmake {$this->builder->makeCmakeArgs()} -DBUILD_SHARED_LIBS=OFF -DBUILD_CURL_EXE=OFF -DBUILD_LIBCURL_DOCS=OFF {$extra} ..")
->exec("make -j{$this->builder->concurrency}") ->execWithEnv("make -j{$this->builder->concurrency}")
->exec('make install DESTDIR=' . BUILD_ROOT_PATH); ->execWithEnv('make install DESTDIR=' . BUILD_ROOT_PATH);
// patch pkgconf // patch pkgconf
$this->patchPkgconfPrefix(['libcurl.pc']); $this->patchPkgconfPrefix(['libcurl.pc']);
shell()->cd(BUILD_LIB_PATH . '/cmake/CURL/') shell()->cd(BUILD_LIB_PATH . '/cmake/CURL/')

View File

@@ -26,15 +26,16 @@ trait freetype
$suggested .= ' '; $suggested .= ' ';
shell()->cd($this->source_dir) shell()->cd($this->source_dir)
->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()])
->exec('sh autogen.sh') ->exec('sh autogen.sh')
->exec( ->execWithEnv(
'./configure ' . './configure ' .
'--enable-static --disable-shared --without-harfbuzz --prefix= ' . '--enable-static --disable-shared --without-harfbuzz --prefix= ' .
$suggested $suggested
) )
->exec('make clean') ->execWithEnv('make clean')
->exec("make -j{$this->builder->concurrency}") ->execWithEnv("make -j{$this->builder->concurrency}")
->exec('make install DESTDIR=' . BUILD_ROOT_PATH); ->execWithEnv('make install DESTDIR=' . BUILD_ROOT_PATH);
$this->patchPkgconfPrefix(['freetype2.pc']); $this->patchPkgconfPrefix(['freetype2.pc']);
FileSystem::replaceFileStr( FileSystem::replaceFileStr(
BUILD_ROOT_PATH . '/lib/pkgconfig/freetype2.pc', BUILD_ROOT_PATH . '/lib/pkgconfig/freetype2.pc',

View File

@@ -11,7 +11,8 @@ trait gettext
$extra = $this->builder->getLib('ncurses') ? ('--with-libncurses-prefix=' . BUILD_ROOT_PATH . ' ') : ''; $extra = $this->builder->getLib('ncurses') ? ('--with-libncurses-prefix=' . BUILD_ROOT_PATH . ' ') : '';
$extra .= $this->builder->getLib('libxml2') ? ('--with-libxml2-prefix=' . BUILD_ROOT_PATH . ' ') : ''; $extra .= $this->builder->getLib('libxml2') ? ('--with-libxml2-prefix=' . BUILD_ROOT_PATH . ' ') : '';
shell()->cd($this->source_dir) shell()->cd($this->source_dir)
->exec( ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()])
->execWithEnv(
'./configure ' . './configure ' .
'--enable-static ' . '--enable-static ' .
'--disable-shared ' . '--disable-shared ' .
@@ -21,8 +22,8 @@ trait gettext
'--with-libiconv-prefix=' . BUILD_ROOT_PATH . ' ' . '--with-libiconv-prefix=' . BUILD_ROOT_PATH . ' ' .
'--prefix=' . BUILD_ROOT_PATH '--prefix=' . BUILD_ROOT_PATH
) )
->exec('make clean') ->execWithEnv('make clean')
->exec("make -j{$this->builder->concurrency}") ->execWithEnv("make -j{$this->builder->concurrency}")
->exec('make install'); ->execWithEnv('make install');
} }
} }

View File

@@ -16,13 +16,14 @@ trait gmp
protected function build(): void protected function build(): void
{ {
shell()->cd($this->source_dir) shell()->cd($this->source_dir)
->exec( ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()])
->execWithEnv(
'./configure ' . './configure ' .
'--enable-static --disable-shared ' . '--enable-static --disable-shared ' .
'--prefix=' '--prefix='
) )
->exec('make clean') ->execWithEnv('make clean')
->exec("make -j{$this->builder->concurrency}") ->execWithEnv("make -j{$this->builder->concurrency}")
->exec('make install DESTDIR=' . BUILD_ROOT_PATH); ->exec('make install DESTDIR=' . BUILD_ROOT_PATH);
$this->patchPkgconfPrefix(['gmp.pc']); $this->patchPkgconfPrefix(['gmp.pc']);
} }

View File

@@ -19,7 +19,7 @@ trait imagemagick
protected function build(): void protected function build(): void
{ {
// TODO: imagemagick build with bzip2 failed with bugs, we need to fix it in the future // 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 = ''; $required_libs = '';
$optional_libs = [ $optional_libs = [
'libzip' => 'zip', 'libzip' => 'zip',
@@ -39,15 +39,18 @@ trait imagemagick
} }
} }
$ldflags = $this instanceof LinuxLibraryBase ? ('LDFLAGS="-static" ') : ''; $ldflags = $this instanceof LinuxLibraryBase ? ('-static') : '';
// libxml iconv patch // libxml iconv patch
$required_libs .= $this instanceof MacOSLibraryBase ? (' -liconv') : ''; $required_libs .= $this instanceof MacOSLibraryBase ? ('-liconv') : '';
shell()->cd($this->source_dir) shell()->cd($this->source_dir)
->exec( ->setEnv([
'PKG_CONFIG="$PKG_CONFIG --static" ' . 'CFLAGS' => $this->getLibExtraCFlags(),
$ldflags . 'LDFLAGS' => $this->getLibExtraLdFlags() ?: $ldflags,
"LIBS='{$required_libs}' " . 'LIBS' => $this->getLibExtraLibs() ?: $required_libs,
'PKG_CONFIG' => '$PKG_CONFIG --static',
])
->execWithEnv(
'./configure ' . './configure ' .
'--enable-static --disable-shared ' . '--enable-static --disable-shared ' .
$extra . $extra .

View File

@@ -25,9 +25,15 @@ trait ldap
$alt .= $this->builder->getLib('libsodium') ? '--with-argon2=libsodium ' : '--enable-argon2=no '; $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=' . BUILD_ROOT_PATH . '/bin/pkg-config');
f_putenv('PKG_CONFIG_PATH=' . BUILD_LIB_PATH . '/pkgconfig'); f_putenv('PKG_CONFIG_PATH=' . BUILD_LIB_PATH . '/pkgconfig');
$ldflags = '-L' . BUILD_LIB_PATH;
shell()->cd($this->source_dir) shell()->cd($this->source_dir)
->exec( ->setEnv([
$this->builder->makeAutoconfFlags(AUTOCONF_LDFLAGS | AUTOCONF_CPPFLAGS) . 'CFLAGS' => $this->getLibExtraCFlags(),
'LDFLAGS' => $this->getLibExtraLdFlags() ?: $ldflags,
'LIBS' => $this->getLibExtraLibs(),
])
->execWithEnv(
$this->builder->makeAutoconfFlags(AUTOCONF_CPPFLAGS) .
' ./configure ' . ' ./configure ' .
'--enable-static ' . '--enable-static ' .
'--disable-shared ' . '--disable-shared ' .

View File

@@ -11,9 +11,10 @@ trait libargon2
protected function build() protected function build()
{ {
shell()->cd($this->source_dir) shell()->cd($this->source_dir)
->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()])
->exec("make PREFIX='' clean") ->exec("make PREFIX='' clean")
->exec("make -j{$this->builder->concurrency} PREFIX=''") ->execWithEnv("make -j{$this->builder->concurrency} PREFIX=''")
->exec("make install PREFIX='' DESTDIR=" . BUILD_ROOT_PATH); ->execWithEnv("make install PREFIX='' DESTDIR=" . BUILD_ROOT_PATH);
$this->patchPkgconfPrefix(['libargon2.pc']); $this->patchPkgconfPrefix(['libargon2.pc']);

View File

@@ -22,9 +22,10 @@ trait libavif
FileSystem::resetDir($this->source_dir . '/build'); FileSystem::resetDir($this->source_dir . '/build');
// Start build // Start build
shell()->cd($this->source_dir . '/build') shell()->cd($this->source_dir . '/build')
->exec("cmake {$this->builder->makeCmakeArgs()} -DBUILD_SHARED_LIBS=OFF ..") ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()])
->exec("cmake --build . -j {$this->builder->concurrency}") ->execWithEnv("cmake {$this->builder->makeCmakeArgs()} -DBUILD_SHARED_LIBS=OFF ..")
->exec('make install DESTDIR=' . BUILD_ROOT_PATH); ->execWithEnv("cmake --build . -j {$this->builder->concurrency}")
->execWithEnv('make install DESTDIR=' . BUILD_ROOT_PATH);
// patch pkgconfig // patch pkgconfig
$this->patchPkgconfPrefix(['libavif.pc']); $this->patchPkgconfPrefix(['libavif.pc']);
$this->cleanLaFiles(); $this->cleanLaFiles();

View File

@@ -14,8 +14,9 @@ trait libcares
protected function build(): void protected function build(): void
{ {
shell()->cd($this->source_dir) shell()->cd($this->source_dir)
->exec('./configure --prefix=' . BUILD_ROOT_PATH . ' --enable-static --disable-shared --disable-tests') ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()])
->exec("make -j {$this->builder->concurrency}") ->execWithEnv('./configure --prefix=' . BUILD_ROOT_PATH . ' --enable-static --disable-shared --disable-tests')
->execWithEnv("make -j {$this->builder->concurrency}")
->exec('make install'); ->exec('make install');
} }
} }

View File

@@ -20,7 +20,8 @@ trait libevent
FileSystem::resetDir($this->source_dir . '/build'); FileSystem::resetDir($this->source_dir . '/build');
// Start build // Start build
shell()->cd($this->source_dir . '/build') shell()->cd($this->source_dir . '/build')
->exec( ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()])
->execWithEnv(
'cmake ' . 'cmake ' .
'-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' ' . '-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' ' .
"-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " . "-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " .
@@ -33,7 +34,7 @@ trait libevent
'-DEVENT__DISABLE_SAMPLES=ON ' . '-DEVENT__DISABLE_SAMPLES=ON ' .
'..' '..'
) )
->exec("cmake --build . -j {$this->builder->concurrency}") ->execWithEnv("cmake --build . -j {$this->builder->concurrency}")
->exec('make install'); ->exec('make install');
} }
} }

View File

@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
namespace SPC\builder\unix\library;
use SPC\exception\FileSystemException;
use SPC\exception\RuntimeException;
use SPC\store\FileSystem;
trait librabbitmq
{
/**
* @throws RuntimeException
* @throws FileSystemException
*/
protected function build(): void
{
// CMake needs a clean build directory
FileSystem::resetDir($this->source_dir . '/build');
// Start build
shell()->cd($this->source_dir . '/build')
->exec(
'cmake ' .
'-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' ' .
"-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " .
'-DCMAKE_BUILD_TYPE=Release ' .
'-DBUILD_SHARED_LIBS=OFF ' .
'-DBUILD_STATIC_LIBS=ON ' .
'..'
)
->exec("cmake --build . -j {$this->builder->concurrency}")
->exec('make install');
}
}

View File

@@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
namespace SPC\builder\unix\library;
use SPC\exception\FileSystemException;
use SPC\exception\RuntimeException;
trait libtiff
{
/**
* @throws FileSystemException
* @throws RuntimeException
*/
protected function build(): void
{
shell()->cd($this->source_dir)
->exec(
'./configure ' .
'--enable-static --disable-shared ' .
'--disable-cxx ' .
'--prefix='
)
->exec('make clean')
->exec("make -j{$this->builder->concurrency}")
->exec('make install DESTDIR=' . BUILD_ROOT_PATH);
$this->patchPkgconfPrefix(['libtiff-4.pc']);
}
}

View File

@@ -0,0 +1,46 @@
<?php
declare(strict_types=1);
namespace SPC\builder\unix\library;
use SPC\exception\FileSystemException;
use SPC\exception\RuntimeException;
use SPC\store\FileSystem;
trait libuuid
{
/**
* @throws FileSystemException
* @throws RuntimeException
*/
protected function build(): void
{
FileSystem::resetDir($this->source_dir . '/build');
shell()->cd($this->source_dir . '/build')
->exec(
'cmake ' .
"{$this->builder->makeCmakeArgs()} " .
'..'
)
->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);
}
}

View File

@@ -17,13 +17,13 @@ trait ncurses
'--with-curses-h ' . '--with-curses-h ' .
'--enable-pc-files ' . '--enable-pc-files ' .
'--enable-echo ' . '--enable-echo ' .
// '--enable-widec ' . '--disable-widec ' .
'--with-normal ' . '--with-normal ' .
'--with-ticlib ' . '--with-ticlib ' .
'--without-tests ' . '--without-tests ' .
'--without-dlsym ' . '--without-dlsym ' .
'--without-debug ' . '--without-debug ' .
'-enable-symlinks' . '-enable-symlinks ' .
'--bindir=' . BUILD_ROOT_PATH . '/bin ' . '--bindir=' . BUILD_ROOT_PATH . '/bin ' .
'--includedir=' . BUILD_ROOT_PATH . '/include ' . '--includedir=' . BUILD_ROOT_PATH . '/include ' .
'--libdir=' . BUILD_ROOT_PATH . '/lib ' . '--libdir=' . BUILD_ROOT_PATH . '/lib ' .

View File

@@ -8,15 +8,12 @@ trait pkgconfig
{ {
protected function build(): void protected function build(): void
{ {
$macos_env = "CFLAGS='{$this->builder->arch_c_flags} -Wimplicit-function-declaration' "; $cflags = PHP_OS_FAMILY !== 'Linux' ? "{$this->builder->arch_c_flags} -Wimplicit-function-declaration -Wno-int-conversion" : '';
$linux_env = 'LDFLAGS=--static '; $ldflags = PHP_OS_FAMILY !== 'Linux' ? '' : '--static';
shell()->cd($this->source_dir) shell()->cd($this->source_dir)
->exec( ->setEnv(['CFLAGS' => $this->getLibExtraCFlags() ?: $cflags, 'LDFLAGS' => $this->getLibExtraLdFlags() ?: $ldflags, 'LIBS' => $this->getLibExtraLibs()])
match (PHP_OS_FAMILY) { ->execWithEnv(
'Darwin' => $macos_env,
default => $linux_env,
} .
'./configure ' . './configure ' .
'--disable-shared ' . '--disable-shared ' .
'--enable-static ' . '--enable-static ' .
@@ -30,8 +27,8 @@ trait pkgconfig
'--without-pc-path' '--without-pc-path'
) )
->exec('make clean') ->exec('make clean')
->exec("make -j{$this->builder->concurrency}") ->execWithEnv("make -j{$this->builder->concurrency}")
->exec('make install-exec'); ->execWithEnv('make install-exec');
shell()->exec('strip ' . BUILD_ROOT_PATH . '/bin/pkg-config'); shell()->exec('strip ' . BUILD_ROOT_PATH . '/bin/pkg-config');
} }
} }

View File

@@ -27,26 +27,31 @@ trait postgresql
'libxslt' => 'libxslt', 'libxslt' => 'libxslt',
'icu' => 'icu-i18n', 'icu' => 'icu-i18n',
]; ];
$error_exec_cnt = 0;
foreach ($optional_packages as $lib => $pkg) { foreach ($optional_packages as $lib => $pkg) {
if ($this->getBuilder()->getLib($lib)) { if ($this->getBuilder()->getLib($lib)) {
$packages .= ' ' . $pkg; $packages .= ' ' . $pkg;
$output = shell()->execWithResult("pkg-config --static {$pkg}"); $output = shell()->execWithResult("pkg-config --static {$pkg}");
$error_exec_cnt += $output[0] === 0 ? 0 : 1;
logger()->info(var_export($output[1], true)); logger()->info(var_export($output[1], true));
} }
} }
$output = shell()->execWithResult("pkg-config --cflags-only-I --static {$packages}"); $output = shell()->execWithResult("pkg-config --cflags-only-I --static {$packages}");
$error_exec_cnt += $output[0] === 0 ? 0 : 1;
if (!empty($output[1][0])) { if (!empty($output[1][0])) {
$cppflags = $output[1][0]; $cppflags = $output[1][0];
$envs .= " CPPFLAGS=\"{$cppflags}\""; $envs .= " CPPFLAGS=\"{$cppflags}\"";
} }
$output = shell()->execWithResult("pkg-config --libs-only-L --static {$packages}"); $output = shell()->execWithResult("pkg-config --libs-only-L --static {$packages}");
$error_exec_cnt += $output[0] === 0 ? 0 : 1;
if (!empty($output[1][0])) { if (!empty($output[1][0])) {
$ldflags = $output[1][0]; $ldflags = $output[1][0];
$envs .= $this instanceof MacOSLibraryBase ? " LDFLAGS=\"{$ldflags}\" " : " LDFLAGS=\"{$ldflags} -static\" "; $envs .= $this instanceof MacOSLibraryBase ? " LDFLAGS=\"{$ldflags}\" " : " LDFLAGS=\"{$ldflags} -static\" ";
} }
$output = shell()->execWithResult("pkg-config --libs-only-l --static {$packages}"); $output = shell()->execWithResult("pkg-config --libs-only-l --static {$packages}");
$error_exec_cnt += $output[0] === 0 ? 0 : 1;
if (!empty($output[1][0])) { if (!empty($output[1][0])) {
$libs = $output[1][0]; $libs = $output[1][0];
$libcpp = ''; $libcpp = '';
@@ -55,6 +60,9 @@ trait postgresql
} }
$envs .= " LIBS=\"{$libs}{$libcpp}\" "; $envs .= " LIBS=\"{$libs}{$libcpp}\" ";
} }
if ($error_exec_cnt > 0) {
throw new RuntimeException('Failed to get pkg-config information!');
}
FileSystem::resetDir($this->source_dir . '/build'); FileSystem::resetDir($this->source_dir . '/build');

View 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']);
}
}

View File

@@ -20,7 +20,6 @@ trait xz
'./configure ' . './configure ' .
'--enable-static ' . '--enable-static ' .
'--disable-shared ' . '--disable-shared ' .
"--host={$this->builder->getOption('gnu-arch')}-unknown-linux " .
'--disable-scripts ' . '--disable-scripts ' .
'--disable-doc ' . '--disable-doc ' .
'--with-libiconv ' . '--with-libiconv ' .

View File

@@ -13,6 +13,7 @@ use SPC\store\FileSystem;
use SPC\store\SourceManager; use SPC\store\SourceManager;
use SPC\store\SourcePatcher; use SPC\store\SourcePatcher;
use SPC\util\DependencyUtil; use SPC\util\DependencyUtil;
use SPC\util\GlobalEnvManager;
class WindowsBuilder extends BuilderBase class WindowsBuilder extends BuilderBase
{ {
@@ -33,6 +34,8 @@ class WindowsBuilder extends BuilderBase
{ {
$this->options = $options; $this->options = $options;
GlobalEnvManager::init($this);
// ---------- set necessary options ---------- // ---------- set necessary options ----------
// set sdk (require visual studio 16 or 17) // set sdk (require visual studio 16 or 17)
$vs = SystemUtil::findVisualStudio()['version']; $vs = SystemUtil::findVisualStudio()['version'];
@@ -42,10 +45,13 @@ class WindowsBuilder extends BuilderBase
$this->zts = $this->getOption('enable-zts', false); $this->zts = $this->getOption('enable-zts', false);
// set concurrency // set concurrency
$this->concurrency = SystemUtil::getCpuCount(); $this->concurrency = intval(getenv('SPC_CONCURRENCY'));
// make cmake toolchain // make cmake toolchain
$this->cmake_toolchain_file = SystemUtil::makeCmakeToolchainFile(); $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 public function buildPHP(int $build_target = BUILD_TARGET_NONE): void
{ {
// ---------- Update extra-libs ---------- // ---------- Update extra-libs ----------
$extra_libs = $this->getOption('extra-libs', ''); $extra_libs = getenv('SPC_EXTRA_LIBS') ?: '';
$extra_libs .= (empty($extra_libs) ? '' : ' ') . implode(' ', $this->getAllStaticLibFiles()); $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; $enableCli = ($build_target & BUILD_TARGET_CLI) === BUILD_TARGET_CLI;
$enableFpm = ($build_target & BUILD_TARGET_FPM) === BUILD_TARGET_FPM; $enableFpm = ($build_target & BUILD_TARGET_FPM) === BUILD_TARGET_FPM;
$enableMicro = ($build_target & BUILD_TARGET_MICRO) === BUILD_TARGET_MICRO; $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 ($this->getOption('with-upx-pack', false)) {
if (!file_exists($makefile . '.originfile')) { if (!file_exists($makefile . '.originfile')) {
copy($makefile, $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)"); FileSystem::replaceFileStr($makefile, '@$(_MICRO_MT)', "@$(_MICRO_MT)\n\t@$(_MICRO_UPX)");
} }
} elseif (file_exists($makefile . '.originfile')) { } elseif (file_exists($makefile . '.originfile')) {
@@ -85,6 +92,14 @@ class WindowsBuilder extends BuilderBase
unlink($makefile . '.originfile'); unlink($makefile . '.originfile');
} }
if (($logo = $this->getOption('with-micro-logo')) !== null) {
// realpath
$logo = realpath($logo);
$micro_logo = '--enable-micro-logo=' . $logo . ' ';
} else {
$micro_logo = '';
}
cmd()->cd(SOURCE_PATH . '\php-src') cmd()->cd(SOURCE_PATH . '\php-src')
->exec( ->exec(
"{$this->sdk_prefix} configure.bat --task-args \"" . "{$this->sdk_prefix} configure.bat --task-args \"" .
@@ -94,7 +109,7 @@ class WindowsBuilder extends BuilderBase
'--with-extra-includes=' . BUILD_INCLUDE_PATH . ' ' . '--with-extra-includes=' . BUILD_INCLUDE_PATH . ' ' .
'--with-extra-libs=' . BUILD_LIB_PATH . ' ' . '--with-extra-libs=' . BUILD_LIB_PATH . ' ' .
($enableCli ? '--enable-cli=yes ' : '--enable-cli=no ') . ($enableCli ? '--enable-cli=yes ' : '--enable-cli=no ') .
($enableMicro ? '--enable-micro=yes ' : '--enable-micro=no ') . ($enableMicro ? ('--enable-micro=yes ' . $micro_logo) : '--enable-micro=no ') .
($enableEmbed ? '--enable-embed=yes ' : '--enable-embed=no ') . ($enableEmbed ? '--enable-embed=yes ' : '--enable-embed=no ') .
"{$this->makeExtensionArgs()} " . "{$this->makeExtensionArgs()} " .
$zts . $zts .
@@ -179,10 +194,12 @@ class WindowsBuilder extends BuilderBase
SourcePatcher::patchMicro(['phar']); SourcePatcher::patchMicro(['phar']);
} }
cmd()->cd(SOURCE_PATH . '\php-src')->exec("{$this->sdk_prefix} nmake_micro_wrapper.bat --task-args micro"); try {
cmd()->cd(SOURCE_PATH . '\php-src')->exec("{$this->sdk_prefix} nmake_micro_wrapper.bat --task-args micro");
if ($this->phar_patched) { } finally {
SourcePatcher::patchMicro(['phar'], true); if ($this->phar_patched) {
SourcePatcher::patchMicro(['phar'], true);
}
} }
$this->deployBinary(BUILD_TARGET_MICRO); $this->deployBinary(BUILD_TARGET_MICRO);
@@ -309,7 +326,7 @@ class WindowsBuilder extends BuilderBase
// with-upx-pack for cli // with-upx-pack for cli
if ($this->getOption('with-upx-pack', false) && $type === BUILD_TARGET_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'); logger()->info('Deploying ' . $this->getBuildTypeName($type) . ' file');

View File

@@ -12,29 +12,13 @@ class curl extends WindowsLibraryBase
protected function build(): void protected function build(): void
{ {
// reset cmake cmd()->cd($this->source_dir . '\winbuild')
FileSystem::resetDir($this->source_dir . '\build');
// start build
cmd()->cd($this->source_dir)
->execWithWrapper( ->execWithWrapper(
$this->builder->makeSimpleWrapper('cmake'), $this->builder->makeSimpleWrapper('nmake'),
'-B build ' . '/f Makefile.vc WITH_DEVEL=' . BUILD_ROOT_PATH . ' ' .
'-A x64 ' . 'WITH_PREFIX=' . BUILD_ROOT_PATH . ' ' .
"-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " . 'mode=static RTLIBCFG=static WITH_SSL=static WITH_NGHTTP2=static WITH_SSH2=static ENABLE_IPV6=yes WITH_ZLIB=static MACHINE=x64 DEBUG=no'
'-DCMAKE_BUILD_TYPE=Release ' .
'-DBUILD_SHARED_LIBS=OFF ' .
'-DBUILD_STATIC_LIBS=ON ' .
'-DBUILD_CURL_EXE=OFF ' .
'-DUSE_ZLIB=ON ' .
'-DCURL_USE_OPENSSL=ON ' .
'-DCURL_USE_LIBLSSH2=ON ' .
'-DUSE_NGHTTP2=ON ' . // php-src with curl needs nghttp2
'-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' '
)
->execWithWrapper(
$this->builder->makeSimpleWrapper('cmake'),
"--build build --config Release --target install -j{$this->builder->concurrency}"
); );
FileSystem::copyDir($this->source_dir . '\include\curl', BUILD_INCLUDE_PATH . '\curl');
} }
} }

View File

@@ -0,0 +1,46 @@
<?php
declare(strict_types=1);
namespace SPC\builder\windows\library;
use SPC\builder\windows\SystemUtil;
use SPC\exception\RuntimeException;
use SPC\store\FileSystem;
class libffi_win extends WindowsLibraryBase
{
public const NAME = 'libffi-win';
protected function build()
{
$vs_ver_dir = match (SystemUtil::findVisualStudio()['version']) {
'vs17' => '/win32/vs17_x64',
'vs16' => '/win32/vs16_x64',
default => throw new RuntimeException('Current VS version is not supported yet!'),
};
// start build
cmd()->cd($this->source_dir . $vs_ver_dir)
->execWithWrapper(
$this->builder->makeSimpleWrapper('msbuild'),
'libffi-msvc.sln /t:Rebuild /p:Configuration=Release /p:Platform=x64'
);
FileSystem::createDir(BUILD_LIB_PATH);
FileSystem::createDir(BUILD_INCLUDE_PATH);
copy($this->source_dir . $vs_ver_dir . '\x64\Release\libffi.lib', BUILD_LIB_PATH . '\libffi.lib');
copy($this->source_dir . $vs_ver_dir . '\x64\Release\libffi.pdb', BUILD_LIB_PATH . '\libffi.pdb');
copy($this->source_dir . '\include\ffi.h', BUILD_INCLUDE_PATH . '\ffi.h');
FileSystem::replaceFileStr(BUILD_INCLUDE_PATH . '\ffi.h', '#define LIBFFI_H', "#define LIBFFI_H\n#define FFI_BUILDING");
copy($this->source_dir . '\src\x86\ffitarget.h', BUILD_INCLUDE_PATH . '\ffitarget.h');
copy($this->source_dir . '\fficonfig.h', BUILD_INCLUDE_PATH . '\fficonfig.h');
// copy($this->source_dir . '\msvc_build\out\static-Release\X64\libffi.lib', BUILD_LIB_PATH . '\libffi.lib');
// copy($this->source_dir . '\msvc_build\include\ffi.h', BUILD_INCLUDE_PATH . '\ffi.h');
// copy($this->source_dir . '\msvc_build\include\fficonfig.h', BUILD_INCLUDE_PATH . '\fficonfig.h');
// copy($this->source_dir . '\src\x86\ffitarget.h', BUILD_INCLUDE_PATH . '\ffitarget.h');
// FileSystem::replaceFileStr(BUILD_INCLUDE_PATH . '\ffi.h', '..\..\src\x86\ffitarget.h', 'ffitarget.h');
}
}

View File

@@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
namespace SPC\builder\windows\library;
use SPC\store\FileSystem;
class librabbitmq extends WindowsLibraryBase
{
public const NAME = 'librabbitmq';
protected function build(): void
{
// reset cmake
FileSystem::resetDir($this->source_dir . '\build');
// start build
cmd()->cd($this->source_dir)
->execWithWrapper(
$this->builder->makeSimpleWrapper('cmake'),
'-B build ' .
'-A x64 ' .
"-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " .
'-DCMAKE_BUILD_TYPE=Release ' .
'-DBUILD_SHARED_LIBS=OFF ' .
'-DBUILD_STATIC_LIBS=ON ' .
'-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' '
)
->execWithWrapper(
$this->builder->makeSimpleWrapper('cmake'),
"--build build --config Release --target install -j{$this->builder->concurrency}"
);
rename(BUILD_LIB_PATH . '\librabbitmq.4.lib', BUILD_LIB_PATH . '\rabbitmq.4.lib');
}
}

View File

@@ -23,8 +23,10 @@ class nghttp2 extends WindowsLibraryBase
'-A x64 ' . '-A x64 ' .
"-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " . "-DCMAKE_TOOLCHAIN_FILE={$this->builder->cmake_toolchain_file} " .
'-DCMAKE_BUILD_TYPE=Release ' . '-DCMAKE_BUILD_TYPE=Release ' .
'-DBUILD_SHARED_LIBS=OFF ' . '-DENABLE_SHARED_LIB=OFF ' .
'-DENABLE_STATIC_LIB=ON ' .
'-DBUILD_STATIC_LIBS=ON ' . '-DBUILD_STATIC_LIBS=ON ' .
'-DBUILD_SHARED_LIBS=OFF ' .
'-DENABLE_STATIC_CRT=ON ' . '-DENABLE_STATIC_CRT=ON ' .
'-DENABLE_LIB_ONLY=ON ' . '-DENABLE_LIB_ONLY=ON ' .
'-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' ' '-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH . ' '

View 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');
}
}

View File

@@ -25,7 +25,7 @@ abstract class BaseCommand extends Command
protected OutputInterface $output; protected OutputInterface $output;
public function __construct(string $name = null) public function __construct(?string $name = null)
{ {
parent::__construct($name); parent::__construct($name);
$this->addOption('debug', null, null, 'Enable debug mode'); $this->addOption('debug', null, null, 'Enable debug mode');

View File

@@ -10,6 +10,7 @@ use SPC\exception\WrongUsageException;
use SPC\store\FileSystem; use SPC\store\FileSystem;
use SPC\store\SourcePatcher; use SPC\store\SourcePatcher;
use SPC\util\DependencyUtil; use SPC\util\DependencyUtil;
use SPC\util\GlobalEnvManager;
use SPC\util\LicenseDumper; use SPC\util\LicenseDumper;
use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
@@ -37,8 +38,8 @@ class BuildCliCommand extends BuildCommand
$this->addOption('with-suggested-exts', 'E', null, 'Build with suggested extensions for selected exts'); $this->addOption('with-suggested-exts', 'E', null, 'Build with suggested extensions for selected exts');
$this->addOption('with-added-patch', 'P', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Inject patch script outside'); $this->addOption('with-added-patch', 'P', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Inject patch script outside');
$this->addOption('without-micro-ext-test', null, null, 'Disable phpmicro with extension test code'); $this->addOption('without-micro-ext-test', null, null, 'Disable phpmicro with extension test code');
$this->addOption('with-upx-pack', null, null, 'Compress / pack binary using UPX tool (linux/windows only)'); $this->addOption('with-upx-pack', null, null, 'Compress / pack binary using UPX tool (linux/windows only)');
$this->addOption('with-micro-logo', null, InputOption::VALUE_REQUIRED, 'Use custom .ico for micro.sfx (windows only)');
} }
public function handle(): int public function handle(): int
@@ -63,6 +64,14 @@ class BuildCliCommand extends BuildCommand
if ($rule === BUILD_TARGET_ALL) { if ($rule === BUILD_TARGET_ALL) {
logger()->warning('--build-all option makes `--no-strip` always true, be aware!'); logger()->warning('--build-all option makes `--no-strip` always true, be aware!');
} }
if (($rule & BUILD_TARGET_MICRO) === BUILD_TARGET_MICRO && $this->getOption('with-micro-logo')) {
$logo = $this->getOption('with-micro-logo');
if (!file_exists($logo)) {
logger()->error('Logo file ' . $logo . ' not exist !');
return static::FAILURE;
}
}
// Check upx // Check upx
$suffix = PHP_OS_FAMILY === 'Windows' ? '.exe' : ''; $suffix = PHP_OS_FAMILY === 'Windows' ? '.exe' : '';
if ($this->getOption('with-upx-pack')) { if ($this->getOption('with-upx-pack')) {
@@ -96,8 +105,8 @@ class BuildCliCommand extends BuildCommand
$indent_texts = [ $indent_texts = [
'Build OS' => PHP_OS_FAMILY . ' (' . php_uname('m') . ')', 'Build OS' => PHP_OS_FAMILY . ' (' . php_uname('m') . ')',
'Build SAPI' => $builder->getBuildTypeName($rule), 'Build SAPI' => $builder->getBuildTypeName($rule),
'Extensions (' . count($extensions) . ')' => implode(', ', $extensions), 'Extensions (' . count($extensions) . ')' => implode(',', $extensions),
'Libraries (' . count($libraries) . ')' => implode(', ', $libraries), 'Libraries (' . count($libraries) . ')' => implode(',', $libraries),
'Strip Binaries' => $builder->getOption('no-strip') ? 'no' : 'yes', 'Strip Binaries' => $builder->getOption('no-strip') ? 'no' : 'yes',
'Enable ZTS' => $builder->getOption('enable-zts') ? 'yes' : 'no', 'Enable ZTS' => $builder->getOption('enable-zts') ? 'yes' : 'no',
]; ];
@@ -109,7 +118,6 @@ class BuildCliCommand extends BuildCommand
} }
if ($this->input->getOption('with-upx-pack') && in_array(PHP_OS_FAMILY, ['Linux', 'Windows'])) { if ($this->input->getOption('with-upx-pack') && in_array(PHP_OS_FAMILY, ['Linux', 'Windows'])) {
$indent_texts['UPX Pack'] = 'enabled'; $indent_texts['UPX Pack'] = 'enabled';
$builder->setOption('upx-exec', FileSystem::convertPath(PKG_ROOT_PATH . '/bin/upx' . $suffix));
} }
try { try {
$ver = $builder->getPHPVersion(); $ver = $builder->getPHPVersion();
@@ -123,6 +131,7 @@ class BuildCliCommand extends BuildCommand
if (!empty($not_included)) { if (!empty($not_included)) {
$indent_texts['Extra Exts (' . count($not_included) . ')'] = implode(', ', $not_included); $indent_texts['Extra Exts (' . count($not_included) . ')'] = implode(', ', $not_included);
} }
$this->printFormatInfo($this->getDefinedEnvs(), true);
$this->printFormatInfo($indent_texts); $this->printFormatInfo($indent_texts);
logger()->notice('Build will start after 2s ...'); logger()->notice('Build will start after 2s ...');
sleep(2); sleep(2);
@@ -218,7 +227,18 @@ class BuildCliCommand extends BuildCommand
return $rule; 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 // calculate space count for every line
$maxlen = 0; $maxlen = 0;
@@ -228,14 +248,14 @@ class BuildCliCommand extends BuildCommand
foreach ($indent_texts as $k => $v) { foreach ($indent_texts as $k => $v) {
if (is_string($v)) { if (is_string($v)) {
/* @phpstan-ignore-next-line */ /* @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)) { } elseif (is_array($v) && !is_assoc_array($v)) {
$first = array_shift($v); $first = array_shift($v);
/* @phpstan-ignore-next-line */ /* @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) { foreach ($v as $vs) {
/* @phpstan-ignore-next-line */ /* @phpstan-ignore-next-line */
logger()->info(str_pad('', $maxlen + 2) . ConsoleColor::yellow($vs)); logger()->{$debug ? 'debug' : 'info'}(str_pad('', $maxlen + 2) . ConsoleColor::yellow($vs));
} }
} }
} }

View File

@@ -8,7 +8,7 @@ use Symfony\Component\Console\Input\InputOption;
abstract class BuildCommand extends BaseCommand abstract class BuildCommand extends BaseCommand
{ {
public function __construct(string $name = null) public function __construct(?string $name = null)
{ {
parent::__construct($name); parent::__construct($name);

View File

@@ -36,26 +36,61 @@ class DownloadCommand extends BaseCommand
$this->addOption('custom-url', 'U', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Specify custom source download url, e.g "php-src:https://downloads.php.net/~eric/php-8.3.0beta1.tar.gz"'); $this->addOption('custom-url', 'U', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Specify custom source download url, e.g "php-src:https://downloads.php.net/~eric/php-8.3.0beta1.tar.gz"');
$this->addOption('from-zip', 'Z', InputOption::VALUE_REQUIRED, 'Fetch from zip archive'); $this->addOption('from-zip', 'Z', InputOption::VALUE_REQUIRED, 'Fetch from zip archive');
$this->addOption('for-extensions', 'e', InputOption::VALUE_REQUIRED, 'Fetch by extensions, e.g "openssl,mbstring"'); $this->addOption('for-extensions', 'e', InputOption::VALUE_REQUIRED, 'Fetch by extensions, e.g "openssl,mbstring"');
$this->addOption('for-libs', 'l', InputOption::VALUE_REQUIRED, 'Fetch by libraries, e.g "libcares,openssl,onig"');
$this->addOption('without-suggestions', null, null, 'Do not fetch suggested sources when using --for-extensions'); $this->addOption('without-suggestions', null, null, 'Do not fetch suggested sources when using --for-extensions');
$this->addOption('ignore-cache-sources', null, InputOption::VALUE_REQUIRED, 'Ignore some source caches, comma separated, e.g "php-src,curl,openssl"', '');
$this->addOption('retry', 'R', InputOption::VALUE_REQUIRED, 'Set retry time when downloading failed (default: 0)', '0');
} }
/**
* @throws FileSystemException
* @throws WrongUsageException
*/
public function initialize(InputInterface $input, OutputInterface $output): void public function initialize(InputInterface $input, OutputInterface $output): void
{ {
if ( // mode: --all
$input->getOption('all') if ($input->getOption('all')) {
|| $input->getOption('clean') $input->setArgument('sources', implode(',', array_keys(Config::getSources())));
|| $input->getOption('from-zip') parent::initialize($input, $output);
|| $input->getOption('for-extensions') return;
) { }
// mode: --clean and --from-zip
if ($input->getOption('clean') || $input->getOption('from-zip')) {
$input->setArgument('sources', ''); $input->setArgument('sources', '');
parent::initialize($input, $output);
return;
}
// mode: normal
if (!empty($input->getArgument('sources'))) {
$final_sources = array_map('trim', array_filter(explode(',', $input->getArgument('sources'))));
} else {
$final_sources = [];
}
// mode: --for-extensions
if ($for_ext = $input->getOption('for-extensions')) {
$ext = array_map('trim', array_filter(explode(',', $for_ext)));
$sources = $this->calculateSourcesByExt($ext, !$input->getOption('without-suggestions'));
if (PHP_OS_FAMILY !== 'Windows') {
array_unshift($sources, 'pkg-config');
}
array_unshift($sources, 'php-src', 'micro');
$final_sources = array_merge($final_sources, array_diff($sources, $final_sources));
}
// mode: --for-libs
if ($for_lib = $input->getOption('for-libs')) {
$lib = array_map('trim', array_filter(explode(',', $for_lib)));
$sources = $this->calculateSourcesByLib($lib, !$input->getOption('without-suggestions'));
$final_sources = array_merge($final_sources, array_diff($sources, $final_sources));
}
if (!empty($final_sources)) {
$input->setArgument('sources', implode(',', $final_sources));
} }
parent::initialize($input, $output); parent::initialize($input, $output);
} }
/** /**
* @throws DownloaderException
* @throws RuntimeException
* @throws FileSystemException * @throws FileSystemException
* @throws RuntimeException
*/ */
public function handle(): int public function handle(): int
{ {
@@ -93,6 +128,10 @@ class DownloadCommand extends BaseCommand
return static::FAILURE; return static::FAILURE;
} }
// retry
$retry = intval($this->getOption('retry'));
f_putenv('SPC_RETRY_TIME=' . $retry);
// Use shallow-clone can reduce git resource download // Use shallow-clone can reduce git resource download
if ($this->getOption('shallow-clone')) { if ($this->getOption('shallow-clone')) {
define('GIT_SHALLOW_CLONE', true); define('GIT_SHALLOW_CLONE', true);
@@ -107,20 +146,12 @@ class DownloadCommand extends BaseCommand
Config::$source['openssl']['regex'] = '/href="(?<file>openssl-(?<version>1.[^"]+)\.tar\.gz)\"/'; Config::$source['openssl']['regex'] = '/href="(?<file>openssl-(?<version>1.[^"]+)\.tar\.gz)\"/';
} }
// --for-extensions $chosen_sources = array_map('trim', array_filter(explode(',', $this->getArgument('sources'))));
if ($for_ext = $this->getOption('for-extensions')) { $force_list = array_map('trim', array_filter(explode(',', $this->getOption('ignore-cache-sources'))));
$ext = array_map('trim', array_filter(explode(',', $for_ext)));
$sources = $this->calculateSourcesByExt($ext, !$this->getOption('without-suggestions')); if ($this->getOption('all')) {
array_unshift($sources, 'php-src', 'micro', 'pkg-config'); logger()->notice('Downloading with --all option will take more times to download, we recommend you to download with --for-extensions option !');
} else {
// get source list that will be downloaded
$sources = array_map('trim', array_filter(explode(',', $this->getArgument('sources'))));
if (empty($sources)) {
logger()->notice('Downloading with --all option will take more times to download, we recommend you to download with --for-extensions option !');
$sources = array_keys(Config::getSources());
}
} }
$chosen_sources = $sources;
// Process -U options // Process -U options
$custom_urls = []; $custom_urls = [];
@@ -151,7 +182,7 @@ class DownloadCommand extends BaseCommand
Downloader::downloadSource($source, $new_config, true); Downloader::downloadSource($source, $new_config, true);
} else { } else {
logger()->info("Fetching source {$source} [{$ni}/{$cnt}]"); logger()->info("Fetching source {$source} [{$ni}/{$cnt}]");
Downloader::downloadSource($source, Config::getSource($source)); Downloader::downloadSource($source, Config::getSource($source), in_array($source, $force_list));
} }
} }
$time = round(microtime(true) - START_TIME, 3); $time = round(microtime(true) - START_TIME, 3);
@@ -166,6 +197,10 @@ class DownloadCommand extends BaseCommand
} }
} }
/**
* @throws RuntimeException
* @throws WrongUsageException
*/
private function downloadFromZip(string $path): int private function downloadFromZip(string $path): int
{ {
if (!file_exists($path)) { if (!file_exists($path)) {
@@ -191,8 +226,10 @@ class DownloadCommand extends BaseCommand
if (PHP_OS_FAMILY !== 'Windows') { if (PHP_OS_FAMILY !== 'Windows') {
$abs_path = realpath($path); $abs_path = realpath($path);
f_passthru('mkdir ' . DOWNLOAD_PATH . ' && cd ' . DOWNLOAD_PATH . ' && unzip ' . escapeshellarg($abs_path)); f_passthru('mkdir ' . DOWNLOAD_PATH . ' && cd ' . DOWNLOAD_PATH . ' && unzip ' . escapeshellarg($abs_path));
} else {
// Windows TODO
throw new WrongUsageException('Windows currently does not support --from-zip !');
} }
// Windows TODO
if (!file_exists(DOWNLOAD_PATH . '/.lock.json')) { if (!file_exists(DOWNLOAD_PATH . '/.lock.json')) {
throw new RuntimeException('.lock.json not exist in "downloads/"'); throw new RuntimeException('.lock.json not exist in "downloads/"');
@@ -208,7 +245,8 @@ class DownloadCommand extends BaseCommand
/** /**
* Calculate the sources by extensions * Calculate the sources by extensions
* *
* @param array $extensions extension list * @param array $extensions extension list
* @param bool $include_suggests include suggested libs and extensions (default: true)
* @throws FileSystemException * @throws FileSystemException
* @throws WrongUsageException * @throws WrongUsageException
*/ */
@@ -226,4 +264,22 @@ class DownloadCommand extends BaseCommand
} }
return array_values(array_unique($sources)); return array_values(array_unique($sources));
} }
/**
* Calculate the sources by libraries
*
* @param array $libs library list
* @param bool $include_suggests include suggested libs (default: true)
* @throws FileSystemException
* @throws WrongUsageException
*/
private function calculateSourcesByLib(array $libs, bool $include_suggests = true): array
{
$libs = DependencyUtil::getLibs($libs, $include_suggests);
$sources = [];
foreach ($libs as $library) {
$sources[] = Config::getLib($library, 'source');
}
return array_values(array_unique($sources));
}
} }

View File

@@ -40,6 +40,15 @@ class LinuxToolCheckList
'xz', 'xz',
]; ];
public const TOOLS_ARCH = [
'base-devel', 'cmake',
];
private const PROVIDED_COMMAND = [
'binutils-gold' => 'ld.gold',
'base-devel' => 'automake',
];
/** @noinspection PhpUnused */ /** @noinspection PhpUnused */
#[AsCheckItem('if necessary tools are installed', limit_os: 'Linux', level: 999)] #[AsCheckItem('if necessary tools are installed', limit_os: 'Linux', level: 999)]
public function checkCliTools(): ?CheckResult public function checkCliTools(): ?CheckResult
@@ -49,12 +58,13 @@ class LinuxToolCheckList
$required = match ($distro['dist']) { $required = match ($distro['dist']) {
'alpine' => self::TOOLS_ALPINE, 'alpine' => self::TOOLS_ALPINE,
'redhat' => self::TOOLS_RHEL, 'redhat' => self::TOOLS_RHEL,
'arch' => self::TOOLS_ARCH,
default => self::TOOLS_DEBIAN, default => self::TOOLS_DEBIAN,
}; };
$missing = []; $missing = [];
foreach ($required as $cmd) { foreach ($required as $package) {
if ($this->findCommand($cmd) === null) { if ($this->findCommand(self::PROVIDED_COMMAND[$package] ?? $package) === null) {
$missing[] = $cmd; $missing[] = $package;
} }
} }
if (!empty($missing)) { if (!empty($missing)) {
@@ -63,6 +73,7 @@ class LinuxToolCheckList
'alpine', 'alpine',
'redhat', 'redhat',
'Deepin', 'Deepin',
'arch',
'debian' => CheckResult::fail(implode(', ', $missing) . ' not installed on your system', 'install-linux-tools', [$distro, $missing]), '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'), default => CheckResult::fail(implode(', ', $missing) . ' not installed on your system'),
}; };
@@ -70,6 +81,22 @@ class LinuxToolCheckList
return CheckResult::ok(); 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 */ /** @noinspection PhpUnused */
#[AsCheckItem('if necessary linux headers are installed', limit_os: 'Linux')] #[AsCheckItem('if necessary linux headers are installed', limit_os: 'Linux')]
public function checkSystemOSPackages(): ?CheckResult public function checkSystemOSPackages(): ?CheckResult
@@ -94,6 +121,7 @@ class LinuxToolCheckList
'ubuntu', 'debian', 'Deepin' => 'apt-get install -y', 'ubuntu', 'debian', 'Deepin' => 'apt-get install -y',
'alpine' => 'apk add', 'alpine' => 'apk add',
'redhat' => 'dnf install -y', '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.'), default => throw new RuntimeException('Current linux distro does not have an auto-install script for musl packages yet.'),
}; };
$prefix = ''; $prefix = '';

View File

@@ -37,10 +37,12 @@ class MacOSToolCheckList
#[AsCheckItem('if homebrew has installed', limit_os: 'Darwin', level: 998)] #[AsCheckItem('if homebrew has installed', limit_os: 'Darwin', level: 998)]
public function checkBrew(): ?CheckResult public function checkBrew(): ?CheckResult
{ {
// 检查 homebrew 是否已经安装 if (($path = $this->findCommand('brew')) === null) {
if ($this->findCommand('brew') === null) {
return CheckResult::fail('Homebrew is not installed', 'brew'); 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(); return CheckResult::ok();
} }

View File

@@ -20,7 +20,7 @@ class OSCheckList
return CheckResult::fail('Current OS is not supported: ' . PHP_OS_FAMILY); return CheckResult::fail('Current OS is not supported: ' . PHP_OS_FAMILY);
} }
$distro = PHP_OS_FAMILY === 'Linux' ? (' ' . SystemUtil::getOSRelease()['dist']) : ''; $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)')); return CheckResult::ok(PHP_OS_FAMILY . ' ' . php_uname('m') . $distro . ', supported' . ($known_distro ? '' : ' (but not tested on this distro)'));
} }
} }

View File

@@ -7,6 +7,7 @@ namespace SPC\store;
use SPC\exception\DownloaderException; use SPC\exception\DownloaderException;
use SPC\exception\FileSystemException; use SPC\exception\FileSystemException;
use SPC\exception\RuntimeException; use SPC\exception\RuntimeException;
use SPC\exception\WrongUsageException;
use SPC\store\source\CustomSourceBase; use SPC\store\source\CustomSourceBase;
/** /**
@@ -26,7 +27,8 @@ class Downloader
{ {
logger()->debug("finding {$name} source from bitbucket tag"); logger()->debug("finding {$name} source from bitbucket tag");
$data = json_decode(self::curlExec( $data = json_decode(self::curlExec(
url: "https://api.bitbucket.org/2.0/repositories/{$source['repo']}/refs/tags" url: "https://api.bitbucket.org/2.0/repositories/{$source['repo']}/refs/tags",
retry: intval(getenv('SPC_RETRY_TIME') ? getenv('SPC_RETRY_TIME') : 0)
), true); ), true);
$ver = $data['values'][0]['name']; $ver = $data['values'][0]['name'];
if (!$ver) { if (!$ver) {
@@ -35,7 +37,8 @@ class Downloader
$url = "https://bitbucket.org/{$source['repo']}/get/{$ver}.tar.gz"; $url = "https://bitbucket.org/{$source['repo']}/get/{$ver}.tar.gz";
$headers = self::curlExec( $headers = self::curlExec(
url: $url, url: $url,
method: 'HEAD' method: 'HEAD',
retry: intval(getenv('SPC_RETRY_TIME') ? getenv('SPC_RETRY_TIME') : 0)
); );
preg_match('/^content-disposition:\s+attachment;\s*filename=("?)(?<filename>.+\.tar\.gz)\1/im', $headers, $matches); preg_match('/^content-disposition:\s+attachment;\s*filename=("?)(?<filename>.+\.tar\.gz)\1/im', $headers, $matches);
if ($matches) { if ($matches) {
@@ -62,7 +65,8 @@ class Downloader
logger()->debug("finding {$name} source from github {$type} tarball"); logger()->debug("finding {$name} source from github {$type} tarball");
$data = json_decode(self::curlExec( $data = json_decode(self::curlExec(
url: "https://api.github.com/repos/{$source['repo']}/{$type}", url: "https://api.github.com/repos/{$source['repo']}/{$type}",
hooks: [[CurlHook::class, 'setupGithubToken']] hooks: [[CurlHook::class, 'setupGithubToken']],
retry: intval(getenv('SPC_RETRY_TIME') ? getenv('SPC_RETRY_TIME') : 0)
), true); ), true);
$url = $data[0]['tarball_url']; $url = $data[0]['tarball_url'];
if (!$url) { if (!$url) {
@@ -72,6 +76,7 @@ class Downloader
url: $url, url: $url,
method: 'HEAD', method: 'HEAD',
hooks: [[CurlHook::class, 'setupGithubToken']], hooks: [[CurlHook::class, 'setupGithubToken']],
retry: intval(getenv('SPC_RETRY_TIME') ? getenv('SPC_RETRY_TIME') : 0)
); );
preg_match('/^content-disposition:\s+attachment;\s*filename=("?)(?<filename>.+\.tar\.gz)\1/im', $headers, $matches); preg_match('/^content-disposition:\s+attachment;\s*filename=("?)(?<filename>.+\.tar\.gz)\1/im', $headers, $matches);
if ($matches) { if ($matches) {
@@ -97,6 +102,7 @@ class Downloader
$data = json_decode(self::curlExec( $data = json_decode(self::curlExec(
url: "https://api.github.com/repos/{$source['repo']}/releases", url: "https://api.github.com/repos/{$source['repo']}/releases",
hooks: [[CurlHook::class, 'setupGithubToken']], hooks: [[CurlHook::class, 'setupGithubToken']],
retry: intval(getenv('SPC_RETRY_TIME') ? getenv('SPC_RETRY_TIME') : 0)
), true); ), true);
$url = null; $url = null;
foreach ($data as $release) { foreach ($data as $release) {
@@ -130,7 +136,7 @@ class Downloader
public static function getFromFileList(string $name, array $source): array public static function getFromFileList(string $name, array $source): array
{ {
logger()->debug("finding {$name} source from file list"); logger()->debug("finding {$name} source from file list");
$page = self::curlExec($source['url']); $page = self::curlExec($source['url'], retry: intval(getenv('SPC_RETRY_TIME') ? getenv('SPC_RETRY_TIME') : 0));
preg_match_all($source['regex'], $page, $matches); preg_match_all($source['regex'], $page, $matches);
if (!$matches) { if (!$matches) {
throw new DownloaderException("Failed to get {$name} version"); throw new DownloaderException("Failed to get {$name} version");
@@ -175,7 +181,7 @@ class Downloader
} }
}; };
self::registerCancelEvent($cancel_func); self::registerCancelEvent($cancel_func);
self::curlDown(url: $url, path: FileSystem::convertPath(DOWNLOAD_PATH . "/{$filename}")); self::curlDown(url: $url, path: FileSystem::convertPath(DOWNLOAD_PATH . "/{$filename}"), retry: intval(getenv('SPC_RETRY_TIME') ? getenv('SPC_RETRY_TIME') : 0));
self::unregisterCancelEvent(); self::unregisterCancelEvent();
logger()->debug("Locking {$filename}"); logger()->debug("Locking {$filename}");
self::lockSource($name, ['source_type' => 'archive', 'filename' => $filename, 'move_path' => $move_path]); self::lockSource($name, ['source_type' => 'archive', 'filename' => $filename, 'move_path' => $move_path]);
@@ -203,7 +209,7 @@ class Downloader
* @throws FileSystemException * @throws FileSystemException
* @throws RuntimeException * @throws RuntimeException
*/ */
public static function downloadGit(string $name, string $url, string $branch, ?string $move_path = null): void public static function downloadGit(string $name, string $url, string $branch, ?string $move_path = null, int $retry = 0): void
{ {
$download_path = FileSystem::convertPath(DOWNLOAD_PATH . "/{$name}"); $download_path = FileSystem::convertPath(DOWNLOAD_PATH . "/{$name}");
if (file_exists($download_path)) { if (file_exists($download_path)) {
@@ -217,14 +223,25 @@ class Downloader
FileSystem::removeDir($download_path); FileSystem::removeDir($download_path);
} }
}; };
self::registerCancelEvent($cancel_func); try {
f_passthru( self::registerCancelEvent($cancel_func);
SPC_GIT_EXEC . ' clone' . $check . f_passthru(
' --config core.autocrlf=false ' . SPC_GIT_EXEC . ' clone' . $check .
"--branch \"{$branch}\" " . (defined('GIT_SHALLOW_CLONE') ? '--depth 1 --single-branch' : '') . " --recursive \"{$url}\" \"{$download_path}\"" ' --config core.autocrlf=false ' .
); "--branch \"{$branch}\" " . (defined('GIT_SHALLOW_CLONE') ? '--depth 1 --single-branch' : '') . " --recursive \"{$url}\" \"{$download_path}\""
self::unregisterCancelEvent(); );
} catch (RuntimeException $e) {
if ($e->getCode() === 2 || $e->getCode() === -1073741510) {
throw new WrongUsageException('Keyboard interrupted, download failed !');
}
if ($retry > 0) {
self::downloadGit($name, $url, $branch, $move_path, $retry - 1);
return;
}
throw $e;
} finally {
self::unregisterCancelEvent();
}
// Lock // Lock
logger()->debug("Locking git source {$name}"); logger()->debug("Locking git source {$name}");
self::lockSource($name, ['source_type' => 'dir', 'dirname' => $name, 'move_path' => $move_path]); self::lockSource($name, ['source_type' => 'dir', 'dirname' => $name, 'move_path' => $move_path]);
@@ -246,6 +263,10 @@ class Downloader
}*/ }*/
} }
/**
* @throws DownloaderException
* @throws FileSystemException
*/
public static function downloadPackage(string $name, ?array $pkg = null, bool $force = false): void public static function downloadPackage(string $name, ?array $pkg = null, bool $force = false): void
{ {
if ($pkg === null) { if ($pkg === null) {
@@ -307,13 +328,19 @@ class Downloader
self::downloadFile($name, $url, $filename, $pkg['extract'] ?? null); self::downloadFile($name, $url, $filename, $pkg['extract'] ?? null);
break; break;
case 'git': // Git repo case 'git': // Git repo
self::downloadGit($name, $pkg['url'], $pkg['rev'], $pkg['extract'] ?? null); self::downloadGit(
$name,
$pkg['url'],
$pkg['rev'],
$pkg['extract'] ?? null,
intval(getenv('SPC_RETRY_TIME') ? getenv('SPC_RETRY_TIME') : 0)
);
break; break;
case 'custom': // Custom download method, like API-based download or other case 'custom': // Custom download method, like API-based download or other
$classes = FileSystem::getClassesPsr4(ROOT_DIR . '/src/SPC/store/source', 'SPC\\store\\source'); $classes = FileSystem::getClassesPsr4(ROOT_DIR . '/src/SPC/store/source', 'SPC\\store\\source');
foreach ($classes as $class) { foreach ($classes as $class) {
if (is_a($class, CustomSourceBase::class, true) && $class::NAME === $name) { if (is_a($class, CustomSourceBase::class, true) && $class::NAME === $name) {
(new $class())->fetch(); (new $class())->fetch($force);
break; break;
} }
} }
@@ -401,13 +428,19 @@ class Downloader
self::downloadFile($name, $url, $filename, $source['path'] ?? null); self::downloadFile($name, $url, $filename, $source['path'] ?? null);
break; break;
case 'git': // Git repo case 'git': // Git repo
self::downloadGit($name, $source['url'], $source['rev'], $source['path'] ?? null); self::downloadGit(
$name,
$source['url'],
$source['rev'],
$source['path'] ?? null,
intval(getenv('SPC_RETRY_TIME') ? getenv('SPC_RETRY_TIME') : 0)
);
break; break;
case 'custom': // Custom download method, like API-based download or other case 'custom': // Custom download method, like API-based download or other
$classes = FileSystem::getClassesPsr4(ROOT_DIR . '/src/SPC/store/source', 'SPC\\store\\source'); $classes = FileSystem::getClassesPsr4(ROOT_DIR . '/src/SPC/store/source', 'SPC\\store\\source');
foreach ($classes as $class) { foreach ($classes as $class) {
if (is_a($class, CustomSourceBase::class, true) && $class::NAME === $name) { if (is_a($class, CustomSourceBase::class, true) && $class::NAME === $name) {
(new $class())->fetch(); (new $class())->fetch($force);
break; break;
} }
} }
@@ -431,57 +464,71 @@ class Downloader
* *
* @throws DownloaderException * @throws DownloaderException
*/ */
public static function curlExec(string $url, string $method = 'GET', array $headers = [], array $hooks = []): string public static function curlExec(string $url, string $method = 'GET', array $headers = [], array $hooks = [], int $retry = 0): string
{ {
foreach ($hooks as $hook) { foreach ($hooks as $hook) {
$hook($method, $url, $headers); $hook($method, $url, $headers);
} }
FileSystem::findCommandPath('curl'); try {
FileSystem::findCommandPath('curl');
$methodArg = match ($method) { $methodArg = match ($method) {
'GET' => '', 'GET' => '',
'HEAD' => '-I', 'HEAD' => '-I',
default => "-X \"{$method}\"", default => "-X \"{$method}\"",
}; };
$headerArg = implode(' ', array_map(fn ($v) => '"-H' . $v . '"', $headers)); $headerArg = implode(' ', array_map(fn ($v) => '"-H' . $v . '"', $headers));
$cmd = SPC_CURL_EXEC . " -sfSL {$methodArg} {$headerArg} \"{$url}\""; $cmd = SPC_CURL_EXEC . " -sfSL {$methodArg} {$headerArg} \"{$url}\"";
if (getenv('CACHE_API_EXEC') === 'yes') { if (getenv('CACHE_API_EXEC') === 'yes') {
if (!file_exists(FileSystem::convertPath(DOWNLOAD_PATH . '/.curl_exec_cache'))) { if (!file_exists(FileSystem::convertPath(DOWNLOAD_PATH . '/.curl_exec_cache'))) {
$cache = []; $cache = [];
} else { } else {
$cache = json_decode(file_get_contents(FileSystem::convertPath(DOWNLOAD_PATH . '/.curl_exec_cache')), true); $cache = json_decode(file_get_contents(FileSystem::convertPath(DOWNLOAD_PATH . '/.curl_exec_cache')), true);
} }
if (isset($cache[$cmd]) && $cache[$cmd]['expire'] >= time()) { if (isset($cache[$cmd]) && $cache[$cmd]['expire'] >= time()) {
return $cache[$cmd]['cache'];
}
f_exec($cmd, $output, $ret);
if ($ret === 2 || $ret === -1073741510) {
throw new RuntimeException('failed http fetch');
}
if ($ret !== 0) {
throw new DownloaderException('failed http fetch');
}
$cache[$cmd]['cache'] = implode("\n", $output);
$cache[$cmd]['expire'] = time() + 3600;
file_put_contents(FileSystem::convertPath(DOWNLOAD_PATH . '/.curl_exec_cache'), json_encode($cache));
return $cache[$cmd]['cache']; return $cache[$cmd]['cache'];
} }
f_exec($cmd, $output, $ret); f_exec($cmd, $output, $ret);
if ($ret === 2 || $ret === -1073741510) {
throw new RuntimeException('failed http fetch');
}
if ($ret !== 0) { if ($ret !== 0) {
throw new DownloaderException('failed http fetch'); throw new DownloaderException('failed http fetch');
} }
$cache[$cmd]['cache'] = implode("\n", $output); return implode("\n", $output);
$cache[$cmd]['expire'] = time() + 3600; } catch (DownloaderException $e) {
file_put_contents(FileSystem::convertPath(DOWNLOAD_PATH . '/.curl_exec_cache'), json_encode($cache)); if ($retry > 0) {
return $cache[$cmd]['cache']; logger()->notice('Retrying curl exec ...');
return self::curlExec($url, $method, $headers, $hooks, $retry - 1);
}
throw $e;
} }
f_exec($cmd, $output, $ret);
if ($ret !== 0) {
throw new DownloaderException('failed http fetch');
}
return implode("\n", $output);
} }
/** /**
* Use curl to download sources from url * Use curl to download sources from url
* *
* @throws DownloaderException
* @throws RuntimeException * @throws RuntimeException
*/ */
public static function curlDown(string $url, string $path, string $method = 'GET', array $headers = [], array $hooks = []): void public static function curlDown(string $url, string $path, string $method = 'GET', array $headers = [], array $hooks = [], int $retry = 0): void
{ {
$used_headers = $headers;
foreach ($hooks as $hook) { foreach ($hooks as $hook) {
$hook($method, $url, $headers); $hook($method, $url, $used_headers);
} }
$methodArg = match ($method) { $methodArg = match ($method) {
@@ -489,10 +536,23 @@ class Downloader
'HEAD' => '-I', 'HEAD' => '-I',
default => "-X \"{$method}\"", default => "-X \"{$method}\"",
}; };
$headerArg = implode(' ', array_map(fn ($v) => '"-H' . $v . '"', $headers)); $headerArg = implode(' ', array_map(fn ($v) => '"-H' . $v . '"', $used_headers));
$check = !defined('DEBUG_MODE') ? 's' : '#'; $check = !defined('DEBUG_MODE') ? 's' : '#';
$cmd = SPC_CURL_EXEC . " -{$check}fSL -o \"{$path}\" {$methodArg} {$headerArg} \"{$url}\""; $cmd = SPC_CURL_EXEC . " -{$check}fSL -o \"{$path}\" {$methodArg} {$headerArg} \"{$url}\"";
f_passthru($cmd); try {
f_passthru($cmd);
} catch (RuntimeException $e) {
var_dump($e->getCode());
if ($e->getCode() === 2 || $e->getCode() === -1073741510) {
throw new WrongUsageException('Keyboard interrupted, download failed !');
}
if ($retry > 0) {
logger()->notice('Retrying curl download ...');
self::curlDown($url, $path, $method, $used_headers, retry: intval(getenv('SPC_RETRY_TIME') ? getenv('SPC_RETRY_TIME') : 0));
return;
}
throw $e;
}
} }
/** /**
@@ -505,7 +565,7 @@ class Downloader
if (PHP_OS_FAMILY === 'Windows') { if (PHP_OS_FAMILY === 'Windows') {
sapi_windows_set_ctrl_handler($callback); sapi_windows_set_ctrl_handler($callback);
} elseif (extension_loaded('pcntl')) { } elseif (extension_loaded('pcntl')) {
pcntl_signal(SIGINT, $callback); pcntl_signal(2, $callback);
} else { } else {
logger()->debug('You have not enabled `pcntl` extension, cannot prevent download file corruption when Ctrl+C'); logger()->debug('You have not enabled `pcntl` extension, cannot prevent download file corruption when Ctrl+C');
} }
@@ -519,7 +579,7 @@ class Downloader
if (PHP_OS_FAMILY === 'Windows') { if (PHP_OS_FAMILY === 'Windows') {
sapi_windows_set_ctrl_handler(null); sapi_windows_set_ctrl_handler(null);
} elseif (extension_loaded('pcntl')) { } elseif (extension_loaded('pcntl')) {
pcntl_signal(SIGINT, SIG_IGN); pcntl_signal(2, SIG_IGN);
} }
} }
} }

View File

@@ -24,6 +24,7 @@ class PackageManager
default => throw new WrongUsageException('Unsupported OS!'), default => throw new WrongUsageException('Unsupported OS!'),
}; };
$config = Config::getPkg("{$pkg_name}-{$arch}-{$os}"); $config = Config::getPkg("{$pkg_name}-{$arch}-{$os}");
$pkg_name = "{$pkg_name}-{$arch}-{$os}";
} }
if ($config === null) { if ($config === null) {
throw new WrongUsageException("Package [{$pkg_name}] does not exist, please check the name and correct it !"); throw new WrongUsageException("Package [{$pkg_name}] does not exist, please check the name and correct it !");

View File

@@ -8,5 +8,5 @@ abstract class CustomSourceBase
{ {
public const NAME = 'unknown'; public const NAME = 'unknown';
abstract public function fetch(); abstract public function fetch(bool $force = false);
} }

View File

@@ -7,7 +7,6 @@ namespace SPC\store\source;
use JetBrains\PhpStorm\ArrayShape; use JetBrains\PhpStorm\ArrayShape;
use SPC\exception\DownloaderException; use SPC\exception\DownloaderException;
use SPC\exception\FileSystemException; use SPC\exception\FileSystemException;
use SPC\exception\RuntimeException;
use SPC\store\Downloader; use SPC\store\Downloader;
class PhpSource extends CustomSourceBase class PhpSource extends CustomSourceBase
@@ -16,13 +15,12 @@ class PhpSource extends CustomSourceBase
/** /**
* @throws DownloaderException * @throws DownloaderException
* @throws RuntimeException
* @throws FileSystemException * @throws FileSystemException
*/ */
public function fetch(): void public function fetch(bool $force = false): void
{ {
$major = defined('SPC_BUILD_PHP_VERSION') ? SPC_BUILD_PHP_VERSION : '8.1'; $major = defined('SPC_BUILD_PHP_VERSION') ? SPC_BUILD_PHP_VERSION : '8.1';
Downloader::downloadSource('php-src', self::getLatestPHPInfo($major)); Downloader::downloadSource('php-src', self::getLatestPHPInfo($major), $force);
} }
/** /**
@@ -34,7 +32,10 @@ class PhpSource extends CustomSourceBase
public function getLatestPHPInfo(string $major_version): array public function getLatestPHPInfo(string $major_version): array
{ {
// 查找最新的小版本号 // 查找最新的小版本号
$info = json_decode(Downloader::curlExec(url: "https://www.php.net/releases/index.php?json&version={$major_version}"), true); $info = json_decode(Downloader::curlExec(
url: "https://www.php.net/releases/index.php?json&version={$major_version}",
retry: intval(getenv('SPC_RETRY_TIME') ? getenv('SPC_RETRY_TIME') : 0)
), true);
if (!isset($info['version'])) { if (!isset($info['version'])) {
throw new DownloaderException("Version {$major_version} not found."); throw new DownloaderException("Version {$major_version} not found.");
} }

View File

@@ -6,7 +6,6 @@ namespace SPC\store\source;
use SPC\exception\DownloaderException; use SPC\exception\DownloaderException;
use SPC\exception\FileSystemException; use SPC\exception\FileSystemException;
use SPC\exception\RuntimeException;
use SPC\store\Downloader; use SPC\store\Downloader;
class PostgreSQLSource extends CustomSourceBase class PostgreSQLSource extends CustomSourceBase
@@ -15,12 +14,11 @@ class PostgreSQLSource extends CustomSourceBase
/** /**
* @throws DownloaderException * @throws DownloaderException
* @throws RuntimeException
* @throws FileSystemException * @throws FileSystemException
*/ */
public function fetch(): void public function fetch(bool $force = false): void
{ {
Downloader::downloadSource('postgresql', self::getLatestInfo()); Downloader::downloadSource('postgresql', self::getLatestInfo(), $force);
} }
/** /**

View File

@@ -62,12 +62,17 @@ class DependencyUtil
if ($include_suggested_libs) { if ($include_suggested_libs) {
foreach ($dep_list as $name => $obj) { foreach ($dep_list as $name => $obj) {
$del_list = [];
foreach ($obj['suggests'] as $id => $suggest) { foreach ($obj['suggests'] as $id => $suggest) {
if (!str_starts_with($suggest, 'ext@')) { if (!str_starts_with($suggest, 'ext@')) {
$dep_list[$name]['depends'][] = $suggest; $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) { if ($include_suggested_exts) {
// check every deps suggests contains ext@ // check every deps suggests contains ext@
foreach ($dep_list as $name => $obj) { foreach ($dep_list as $name => $obj) {
$del_list = [];
foreach ($obj['suggests'] as $id => $suggest) { foreach ($obj['suggests'] as $id => $suggest) {
if (str_starts_with($suggest, 'ext@')) { if (str_starts_with($suggest, 'ext@')) {
$dep_list[$name]['depends'][] = $suggest; $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) { if ($include_suggested_libs) {
// check every deps suggests // check every deps suggests
foreach ($dep_list as $name => $obj) { foreach ($dep_list as $name => $obj) {
$del_list = [];
foreach ($obj['suggests'] as $id => $suggest) { foreach ($obj['suggests'] as $id => $suggest) {
if (!str_starts_with($suggest, 'ext@')) { if (!str_starts_with($suggest, 'ext@')) {
$dep_list[$name]['depends'][] = $suggest; $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']);
} }
} }

View 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($builder),
'Darwin' => self::initDarwinEnv($builder),
'Linux' => self::initLinuxEnv($builder),
'BSD' => 'TODO',
default => logger()->warning('Unknown OS: ' . PHP_OS_FAMILY),
};
}
private static function initWindowsEnv(BuilderBase $builder): 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 (\SPC\builder\linux\SystemUtil::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;
}
}

View File

@@ -62,7 +62,12 @@ class UnixShell
public function setEnv(array $env): 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; return $this;
} }

View 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 $$?;

View File

@@ -13,7 +13,7 @@ declare(strict_types=1);
// If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`). // If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`).
$extensions = match (PHP_OS_FAMILY) { $extensions = match (PHP_OS_FAMILY) {
'Linux', 'Darwin' => 'pgsql,pdo_pgsql', 'Linux', 'Darwin' => 'readline,pgsql,xml,dom,mbstring,mbregex,pdo_pgsql',
'Windows' => 'mbstring,pdo_sqlite,mbregex', 'Windows' => 'mbstring,pdo_sqlite,mbregex',
}; };
@@ -27,7 +27,7 @@ $with_libs = match (PHP_OS_FAMILY) {
// You can use `common`, `bulk`, `minimal` or `none`. // You can use `common`, `bulk`, `minimal` or `none`.
// note: combination is only available for *nix platform. Windows must use `none` combination // note: combination is only available for *nix platform. Windows must use `none` combination
$base_combination = match (PHP_OS_FAMILY) { $base_combination = match (PHP_OS_FAMILY) {
'Linux', 'Darwin' => 'common', 'Linux', 'Darwin' => 'none',
'Windows' => 'none', 'Windows' => 'none',
}; };
@@ -69,7 +69,7 @@ if (PHP_OS_FAMILY === 'Windows') {
echo match ($argv[1]) { echo match ($argv[1]) {
'extensions' => $final_extensions, 'extensions' => $final_extensions,
'libs' => $final_libs, 'libs' => $final_libs,
'libs_cmd' => ($final_libs === '' ? '' : (' --with-libs="' . $final_libs . '"')), 'libs_cmd' => ($final_libs === '' ? '' : (' --with-libs=' . $final_libs)),
'cmd' => $final_extensions_cmd . ($final_libs === '' ? '' : (' --with-libs="' . $final_libs . '"')), 'cmd' => $final_extensions_cmd . ($final_libs === '' ? '' : (' --with-libs=' . $final_libs)),
default => '', default => '',
}; };

View File

@@ -0,0 +1,6 @@
<?php
declare(strict_types=1);
assert(function_exists('uuid_create'));
assert(strlen(uuid_create(0)) === 36);