dunglas / frankenphp

🧟 The modern PHP app server
https://frankenphp.dev
MIT License
6.8k stars 233 forks source link

Xcaddy won't build #825

Closed bpolaszek closed 4 months ago

bpolaszek commented 4 months ago

What happened?

Hello there, I tried building FrankenPHP with Xcaddy but it crashes (MacOS Sonoma, Apple M1).

Copy/pasted from the docs:

CGO_ENABLED=1 \
XCADDY_GO_BUILD_FLAGS="-ldflags '-w -s'" \
xcaddy build \
    --output frankenphp \
    --with github.com/dunglas/frankenphp/caddy \
    --with github.com/dunglas/mercure/caddy \
    --with github.com/dunglas/vulcain/caddy
xcaddy version
v0.3.5 h1:XyC3clncb2Q3gTQC6hOJerRt3FS9+vAljW1f8jlryZA=
go version
go version go1.22.3 darwin/arm64

Any ideas?

Build Type

Custom (tell us more in the description)

Worker Mode

No

Operating System

macOS

CPU Architecture

Apple Silicon

PHP configuration

N/A

Relevant log output

2024/05/29 09:39:05 [INFO] exec (timeout=0s): /opt/homebrew/bin/go get -d -v -ldflags -w -s
2024/05/29 09:39:05 [INFO] Build environment ready
2024/05/29 09:39:05 [INFO] Building Caddy
2024/05/29 09:39:05 [INFO] exec (timeout=0s): /opt/homebrew/bin/go mod tidy -e
2024/05/29 09:39:05 [INFO] exec (timeout=0s): /opt/homebrew/bin/go build -o /opt/homebrew/bin/frankenphp -ldflags -w -s
# github.com/dunglas/frankenphp
In file included from /Users/benoit/go/pkg/mod/github.com/dunglas/frankenphp@v1.1.5/cgi.go:3:
./frankenphp.h:4:10: fatal error: 'Zend/zend_types.h' file not found
#include <Zend/zend_types.h>
         ^~~~~~~~~~~~~~~~~~~
1 error generated.
2024/05/29 09:39:07 [INFO] Cleaning up temporary folder: /opt/homebrew/bin/buildenv_2024-05-29-0939.1205888312
2024/05/29 09:39:07 [FATAL] exit status 1
dunglas commented 4 months ago

PHP sources are missing (they are included in the builder images we provide), otherwise you need to install them by yourself as described in the "compile form sources" docs.

bpolaszek commented 4 months ago

My bad, didn't understand that step was required prior to using Xcaddy (all that go stuff is black box to me). Sorry for disturbing! Still not lucky, unfortunately. No biggie (don't waste your time investigating, I was just curious about building FrankenPHP with Xcaddy, hoping it would work in a snap).

2024/05/29 16:22:10 [INFO] Build environment ready
2024/05/29 16:22:10 [INFO] Building Caddy
2024/05/29 16:22:10 [INFO] exec (timeout=0s): /opt/homebrew/bin/go mod tidy -e
2024/05/29 16:22:10 [INFO] exec (timeout=0s): /opt/homebrew/bin/go build -o /tmp/php-8.3.7/frankenphp -ldflags -w -s
# caddy
/opt/homebrew/Cellar/go/1.22.3/libexec/pkg/tool/darwin_arm64/link: running cc failed: exit status 1
ld: warning: ignoring duplicate libraries: '-largon2', '-laspell', '-lbz2', '-lc++', '-lcom_err', '-lcrypto', '-lcurl', '-ledit', '-lexslt', '-lffi', '-lgd', '-lgmp', '-lgssapi_krb5', '-liconv', '-licudata', '-licui18n', '-licuio', '-licuuc', '-lintl', '-lk5crypto', '-lkrb5', '-llber', '-lldap', '-lm', '-lncurses', '-lnetwork', '-lodbc', '-lonig', '-lpcre2-8', '-lpq', '-lpspell', '-lresolv', '-lsodium', '-lsqlite3', '-lssl', '-lsybdb', '-ltidy', '-lxml2', '-lxslt', '-lz', '-lzip'
Undefined symbols for architecture arm64:
  "_compiler_globals", referenced from:
      _execute_script_cli in 000007.o
  "_core_globals", referenced from:
      _frankenphp_worker_request_shutdown in 000007.o
      _frankenphp_request_reset in 000007.o
      _frankenphp_worker_request_startup in 000007.o
  "_executor_globals", referenced from:
      _zif_frankenphp_handle_request in 000007.o
      _frankenphp_execute_script in 000007.o
      _execute_script_cli in 000007.o
      _frankenphp_worker_request_shutdown in 000007.o
      _frankenphp_request_reset in 000007.o
      _frankenphp_worker_request_startup in 000007.o
  "_sapi_globals", referenced from:
      _zif_frankenphp_finish_request in 000007.o
      _zif_frankenphp_request_headers in 000007.o
      _zif_frankenphp_response_headers in 000007.o
      _zif_frankenphp_handle_request in 000007.o
      _zif_headers_send in 000007.o
      _zif_headers_send in 000007.o
      _frankenphp_update_server_context in 000007.o
      ...
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

2024/05/29 16:22:15 [INFO] Cleaning up temporary folder: /tmp/php-8.3.7/buildenv_2024-05-29-1622.2977248618
2024/05/29 16:22:15 [FATAL] exit status 1
dunglas commented 4 months ago

It looks like you didn't enable ZTS support. Did you compile PHP with these flags: https://frankenphp.dev/docs/compile/#linux ?

As FrankenPHP uses cgo (because PHP is written in C), it's more complicated to build than usual C programs. You need libphp compiled with the proper options.

nikspyratos commented 4 months ago

I'm having the same error of of 'Zend/zend_types.h' file not found in the static builds (trying to build a Laravel app) instead of while building xcaddy. Also on Sonoma.