<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Aug 23, 2019 at 2:28 AM Jakub Piotr Cłapa <<a href="mailto:jpc-ml@zenburn.net">jpc-ml@zenburn.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi,<br>
<br>
I spent some time trying to cross-compile NumPy for Linux ARM64 on a <br>
macOS host as part of an OpenWRT compilation [1]. It was not so bad but <br>
certainly not trivial and I was wondering if we could use my experience <br>
to help streamline the process.<br></blockquote><div><br></div><div>Thanks, that would be great!</div><div><br></div><div>We have quite some issues with cross-compilation, and usually they're hard to resolve (plus it's not something we officially support - but there's a clear need for improvement). Note that conda is also a cross-compiler (to the same system), sometimes worth looking into how it deals with (numpy.)distutils issues.<br></div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
I encountered two challenges:<br>
<br>
1. Python distutils did not allow me to provide a proper cross-ranlib <br>
program path. I opened an issue for this on the Python bug tracker [2].<br></blockquote><div><br></div><div>That seems like a straightforward enough patch. distutils isn't well-maintained but hopefully that gets merged soon. If it doesn't get responses in a couple of weeks, please feel free to ping me and I can review/test (I'm not a core Python dev, but it may help push it forwards).<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
2. numpy distutils scripts check sys.platform in many places. <br>
sys.platform returns the platform on which compilation occurs (darwin in <br>
my case) which in case of cross-compilation is not the one on which the <br>
code will be run (linux). This of course results in invalid compiler and <br>
linker flags.<br>
<br>
I made a quick'n'dirty fix [3] and got numpy to compile and run <br>
correctly (but I have yet to run the full test suite). Of course this is <br>
not a proper way to solve this so I was hoping to get some feedback on <br>
the preferred/best way. I did not find any info about an official way to <br>
do this with distutils.<br>
<br>
One idea (from @commodo on GitHub) would be to just change my hardcoded <br>
string ("Linux") to something like this:<br>
<br>
target_platform = os.getenviron(“TARGET_PLATFORM”, sys.platform)<br></blockquote><div><br></div><div>That seems reasonable enough. Prefixing that name with NPY_ would be good, to not get accidental clashes.</div><div><br></div><div>I'm not sure if there's a more standard/preferred way, I haven't come across it in distutils. There's some issues with reasonably detailed discussion for SciPy - this one may be useful: <a href="https://github.com/scipy/scipy/issues/8571">https://github.com/scipy/scipy/issues/8571</a></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
It could also be further refactored by moving it to a single place but <br>
while certainly more elegant and "proper" it may ultimately make it less <br>
readable and harder to follow. I am also unsure where would be the best <br>
place to put it and how to pass it around to other modules.<br></blockquote><div><br></div><div>Keeping all platform comparisons where they are now seems right. Just need one central place to parse NPY_TARGET_PLATFORM - perhaps in numpy/distutils/misc_util.py</div><div><br></div><div>Cheers,<br></div><div>Ralf</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
[1]: <a href="https://github.com/openwrt/packages/pull/9797" rel="noreferrer" target="_blank">https://github.com/openwrt/packages/pull/9797</a><br>
[2]: <a href="https://bugs.python.org/issue37916" rel="noreferrer" target="_blank">https://bugs.python.org/issue37916</a><br>
[3]: <br>
<a href="https://github.com/openwrt/packages/pull/9797/commits/e701e122fb9c78d5cecffb88c1d750178a239083#diff-1ea8d839590bcdc406854d3998a96704" rel="noreferrer" target="_blank">https://github.com/openwrt/packages/pull/9797/commits/e701e122fb9c78d5cecffb88c1d750178a239083#diff-1ea8d839590bcdc406854d3998a96704</a><br>
_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@python.org" target="_blank">NumPy-Discussion@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/numpy-discussion" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/numpy-discussion</a><br>
</blockquote></div></div>