crazywhalecc / static-php-cli

Build standalone PHP binary on Linux, macOS, FreeBSD, Windows, with PHP project together, with popular extensions included.
https://static-php.dev
MIT License
1.26k stars 217 forks source link

Compile failed on Linux(aarch64) with fpm SAPI #217

Closed crazywhalecc closed 10 months ago

crazywhalecc commented 11 months ago

Build Command

bin/spc build bcmath --debug --build-fpm

Console Log

/root/static-php-cli/source/php-src/sapi/fpm/fpm/fpm_atomic.h:136:2: error: #error Unsupported processor. Please open a bug report (bugs.php.net).
  136 | #error Unsupported processor. Please open a bug report (bugs.php.net).
      |  ^~~~~
/root/static-php-cli/source/php-src/sapi/fpm/fpm/fpm_atomic.h:140:32: error: unknown type name ‘atomic_t’
  140 | static inline int fpm_spinlock(atomic_t *lock, int try_once) /* {{{ */
      |                                ^~~~~~~~
In file included from /root/static-php-cli/source/php-src/sapi/fpm/fpm/fpm.c:19:
/root/static-php-cli/source/php-src/sapi/fpm/fpm/fpm_scoreboard.h:23:17: error: unknown type name ‘atomic_t’
   23 |                 atomic_t lock;
      |                 ^~~~~~~~
/root/static-php-cli/source/php-src/sapi/fpm/fpm/fpm_scoreboard.h:52:17: error: unknown type name ‘atomic_t’
   52 |                 atomic_t lock;
      |                 ^~~~~~~~
make: *** [Makefile:393: sapi/fpm/fpm/fpm.lo] Error 1
make: *** Waiting for unfinished jobs....
In file included from /root/static-php-cli/source/php-src/sapi/fpm/fpm/fpm_scoreboard.h:13,
                 from /root/static-php-cli/source/php-src/sapi/fpm/fpm/fpm_children.c:26:
/root/static-php-cli/source/php-src/sapi/fpm/fpm/fpm_atomic.h:136:2: error: #error Unsupported processor. Please open a bug report (bugs.php.net).
  136 | #error Unsupported processor. Please open a bug report (bugs.php.net).
      |  ^~~~~
/root/static-php-cli/source/php-src/sapi/fpm/fpm/fpm_atomic.h:140:32: error: unknown type name ‘atomic_t’
  140 | static inline int fpm_spinlock(atomic_t *lock, int try_once) /* {{{ */
      |                                ^~~~~~~~
In file included from /root/static-php-cli/source/php-src/sapi/fpm/fpm/fpm_children.c:26:
/root/static-php-cli/source/php-src/sapi/fpm/fpm/fpm_scoreboard.h:23:17: error: unknown type name ‘atomic_t’
   23 |                 atomic_t lock;
      |                 ^~~~~~~~
/root/static-php-cli/source/php-src/sapi/fpm/fpm/fpm_scoreboard.h:52:17: error: unknown type name ‘atomic_t’
   52 |                 atomic_t lock;
      |                 ^~~~~~~~
make: *** [Makefile:395: sapi/fpm/fpm/fpm_children.lo] Error 1

System Info

# uname -a
Linux localhost.localdomain 5.14.0-284.30.1.el9_2.aarch64 #1 SMP PREEMPT_DYNAMIC Tue Sep 12 13:39:16 UTC 2023 aarch64 aarch64 aarch64 GNU/Linux

# cat /etc/os-release
NAME="AlmaLinux"
VERSION="9.2 (Turquoise Kodkod)"
ID="almalinux"
ID_LIKE="rhel centos fedora"
VERSION_ID="9.2"
PLATFORM_ID="platform:el9"
PRETTY_NAME="AlmaLinux 9.2 (Turquoise Kodkod)"
ANSI_COLOR="0;34"
LOGO="fedora-logo-icon"
CPE_NAME="cpe:/o:almalinux:almalinux:9::baseos"
HOME_URL="https://almalinux.org/"
DOCUMENTATION_URL="https://wiki.almalinux.org/"
BUG_REPORT_URL="https://bugs.almalinux.org/"

ALMALINUX_MANTISBT_PROJECT="AlmaLinux-9"
ALMALINUX_MANTISBT_PROJECT_VERSION="9.2"
REDHAT_SUPPORT_PRODUCT="AlmaLinux"
REDHAT_SUPPORT_PRODUCT_VERSION="9.2"

Other Info

Compile pure C program with __arch64__ successfully..

#include <stdio.h>
int main() {
#if (__arch64__ || __arch64)
    printf("ARM!\n");
#else
    printf("Not ARM!\n");
    return 0;
}
ARM!
jingjingxyk commented 11 months ago

缺 linux-headers 头文件吧

crazywhalecc commented 11 months ago

@jingjingxyk

Package kernel-headers-5.14.0-284.30.1.el9_2.aarch64 is already installed.
DubbleClick commented 11 months ago

Is this a bug with aarch64-linux-musl too, or just the gcc wrapper?

crazywhalecc commented 11 months ago

Is this a bug with aarch64-linux-musl too, or just the gcc wrapper?

It seems that it only fails to compile on AlmaLinux-aarch64. It works fine on both alpine and debian of my arm64 architecture.

DubbleClick commented 11 months ago

I meant if it also happened when you build musl-cross-compile (TARGET=aarch64-linux-musl) and then use aarch64-linux-musl to compile php-fpm. I don't have an ARM64 machine, so I cannot test this. :/

crazywhalecc commented 11 months ago

I meant if it also happened when you build musl-cross-compile (TARGET=aarch64-linux-musl) and then use aarch64-linux-musl to compile php-fpm. I don't have an ARM64 machine, so I cannot test this. :/

I finally tested on clean debian 12 arm64 platform and use spc doctor --auto-fix, got the same error:

image
DubbleClick commented 11 months ago

I can't see the configure command so I don't know if that's musl-gcc wrapper or aarch64-linux-musl compiler.

Maybe I will rent an aarch64 VM to test this.

crazywhalecc commented 11 months ago

@DubbleClick I uploaded the entire php-src and found no useful information so far.

php-src.tar.bz2.zip

GitHub only allows me to upload files smaller than 25MB, and not in bz2 format, so I can only compress it again.

DubbleClick commented 11 months ago

It's musl-gcc wrapper. Can you try with the cplusplus branch at https://github.com/crazywhalecc/static-php-cli/pull/214? It contains a lot of fixes and might just implicitly tackle this too. It seems to be missing various system headers, but compiling gcc with musl-cross-make will produce new ones.

/usr/bin/ld: /tmp/ccAzYpTF.o: in function `main':
conftest.c:(.text+0x8): undefined reference to `__dns_search

and I remember something about dns problems with aarch64/gcc for static builds.

Either way I will see to get access to an arm64 system that I can test on next week.

DubbleClick commented 11 months ago

I spun up an arm64 almalinux (minimal) vm, installed php, composer and zip, copied spc over, ran spc doctor -> spc build snappy and it worked.


[13:36:03] [INFO] [EXEC] strip --strip-all php-fpm
[13:36:03] [DEBU] Running command with direct output: cd '/opt/static-php-cli/source/php-src/sapi/fpm' && strip --strip-all php-fpm
[13:36:03] [INFO] Deploying fpm file
[13:36:03] [INFO] [EXEC] cp '/opt/static-php-cli/source/php-src/sapi/fpm/php-fpm' '/opt/static-php-cli/buildroot/bin/'
[13:36:03] [DEBU] Running command with direct output: cp '/opt/static-php-cli/source/php-src/sapi/fpm/php-fpm' '/opt/static-php-cli/buildroot/bin/'
[13:36:03] [INFO] Build complete, used 219.747 s !
[13:36:03] [INFO] Static php-fpm binary path: /opt/static-php-cli/buildroot/bin/php-fpm
[13:36:03] [DEBU] Making new directory recursive: /opt/static-php-cli/buildroot/license
[13:36:03] [INFO] License path: /opt/static-php-cli/buildroot/license/
[root@aarch64 static-php-cli]# uname -a
Linux aarch64 5.14.0-284.11.1.el9_2.aarch64 #1 SMP PREEMPT_DYNAMIC Tue May 9 09:48:54 UTC 2023 aarch64 aarch64 aarch64 GNU/Linux```
crazywhalecc commented 11 months ago

@DubbleClick How did you install musl? I used the doctor from the default branch.

DubbleClick commented 11 months ago

From the c++ branch pull request (#214 ) it worked right away. I didn't do extensive testing yet because imap fails with an error that makes little sense, but compiling the list of default extensions worked fine.

crazywhalecc commented 11 months ago

I don't have much free time this week and may not be able to work on it. I'll be diving into it over the weekend and next week.

DubbleClick commented 11 months ago

No problem, I will be able to get Alpine support done this week so all that's left will be MacOS support.