Browse Source

ci: add Apple Silicon build script (#313)

Kévin Dunglas 1 year ago
parent
commit
2e72b50d10
3 changed files with 60 additions and 81 deletions
  1. 0 80
      .circleci/config.yml
  2. 2 1
      .gitignore
  3. 58 0
      build-mac-arm.sh

+ 0 - 80
.circleci/config.yml

@@ -1,80 +0,0 @@
-version: 2.1
-
-orbs:
-  gh: circleci/github-cli@2.2.0
-
-jobs:
-  release_mac_arm:
-    macos:
-      xcode: 14.3.1
-    environment:
-      HOMEBREW_NO_AUTO_UPDATE: 1
-      PHP_EXTENSIONS: bcmath,calendar,ctype,curl,dba,dom,exif,filter,fileinfo,gd,iconv,intl,mbstring,mbregex,mysqli,mysqlnd,opcache,openssl,pcntl,pdo,pdo_mysql,pdo_pgsql,pdo_sqlite,pgsql,phar,posix,readline,redis,session,simplexml,sockets,sqlite3,tokenizer,xml,xmlreader,xmlwriter,zip,zlib,apcu
-    steps:
-      - checkout
-      - run: brew install --formula go automake cmake composer
-      - run:
-          name: Clone static-php-cli
-          command: git clone --depth 1 https://github.com/crazywhalecc/static-php-cli
-      - restore_cache:
-          keys:
-            - spc-{{ checksum "static-php-cli/composer.json" }}
-      - run:
-          name: Install static-php-cli and fetch libraries sources
-          working_directory: static-php-cli/
-          command: |
-            composer install --no-dev -a
-            ./bin/spc fetch --for-extensions="$PHP_EXTENSIONS"
-      - save_cache:
-          key: spc-{{ checksum "static-php-cli/composer.json" }}
-          paths:
-            - static-php-cli/downloads/
-            - static-php-cli/vendor/
-      - run:
-          working_directory: static-php-cli/
-          name: Build libphp.a
-          command: ./bin/spc build --enable-zts --build-embed "$PHP_EXTENSIONS"
-      - run:
-          working_directory: static-php-cli/
-          name: Set CGO flags
-          command: |
-            if [ -z "$CIRCLE_TAG" ]; then export FRANKENPHP_VERSION=$CIRCLE_SHA1; else export FRANKENPHP_VERSION=${CIRCLE_TAG:1}; fi
-            echo "export CGO_CFLAGS='-DFRANKENPHP_VERSION=$FRANKENPHP_VERSION $(./buildroot/bin/php-config --includes | sed s#-I/#-I$PWD/buildroot/#g)'" >> "$BASH_ENV"
-            echo "export CGO_LDFLAGS='-framework CoreFoundation -framework SystemConfiguration $(./buildroot/bin/php-config --ldflags) $(./buildroot/bin/php-config --libs)'" >> "$BASH_ENV"
-            echo "export PHP_VERSION='$(./buildroot/bin/php-config --version)'" >> "$BASH_ENV"
-            echo "export FRANKENPHP_VERSION='$FRANKENPHP_VERSION'" >> "$BASH_ENV"
-      - restore_cache:
-          keys:
-            - go-mod-v4-{{ checksum "caddy/go.sum" }}
-      - run:
-          name: Build FrankenPHP
-          working_directory: caddy/frankenphp/
-          command: |
-            go env
-            go build -buildmode=pie -tags "cgo netgo osusergo static_build" -ldflags "-linkmode=external -extldflags -static-pie -w -s -X 'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP $FRANKENPHP_VERSION PHP $PHP_VERSION Caddy'" -o frankenphp-mac-arm64
-            ./frankenphp-mac-arm64 version
-      - gh/setup
-      - run:
-          name: Upload asset
-          working_directory: caddy/frankenphp/
-          command: |
-            if [ -n "$CIRCLE_TAG" ]; then
-              gh release upload $CIRCLE_TAG frankenphp-mac-arm64 --repo dunglas/frankenphp --clobber
-            fi
-      - store_artifacts:
-          path: caddy/frankenphp/frankenphp-mac-arm64
-          destination: frankenphp-mac-arm64
-      - save_cache:
-          key: go-mod-v4-{{ checksum "caddy/go.sum" }}
-          paths:
-            - "~/go/pkg/mod"
-
-workflows:
-  release:
-    jobs:
-      - release_mac_arm:
-          filters:
-            branches:
-              ignore: /.*/
-            tags:
-              only: /^v.*/

+ 2 - 1
.gitignore

@@ -1,6 +1,7 @@
 /caddy/frankenphp/frankenphp
 /caddy/frankenphp/frankenphp
 /internal/testserver/testserver
 /internal/testserver/testserver
-internal/testcli/testcli
+/internal/testcli/testcli
+/dist
 .idea/
 .idea/
 .vscode/
 .vscode/
 __debug_bin
 __debug_bin

+ 58 - 0
build-mac-arm.sh

@@ -0,0 +1,58 @@
+#!/bin/sh
+
+set -o errexit
+trap 'echo "Aborting due to errexit on line $LINENO. Exit code: $?" >&2' ERR
+set -o errtrace
+set -o pipefail
+set -o xtrace
+
+if ! type "git" > /dev/null; then
+    echo "The \"git\" command must be installed."
+    exit 1
+fi
+
+export CURRENT_REF="$(git rev-parse --abbrev-ref HEAD)"
+
+if [ -n "$1" ]; then
+    export TAG="1"
+    export FRANKENPHP_VERSION="$1"
+    git checkout $FRANKENPHP_VERSION
+else
+    export TAG="0"
+    export FRANKENPHP_VERSION="$(git rev-parse --verify HEAD)"
+fi
+
+export PHP_EXTENSIONS="calendar,ctype,curl,dba,dom,exif,filter,fileinfo,gd,iconv,intl,mbstring,mbregex,mysqli,mysqlnd,opcache,openssl,pcntl,pdo,pdo_mysql,pdo_pgsql,pdo_sqlite,pgsql,phar,posix,readline,redis,session,simplexml,sockets,sqlite3,tokenizer,xml,xmlreader,xmlwriter,zip,zlib,apcu"
+
+brew install --formula --quiet  automake cmake composer go gh
+
+mkdir -p dist/
+cd dist/
+
+if [ -d "static-php-cli/" ]; then
+    cd static-php-cli/
+    git pull
+else
+    git clone --depth 1 https://github.com/crazywhalecc/static-php-cli
+    cd static-php-cli/
+fi
+
+composer install --no-dev -a
+./bin/spc fetch --for-extensions="$PHP_EXTENSIONS"
+./bin/spc build --enable-zts --build-embed "$PHP_EXTENSIONS"
+export CGO_CFLAGS="-DFRANKENPHP_VERSION=$FRANKENPHP_VERSION $(./buildroot/bin/php-config --includes | sed s#-I/#-I$PWD/buildroot/#g)"
+export CGO_LDFLAGS="-framework CoreFoundation -framework SystemConfiguration $(./buildroot/bin/php-config --ldflags) $(./buildroot/bin/php-config --libs)"
+export PHP_VERSION="$(./buildroot/bin/php-config --version)"
+
+cd ../../caddy/frankenphp/
+go env
+go build -buildmode=pie -tags "cgo netgo osusergo static_build" -ldflags "-linkmode=external -extldflags -static-pie -w -s -X 'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP $FRANKENPHP_VERSION PHP $PHP_VERSION Caddy'" -o ../../dist/frankenphp-mac-arm64
+
+cd ../../dist/
+./frankenphp-mac-arm64 version
+
+if  [ "$TAG" -eq "1" ]; then
+    gh release upload $FRANKENPHP_VERSION frankenphp-mac-arm64 --repo dunglas/frankenphp --clobber
+fi
+
+git checkout "$CURRENT_REF"