Skip to content

Commit 69c43ee

Browse files
authored
chore: use upstream e-dant/watcher headers and build system (#1119)
1 parent dad858b commit 69c43ee

File tree

14 files changed

+120
-155
lines changed

14 files changed

+120
-155
lines changed

.github/actions/watcher/action.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: watcher
2+
description: Install e-dant/watcher
3+
runs:
4+
using: composite
5+
steps:
6+
-
7+
name: Determine e-dant/watcher version
8+
id: determine-watcher-version
9+
run: echo version="$(gh release view --repo e-dant/watcher --json tagName --template '{{ .tagName }}')" >> "${GITHUB_OUTPUT}"
10+
shell: bash
11+
env:
12+
GH_TOKEN: ${{ github.token }}
13+
-
14+
name: Cache e-dant/watcher
15+
id: cache-watcher
16+
uses: actions/cache@v4
17+
with:
18+
path: watcher/target
19+
key: watcher-${{ runner.os }}-${{ runner.arch }}-${{ steps.determine-watcher-version.outputs.version }}-${{ env.CC && env.CC || 'gcc' }}
20+
-
21+
if: steps.cache-watcher.outputs.cache-hit != 'true'
22+
name: Compile e-dant/watcher
23+
run: |
24+
mkdir watcher
25+
gh release download --repo e-dant/watcher -A tar.gz -O - | tar -xz -C watcher --strip-components 1
26+
cd watcher
27+
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
28+
cmake --build build
29+
sudo cmake --install build --prefix target
30+
shell: bash
31+
env:
32+
GH_TOKEN: ${{ github.token }}
33+
-
34+
name: Update LD_LIBRARY_PATH
35+
run: |
36+
sudo sh -c "echo ${PWD}/watcher/target/lib > /etc/ld.so.conf.d/watcher.conf"
37+
sudo ldconfig
38+
shell: bash

.github/workflows/docker.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ jobs:
214214
run: |
215215
docker run --platform=${{ matrix.platform }} --rm \
216216
"$(jq -r '."builder-${{ matrix.variant }}"."containerimage.config.digest"' <<< "${METADATA}")" \
217-
sh -c 'go test -tags watcher ${{ matrix.race }} -v ./... && cd caddy && go test -tags watcher,brotli,nobadger,nomysql,nopgx ${{ matrix.race }} -v ./...'
217+
sh -c 'go test -tags ${{ matrix.race }} -v ./... && cd caddy && go test -tags nobadger,nomysql,nopgx ${{ matrix.race }} -v ./...'
218218
env:
219219
METADATA: ${{ steps.build.outputs.metadata }}
220220
# Adapted from https://docs.docker.com/build/ci/github-actions/multi-platform/

.github/workflows/sanitizers.yaml

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@ jobs:
2828
CC: clang
2929
CXX: clang++
3030
USE_ZEND_ALLOC: 0
31-
LIBRARY_PATH: ${{ github.workspace }}/php/target/lib
31+
LIBRARY_PATH: ${{ github.workspace }}/php/target/lib:${{ github.workspace }}/watcher/target/lib
3232
LD_LIBRARY_PATH: ${{ github.workspace }}/php/target/lib
33-
EDANT_WATCHER_VERSION: next
3433
steps:
3534
-
3635
name: Remove local PHP
@@ -97,26 +96,13 @@ jobs:
9796
name: Add PHP to the PATH
9897
run: echo "$(pwd)/php/target/bin" >> "$GITHUB_PATH"
9998
-
100-
if: matrix.sanitizer != 'msan'
101-
uses: actions/checkout@v4
102-
name: Checkout watcher
103-
with:
104-
repository: e-dant/watcher
105-
ref: ${{ env.EDANT_WATCHER_VERSION }}
106-
path: 'edant/watcher'
107-
-
108-
if: matrix.sanitizer != 'msan'
109-
name: Compile edant/watcher
110-
run: |
111-
cd edant/watcher/watcher-c/
112-
"$CC" -o libwatcher.so ./src/watcher-c.cpp -I ./include -I ../include -std=c++17 -Wall -Wextra -fPIC -shared ${{ matrix.sanitizer == 'msan' && '-fsanitize=memory -fno-omit-frame-pointer -fno-optimize-sibling-calls' || '' }}
113-
sudo cp libwatcher.so /usr/local/lib/libwatcher.so
114-
sudo ldconfig
99+
name: Install e-dant/watcher
100+
uses: ./.github/actions/watcher
115101
-
116102
name: Set Set CGO flags
117103
run: |
118104
{
119-
echo "CGO_CFLAGS=$CFLAGS $(php-config --includes)"
105+
echo "CGO_CFLAGS=$CFLAGS -I${PWD}/watcher/target/include $(php-config --includes)"
120106
echo "CGO_LDFLAGS=$LDFLAGS $(php-config --ldflags) $(php-config --libs)"
121107
} >> "$GITHUB_ENV"
122108
-

.github/workflows/tests.yaml

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
env:
2424
GOEXPERIMENT: cgocheck2
2525
GOMAXPROCS: 10
26-
EDANT_WATCHER_VERSION: next
26+
LIBRARY_PATH: ${{ github.workspace }}/watcher/target/lib
2727
steps:
2828
-
2929
uses: actions/checkout@v4
@@ -45,23 +45,11 @@ jobs:
4545
phpts: ts
4646
debug: true
4747
-
48-
uses: actions/checkout@v4
49-
name: Checkout watcher
50-
with:
51-
repository: e-dant/watcher
52-
ref: ${{ env.EDANT_WATCHER_VERSION }}
53-
path: 'edant/watcher'
54-
-
55-
name: Compile edant/watcher
56-
run: |
57-
cd edant/watcher/watcher-c/
58-
cc -o libwatcher.so ./src/watcher-c.cpp -I ./include -I ../include -std=c++17 -O3 -Wall -Wextra -fPIC -shared
59-
sudo cp libwatcher.so /usr/local/lib/libwatcher.so
60-
sudo ldconfig
48+
name: Install e-dant/watcher
49+
uses: ./.github/actions/watcher
6150
-
62-
name: Set CGO flags
63-
run: |
64-
echo "CGO_CFLAGS=$(php-config --includes)" >> "$GITHUB_ENV"
51+
name: Set Set CGO flags
52+
run: echo "CGO_CFLAGS=-I${PWD}/watcher/target/include $(php-config --includes)" >> "${GITHUB_ENV}"
6553
-
6654
name: Build
6755
run: go build
@@ -71,11 +59,11 @@ jobs:
7159
run: go build
7260
-
7361
name: Run library tests
74-
run: go test -tags watcher -race -v ./...
62+
run: go test -race -v ./...
7563
-
7664
name: Run Caddy module tests
7765
working-directory: caddy/
78-
run: go test -tags watcher,brotli,nobadger,nomysql,nopgx -race -v ./...
66+
run: go test -tags nobadger,nomysql,nopgx -race -v ./...
7967
-
8068
name: Build the server
8169
working-directory: caddy/frankenphp/

Dockerfile

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ ENV PATH=/usr/local/go/bin:$PATH
6161
# This is required to link the FrankenPHP binary to the PHP binary
6262
RUN apt-get update && \
6363
apt-get -y --no-install-recommends install \
64+
cmake \
6465
libargon2-dev \
6566
libbrotli-dev \
6667
libcurl4-openssl-dev \
@@ -89,19 +90,26 @@ COPY --link caddy caddy
8990
COPY --link internal internal
9091
COPY --link testdata testdata
9192

92-
# install edant/watcher (necessary for file watching)
93-
ARG EDANT_WATCHER_VERSION=release
93+
# Install e-dant/watcher (necessary for file watching)
9494
WORKDIR /usr/local/src/watcher
95-
RUN curl -L https://github.com/e-dant/watcher/archive/refs/heads/$EDANT_WATCHER_VERSION.tar.gz | tar xz
96-
WORKDIR /usr/local/src/watcher/watcher-$EDANT_WATCHER_VERSION/watcher-c
97-
RUN cc -o libwatcher.so ./src/watcher-c.cpp -I ./include -I ../include -std=c++17 -O3 -Wall -Wextra -fPIC -shared && \
98-
cp libwatcher.so /usr/local/lib/libwatcher.so && \
99-
ldconfig /usr/local/lib
95+
RUN curl -s https://api.github.com/repos/e-dant/watcher/releases/latest | \
96+
grep tarball_url | \
97+
awk '{ print $2 }' | \
98+
sed 's/,$//' | \
99+
sed 's/"//g' | \
100+
xargs curl -L | \
101+
tar xz --strip-components 1 && \
102+
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release && \
103+
cmake --build build && \
104+
cmake --install build && \
105+
ldconfig
100106

101107
# See https://github.com/docker-library/php/blob/master/8.3/bookworm/zts/Dockerfile#L57-L59 for PHP values
102108
ENV CGO_CFLAGS="-DFRANKENPHP_VERSION=$FRANKENPHP_VERSION $PHP_CFLAGS"
103109
ENV CGO_CPPFLAGS=$PHP_CPPFLAGS
104-
ENV CGO_LDFLAGS="-lssl -lcrypto -lreadline -largon2 -lcurl -lonig -lz $PHP_LDFLAGS"
110+
ENV CGO_LDFLAGS="-L/usr/local/lib -lssl -lcrypto -lreadline -largon2 -lcurl -lonig -lz $PHP_LDFLAGS"
111+
112+
RUN echo $CGO_LDFLAGS
105113

106114
WORKDIR /go/src/app/caddy/frankenphp
107115
RUN GOBIN=/usr/local/bin go install -tags 'nobadger,nomysql,nopgx' -ldflags "-w -s -X 'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP $FRANKENPHP_VERSION PHP $PHP_VERSION Caddy'" && \

alpine.Dockerfile

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ RUN apk add --no-cache --virtual .build-deps \
7171
git \
7272
gnu-libiconv-dev \
7373
libsodium-dev \
74-
# Needed for the file watcher
74+
# Needed for the file watcher \
75+
cmake \
7576
libstdc++ \
7677
libxml2-dev \
7778
linux-headers \
@@ -111,14 +112,18 @@ COPY --link caddy caddy
111112
COPY --link internal internal
112113
COPY --link testdata testdata
113114

114-
# install edant/watcher (necessary for file watching)
115-
ARG EDANT_WATCHER_VERSION=release
115+
# Install e-dant/watcher (necessary for file watching)
116116
WORKDIR /usr/local/src/watcher
117-
RUN curl -L https://github.com/e-dant/watcher/archive/refs/heads/$EDANT_WATCHER_VERSION.tar.gz | tar xz
118-
WORKDIR /usr/local/src/watcher/watcher-$EDANT_WATCHER_VERSION/watcher-c
119-
RUN cc -o libwatcher.so ./src/watcher-c.cpp -I ./include -I ../include -std=c++17 -O3 -Wall -Wextra -fPIC -shared && \
120-
cp libwatcher.so /usr/local/lib/libwatcher.so && \
121-
ldconfig /usr/local/lib
117+
RUN curl -s https://api.github.com/repos/e-dant/watcher/releases/latest | \
118+
grep tarball_url | \
119+
awk '{ print $2 }' | \
120+
sed 's/,$//' | \
121+
sed 's/"//g' | \
122+
xargs curl -L | \
123+
tar xz --strip-components 1 && \
124+
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release && \
125+
cmake --build build && \
126+
cmake --install build
122127

123128
# See https://github.com/docker-library/php/blob/master/8.3/alpine3.20/zts/Dockerfile#L53-L55
124129
ENV CGO_CFLAGS="-DFRANKENPHP_VERSION=$FRANKENPHP_VERSION $PHP_CFLAGS"

build-static.sh

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!/bin/bash
22

33
set -o errexit
44
set -x
@@ -120,6 +120,29 @@ else
120120
./bin/spc build --debug --enable-zts --build-embed ${extraOpts} "${PHP_EXTENSIONS}" --with-libs="${PHP_EXTENSION_LIBS}"
121121
fi
122122

123+
curlGitHubHeaders=(--header "X-GitHub-Api-Version: 2022-11-28")
124+
if [ "${GITHUB_TOKEN}" ]; then
125+
curlGitHubHeaders+=(--header "Authorization: Bearer ${GITHUB_TOKEN}")
126+
fi
127+
128+
# Compile e-dant/watcher as a static library
129+
mkdir watcher
130+
cd watcher
131+
curl -f --retry 5 "${curlGitHubHeaders[@]}" https://api.github.com/repos/e-dant/watcher/releases/latest |
132+
grep tarball_url |
133+
awk '{ print $2 }' |
134+
sed 's/,$//' |
135+
sed 's/"//g' |
136+
xargs curl -fL --retry 5 "${curlGitHubHeaders[@]}" |
137+
tar xz --strip-components 1
138+
cd watcher-c
139+
cc -c -o libwatcher-c.o ./src/watcher-c.cpp -I ./include -I ../include -std=c++17 -Wall -Wextra -fPIC
140+
ar rcs libwatcher-c.a libwatcher-c.o
141+
cp libwatcher-c.a ../../buildroot/lib/libwatcher-c.a
142+
mkdir -p ../../buildroot/include/wtr
143+
cp -R include/wtr/watcher-c.h ../../buildroot/include/wtr/watcher-c.h
144+
cd ../../
145+
123146
# See https://github.com/docker-library/php/blob/master/8.3/alpine3.20/zts/Dockerfile#L53-L55
124147
CGO_CFLAGS="-DFRANKENPHP_VERSION=${FRANKENPHP_VERSION} -I${PWD}/buildroot/include/ $(./buildroot/bin/php-config --includes | sed s#-I/#-I"${PWD}"/buildroot/#g)"
125148
if [ -n "${DEBUG_SYMBOLS}" ]; then
@@ -136,22 +159,13 @@ elif [ "${os}" = "linux" ] && [ -z "${DEBUG_SYMBOLS}" ]; then
136159
CGO_LDFLAGS="-Wl,-O1 -pie"
137160
fi
138161
139-
CGO_LDFLAGS="${CGO_LDFLAGS} ${PWD}/buildroot/lib/libbrotlicommon.a ${PWD}/buildroot/lib/libbrotlienc.a ${PWD}/buildroot/lib/libbrotlidec.a $(./buildroot/bin/php-config --ldflags || true) $(./buildroot/bin/php-config --libs | sed -e 's/-lgcc_s//g' || true)"
162+
CGO_LDFLAGS="${CGO_LDFLAGS} ${PWD}/buildroot/lib/libbrotlicommon.a ${PWD}/buildroot/lib/libbrotlienc.a ${PWD}/buildroot/lib/libbrotlidec.a ${PWD}/buildroot/lib/libwatcher-c.a $(./buildroot/bin/php-config --ldflags || true) $(./buildroot/bin/php-config --libs | sed -e 's/-lgcc_s//g' || true)"
140163
if [ "${os}" = "linux" ]; then
141164
if echo "${PHP_EXTENSIONS}" | grep -qE "\b(intl|imagick|grpc|v8js|protobuf|mongodb|tbb)\b"; then
142165
CGO_LDFLAGS="${CGO_LDFLAGS} -lstdc++"
143166
fi
144167
fi
145168
146-
# install edant/watcher for file watching (static version)
147-
git clone --branch="${EDANT_WATCHER_VERSION:-release}" https://github.com/e-dant/watcher watcher
148-
cd watcher/watcher-c
149-
cc -c -o libwatcher.o ./src/watcher-c.cpp -I ./include -I ../include -std=c++17 -Wall -Wextra -fPIC
150-
ar rcs libwatcher.a libwatcher.o
151-
cp libwatcher.a "../../buildroot/lib/libwatcher.a"
152-
cd ../../
153-
CGO_LDFLAGS="${CGO_LDFLAGS} -lstdc++ ${PWD}/buildroot/lib/libwatcher.a"
154-
155169
export CGO_LDFLAGS
156170
157171
LIBPHP_VERSION="$(./buildroot/bin/php-config --version)"
@@ -182,7 +196,7 @@ if [ "${os}" = "linux" ]; then
182196
183197
git checkout "$(git describe --tags "$(git rev-list --tags --max-count=1 || true)" || true)"
184198
185-
curl -f -L --retry 5 https://raw.githubusercontent.com/tweag/rust-alpine-mimalloc/b26002b49d466a295ea8b50828cb7520a71a872a/mimalloc.diff -o mimalloc.diff
199+
curl -fL --retry 5 https://raw.githubusercontent.com/tweag/rust-alpine-mimalloc/b26002b49d466a295ea8b50828cb7520a71a872a/mimalloc.diff -o mimalloc.diff
186200
patch -p1 <mimalloc.diff
187201
188202
mkdir -p out/

dev-alpine.Dockerfile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ RUN apk add --no-cache \
3737
# Dev tools \
3838
git \
3939
clang \
40+
cmake \
4041
llvm \
4142
gdb \
4243
valgrind \
@@ -63,14 +64,13 @@ RUN git clone --branch=PHP-8.3 https://github.com/php/php-src.git . && \
6364
echo "opcache.enable=1" >> /usr/local/lib/php.ini && \
6465
php --version
6566

66-
# install edant/watcher (necessary for file watching)
67+
# Install e-dant/watcher (necessary for file watching)
6768
ARG EDANT_WATCHER_VERSION=release
6869
WORKDIR /usr/local/src/watcher
69-
RUN git clone --branch=$EDANT_WATCHER_VERSION https://github.com/e-dant/watcher .
70-
WORKDIR /usr/local/src/watcher/watcher-c
71-
RUN cc -o libwatcher.so ./src/watcher-c.cpp -I ./include -I ../include -std=c++17 -O3 -Wall -Wextra -fPIC -shared && \
72-
cp libwatcher.so /usr/local/lib/libwatcher.so && \
73-
ldconfig /usr/local/lib
70+
RUN git clone --branch=$EDANT_WATCHER_VERSION https://github.com/e-dant/watcher . && \
71+
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release && \
72+
cmake --build build/ && \
73+
cmake --install build
7474

7575
WORKDIR /go/src/app
7676
COPY . .

dev.Dockerfile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ RUN apt-get update && \
3636
# Dev tools \
3737
git \
3838
clang \
39+
cmake \
3940
llvm \
4041
gdb \
4142
valgrind \
@@ -65,14 +66,13 @@ RUN git clone --branch=PHP-8.3 https://github.com/php/php-src.git . && \
6566
echo "opcache.enable=1" >> /usr/local/lib/php.ini && \
6667
php --version
6768

68-
# install edant/watcher (necessary for file watching)
69+
# Install e-dant/watcher (necessary for file watching)
6970
ARG EDANT_WATCHER_VERSION=release
7071
WORKDIR /usr/local/src/watcher
71-
RUN git clone --branch=$EDANT_WATCHER_VERSION https://github.com/e-dant/watcher .
72-
WORKDIR /usr/local/src/watcher/watcher-c
73-
RUN cc -o libwatcher.so ./src/watcher-c.cpp -I ./include -I ../include -std=c++17 -O3 -Wall -Wextra -fPIC -shared && \
74-
cp libwatcher.so /usr/local/lib/libwatcher.so && \
75-
ldconfig /usr/local/lib
72+
RUN git clone --branch=$EDANT_WATCHER_VERSION https://github.com/e-dant/watcher . && \
73+
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release && \
74+
cmake --build build/ && \
75+
cmake --install build
7676

7777
WORKDIR /go/src/app
7878
COPY . .

frankenphp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ package frankenphp
1414

1515
// #cgo darwin pkg-config: libxml-2.0
1616
// #cgo CFLAGS: -Wall -Werror
17-
// #cgo CFLAGS: -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib
17+
// #cgo CFLAGS: -I/usr/local/include -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib
1818
// #cgo linux CFLAGS: -D_GNU_SOURCE
1919
// #cgo darwin LDFLAGS: -L/opt/homebrew/opt/libiconv/lib -liconv
2020
// #cgo linux LDFLAGS: -lresolv

0 commit comments

Comments
 (0)