-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
BUG: Cannot cross-compile Numpy to OpenHarmony OS (AArch64) platform. #28861
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The cross-file approach is preferred I think. The cross build is correctly configured:
The first failure:
The file extension for Python extension modules is I think the fix is to add The more robust but slower way of doing it is running the build as a native build under QEMU rather than as a cross build. |
@rgommers Really, really, really thank you! The problem that has been bothering me for almost a week is finally solved! Following your solution, I changed the meson cross file (specifying python as cross-python in crossenv, and changing the linking options that were problematic before): [constants]
ohos_sdk = '/home/xhw/Desktop/OH/oh-cross-toolchain/ohos-sdk/14'
toolchain = ohos_sdk / 'native/llvm/bin'
sysroot = ohos_sdk / 'native/sysroot'
host_cpu = 'aarch64'
host_arch = 'aarch64'
dist_root = '/home/xhw/Desktop/OH/oh-edu-python/dist.aarch64'
common_flags = ['--sysroot=' + sysroot, '--target=' + host_cpu + '-linux-ohos']
common_c_flags = ['-fPIC', '-D__MUSL__=1', '-I' + dist_root/'include', '-I' + dist_root/'include/lzma', '-I' + dist_root/'include/ncursesw', '-I' + dist_root/'include/readline', '-I' + dist_root/'ssl/include']
common_ld_flags = ['-fuse-ld=lld', '-L' + dist_root/'lib', '-L' + dist_root/'ssl/lib64', '-lpython3.11']
[built-in options]
c_args = common_flags + common_c_flags
cpp_args = common_flags + common_c_flags
c_link_args = common_flags + common_ld_flags
cpp_link_args = common_flags + common_ld_flags
[properties]
cmake_toolchain_file = ohos_sdk / 'native/build/cmake/ohos.toolchain.cmake'
sizeof_long_double = 8
longdouble_format = 'IEEE_DOUBLE_LE'
[binaries]
c = toolchain / 'clang'
cpp = toolchain / 'clang++'
python = '/home/xhw/Desktop/OH/oh-python-pkgs/crossenv_aarch64/cross/bin/python3'
cython = ''
cython3 = cython
as = toolchain / 'llvm-as'
ld = toolchain / 'ld.lld'
c_ld = ld
cpp_ld = ld
lld = toolchain / 'ld.lld'
strip = toolchain / 'llvm-strip'
ranlib = toolchain / 'llvm-ranlib'
objdump = toolchain / 'llvm-objdump'
objcopy = toolchain / 'llvm-objcopy'
readelf = toolchain / 'llvm-readelf'
nm = toolchain / 'llvm-nm'
ar = toolchain / 'llvm-ar'
profdata = toolchain / 'llvm-profdata'
[host_machine]
system = 'ohos'
kernel = 'linux'
cpu_family = host_cpu
cpu = host_cpu
endian = 'little' and compiled with crossenv. I ran the script as follows: $BUILD_PIP install crossenv
$BUILD_PYTHON -m crossenv \
$HOST_PYTHON \
crossenv_aarch64
. crossenv_aarch64/bin/activate
cd numpy
VENDORED_MESON=${p_DIR}/numpy/vendored-meson/meson/meson.py
python ${VENDORED_MESON} setup --reconfigure --prefix=${p_DIR}/dist --cross-file ../ohos-build.meson.ini build-ohos
cd build-ohos
python ${VENDORED_MESON} compile
python ${VENDORED_MESON} install the problem was solved! |
Great, glad you solved it and thanks for sharing the solution! |
Worth sticking into a wiki somewhere? |
We have docs on cross-compilation, I'll make a quick update to that. |
Problem: Cannot cross-compile Numpy to OpenHarmony OS (AArch64) platform.
Background
Hello! I currently need to cross-compile the numpy library to the OpenHarmony AArch64 platform. It uses a modified linux kernel and musl libc, so I can't just download the officially compiled binary.
But I'm having a lot of problems compiling it.
Checkings
Before trying to cross-compile numpy, I checked the following:
Try 1: Use Crossenv + pip
I then proceeded to prepare the environment as follows:
The log file for the above command is here: Log 1: Paste Bin.
In the crossenv environment I executed the following command:
And the log file: Log 2: Paste Bin;
Looks like it worked, right? The binary suffix of the output indicates that the architecture is correct.
But this is problematic:
readelf
outputs thex86_64
architecture instead:This method didn't work, so I tried another.
Try 2: Use meson + Cross Compile
I then quit the crossenv environment, downloaded the numpy source code and tried again:
I defined my own
ohos-build.meson.ini
configuration file as follows:It still failed, the logs are as follows (it seems that x86_64 was incorrectly used as the target platform):
Log 3: Paste Bin;
It seems that vendored-meson can't have failed to deal with the cross-compilation case?
So how should I cross-compile numpy correctly? Thanks a lot!
The text was updated successfully, but these errors were encountered: