From dc19d0c61d7cfa2aae001ae7e85a355dc7464cee Mon Sep 17 00:00:00 2001 From: Jerry Ma Date: Wed, 31 Jan 2024 11:26:40 +0800 Subject: [PATCH 1/7] Create build-macos-aarch64.yml --- .github/workflows/build-macos-aarch64.yml | 117 ++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 .github/workflows/build-macos-aarch64.yml diff --git a/.github/workflows/build-macos-aarch64.yml b/.github/workflows/build-macos-aarch64.yml new file mode 100644 index 00000000..73a700e8 --- /dev/null +++ b/.github/workflows/build-macos-aarch64.yml @@ -0,0 +1,117 @@ +name: CI on arm64 macOS + +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 + build-fpm: + description: build fpm 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 macOS arm64 + runs-on: macos-14 + steps: + - uses: actions/checkout@v3 + + # Install macOS missing packages and mark os suffix + - run: | + brew install automake gzip + echo "SPC_BUILD_OS=macos" >> $GITHUB_ENV + + # Cache composer dependencies + - id: cache-composer-deps + uses: actions/cache@v3 + 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 + + # Cache downloaded source + - id: cache-download + uses: actions/cache@v3 + with: + path: downloads + key: php-${{ inputs.version }}-dependencies-${{ inputs.extensions }} + + # With or without debug + - if: inputs.debug == true + run: echo "SPC_BUILD_DEBUG=--debug" >> $GITHUB_ENV + + # With target select: cli, micro or both + - if: ${{ inputs.build-cli == true }} + run: echo "SPC_BUILD_CLI=--build-cli" >> $GITHUB_ENV + - if: ${{ inputs.build-micro == true }} + run: echo "SPC_BUILD_MICRO=--build-micro" >> $GITHUB_ENV + - if: ${{ inputs.build-fpm == true }} + run: echo "SPC_BUILD_FPM=--build-fpm" >> $GITHUB_ENV + + # 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@v3 + with: + name: php-${{ inputs.version }}-${{ env.SPC_BUILD_OS }} + path: buildroot/bin/php + + # Upload micro self-extracted executable + - if: ${{ inputs.build-micro == true }} + uses: actions/upload-artifact@v3 + with: + name: micro-${{ inputs.version }}-${{ env.SPC_BUILD_OS }} + path: buildroot/bin/micro.sfx + + # Upload fpm executable + - if: ${{ inputs.build-fpm == true }} + uses: actions/upload-artifact@v3 + with: + name: php-fpm-${{ inputs.version }}-${{ env.SPC_BUILD_OS }} + path: buildroot/bin/php-fpm + + # Upload extensions metadata + - uses: actions/upload-artifact@v3 + with: + name: license-files + path: buildroot/license/ + - uses: actions/upload-artifact@v3 + with: + name: build-meta + path: | + buildroot/build-extensions.json + buildroot/build-libraries.json From 2064172bed9fc98ee549cb922e2f9972eaffa0ce Mon Sep 17 00:00:00 2001 From: Jerry Ma Date: Wed, 31 Jan 2024 11:58:56 +0800 Subject: [PATCH 2/7] Update build-macos-aarch64.yml --- .github/workflows/build-macos-aarch64.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/build-macos-aarch64.yml b/.github/workflows/build-macos-aarch64.yml index 73a700e8..f43b1ab5 100644 --- a/.github/workflows/build-macos-aarch64.yml +++ b/.github/workflows/build-macos-aarch64.yml @@ -46,6 +46,16 @@ jobs: brew install automake gzip echo "SPC_BUILD_OS=macos" >> $GITHUB_ENV + + - name: "Setup PHP" + uses: shivammathur/setup-php@v2 + with: + php-version: 8.1 + tools: pecl, composer + extensions: curl, openssl, mbstring, tokenizer + ini-values: memory_limit=-1 + + # Cache composer dependencies - id: cache-composer-deps uses: actions/cache@v3 From 2549597871a7ad84a25c5bdfd571c22f76478b13 Mon Sep 17 00:00:00 2001 From: Jerry Ma Date: Fri, 2 Feb 2024 09:44:37 +0800 Subject: [PATCH 3/7] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f1b3356b..6b87108d 100755 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ Here is the supported OS and arch, where :octocat: represents support for GitHub | | x86_64 | aarch64 | |---------|----------------------|----------------------| -| macOS | :octocat: :computer: | :computer: | +| macOS | :octocat: :computer: | :octocat: :computer: | | Linux | :octocat: :computer: | :octocat: :computer: | | Windows | :computer: | | | FreeBSD | :computer: | :computer: | From 2591b48abeb811900763f2b77f77af333a04d955 Mon Sep 17 00:00:00 2001 From: Jerry Ma Date: Fri, 2 Feb 2024 09:45:55 +0800 Subject: [PATCH 4/7] Update README-zh.md --- README-zh.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README-zh.md b/README-zh.md index ace31198..a7a8e26d 100755 --- a/README-zh.md +++ b/README-zh.md @@ -63,7 +63,7 @@ static-php-cli(简称 `spc`)有许多特性: | | x86_64 | aarch64 | |---------|----------------------|----------------------| -| macOS | :octocat: :computer: | :computer: | +| macOS | :octocat: :computer: | :octocat: :computer: | | Linux | :octocat: :computer: | :octocat: :computer: | | Windows | | | | FreeBSD | :computer: | :computer: | From 839931d65fe0b06b907031ee58b02975a900f75b Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sun, 4 Feb 2024 10:56:29 +0800 Subject: [PATCH 5/7] add static-php-cli.version ini for php-src --- src/SPC/ConsoleApplication.php | 2 +- src/SPC/command/BuildCliCommand.php | 3 +++ src/SPC/store/SourcePatcher.php | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/SPC/ConsoleApplication.php b/src/SPC/ConsoleApplication.php index 19cf3083..4d2db5fe 100644 --- a/src/SPC/ConsoleApplication.php +++ b/src/SPC/ConsoleApplication.php @@ -23,7 +23,7 @@ use Symfony\Component\Console\Command\ListCommand; */ final class ConsoleApplication extends Application { - public const VERSION = '2.1.0-beta.1'; + public const VERSION = '2.1.0-beta.2'; public function __construct() { diff --git a/src/SPC/command/BuildCliCommand.php b/src/SPC/command/BuildCliCommand.php index e79bc46b..9e90cc4c 100644 --- a/src/SPC/command/BuildCliCommand.php +++ b/src/SPC/command/BuildCliCommand.php @@ -104,6 +104,9 @@ class BuildCliCommand extends BuildCommand SourcePatcher::patchHardcodedINI($custom_ini); } + // add static-php-cli.version to main.c, in order to debug php failure more easily + SourcePatcher::patchSPCVersionToPHP($this->getApplication()->getVersion()); + // start to build $builder->buildPHP($rule); diff --git a/src/SPC/store/SourcePatcher.php b/src/SPC/store/SourcePatcher.php index 920d0564..a7a9bbca 100644 --- a/src/SPC/store/SourcePatcher.php +++ b/src/SPC/store/SourcePatcher.php @@ -296,4 +296,20 @@ class SourcePatcher $lines[$line_num + 1] = "\t" . '"$(LINK)" /nologo $(PHP_GLOBAL_OBJS_RESP) $(CLI_GLOBAL_OBJS_RESP) $(STATIC_EXT_OBJS_RESP) $(STATIC_EXT_LIBS) $(ASM_OBJS) $(LIBS) $(LIBS_CLI) $(BUILD_DIR)\php.exe.res /out:$(BUILD_DIR)\php.exe $(LDFLAGS) $(LDFLAGS_CLI) /ltcg /nodefaultlib:msvcrt /nodefaultlib:msvcrtd /ignore:4286'; FileSystem::writeFile(SOURCE_PATH . '/php-src/Makefile', implode("\r\n", $lines)); } + + /** + * Add additional `static-php-cli.version` ini value for PHP source. + * + * @throws FileSystemException + */ + public static function patchSPCVersionToPHP(string $version = 'unknown'): void + { + // detect patch + $file = FileSystem::readFile(SOURCE_PATH . '/php-src/main/main.c'); + if (!str_contains($file, 'static-php-cli.version')) { + logger()->debug('Inserting static-php-cli.version to php-src'); + $file = str_replace('PHP_INI_BEGIN()', "PHP_INI_BEGIN()\n\tPHP_INI_ENTRY(\"static-php-cli.version\",\t\"{$version}\",\tPHP_INI_ALL,\tNULL)", $file); + FileSystem::writeFile(SOURCE_PATH . '/php-src/main/main.c', $file); + } + } } From 2440a65d8e68532cb286ffb19a5d72674ffedb8e Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sun, 4 Feb 2024 11:12:30 +0800 Subject: [PATCH 6/7] fix windows test --- .github/workflows/tests.yml | 2 +- src/globals/test-extensions.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index fe25afa0..747db27a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -154,4 +154,4 @@ jobs: run: bin/spc download --for-extensions="$(php src/globals/test-extensions.php extensions)" --with-php=${{ matrix.php }} --debug - name: "Run Build Tests (build)" - run: bin/spc build $(php src/globals/test-extensions.php cmd) --build-cli --build-micro --build-fpm --debug + run: bin/spc build "$(php src/globals/test-extensions.php extensions)" $(php src/globals/test-extensions.php libs_cmd) --build-cli --build-micro --build-fpm --debug diff --git a/src/globals/test-extensions.php b/src/globals/test-extensions.php index b65431b9..13d8bba7 100644 --- a/src/globals/test-extensions.php +++ b/src/globals/test-extensions.php @@ -69,6 +69,7 @@ if (PHP_OS_FAMILY === 'Windows') { echo match ($argv[1]) { 'extensions' => $final_extensions, 'libs' => $final_libs, + 'libs_cmd' => ($final_libs === '' ? '' : (' --with-libs="' . $final_libs . '"')), 'cmd' => $final_extensions_cmd . ($final_libs === '' ? '' : (' --with-libs="' . $final_libs . '"')), default => '', }; From 9ee7d7769a16dcff225521e3d01e81f0a0742e76 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sun, 4 Feb 2024 11:22:11 +0800 Subject: [PATCH 7/7] add arm macos test --- .github/workflows/tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 747db27a..b04a1324 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -115,6 +115,7 @@ jobs: - ubuntu-latest - macos-latest - windows-latest + - macos-14 fail-fast: false steps: - name: "Checkout"