Skip to content
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

Cross compiling build error with fortran, MacOS-arm64, and cibuildwheel. #548

Closed
joanibal opened this issue Dec 5, 2023 · 7 comments
Closed
Labels
question Further information is requested

Comments

@joanibal
Copy link

joanibal commented Dec 5, 2023

Hello,

I'm trying to create apple silicon python wheels for my application using cibuildwheel, meson-python, and a macos-12 github runner.
However, I can not seem to figure out how to do this.

In particular I can't get passed this error

../meson.build:79:0: ERROR: 'fortran' compiler binary not defined in cross or native file

Indeed the meson cross file does not mention fortran and it would seem that it is hard coded here.
I'm new to meson, so my apologies if I overlooked something basic.

   [binaries]
   c = ['cc', '-arch', 'arm64']
   cpp = ['c++', '-arch', 'arm64']
   objc = ['cc', '-arch', 'arm64']
   objcpp = ['c++', '-arch', 'arm64']
   [host_machine]
   system = 'darwin'
   cpu = 'arm64'
   cpu_family = 'aarch64'
   endian = 'little'

Most of the CI I have setup for building wheels is based on Scipy since it has a similar set of dependencies (LAPACK and gfortran). I have tried to mirror what they have done to create MacOS-arm64 wheels, but their process for MacOS-arm64 wheels was much less clear to me.

Thank you for any help!

@rgommers
Copy link
Contributor

rgommers commented Dec 5, 2023

Most of the CI I have setup for building wheels is based on Scipy since it has a similar set of dependencies (LAPACK and gfortran). I have tried to mirror what they have done to create MacOS-arm64 wheels, but their process for MacOS-arm64 wheels was much less clear to me.

A quick hint on this: SciPy uses Cirrus CI, which provides native macOS arm64 runners. There's some cibuildwheel config at the bottom of its pyproject.toml, and then:

@dnicolodi
Copy link
Member

Does Xcode come with a fortran compiler capable of cross compilation?

@joanibal
Copy link
Author

joanibal commented Dec 5, 2023

Thanks @rgommers , I hadn't realized that Cirrus Ci had macOS arm64 runners. I was hesitant to add another CI provider, but I now see that it will likely be much easier than cross compiling on macOS.

@joanibal
Copy link
Author

joanibal commented Dec 5, 2023

Does Xcode come with a fortran compiler capable of cross compilation?

I'm new to apple, but I don't believe Xcode comes with any Fortran compiler. I was planning on using gfortran for that reason.
However, I now see that I had taken for granted that gfortran could cross compile from macOS x86_64 to macOS arm64.
From what I can find here, even if cross compiling is possible getting a capable gfortran compiler seems complicated.

I'm going to close this issue since I see that it is best to avoid cross compiling altogether in this case. Thank you for your help!

@joanibal joanibal closed this as completed Dec 5, 2023
@rgommers
Copy link
Contributor

rgommers commented Dec 6, 2023

Fortran compilers are indeed a major issue, on macOS and even more on Windows. Apple doesn't provide one, and the Gfortran builds one can find try to keep compatibility with Apple's Clang, but there are regularly issues when there's an OS update. They also require specific macOS SDK versions, and for wheels require bundling libgcc, libgfortran and libquadmath (delocate will take care of that, but to be a good citizen you should note in your license that these are LGPL components).

This is all messy, and I recommend looking at this very recent PR that streamlined this as much as possible: numpy/numpy#25253.

@rgommers rgommers added the question Further information is requested label Dec 6, 2023
@joanibal
Copy link
Author

joanibal commented Dec 7, 2023

Switching to Cirrus CI and following the configuration files from Scipy/Numpy fixed my issues and I can now build wheels for macOS-arm64. Thanks for your help!

Now that macOS-arm64 is in a good place, I'll have to give the window wheels another shot. I got close before (again basically just coping the workflow from Scipy), but got stuck on linking errors related to "relocation truncated to fit: IMAGE_REL_AMD64_REL32 against symbol". I see that you recently modified the meson.build files in Scipy for windows, so I'll make the corresponding changes in my project to see if that does the trick.

Thanks again for all your help!

@rgommers
Copy link
Contributor

That sounds like progress, thanks for the update @joanibal. The "relocation truncated" issue doesn't ring a bell for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants