package/python-numpy: fix build with BR2_i386
PATCH 1/1 package/python-numpy: fix build with BR2_i386
Buildroot commit [1] on the master branch introduced a method to pass the 'longdouble_format' property for python-numpy.
On 2025.02, it was thought that this change was not required. The program that check the architecture is not present on 2025.02.x python-numpy v1.25.0, and was introduced upstream in v.1.25.1 [2]. However, the python-numpy build can still fail on some architecture because of the 'long double size' with the following error:
``` Checking for size of "long double" : 12 ../output-1/build/python-numpy-1.25.0/numpy/core/meson.build:371:2: ERROR: Problem encountered: This should not be possible, 12 bits of "content" should still result in sizeof() being 16. Please report this error! ```
This error is reproducible with the following defconfig:
``` BR2_i386=y BR2_x86_core2=y BR2_TOOLCHAIN_EXTERNAL=y BR2_TOOLCHAIN_EXTERNAL_BOOTLIN=y BR2_PACKAGE_PYTHON3=y BR2_PACKAGE_PYTHON_NUMPY=y ```
This commit backport [2][3] to be able to pass the 'longdouble_format' property to meson and backport the changes introduced on the master branch [1] to pass the format to meson.
[1] 62648d9892 package/python-numpy: bump version to 2.4.0
[2] https://github.com/numpy/numpy/commit/f1cddd3a159f0fdba8bb744f6e721a5242859474
[3] https://github.com/numpy/numpy/commit/582a4024971f30674555d7bf3b8fdc194766f43f
(alternative to commit 62648d98926cc96c680ce4698bb631188b2f72d9)
--- ...double-identification-to-C-for-meson.patch | 150 ++++++++++++++++++ ...ow-specifying-the-long-double-format.patch | 41 +++++ package/python-numpy/python-numpy.mk | 45 ++++++ 3 files changed, 236 insertions(+) create mode 100644 package/python-numpy/0003-BLD-Port-long-double-identification-to-C-for-meson.patch create mode 100644 package/python-numpy/0004-BLD-allow-specifying-the-long-double-format.patch
package/python-numpy/0003-BLD-Port-long-double-identification-to-C-for-meson.patch new file +150 -0
@@ -0,0 +1,150 @@ +From f1cddd3a159f0fdba8bb744f6e721a5242859474 Mon Sep 17 00:00:00 2001 +From: matoro <[email protected]> +Date: Sun, 18 Jun 2023 19:39:06 -0400 +Subject: [PATCH] BLD: Port long double identification to C for meson + +This ports the old Python code for identifying the long double +representation to C, so that it can be easily invoked by meson. The +original implementation is at https://github.com/numpy/numpy/blob/eead09a3d02c09374942cdc787c0b5e4fe9e7472/numpy/core/setup_common.py#L264-L434 + +The C portion of the code has been tested and confirmed to work on +systems with the following formats, either natively or via an +alternative ABI: INTEL_EXTENDED_16_BYTES_LE, IEEE_QUAD_BE, +IEEE_QUAD_LE, IBM_DOUBLE_DOUBLE_BE, IBM_DOUBLE_DOUBLE_LE, +IEEE_DOUBLE_BE, INTEL_EXTENDED_12_BYTES_LE. + +The original meson port includes an error condition with the comment +"This should not be possible, 12 bits of "content" should still result +in sizeof() being 16." As far as I can tell this is incorrect, as +compiling on an x86_64 system with 32-bit ABI (gcc -m32) does indeed +have sizeof(long double)==12. This is reflected in the C code. + +Closes gh-23972, closes +https://github.com/mesonbuild/meson/issues/11068. +Upstream: https://github.com/numpy/numpy/commit/f1cddd3a159f0fdba8bb744f6e721a5242859474 +Signed-off-by: Thomas Perale <[email protected]> +--- + numpy/core/meson.build | 110 ++++++++++++++++++++++++++++++++--------- + 1 file changed, 87 insertions(+), 23 deletions(-) + +diff --git a/numpy/core/meson.build b/numpy/core/meson.build +index f375e9647f3a..754005c8306a 100644 +--- a/numpy/core/meson.build ++++ b/numpy/core/meson.build +@@ -357,29 +357,93 @@ foreach intrin: optional_intrinsics + endif + endforeach + +-# long double representation detection (see setup_common.py) +-# TODO: this is still incomplete, and different from how it's done in the +-# numpy.distutils based build, see https://github.com/mesonbuild/meson/issues/11068 +-longdouble_size = cc.sizeof('long double') +-if longdouble_size == 8 +- if host_machine.endian() == 'little' +- longdouble_format = 'IEEE_DOUBLE_LE' +- else +- longdouble_format = 'IEEE_DOUBLE_BE' +- endif +-elif longdouble_size == 12 +- error('This should not be possible, 12 bits of "content" should still result in sizeof() being 16. Please report this error!' +- ) +-elif longdouble_size == 16 +- if host_machine.endian() == 'little' +- # FIXME: this varies, there's multiple formats here! Not yet implemented. +- # TBD how we deal with the mess of old long double formats. +- longdouble_format = 'INTEL_EXTENDED_16_BYTES_LE' +- else +- error('No idea what this is ....') +- endif +-else +- error('Unknown long double size: ' + londouble_size) ++# This is a port of the old python code for identifying the long double ++# representation to C. The old Python code is in this range: ++# https://github.com/numpy/numpy/blob/eead09a3d02c09374942cdc787c0b5e4fe9e7472/numpy/core/setup_common.py#L264-L434 ++# This port is in service of solving gh-23972 ++# as well as https://github.com/mesonbuild/meson/issues/11068 ++longdouble_format = meson.get_compiler('c').run( ++''' ++#include <stdio.h> ++#include <string.h> ++ ++#define repcmp(z) (memcmp((const char *)&foo.x, z, sizeof(foo.x)) == 0) ++ ++const struct { ++ char before[16]; ++ long double x; ++ char after[8]; ++} foo = {{'\0'}, -123456789.0, {'\0'}}; ++ ++int main(void) { ++ switch (sizeof(foo.x)) { ++ case 8: { ++ if (repcmp( ++ ((const char[]){0000, 0000, 0000, 0124, 0064, 0157, 0235, 0301}))) { ++ fprintf(stdout, "IEEE_DOUBLE_LE"); ++ return 0; ++ } ++ if (repcmp( ++ ((const char[]){0301, 0235, 0157, 0064, 0124, 0000, 0000, 0000}))) { ++ fprintf(stdout, "IEEE_DOUBLE_BE"); ++ return 0; ++ } ++ fprintf(stdout, "UNKNOWN"); ++ return 1; ++ } ++ case 12: { ++ if (repcmp(((const char[]){0000, 0000, 0000, 0000, 0240, 0242, 0171, 0353, ++ 0031, 0300, 0000, 0000}))) { ++ fprintf(stdout, "INTEL_EXTENDED_12_BYTES_LE"); ++ return 0; ++ } ++ if (repcmp(((const char[]){0300, 0031, 0000, 0000, 0353, 0171, 0242, 0240, ++ 0000, 0000, 0000, 0000}))) { ++ fprintf(stdout, "MOTOROLA_EXTENDED_12_BYTES_BE"); ++ return 0; ++ } ++ fprintf(stdout, "UNKNOWN"); ++ return 1; ++ } ++ case 16: { ++ if (repcmp( ++ ((const char[]){0000, 0000, 0000, 0000, 0240, 0242, 0171, 0353, ++ 0031, 0300, 0000, 0000, 0000, 0000, 0000, 0000}))) { ++ fprintf(stdout, "INTEL_EXTENDED_16_BYTES_LE"); ++ return 0; ++ } ++ if (repcmp( ++ ((const char[]){0300, 0031, 0326, 0363, 0105, 0100, 0000, 0000, ++ 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000}))) { ++ fprintf(stdout, "IEEE_QUAD_BE"); ++ return 0; ++ } ++ if (repcmp( ++ ((const char[]){0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, ++ 0000, 0000, 0100, 0105, 0363, 0326, 0031, 0300}))) { ++ fprintf(stdout, "IEEE_QUAD_LE"); ++ return 0; ++ } ++ if (repcmp( ++ ((const char[]){0000, 0000, 0000, 0124, 0064, 0157, 0235, 0301, ++ 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000}))) { ++ fprintf(stdout, "IBM_DOUBLE_DOUBLE_LE"); ++ return 0; ++ } ++ if (repcmp( ++ ((const char[]){0301, 0235, 0157, 0064, 0124, 0000, 0000, 0000, ++ 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000}))) { ++ fprintf(stdout, "IBM_DOUBLE_DOUBLE_BE"); ++ return 0; ++ } ++ fprintf(stdout, "UNKNOWN"); ++ return 1; ++ } ++ } ++} ++''').stdout() ++if longdouble_format == 'UNKNOWN' or longdouble_format == 'UNDEFINED' ++ error('Unknown long double format of size: ' + cc.sizeof('long double').to_string()) + endif + cdata.set10('HAVE_LDOUBLE_' + longdouble_format, true) +
package/python-numpy/0004-BLD-allow-specifying-the-long-double-format.patch new file +41 -0
41 lines not on this page · raw message
package/python-numpy/python-numpy.mk +45 -0
51 lines not on this page · raw message
Signature · 6 lines
2.56.0 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Raphaël Mélotte via buildroot
AppliedIn reply of:
Quoted 30 lines
Buildroot commit [1] on the master branch introduced a method to pass the '
longdouble_format' property for python-numpy.On 2025.02, it was thought that this change was not required. The program that check the architecture is not present on 2025.02.x python-numpy v1.25.0, and was introduced upstream in v.1.25.1 [2]. However, the python-numpy build can still fail on some architecture because of the 'long double size' with the following error:
``` Checking for size of "long double" : 12 ../output-1/build/python-numpy-1.25.0/numpy/core/meson.build:371:2: ERROR: Problem encountered: This should not be possible, 12 bits of "content" should still result in sizeof() being 16. Please report this error! ```This error is reproducible with the following defconfig:
``` BR2_i386=y BR2_x86_core2=y BR2_TOOLCHAIN_EXTERNAL=y BR2_TOOLCHAIN_EXTERNAL_BOOTLIN=y BR2_PACKAGE_PYTHON3=y BR2_PACKAGE_PYTHON_NUMPY=y ```This commit backport [2][3] to be able to pass the '
longdouble_format' property to meson and backport the changes introduced on the master branch [1] to pass the format to meson.
Quoted 8 lines
[1]
62648d9892package/python-numpy: bump version to 2.4.0
[2] https://github.com/numpy/numpy/commit/f1cddd3a159f0fdba8bb744f6e721a5242859474
[3] https://github.com/numpy/numpy/commit/582a4024971f30674555d7bf3b8fdc194766f43fAssisted-by LLMSigned-off-by Thomas Perale <[email protected]>(alternative to commit
62648d98926cc96c680ce4698bb631188b2f72d9)
Applied to 2025.02.x. Thanks
Quoted 257 lines
--- ...double-identification-to-C-for-meson.patch | 150 ++++++++++++++++++ ...ow-specifying-the-long-double-format.patch | 41 +++++ package/python-numpy/python-numpy.mk | 45 ++++++ 3 files changed, 236 insertions(+) create mode 100644 package/python-numpy/0003-BLD-Port-long-double-identification-to-C-for-meson.patch create mode 100644 package/python-numpy/0004-BLD-allow-specifying-the-long-double-format.patchpackage/python-numpy/0003-BLD-Port-long-double-identification-to-C-for-meson.patch new file +150
-0@@ -0,0 +1,150 @@ +From f1cddd3a159f0fdba8bb744f6e721a5242859474 Mon Sep 17 00:00:00 2001 +From: matoro <[email protected]> +Date: Sun, 18 Jun 2023 19:39:06 -0400 +Subject: [PATCH] BLD: Port long double identification to C for meson + +This ports the old Python code for identifying the long double +representation to C, so that it can be easily invoked by meson. The +original implementation is at https://github.com/numpy/numpy/blob/eead09a3d02c09374942cdc787c0b5e4fe9e7472/numpy/core/setup_common.py#L264-L434 + +The C portion of the code has been tested and confirmed to work on +systems with the following formats, either natively or via an +alternative ABI: INTEL_EXTENDED_16_BYTES_LE, IEEE_QUAD_BE, +IEEE_QUAD_LE, IBM_DOUBLE_DOUBLE_BE, IBM_DOUBLE_DOUBLE_LE, +IEEE_DOUBLE_BE, INTEL_EXTENDED_12_BYTES_LE. + +The original meson port includes an error condition with the comment +"This should not be possible, 12 bits of "content" should still result +in sizeof() being 16." As far as I can tell this is incorrect, as +compiling on an x86_64 system with 32-bit ABI (gcc -m32) does indeed +have sizeof(long double)==12. This is reflected in the C code. + +Closes gh-23972, closes +https://github.com/mesonbuild/meson/issues/11068. +Upstream: https://github.com/numpy/numpy/commit/f1cddd3a159f0fdba8bb744f6e721a5242859474 +Signed-off-by: Thomas Perale <[email protected]> +--- + numpy/core/meson.build | 110 ++++++++++++++++++++++++++++++++--------- + 1 file changed, 87 insertions(+), 23 deletions(-) + +diff --git a/numpy/core/meson.build b/numpy/core/meson.build +index f375e9647f3a..754005c8306a 100644 +--- a/numpy/core/meson.build ++++ b/numpy/core/meson.build +@@ -357,29 +357,93 @@ foreach intrin: optional_intrinsics + endif + endforeach + +-# long double representation detection (see setup_common.py) +-# TODO: this is still incomplete, and different from how it's done in the +-# numpy.distutils based build, see https://github.com/mesonbuild/meson/issues/11068 +-longdouble_size = cc.sizeof('long double') +-if longdouble_size == 8 +- if host_machine.endian() == 'little' +- longdouble_format = 'IEEE_DOUBLE_LE' +- else +- longdouble_format = 'IEEE_DOUBLE_BE' +- endif +-elif longdouble_size == 12 +- error('This should not be possible, 12 bits of "content" should still result in sizeof() being 16. Please report this error!' +- ) +-elif longdouble_size == 16 +- if host_machine.endian() == 'little' +- # FIXME: this varies, there's multiple formats here! Not yet implemented. +- # TBD how we deal with the mess of old long double formats. +- longdouble_format = 'INTEL_EXTENDED_16_BYTES_LE' +- else +- error('No idea what this is ....') +- endif +-else +- error('Unknown long double size: ' + londouble_size) ++# This is a port of the old python code for identifying the long double ++# representation to C. The old Python code is in this range: ++# https://github.com/numpy/numpy/blob/eead09a3d02c09374942cdc787c0b5e4fe9e7472/numpy/core/setup_common.py#L264-L434 ++# This port is in service of solving gh-23972 ++# as well as https://github.com/mesonbuild/meson/issues/11068 ++longdouble_format = meson.get_compiler('c').run( ++''' ++#include <stdio.h> ++#include <string.h> ++ ++#define repcmp(z) (memcmp((const char *)&foo.x, z, sizeof(foo.x)) == 0) ++ ++const struct { ++ char before[16]; ++ long double x; ++ char after[8]; ++} foo = {{'\0'}, -123456789.0, {'\0'}}; ++ ++int main(void) { ++ switch (sizeof(foo.x)) { ++ case 8: { ++ if (repcmp( ++ ((const char[]){0000, 0000, 0000, 0124, 0064, 0157, 0235, 0301}))) { ++ fprintf(stdout, "IEEE_DOUBLE_LE"); ++ return 0; ++ } ++ if (repcmp( ++ ((const char[]){0301, 0235, 0157, 0064, 0124, 0000, 0000, 0000}))) { ++ fprintf(stdout, "IEEE_DOUBLE_BE"); ++ return 0; ++ } ++ fprintf(stdout, "UNKNOWN"); ++ return 1; ++ } ++ case 12: { ++ if (repcmp(((const char[]){0000, 0000, 0000, 0000, 0240, 0242, 0171, 0353, ++ 0031, 0300, 0000, 0000}))) { ++ fprintf(stdout, "INTEL_EXTENDED_12_BYTES_LE"); ++ return 0; ++ } ++ if (repcmp(((const char[]){0300, 0031, 0000, 0000, 0353, 0171, 0242, 0240, ++ 0000, 0000, 0000, 0000}))) { ++ fprintf(stdout, "MOTOROLA_EXTENDED_12_BYTES_BE"); ++ return 0; ++ } ++ fprintf(stdout, "UNKNOWN"); ++ return 1; ++ } ++ case 16: { ++ if (repcmp( ++ ((const char[]){0000, 0000, 0000, 0000, 0240, 0242, 0171, 0353, ++ 0031, 0300, 0000, 0000, 0000, 0000, 0000, 0000}))) { ++ fprintf(stdout, "INTEL_EXTENDED_16_BYTES_LE"); ++ return 0; ++ } ++ if (repcmp( ++ ((const char[]){0300, 0031, 0326, 0363, 0105, 0100, 0000, 0000, ++ 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000}))) { ++ fprintf(stdout, "IEEE_QUAD_BE"); ++ return 0; ++ } ++ if (repcmp( ++ ((const char[]){0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, ++ 0000, 0000, 0100, 0105, 0363, 0326, 0031, 0300}))) { ++ fprintf(stdout, "IEEE_QUAD_LE"); ++ return 0; ++ } ++ if (repcmp( ++ ((const char[]){0000, 0000, 0000, 0124, 0064, 0157, 0235, 0301, ++ 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000}))) { ++ fprintf(stdout, "IBM_DOUBLE_DOUBLE_LE"); ++ return 0; ++ } ++ if (repcmp( ++ ((const char[]){0301, 0235, 0157, 0064, 0124, 0000, 0000, 0000, ++ 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000}))) { ++ fprintf(stdout, "IBM_DOUBLE_DOUBLE_BE"); ++ return 0; ++ } ++ fprintf(stdout, "UNKNOWN"); ++ return 1; ++ } ++ } ++} ++''').stdout() ++if longdouble_format == 'UNKNOWN' or longdouble_format == 'UNDEFINED' ++ error('Unknown long double format of size: ' + cc.sizeof('long double').to_string()) + endif + cdata.set10('HAVE_LDOUBLE_' + longdouble_format, true) +package/python-numpy/0004-BLD-allow-specifying-the-long-double-format.patch new file +41
-0@@ -0,0 +1,41 @@ +From 582a4024971f30674555d7bf3b8fdc194766f43f Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Filipe=20La=C3=ADns?= <[email protected]> +Date: Mon, 14 Aug 2023 15:28:17 +0100 +Subject: [PATCH] BLD: allow specifying the long double format to avoid the + runtime check +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Signed-off-by: Filipe Laíns <[email protected]> +Upstream: https://github.com/numpy/numpy/commit/582a4024971f30674555d7bf3b8fdc194766f43f +Signed-off-by: Thomas Perale <[email protected]> +--- + numpy/core/meson.build | 7 +++++-- + 1 file changed, 5 insertions(+), 2 deletions(-) + +diff --git a/numpy/core/meson.build b/numpy/core/meson.build +index 56e805edb855..15bf493bcf7f 100644 +--- a/numpy/core/meson.build ++++ b/numpy/core/meson.build +@@ -380,7 +380,9 @@ endforeach + # https://github.com/numpy/numpy/blob/eead09a3d02c09374942cdc787c0b5e4fe9e7472/numpy/core/setup_common.py#L264-L434 + # This port is in service of solving gh-23972 + # as well as https://github.com/mesonbuild/meson/issues/11068 +-longdouble_format = meson.get_compiler('c').run( ++longdouble_format = meson.get_external_property('longdouble_format', 'UNKNOWN') ++if longdouble_format == 'UNKNOWN' ++ longdouble_format = meson.get_compiler('c').run( + ''' + #include <stdio.h> + #include <string.h> +@@ -459,7 +461,8 @@ int main(void) { + } + } + } +-''').stdout() ++ ''').stdout() ++endif + if longdouble_format == 'UNKNOWN' or longdouble_format == 'UNDEFINED' + error('Unknown long double format of size: ' + cc.sizeof('long double').to_string()) + endifpackage/python-numpy/python-numpy.mk +38
-0@@ -38,6 +38,51 @@ else PYTHON_NUMPY_CONF_OPTS += -Dblas="" endif +# Generated by running this test program under QEMU: +# https://github.com/numpy/numpy/blob/v1.26.4/numpy/core/meson.build#L376-L455 +ifeq ($(BR2_arcle),y) +PYTHON_NUMPY_LONGDOUBLE_FORMAT = IEEE_DOUBLE_LE +else ifeq ($(BR2_aarch64),y) +PYTHON_NUMPY_LONGDOUBLE_FORMAT = IEEE_QUAD_LE +else ifeq ($(BR2_aarch64_be),y) +PYTHON_NUMPY_LONGDOUBLE_FORMAT = IEEE_QUAD_BE +else ifeq ($(BR2_arm),y) +PYTHON_NUMPY_LONGDOUBLE_FORMAT = IEEE_DOUBLE_LE +else ifeq ($(BR2_armeb),y) +PYTHON_NUMPY_LONGDOUBLE_FORMAT = IEEE_DOUBLE_BE +else ifeq ($(BR2_i386),y) +PYTHON_NUMPY_LONGDOUBLE_FORMAT = INTEL_EXTENDED_12_BYTES_LE +else ifeq ($(BR2_or1k),y) +PYTHON_NUMPY_LONGDOUBLE_FORMAT = IEEE_DOUBLE_BE +else ifeq ($(BR2_m68k),y) +PYTHON_NUMPY_LONGDOUBLE_FORMAT = MOTOROLA_EXTENDED_12_BYTES_BE +else ifeq ($(BR2_mips),y) +PYTHON_NUMPY_LONGDOUBLE_FORMAT = IEEE_DOUBLE_BE +else ifeq ($(BR2_mipsel),y) +PYTHON_NUMPY_LONGDOUBLE_FORMAT = IEEE_DOUBLE_LE +else ifeq ($(BR2_powerpc),y) +PYTHON_NUMPY_LONGDOUBLE_FORMAT = IBM_DOUBLE_DOUBLE_BE +else ifeq ($(BR2_powerpc64),y) +PYTHON_NUMPY_LONGDOUBLE_FORMAT = IBM_DOUBLE_DOUBLE_BE +else ifeq ($(BR2_powerpc64le),y) +PYTHON_NUMPY_LONGDOUBLE_FORMAT = IBM_DOUBLE_DOUBLE_LE +else ifeq ($(BR2_riscv),y) +PYTHON_NUMPY_LONGDOUBLE_FORMAT = IEEE_QUAD_LE +else ifeq ($(BR2_sh4)$(BR2_sh4a),y) +PYTHON_NUMPY_LONGDOUBLE_FORMAT = IEEE_DOUBLE_LE +else ifeq ($(BR2_sh4eb)$(BR2_sh4aeb),y) +PYTHON_NUMPY_LONGDOUBLE_FORMAT = IEEE_DOUBLE_BE +else ifeq ($(BR2_sparc),y) +PYTHON_NUMPY_LONGDOUBLE_FORMAT = IEEE_DOUBLE_BE +else ifeq ($(BR2_sparc64),y) +PYTHON_NUMPY_LONGDOUBLE_FORMAT = IEEE_QUAD_BE
package/python-numpy/python-numpy.mk else · line 88
Quoted 10 lines
package/python-numpy/python-numpy.mk +7
-0+else ifeq ($(BR2_x86_64),y) +PYTHON_NUMPY_LONGDOUBLE_FORMAT = INTEL_EXTENDED_16_BYTES_LE +endif + +PYTHON_NUMPY_MESON_EXTRA_PROPERTIES = \ + longdouble_format='$(PYTHON_NUMPY_LONGDOUBLE_FORMAT)' + # Rather than add a host-blas or host-lapack dependencies, just use unoptimized, # in-tree code. HOST_PYTHON_NUMPY_CONF_OPTS = -Dblas="" -Dlapack=""
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot