mirror of
https://github.com/dunglas/frankenphp
synced 2024-11-21 15:22:16 +00:00
feat: Apple Silicon static build and better version name (#205)
* feat: Apple Silicon static build and better version name Build a static binary for macOS and Apple Silicon. Also add the PHP version to the version command. * fix CircleCI Composer cache key * fix export * fix and optims * cleanup
This commit is contained in:
parent
4b7129deeb
commit
b7098f7408
57
.circleci/config.yml
Normal file
57
.circleci/config.yml
Normal file
@ -0,0 +1,57 @@
|
||||
version: 2.1
|
||||
|
||||
jobs:
|
||||
build:
|
||||
macos:
|
||||
xcode: 14.3.1
|
||||
environment:
|
||||
HOMEBREW_NO_AUTO_UPDATE: 1
|
||||
|
||||
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 --with-php=8.2 -A
|
||||
- save_cache:
|
||||
key: spc-{{ checksum "static-php-cli/composer.json" }}
|
||||
paths:
|
||||
- save_cache:tatic-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 --debug "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"
|
||||
- run:
|
||||
working_directory: static-php-cli/
|
||||
name: Set CGO flags
|
||||
command: |
|
||||
echo "export CGO_CFLAGS='$(./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"
|
||||
- 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 $CIRCLE_SHA1 PHP $PHP_VERSION Caddy'"
|
||||
./frankenphp version
|
||||
- store_artifacts:
|
||||
path: caddy/frankenphp/frankenphp
|
||||
destination: frankenphp-arm64-<<pipeline.git.revision>>
|
||||
- save_cache:
|
||||
key: go-mod-v4-{{ checksum "caddy/go.sum" }}
|
||||
paths:
|
||||
- "~/go/pkg/mod"
|
25
.github/workflows/static.yml
vendored
25
.github/workflows/static.yml
vendored
@ -34,7 +34,7 @@ jobs:
|
||||
*.cache-from=type=gha,scope=refs/heads/main-static-builder
|
||||
*.cache-to=type=gha,scope=${{github.ref}}-static-builder
|
||||
env:
|
||||
VERSION: ${{github.ref_name}}
|
||||
VERSION: ${{ github.sha }}
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Copy binary
|
||||
@ -43,12 +43,14 @@ jobs:
|
||||
- name: Upload binary
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: frankenphp-linux-x86_64-dev
|
||||
name: frankenphp-linux-x86_64-${{ github.sha }}
|
||||
path: frankenphp
|
||||
|
||||
build-mac:
|
||||
name: Build macOS binaries
|
||||
name: Build macOS x86_64 binaries
|
||||
runs-on: macos-latest
|
||||
env:
|
||||
HOMEBREW_NO_AUTO_UPDATE: 1
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
@ -58,6 +60,10 @@ jobs:
|
||||
repository: crazywhalecc/static-php-cli
|
||||
path: static-php-cli
|
||||
|
||||
- name: Install missing system dependencies
|
||||
run: brew install automake
|
||||
working-directory: static-php-cli/
|
||||
|
||||
- uses: actions/setup-go@v4
|
||||
with:
|
||||
go-version: '1.21'
|
||||
@ -66,17 +72,13 @@ jobs:
|
||||
working-directory: static-php-cli/
|
||||
run: composer install --no-dev -a
|
||||
|
||||
- name: Install missing system dependencies
|
||||
run: ./bin/spc doctor --auto-fix
|
||||
working-directory: static-php-cli/
|
||||
|
||||
- name: Fetch libraries sources
|
||||
working-directory: static-php-cli/
|
||||
run: ./bin/spc fetch --with-php=8.2 -A
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Build static libphp
|
||||
- name: Build libphp.a
|
||||
working-directory: static-php-cli/
|
||||
run: ./bin/spc build --enable-zts --build-embed --debug "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"
|
||||
|
||||
@ -85,13 +87,16 @@ jobs:
|
||||
run: |
|
||||
echo "CGO_CFLAGS=$(./buildroot/bin/php-config --includes | sed s#-I/#-I$PWD/buildroot/#g)" >> "$GITHUB_ENV"
|
||||
echo "CGO_LDFLAGS=-framework CoreFoundation -framework SystemConfiguration $(./buildroot/bin/php-config --ldflags) $(./buildroot/bin/php-config --libs)" >> "$GITHUB_ENV"
|
||||
echo "PHP_VERSION=$(./buildroot/bin/php-config --version)" >> "$GITHUB_ENV"
|
||||
|
||||
- name: Build FrankenPHP
|
||||
working-directory: caddy/frankenphp/
|
||||
run: go build -buildmode=pie -tags "cgo netgo osusergo static_build" -ldflags "-linkmode=external -extldflags -static-pie -w -s"
|
||||
run: |
|
||||
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 ${{ github.sha }} PHP $PHP_VERSION Caddy'"
|
||||
./frankenphp version
|
||||
|
||||
- name: Upload binary
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: frankenphp-mac-x86_64-dev
|
||||
name: frankenphp-mac-x86_64-${{ github.sha }}
|
||||
path: caddy/frankenphp/frankenphp
|
||||
|
2
.github/workflows/tests.yml
vendored
2
.github/workflows/tests.yml
vendored
@ -22,7 +22,7 @@ jobs:
|
||||
env:
|
||||
phpts: ts
|
||||
|
||||
- name: Set include flags
|
||||
- name: Set CGO flags
|
||||
run: echo "CGO_CFLAGS=$(php-config --includes)" >> "$GITHUB_ENV"
|
||||
|
||||
- name: Build
|
||||
|
27
Dockerfile
27
Dockerfile
@ -11,17 +11,17 @@ ENV PATH /usr/local/go/bin:$PATH
|
||||
# This is required to link the FrankenPHP binary to the PHP binary
|
||||
RUN apt-get update && \
|
||||
apt-get -y --no-install-recommends install \
|
||||
libargon2-dev \
|
||||
libcurl4-openssl-dev \
|
||||
libonig-dev \
|
||||
libreadline-dev \
|
||||
libsodium-dev \
|
||||
libsqlite3-dev \
|
||||
libssl-dev \
|
||||
libxml2-dev \
|
||||
zlib1g-dev \
|
||||
&& \
|
||||
apt-get clean
|
||||
libargon2-dev \
|
||||
libcurl4-openssl-dev \
|
||||
libonig-dev \
|
||||
libreadline-dev \
|
||||
libsodium-dev \
|
||||
libsqlite3-dev \
|
||||
libssl-dev \
|
||||
libxml2-dev \
|
||||
zlib1g-dev \
|
||||
&& \
|
||||
apt-get clean
|
||||
|
||||
WORKDIR /go/src/app
|
||||
|
||||
@ -44,9 +44,10 @@ COPY testdata testdata
|
||||
ENV CGO_LDFLAGS="-lssl -lcrypto -lreadline -largon2 -lcurl -lonig -lz $PHP_LDFLAGS" CGO_CFLAGS=$PHP_CFLAGS CGO_CPPFLAGS=$PHP_CPPFLAGS
|
||||
|
||||
RUN cd caddy/frankenphp && \
|
||||
go build -ldflags "-X 'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP $FRANKENPHP_VERSION Caddy'" && \
|
||||
go build -ldflags "-X 'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP $FRANKENPHP_VERSION PHP $PHP_VERSION Caddy'" && \
|
||||
cp frankenphp /usr/local/bin && \
|
||||
cp /go/src/app/caddy/frankenphp/Caddyfile /etc/Caddyfile
|
||||
cp Caddyfile /etc/Caddyfile && \
|
||||
frankenphp version
|
||||
|
||||
ENTRYPOINT ["/bin/bash","-c"]
|
||||
|
||||
|
@ -9,18 +9,18 @@ COPY --from=golang-base /usr/local/go /usr/local/go
|
||||
ENV PATH /usr/local/go/bin:$PATH
|
||||
|
||||
RUN apk add --no-cache --virtual .build-deps \
|
||||
$PHPIZE_DEPS \
|
||||
argon2-dev \
|
||||
coreutils \
|
||||
curl-dev \
|
||||
gnu-libiconv-dev \
|
||||
libsodium-dev \
|
||||
libxml2-dev \
|
||||
linux-headers \
|
||||
oniguruma-dev \
|
||||
openssl-dev \
|
||||
readline-dev \
|
||||
sqlite-dev
|
||||
$PHPIZE_DEPS \
|
||||
argon2-dev \
|
||||
coreutils \
|
||||
curl-dev \
|
||||
gnu-libiconv-dev \
|
||||
libsodium-dev \
|
||||
libxml2-dev \
|
||||
linux-headers \
|
||||
oniguruma-dev \
|
||||
openssl-dev \
|
||||
readline-dev \
|
||||
sqlite-dev
|
||||
|
||||
WORKDIR /go/src/app
|
||||
|
||||
@ -43,9 +43,10 @@ COPY testdata testdata
|
||||
ENV CGO_LDFLAGS="-lssl -lcrypto -lreadline -largon2 -lcurl -lonig -lz $PHP_LDFLAGS" CGO_CFLAGS=$PHP_CFLAGS CGO_CPPFLAGS=$PHP_CPPFLAGS
|
||||
|
||||
RUN cd caddy/frankenphp && \
|
||||
go build -ldflags "-X 'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP $FRANKENPHP_VERSION Caddy'" && \
|
||||
cp frankenphp /usr/local/bin && \
|
||||
cp /go/src/app/caddy/frankenphp/Caddyfile /etc/Caddyfile
|
||||
go build -ldflags "-X 'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP $FRANKENPHP_VERSION PHP $PHP_VERSION Caddy'" && \
|
||||
cp frankenphp /usr/local/bin && \
|
||||
cp Caddyfile /etc/Caddyfile && \
|
||||
frankenphp version
|
||||
|
||||
ENTRYPOINT ["/bin/sh","-c"]
|
||||
|
||||
|
@ -28,12 +28,14 @@ RUN apk update; \
|
||||
make \
|
||||
php82 \
|
||||
php82-common \
|
||||
php82-curl \
|
||||
php82-dom \
|
||||
php82-mbstring \
|
||||
php82-openssl \
|
||||
php82-pcntl \
|
||||
php82-phar \
|
||||
php82-posix \
|
||||
php82-sodium \
|
||||
php82-tokenizer \
|
||||
php82-xml \
|
||||
php82-xmlwriter \
|
||||
@ -76,4 +78,6 @@ COPY C-Thread-Pool C-Thread-Pool
|
||||
RUN cd caddy/frankenphp && \
|
||||
CGO_CFLAGS="$(/static-php-cli/buildroot/bin/php-config --includes | sed s#-I/#-I/static-php-cli/buildroot/#g)" \
|
||||
CGO_LDFLAGS="$(/static-php-cli/buildroot/bin/php-config --ldflags) $(/static-php-cli/buildroot/bin/php-config --libs | sed -e 's/-lgcc_s//g')" \
|
||||
go build -buildmode=pie -tags "cgo netgo osusergo static_build" -ldflags "-linkmode=external -extldflags -static-pie -s -w -X 'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP $FRANKENPHP_VERSION Caddy'"
|
||||
LIBPHP_VERSION="$(/static-php-cli/buildroot/bin/php-config --version)" \
|
||||
go build -buildmode=pie -tags "cgo netgo osusergo static_build" -ldflags "-linkmode=external -extldflags -static-pie -s -w -X 'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP $FRANKENPHP_VERSION PHP $LIBPHP_VERSION Caddy'" && \
|
||||
./frankenphp version
|
||||
|
Loading…
Reference in New Issue
Block a user