indygreg / python-zstandard

Python bindings to the Zstandard (zstd) compression library
BSD 3-Clause "New" or "Revised" License
496 stars 85 forks source link

ARM64 ERROR: Cannot build on OpenWRT #159

Open erdoukki opened 3 years ago

erdoukki commented 3 years ago

error on OpenWrt 21.02-RC3 on a ARM64 board...

# python3 --version
Python 3.9.6
  ERROR: Failed building wheel for zstandard
...
Failed to build zstandard
ERROR: Could not build wheels for zstandard which use PEP 517 and cannot be installed directly
...

trying to install with :

pip download --no-deps zstandard
tar -zxf zstandard-0.15.2.tar.gz
cd zstandard-0.15.2
python3 setup.py build
python3 setup.py install

get error on build :

root@ultra:~/zstandard-0.15.2# python3 setup.py build 
generating build/zstandard/_cffi.c
(already up-to-date)
not modified: 'build/zstandard/_cffi.c'
running build
running build_py
running build_ext
building 'zstandard.backend_c' extension
gcc -Wno-unused-result -Wsign-compare -DNDEBUG -Os -pipe -mcpu=cortex-a53 -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -ffile-prefix-map=/builder/shared-workdir/build/sdk/build_dir/target-aarch64_cortex-a53_musl/Python-3.9.6=Python-3.9.6 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro -Os -pipe -mcpu=cortex-a53 -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -ffile-prefix-map=/builder/shared-workdir/build/sdk/build_dir/target-aarch64_cortex-a53_musl/Python-3.9.6=Python-3.9.6 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro -DNDEBUG -fno-inline -Os -pipe -mcpu=cortex-a53 -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -ffile-prefix-map=/builder/shared-workdir/build/sdk/build_dir/target-aarch64_cortex-a53_musl/Python-3.9.6=Python-3.9.6 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro -DNDEBUG -fno-inline -I/builder/shared-workdir/build/sdk/staging_dir/toolchain-aarch64_cortex-a53_gcc-8.4.0_musl/usr/include -I/builder/shared-workdir/build/sdk/staging_dir/toolchain-aarch64_cortex-a53_gcc-8.4.0_musl/include/fortify -I/builder/shared-workdir/build/sdk/staging_dir/toolchain-aarch64_cortex-a53_gcc-8.4.0_musl/include -fPIC -Ic-ext -Izstd -I/usr/include/python3.9 -c c-ext/backend_c.c -o build/temp.linux-aarch64-3.9/c-ext/backend_c.o -DZSTD_SINGLE_FILE -DZSTDLIB_VISIBILITY= -DZDICTLIB_VISIBILITY= -DZSTDERRORLIB_VISIBILITY= -fvisibility=hidden
gcc: error: unrecognized command line option '-ffile-prefix-map=/builder/shared-workdir/build/sdk/build_dir/target-aarch64_cortex-a53_musl/Python-3.9.6=Python-3.9.6'
gcc: error: unrecognized command line option '-ffile-prefix-map=/builder/shared-workdir/build/sdk/build_dir/target-aarch64_cortex-a53_musl/Python-3.9.6=Python-3.9.6'
gcc: error: unrecognized command line option '-ffile-prefix-map=/builder/shared-workdir/build/sdk/build_dir/target-aarch64_cortex-a53_musl/Python-3.9.6=Python-3.9.6'
error: command '/usr/bin/gcc' failed with exit code 1
erdoukki commented 3 years ago
root@ultra:~/# pip install zstandard
Looking in indexes: https://pypi.org/simple, https://packagecloud.io/crowdsec/crowdsec/pypi/simple
Collecting zstandard
  Downloading zstandard-0.15.2.tar.gz (1.0 MB)
     |████████████████████████████████| 1.0 MB 376 kB/s 
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Building wheels for collected packages: zstandard
  Building wheel for zstandard (PEP 517) ... error
  ERROR: Failed building wheel for zstandard
Failed to build zstandard
ERROR: Could not build wheels for zstandard which use PEP 517 and cannot be installed directly
root@ultra:~# uname -ar
Linux ultra 5.4.124 #0 SMP Sun Jun 13 22:02:19 2021 aarch64 GNU/Linux
root@ultra:~# gcc --version
gcc (OpenWrt GCC 7.4.0) 7.4.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
erdoukki commented 3 years ago

https://forum.openwrt.org/t/python3-pip3-aarch64-help/74685

danieldjewell commented 2 years ago

I just built the master branch on aarch64 (Termux on Android - on my phone) ... Worked just fine. No errors. (The title of this issue should be "Cannot build on OpenWRT")

This appears to be an issue with the build toolchain on openwrt. I would guess that the python CFLAGS are being picked up from when it was built (which probably wasn't on-device) and those aren't appropriate flags for building on-device. Also check your CFLAGS environment variable.

Try cloning the repository (git clone https://github.com/indygreg/python-zstandard) and running python3 setup.py build from the repo root. That usually gives far more debug info than from running pip install

erdoukki commented 2 years ago

(The title of this issue should be "Cannot build on OpenWRT")

Done !

root@ultra:~/python-zstandard/python-zstandard# echo $CFLAGS
<EMPTY>
root@ultra:~/python-zstandard/python-zstandard# gcc --version
gcc (OpenWrt GCC 7.4.0) 7.4.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Looks like an unsupported switch by the OpenWrt GCC :

gcc: error: unrecognized command line option '-ffile-prefix-map=/builder/shared-workdir/build/sdk/build_dir/target-aarch64_cortex-a53_musl/Python-3.9.6=Python-3.9.6'
root@ultra:~/python-zstandard# cd python-zstandard/
root@ultra:~/python-zstandard/python-zstandard# python3 setup.py build
generating build/zstandard/_cffi.c
regenerated: 'build/zstandard/_cffi.c'
running build
running build_py
creating build/lib.linux-aarch64-3.9
creating build/lib.linux-aarch64-3.9/zstandard
copying zstandard/backend_cffi.py -> build/lib.linux-aarch64-3.9/zstandard
copying zstandard/__init__.py -> build/lib.linux-aarch64-3.9/zstandard
copying zstandard/__init__.pyi -> build/lib.linux-aarch64-3.9/zstandard
copying zstandard/py.typed -> build/lib.linux-aarch64-3.9/zstandard
running build_ext
building 'zstandard.backend_c' extension
creating build/temp.linux-aarch64-3.9
creating build/temp.linux-aarch64-3.9/c-ext
gcc -Wno-unused-result -Wsign-compare -DNDEBUG -Os -pipe -mcpu=cortex-a53 -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -ffile-prefix-map=/builder/shared-workdir/build/sdk/build_dir/target-aarch64_cortex-a53_musl/Python-3.9.6=Python-3.9.6 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro -Os -pipe -mcpu=cortex-a53 -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -ffile-prefix-map=/builder/shared-workdir/build/sdk/build_dir/target-aarch64_cortex-a53_musl/Python-3.9.6=Python-3.9.6 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro -DNDEBUG -fno-inline -Os -pipe -mcpu=cortex-a53 -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -ffile-prefix-map=/builder/shared-workdir/build/sdk/build_dir/target-aarch64_cortex-a53_musl/Python-3.9.6=Python-3.9.6 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro -DNDEBUG -fno-inline -I/builder/shared-workdir/build/sdk/staging_dir/toolchain-aarch64_cortex-a53_gcc-8.4.0_musl/usr/include -I/builder/shared-workdir/build/sdk/staging_dir/toolchain-aarch64_cortex-a53_gcc-8.4.0_musl/include/fortify -I/builder/shared-workdir/build/sdk/staging_dir/toolchain-aarch64_cortex-a53_gcc-8.4.0_musl/include -fPIC -Ic-ext -Izstd -I/usr/include/python3.9 -c c-ext/backend_c.c -o build/temp.linux-aarch64-3.9/c-ext/backend_c.o -DZSTD_SINGLE_FILE -DZSTDLIB_VISIBILITY= -DZDICTLIB_VISIBILITY= -DZSTDERRORLIB_VISIBILITY= -fvisibility=hidden
gcc: error: unrecognized command line option '-ffile-prefix-map=/builder/shared-workdir/build/sdk/build_dir/target-aarch64_cortex-a53_musl/Python-3.9.6=Python-3.9.6'
gcc: error: unrecognized command line option '-ffile-prefix-map=/builder/shared-workdir/build/sdk/build_dir/target-aarch64_cortex-a53_musl/Python-3.9.6=Python-3.9.6'
gcc: error: unrecognized command line option '-ffile-prefix-map=/builder/shared-workdir/build/sdk/build_dir/target-aarch64_cortex-a53_musl/Python-3.9.6=Python-3.9.6'
error: command '/usr/bin/gcc' failed with exit code 1
indygreg commented 2 years ago

The next release of this project will provide Linux aarch64 wheels. That should hopefully make build-from-source problems like this disappear.

Will the new aarch64 wheels (e.g. zstandard-0.16.0.dev0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl) be sufficient for your use case or do you need another binary wheel format to be produced?