-
Notifications
You must be signed in to change notification settings - Fork 0
Add numpy build support with Android/iOS cross-compilation (patch-free) #18
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
Changes from all commits
a038d4c
e3ae53b
3170b8e
9991bd8
0613c39
b5cbab5
e53610d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,2 +1,101 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| package: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: numpy | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: numpy | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # version: "" # Optional: leave empty to use latest | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Pip dependencies needed for building numpy | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Based on void-linux and conda-forge configurations: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # - Cython: Required for building numpy's extension modules | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # - meson-python: Build backend (numpy uses meson build system since 1.26+) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # - build: PEP 517 build frontend (conda-forge uses python -m build) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pip_dependencies: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - Cython | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - meson-python | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - build | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| host_dependencies: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - python3-dev | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - cmake | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Environment variables for the build | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # PKG_CONFIG="" prevents finding host system libraries during cross-compilation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # This is critical for mobile cross-compilation to avoid linking against host libs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cibw_environment: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| LDFLAGS: "-lm" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # PKG_CONFIG: "" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Build script to set up cross-compilation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # For mobile platforms, we create a builddir and meson cross file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cibw_before_all: | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Create build directory following conda-forge pattern | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mkdir -p builddir | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Setting up numpy build for $CIBW_PLATFORM..." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Create meson cross file for mobile platforms | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [ "$CIBW_PLATFORM" = "android" ] || [ "$CIBW_PLATFORM" = "ios" ]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Building for mobile platform: $CIBW_PLATFORM with architecture: $CIBW_ARCHS" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Using no-BLAS mode for simplified mobile builds" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Determine CPU architecture for meson cross file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case "$CIBW_ARCHS" in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| arm64*|aarch64) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CPU="aarch64" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CPU_FAMILY="aarch64" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ;; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| x86_64) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CPU="x86_64" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CPU_FAMILY="x86_64" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ;; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| armv7*|arm) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CPU="armv7" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CPU_FAMILY="arm" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ;; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| x86|i686) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CPU="i686" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CPU_FAMILY="x86" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ;; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| *) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CPU="$CIBW_ARCHS" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CPU_FAMILY="$CIBW_ARCHS" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ;; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| esac | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Create meson cross file with sanity checks disabled | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Using /tmp for cross-platform compatibility | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CROSS_FILE="/tmp/numpy_meson_cross.txt" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cat > "$CROSS_FILE" << 'CROSSEOF' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [binaries] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| c = '${CC:-cc}' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cpp = '${CXX:-c++}' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [host_machine] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| system = '$CIBW_PLATFORM' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cpu_family = '$CPU_FAMILY' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cpu = '$CPU' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| endian = 'little' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [properties] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| skip_sanity_check = true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| longdouble_format = 'IEEE_DOUBLE_LE' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CROSSEOF | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+65
to
+79
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cat > "$CROSS_FILE" << 'CROSSEOF' | |
| [binaries] | |
| c = '${CC:-cc}' | |
| cpp = '${CXX:-c++}' | |
| [host_machine] | |
| system = '$CIBW_PLATFORM' | |
| cpu_family = '$CPU_FAMILY' | |
| cpu = '$CPU' | |
| endian = 'little' | |
| [properties] | |
| skip_sanity_check = true | |
| longdouble_format = 'IEEE_DOUBLE_LE' | |
| CROSSEOF | |
| cat > "$CROSS_FILE" <<- 'CROSSEOF' | |
| [binaries] | |
| c = '${CC:-cc}' | |
| cpp = '${CXX:-c++}' | |
| [host_machine] | |
| system = '$CIBW_PLATFORM' | |
| cpu_family = '$CPU_FAMILY' | |
| cpu = '$CPU' | |
| endian = 'little' | |
| [properties] | |
| skip_sanity_check = true | |
| longdouble_format = 'IEEE_DOUBLE_LE' | |
| CROSSEOF |
Copilot
AI
Dec 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable substitution approach is fragile. The sed command tries to replace '${CC:-cc}' with the value of ${CC:-cc}, but this won't work as expected. If CC is unset, ${CC:-cc} expands to 'cc', but the meson cross file will contain 'c = 'cc'' (with quotes), when it should contain just 'c = cc' (without inner quotes) or 'c = 'cc'' depending on meson's requirements. Consider testing whether the quotes in the heredoc template (lines 67-68) are correct for the final output.
Copilot
AI
Dec 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The sed -i command may not work on macOS/iOS build environments. macOS sed requires a backup extension argument with -i (e.g., sed -i '' or sed -i.bak). Consider using a portable approach that works across both Linux and macOS, such as creating a temporary file or using a different method for variable substitution.
| # Substitute variables in the cross file | |
| sed -i "s/\${CC:-cc}/${CC:-cc}/g" "$CROSS_FILE" | |
| sed -i "s/\${CXX:-c++}/${CXX:-c++}/g" "$CROSS_FILE" | |
| sed -i "s/\$CIBW_PLATFORM/$CIBW_PLATFORM/g" "$CROSS_FILE" | |
| sed -i "s/\$CPU_FAMILY/$CPU_FAMILY/g" "$CROSS_FILE" | |
| sed -i "s/\$CPU/$CPU/g" "$CROSS_FILE" | |
| # Substitute variables in the cross file (portable across macOS and Linux) | |
| sed "s/\${CC:-cc}/${CC:-cc}/g" "$CROSS_FILE" > "$CROSS_FILE.tmp" && mv "$CROSS_FILE.tmp" "$CROSS_FILE" | |
| sed "s/\${CXX:-c++}/${CXX:-c++}/g" "$CROSS_FILE" > "$CROSS_FILE.tmp" && mv "$CROSS_FILE.tmp" "$CROSS_FILE" | |
| sed "s/\$CIBW_PLATFORM/$CIBW_PLATFORM/g" "$CROSS_FILE" > "$CROSS_FILE.tmp" && mv "$CROSS_FILE.tmp" "$CROSS_FILE" | |
| sed "s/\$CPU_FAMILY/$CPU_FAMILY/g" "$CROSS_FILE" > "$CROSS_FILE.tmp" && mv "$CROSS_FILE.tmp" "$CROSS_FILE" | |
| sed "s/\$CPU/$CPU/g" "$CROSS_FILE" > "$CROSS_FILE.tmp" && mv "$CROSS_FILE.tmp" "$CROSS_FILE" |
Copilot
AI
Dec 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The heredoc template uses single quotes ('CROSSEOF') to prevent variable expansion, but then the content has shell variable syntax like '${CC:-cc}' and '$CIBW_PLATFORM'. These won't be expanded during heredoc creation and will be written literally. The sed commands then try to replace these literal strings, but the regex pattern won't correctly match '${CC:-cc}' due to special regex characters. Consider using envsubst or a more robust variable substitution approach, or switch to a heredoc without quotes to allow direct shell expansion.
Copilot
AI
Dec 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cross file is created only when building for mobile platforms (android/ios), but the cibw_config_settings unconditionally references it with '--cross-file=/tmp/numpy_meson_cross.txt'. This will cause build failures on non-mobile platforms where the file doesn't exist. Consider making the cross-file reference conditional or creating a default cross file for all platforms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The commented-out PKG_CONFIG setting creates ambiguity about whether it should be enabled. According to the comment on line 20-21, setting PKG_CONFIG="" is "critical for mobile cross-compilation to avoid linking against host libs", but it's currently disabled. This could lead to cross-compilation issues where host libraries are incorrectly detected. Either enable this setting or update the comment to explain why it's disabled.