[Numpy-discussion] NumPy cross-compilation on macOS host

Jakub Piotr Cłapa jpc-ml at zenburn.net
Fri Aug 23 05:27:39 EDT 2019


Hi,

I spent some time trying to cross-compile NumPy for Linux ARM64 on a 
macOS host as part of an OpenWRT compilation [1]. It was not so bad but 
certainly not trivial and I was wondering if we could use my experience 
to help streamline the process.

I encountered two challenges:

1. Python distutils did not allow me to provide a proper cross-ranlib 
program path. I opened an issue for this on the Python bug tracker [2].

2. numpy distutils scripts check sys.platform in many places. 
sys.platform returns the platform on which compilation occurs (darwin in 
my case) which in case of cross-compilation is not the one on which the 
code will be run (linux). This of course results in invalid compiler and 
linker flags.

I made a quick'n'dirty fix [3] and got numpy to compile and run 
correctly (but I have yet to run the full test suite). Of course this is 
not a proper way to solve this so I was hoping to get some feedback on 
the preferred/best way. I did not find any info about an official way to 
do this with distutils.

One idea (from @commodo on GitHub) would be to just change my hardcoded 
string ("Linux") to something like this:

target_platform = os.getenviron(“TARGET_PLATFORM”, sys.platform)

It could also be further refactored by moving it to a single place but 
while certainly more elegant and "proper" it may ultimately make it less 
readable and harder to follow. I am also unsure where would be the best 
place to put it and how to pass it around to other modules.

[1]: https://github.com/openwrt/packages/pull/9797
[2]: https://bugs.python.org/issue37916
[3]: 
https://github.com/openwrt/packages/pull/9797/commits/e701e122fb9c78d5cecffb88c1d750178a239083#diff-1ea8d839590bcdc406854d3998a96704


More information about the NumPy-Discussion mailing list