-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
BUG: f2py threads.h on MacOS 14.x may need a shim? #27718
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
I think it's time to throw away this code, it's way too hacky. We should be able to define numpy/numpy/_core/include/numpy/npy_common.h Lines 116 to 128 in fbffb8c
|
Hmm, not so easy unfortunately, that requires compile-time checks: Lines 246 to 271 in fbffb8c
That's more robust, but we can't require all |
@tylerjereddy is the only difference between success and failure using GCC 14 vs. 13 on your machine? |
@rgommers no, I was able to confirm that both of those GCC versions fail identically due to missing
I often use a fixed GNU FC version, but also just confirmed this also has the same behavior: |
With conda-forge compilers I currently use, I get this with both GCC 12.3.0 on Linux and Clang 16.0.6 on macOS 14.7:
Gating things only on OS version is clearly not right. |
Agreed, I don't replicate the problem with AppleClang (I only noticed it because MacPorts folks were complaining about GNU toolchain) so full suppression of the header include on OS 14.x seems a bit aggressive. I don't know how much work it would be to get the guard "just right" (investigate clang version and GNU version ranges?). |
It's impossible to get it "just right" without build-time compiler checks AFAICT. I think what we should do (similar to what I suggested as workaround in #19437 (comment)) is to document how to do the compiler checks in the package using Does anyone see a cleaner solution? |
|
Yes, this is correct indeed, and the bug is that I think this was probably always broken, but no one noticed because they weren't yet compiling with |
Looks like the C standards committee saw the error of its ways - in C23 |
Discussion with gcc upstream: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53769
I think this is just untypical to use this header. GCC supports emulated TLS on systems where it is not supported otherwise (and recent macOS support TLS in the OS). |
You mean GCC and/or macOS recognize |
I think gcc normally uses this one, yes. Re emutls, I do not know internals of the implementation, but gcc have some docs on it. |
Is there any real value in using "real" gcc to build things on macOS? As soon as your code uses macOS headers, you hit the infamous "blocks" feature, not implemented in gcc. (e.g. SageMath stopped using gcc on macOS ages ago). |
@dimpase Blocks are only used in ObjC, which is a minuscule part of open-source software. (Besides, gcc upstream plans to support blocks somewhat soon, though I am not aware of intended timeline.) Also it is good for code quality. GCC is one of the two major compilers with its own C++ runtime. Quality code should work with it on whatever system, at least as long as it is C/C++/Fortran. |
No, macOS headers have blocks in plain C as well. Anything related to cryptography on macOS will need to use them; e.g. you can't even build a fully functioning Python using gcc only (you'd hit problems with urllib, IIRC). I certainly agree with the code quality point. |
I do not know how is “fully” defined, but I have certainly built Python with gcc on macOS, and it was functioning.
You mean their cryptography? That is unsurprising, since it uses ObjC (used at least, and perhaps nothing much changed). But there are plenty of open-source cryptography solutions not relying on Apple ObjC extensions. |
how about installing packages from PyPI ? (That is, |
I use MacPorts, I do not think anything fails with Python as such or C/C++ code in Python ports. Rust needs LLVM, so that won’t work with gcc, and there a few select packages which heavily depend on Apple SDK (and perhaps Apple ObjC syntax). BTW, modern gcc supports |
in theory at least, clang supports using |
In fact Apple clang did, I think up to 10.8 |
Isn't this the default on Linux, to use One way or another, |
There is certainly value in building with GCC on macOS, it should work more robustly. For SciPy we rely on Gfortran - no alternative, since Apple doesn't ship a Fortran compiler. I'll have a go at fixing this up now in both NumPy and SciPy. |
sure, that's what everyone does, there is no reliable open-source alternative, as far as I know. |
Attempted fix in gh-27729. @barracuda156 or @tylerjereddy it'd be useful if one of you could confirm that this indeed closes the issue. |
@rgommers For some reason I do not get an error with For |
@barracuda156 that makes sense; |
@rgommers Wait, I did not yet test |
Yes, this indeed. The
This isn't an option, since the patch only changes the f2py-generated C code that is used by |
Turns out that
This should just pick The patch does not apply onto 1.26.4, and I could try to build a suitably newer version of |
@ rgommers Or will it suffice for the testing purpose just to edit manually the script which Instead of passing |
@barracuda156 yes manually editing |
Running the build now, will update in a while. |
@rgommers Yes, it works as expected. Thank you! |
Great - and thanks for all your help! |
Instead of adding __STDC_NO_THREADS__ flag into scipy, we borrow upstream fix for numpy f2py module which scipy uses. See: numpy/numpy#27718
Instead of adding __STDC_NO_THREADS__ flag into scipy, we borrow upstream fix for numpy f2py module which scipy uses. See: numpy/numpy#27718
PS. I don't know what makes you think that blocks are only used in ObjC (in macOS or in general). |
This is a continuing source of issues, therefore in this commit we: - stop using `threads.h` completely, - better document what is happening, and - ensure the f2py TLS define stays unchanged so users can override it at build time by passing the define as a compile flag. Closes numpygh-27718
Downstream in SciPy (see: scipy/scipy#21830), when using GNU toolchain version
14.2.0
from homebrew, I consistently see a SciPy build failure on MacOS ARM because ofscipy/linalg/_flapackmodule.c:90:10: fatal error: threads.h: No such file or directory
.I made a temporary hack (below) to my local NumPy/
f2py
source that fixed the SciPy build issue. I'm not sure if that's exactly what we'd want to do, though GNU docs on the matter do suggest thatthreads.h
is missing on MacOS 14. This part off2py
has caused pain a few times in the past per gh-19437 and gh-24761.The text was updated successfully, but these errors were encountered: