Is there a way to cross compile cython project with zig cc. According to this blog zig can cross compile. An example which cross compiles cython hello world would be great.
Asked
Active
Viewed 496 times
0
-
1There is a possible starting point: https://stackoverflow.com/a/70474888/5769463 which uses using MinGW-w64 for cross compilation. Never used zig cc, so your millage may vary but the overall framework should be very similar. – ead Jul 08 '22 at 04:32
2 Answers
1
You'd need the python headers for the target.
Once you have them, you should be able to run:
# Compile .pyx to .c
cython helloworld.pyx
# Use zig to compile+link
zig build-lib -dynamic -target x86_64-windows \
-I mingw-w64-x86_64-python/mingw64/include/python3.10/ \
-lc \
mingw-w64-x86_64-python/mingw64/bin/libpython3.10.dll \
helloworld.c

daurnimator
- 4,091
- 18
- 34
0
All I had to do was specify CC="zig cc"
in the same line as my cythonize
command with Cython==3.0.0b3
. For example:
CC="zig cc" cythonize -i -3 --no-docstrings ./my_cython_module.pyx
This produced the .c
and .so
files.
Fwiw, I had installed Zig as sudo snap install --classic --beta zig
.

Asclepius
- 57,944
- 17
- 167
- 143