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

REGR: cross-compilation fails for osx-arm64 with meson 1.5.0 #13403

Closed
h-vetinari opened this issue Jul 11, 2024 · 13 comments · Fixed by #13411
Closed

REGR: cross-compilation fails for osx-arm64 with meson 1.5.0 #13403

h-vetinari opened this issue Jul 11, 2024 · 13 comments · Fixed by #13411
Milestone

Comments

@h-vetinari
Copy link
Contributor

Describe the bug
A previously (with meson 1.4.2) working build for osx-arm64 broke with the release of meson 1.5.0, apparently trying to run sanitycheckc_cross.exe with a wrong architecture

The Meson build system
Version: 1.5.0
Source dir: /Users/runner/miniforge3/conda-bld/matplotlib-suite_1720666814590/work
Build dir: /Users/runner/miniforge3/conda-bld/matplotlib-suite_1720666814590/work/builddir
Build type: cross build
Program python3 found: YES (/Users/runner/miniforge3/conda-bld/matplotlib-suite_1720666814590/_build_env/bin/python3)
Project name: matplotlib
Project version: 3.9.1

meson.build:1:0: ERROR: Could not invoke sanity test executable: [Errno 86] Bad CPU type in executable: '/Users/runner/miniforge3/conda-bld/matplotlib-suite_1720666814590/work/builddir/meson-private/sanitycheckc_cross.exe'.

Note that we're cross-compiling three different architectures (the other two being linux-aarch64 and linux-ppc64le, both compiled from linux-64), and osx-arm64 is the only one that broke.

More specifically, the cleaned-up build invocation looks as follows

mkdir builddir
$PREFIX/bin/python -m mesonbuild.mesonmain setup builddir \
    --buildtype release --prefix=$PREFIX -Dlibdir=lib \
    --cross-file $BUILD_PREFIX/meson_cross_file.txt \
    --pkg-config-path=$PREFIX/lib/pkgconfig \
    -Dsystem-freetype=true -Dsystem-qhull=true

and the contents of meson_cross_file.txt are:

[host_machine]
system = 'darwin'
cpu = 'arm64'
cpu_family = 'aarch64'
endian = 'little'
[binaries]
cmake = '$BUILD_PREFIX/bin/cmake'
pkg-config = '$BUILD_PREFIX/bin/pkg-config'

To Reproduce

Build the recipe in https://github.com/conda-forge/matplotlib-feedstock

Reverting back to meson <1.5 causes the build to succeed.

Expected behavior
Build succeeds

system parameters

  • Is this a cross build or just a plain native build (for the same computer)?
    • cross build
  • what operating system (e.g. MacOS Catalina, Windows 10, CentOS 8.0, Ubuntu 18.04, etc.)
    • build environment is macOS-12 image (x64) from azure, target is macOS>=11.0 (arm64)
  • what Python version are you using e.g. 3.8.0
    • 3.9-3.12
  • what meson --version
    • 1.5.0
  • what ninja --version if it's a Ninja build
    • 1.12.1
@eli-schwartz
Copy link
Member

eli-schwartz commented Jul 11, 2024

Would you be able to bisect this by installing different git commits of meson into that feedstock? Nothing obviously jumps out at me as related to this, except maybe c107624 (although that commit does look suspiciously related ;)).

@h-vetinari
Copy link
Contributor Author

although that commit does look suspiciously related ;)

Your suspicion was spot on. I tried this in conda-forge/matplotlib-feedstock#398:

@h-vetinari h-vetinari changed the title REGR: cross-compilation fails on osx-arm64 with meson 1.5.0 REGR: cross-compilation fails for osx-arm64 with meson 1.5.0 Jul 11, 2024
@eli-schwartz
Copy link
Member

Thanks for verifying that. @xclaesse as the author of that commit, can you take a look at this?

(It is bedtime now so that's all the debugging I will be doing for now.)

@h-vetinari
Copy link
Contributor Author

Originally I worried that this would have a huge blast radius for conda-forge (well, for those packages being built by meson at least), as that's one of our main architectures, and we only cross-compile it (due to lack of native agents in azure).

I restarted conda-forge/scipy-feedstock#269 1, and to my surprise, this doesn't run into the same issue:

+ meson setup $SRC_DIR $SRC_DIR/builddir -Dbuildtype=release \
    -Db_ndebug=if-release -Db_vscrt=md -Dblas=blas -Dlapack=lapack -Duse-g77-abi=true \
    --prefix=$PREFIX -Dlibdir=lib --cross-file $BUILD_PREFIX/meson_cross_file.txt \
    --native-file=$SRC_DIR/builddir/meson-python-native-file.ini
The Meson build system
Version: 1.5.0
Source dir: $SRC_DIR
Build dir: $SRC_DIR/builddir
Build type: cross build
Project name: scipy
Project version: 1.14.0
C compiler for the host machine: arm64-apple-darwin20.0.0-clang (clang 16.0.6 "clang version 16.0.6")
C linker for the host machine: arm64-apple-darwin20.0.0-clang ld64 711

One difference that stands out is --native-file, though I don't understand under what conditions this is created; it's not part of the build script, and it doesn't seem to be created in scipy itself either (though there's a cross-compiled setting in __config__.py.in). CC @rgommers

conda-forge/scikit-learn-feedstock#270 similarly passes (and sets --native-file). So it doesn't seem to affect everything, but I don't understand the conditions under which failure happens or not.

Footnotes

  1. originally restricted to windows as it was meant only for debugging add initial support for llvm-flang #13323

@rgommers
Copy link
Contributor

One difference that stands out is --native-file, though I don't understand under what conditions this is created;

--native-file is the setup argument coming from meson-python, to ensure that the native Python interpreter Meson picks is actually the right one (i.e., the one in the environment for which meson-python itself is installed). It's always passed when you build an sdist or wheel with meson-python.

@rgommers
Copy link
Contributor

@h-vetinari this line is wrong: https://github.com/conda-forge/matplotlib-feedstock/blob/414fc00e6cde964337d84b5234673a647cc22c00/recipe/build_base.sh (both because meson-python may redo the configure stage, and because invoking python -m mesonbuild.mesonmain isn't supported by Meson AFAIK). If you adapt it to what's used in scipy-feedstock, that may help.

@h-vetinari
Copy link
Contributor Author

Thanks a lot @rgommers; I fixed the double-execution in conda-forge/matplotlib-feedstock#398 (now just going through meson-python as it should), but the issue persists with 1.5.0, and in fact the same result for the specific commits as above (links to CI logs have been updated below):

lazka added a commit to lazka/meson that referenced this issue Jul 11, 2024
c107624 changed the logic in multiple
places, in particular it looks like it was assumed that is_cross is always
the same as need_exe_wrapper(), but that's not true.

Also the commit only talks about mypy, so this was definitely not intended.

This reverts all the cases where need_exe_wrapper() was introduced back to
is_cross.

The change in backends.py could be a correct simplification, but I don't know
the code base enough, so reverting that too.

See mesonbuild#13403 and mesonbuild#13410
@lazka
Copy link
Contributor

lazka commented Jul 11, 2024

Here is a potential fix: #13411

@eli-schwartz eli-schwartz linked a pull request Jul 11, 2024 that will close this issue
@h-vetinari
Copy link
Contributor Author

Thanks a lot @lazka! 🙏

I've tested your PR in conda-forge/matplotlib-feedstock#398 and it works again! 🥳

@thesamesam thesamesam added this to the 1.5.1 milestone Jul 12, 2024
eli-schwartz pushed a commit that referenced this issue Jul 16, 2024
c107624 changed the logic in multiple
places, in particular it looks like it was assumed that is_cross is always
the same as need_exe_wrapper(), but that's not true.

Also the commit only talks about mypy, so this was definitely not intended.

This reverts all the cases where need_exe_wrapper() was introduced back to
is_cross.

The change in backends.py could be a correct simplification, but I don't know
the code base enough, so reverting that too.

See #13403 and #13410
@h-vetinari
Copy link
Contributor Author

Is there any approximate timeline for a 1.5.1 release?

@eli-schwartz
Copy link
Member

There are two more bugs open on the 1.5.1 milestone, one of them is going to be investigated and hopefully fixed tomorrow. I'd like to get either or both of them fixed in the next couple of days, then release 1.5.1.

eli-schwartz pushed a commit that referenced this issue Jul 25, 2024
c107624 changed the logic in multiple
places, in particular it looks like it was assumed that is_cross is always
the same as need_exe_wrapper(), but that's not true.

Also the commit only talks about mypy, so this was definitely not intended.

This reverts all the cases where need_exe_wrapper() was introduced back to
is_cross.

The change in backends.py could be a correct simplification, but I don't know
the code base enough, so reverting that too.

See #13403 and #13410

(cherry picked from commit d9e2dd6)
@lazka
Copy link
Contributor

lazka commented Jul 27, 2024

@h-vetinari 1.5.1 is out

@h-vetinari
Copy link
Contributor Author

I saw, thanks a lot for everyone's effort!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants