Github messages for voidlinux
 help / color / mirror / Atom feed
* [PR PATCH] [RFC, WIP] common/build-helper/meson.sh: new build helper, used by meson build style
@ 2023-09-18 19:53 ahesford
  2023-09-18 20:02 ` tornaria
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: ahesford @ 2023-09-18 19:53 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 2473 bytes --]

There is a new pull request by ahesford against master on the void-packages repository

https://github.com/ahesford/void-packages meson
https://github.com/void-linux/void-packages/pull/46117

[RFC, WIP] common/build-helper/meson.sh: new build helper, used by meson build style
The `python3-scipy` package now builds with `python3-meson-python`, with some more coming down the pike. The Python build process is necessary to include Python package metadata. For SciPy, this is accomplished by using the `meson` build style to configure a build directory, then overriding `do_build` and `do_install` to build things the PEP517 way (using the pre-configured build directory).

It might be helpful to define a `meson` build helper that can write out the standard cross file for builds, allowing packages like SciPy to use the `python3-pep517` build style with the `meson` helper. There are some issues to be worked out:
1. It seems like the `xbps_meson.cross` is written before `CFLAGS`, *et al.* are properly defined, so this cross file is actually broken. (This is the process by which the `qmake` helper writes its configurations, and they reference `CFLAGS` and others; is the `qmake` helper writing broken configs?)
2. The meson configuration (which would need to happen even with `python3-pep517` plus a `meson` helper) still includes a lot of magic that would have to be brought over to templates. This isn't really easier than the current practice of overriding the one-line `do_build` and `do_install`.

A possible solution would be to define a special-purpose function in the helper, called `vmesoncross` or somesuch, that will only write the configured when called---from a build function where these are properly defined (*e.g.*, `pre_configure`, `do_configure`). We could also define a special `do_configure`-like function in the helper that can be used by the `meson` style to actually do the configuration. This might be a bit ugly, but avoids repetition or violating the typical practice that the actual build functions are only defined in templates or build styles.

A third option is just defining a new `python3-meson` build style that mashes the meson `do_configure` bits from the `meson` style with the `do_build` and `do_install` bits from the `python3-pep517` style.

All of these options are sub-optimal, but I'm not sure which one is least offsensive.

A patch file from https://github.com/void-linux/void-packages/pull/46117.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-meson-46117.patch --]
[-- Type: text/x-diff, Size: 6540 bytes --]

From 3fb3cd93a207ec4f9c5bec3164d454b76e6d7418 Mon Sep 17 00:00:00 2001
From: "Andrew J. Hesford" <ajh@sideband.org>
Date: Mon, 18 Sep 2023 15:40:49 -0400
Subject: [PATCH] common/build-helper/meson.sh: new build helper, used by meson
 build style

---
 common/build-helper/meson.sh            | 90 +++++++++++++++++++++++++
 common/build-style/meson.sh             | 85 +----------------------
 common/environment/build-style/meson.sh |  1 +
 3 files changed, 92 insertions(+), 84 deletions(-)
 create mode 100644 common/build-helper/meson.sh

diff --git a/common/build-helper/meson.sh b/common/build-helper/meson.sh
new file mode 100644
index 0000000000000..ca9fb5827dbd7
--- /dev/null
+++ b/common/build-helper/meson.sh
@@ -0,0 +1,90 @@
+# This bulid-helper writes a Meson cross-file, allowing other build styles
+# to properly drive cross-builds in Meson when appropriate
+
+if [ "$CROSS_BUILD" ]; then
+	mkdir -p "${XBPS_WRAPPERDIR}/meson"
+
+	_MESON_TARGET_ENDIAN=little
+	# drop the -musl suffix to the target cpu, meson doesn't recognize it
+	_MESON_TARGET_CPU=${XBPS_TARGET_MACHINE/-musl/}
+	case "$XBPS_TARGET_MACHINE" in
+		mips|mips-musl|mipshf-musl)
+			_MESON_TARGET_ENDIAN=big
+			_MESON_CPU_FAMILY=mips
+			;;
+		armv*)
+			_MESON_CPU_FAMILY=arm
+			;;
+		i686*)
+			_MESON_CPU_FAMILY=x86
+			;;
+		ppc64le*)
+			_MESON_CPU_FAMILY=ppc64
+			;;
+		ppc64*)
+			_MESON_TARGET_ENDIAN=big
+			_MESON_CPU_FAMILY=ppc64
+			;;
+		ppcle*)
+			_MESON_CPU_FAMILY=ppc
+			;;
+		ppc*)
+			_MESON_TARGET_ENDIAN=big
+			_MESON_CPU_FAMILY=ppc
+			;;
+		*)
+			# if we reached here that means that the cpu and cpu_family
+			# are the same like 'x86_64' and 'aarch64'
+			_MESON_CPU_FAMILY=${_MESON_TARGET_CPU}
+			;;
+	esac
+
+	_MESON_EXE_WRAPPER=""
+	if [[ $build_helper = *"qemu"* ]]; then
+		_MESON_EXE_WRAPPER="exe_wrapper = '/usr/bin/qemu-${XBPS_TARGET_QEMU_MACHINE}-static'"
+	fi
+
+	# Record cross-compiling information in cross file.
+	# CFLAGS and LDFLAGS must be set as c_args and c_link_args.
+	cat > "${XBPS_WRAPPERDIR}/meson/xbps_meson.cross" <<-EOF
+		[binaries]
+		${_MESON_EXE_WRAPPER}
+		c = '${CC}'
+		cpp = '${CXX}'
+		ar = '${XBPS_CROSS_TRIPLET}-gcc-ar'
+		nm = '${NM}'
+		ld = '${LD}'
+		strip = '${STRIP}'
+		readelf = '${READELF}'
+		objcopy = '${OBJCOPY}'
+		pkgconfig = '${PKG_CONFIG}'
+		rust = ['rustc', '--target', '${RUST_TARGET}' ,'--sysroot', '${XBPS_CROSS_BASE}/usr']
+		g-ir-scanner = '${XBPS_CROSS_BASE}/usr/bin/g-ir-scanner'
+		g-ir-compiler = '${XBPS_CROSS_BASE}/usr/bin/g-ir-compiler'
+		g-ir-generate = '${XBPS_CROSS_BASE}/usr/bin/g-ir-generate'
+		llvm-config = '/usr/bin/llvm-config'
+		cups-config = '${XBPS_CROSS_BASE}/usr/bin/cups-config'
+		
+		[properties]
+		needs_exe_wrapper = true
+		
+		[built-in options]
+		c_args = ['$(echo ${CFLAGS} | sed -r "s/\s+/','/g")']
+		c_link_args = ['$(echo ${LDFLAGS} | sed -r "s/\s+/','/g")']
+		
+		cpp_args = ['$(echo ${CXXFLAGS} | sed -r "s/\s+/','/g")']
+		cpp_link_args = ['$(echo ${LDFLAGS} | sed -r "s/\s+/','/g")']
+		
+		[host_machine]
+		system = 'linux'
+		cpu_family = '${_MESON_CPU_FAMILY}'
+		cpu = '${_MESON_TARGET_CPU}'
+		endian = '${_MESON_TARGET_ENDIAN}'
+		EOF
+
+	if [[ $build_helper = *"qemu"* ]]; then
+		sed -e "/\[binaries\]/ a exe_wrapper = '/usr/bin/qemu-${XBPS_TARGET_QEMU_MACHINE}-static'" -i ${meson_crossfile}
+	fi
+
+	unset _MESON_CPU_FAMILY _MESON_TARGET_CPU _MESON_TARGET_ENDIAN _MESON_EXE_WRAPPER
+fi
diff --git a/common/build-style/meson.sh b/common/build-style/meson.sh
index e983c5f42c2f7..5ea2eeda40097 100644
--- a/common/build-style/meson.sh
+++ b/common/build-style/meson.sh
@@ -1,94 +1,11 @@
 #
 # This helper is for templates using meson.
 #
-do_patch() {
-	: ${meson_crossfile:=xbps_meson.cross}
-
-	if [ "$CROSS_BUILD" ]; then
-		_MESON_TARGET_ENDIAN=little
-		# drop the -musl suffix to the target cpu, meson doesn't recognize it
-		_MESON_TARGET_CPU=${XBPS_TARGET_MACHINE/-musl/}
-		case "$XBPS_TARGET_MACHINE" in
-			mips|mips-musl|mipshf-musl)
-				_MESON_TARGET_ENDIAN=big
-				_MESON_CPU_FAMILY=mips
-				;;
-			armv*)
-				_MESON_CPU_FAMILY=arm
-				;;
-			i686*)
-				_MESON_CPU_FAMILY=x86
-				;;
-			ppc64le*)
-				_MESON_CPU_FAMILY=ppc64
-				;;
-			ppc64*)
-				_MESON_TARGET_ENDIAN=big
-				_MESON_CPU_FAMILY=ppc64
-				;;
-			ppcle*)
-				_MESON_CPU_FAMILY=ppc
-				;;
-			ppc*)
-				_MESON_TARGET_ENDIAN=big
-				_MESON_CPU_FAMILY=ppc
-				;;
-			*)
-				# if we reached here that means that the cpu and cpu_family
-				# are the same like 'x86_64' and 'aarch64'
-				_MESON_CPU_FAMILY=${_MESON_TARGET_CPU}
-				;;
-		esac
-
-		# Record cross-compiling information in cross file.
-		# CFLAGS and LDFLAGS must be set as c_args and c_link_args.
-		cat > ${meson_crossfile} <<EOF
-[binaries]
-c = '${CC}'
-cpp = '${CXX}'
-ar = '${XBPS_CROSS_TRIPLET}-gcc-ar'
-nm = '${NM}'
-ld = '${LD}'
-strip = '${STRIP}'
-readelf = '${READELF}'
-objcopy = '${OBJCOPY}'
-pkgconfig = '${PKG_CONFIG}'
-rust = ['rustc', '--target', '${RUST_TARGET}' ,'--sysroot', '${XBPS_CROSS_BASE}/usr']
-g-ir-scanner = '${XBPS_CROSS_BASE}/usr/bin/g-ir-scanner'
-g-ir-compiler = '${XBPS_CROSS_BASE}/usr/bin/g-ir-compiler'
-g-ir-generate = '${XBPS_CROSS_BASE}/usr/bin/g-ir-generate'
-llvm-config = '/usr/bin/llvm-config'
-cups-config = '${XBPS_CROSS_BASE}/usr/bin/cups-config'
-
-[properties]
-needs_exe_wrapper = true
-
-[built-in options]
-c_args = ['$(echo ${CFLAGS} | sed -r "s/\s+/','/g")']
-c_link_args = ['$(echo ${LDFLAGS} | sed -r "s/\s+/','/g")']
-
-cpp_args = ['$(echo ${CXXFLAGS} | sed -r "s/\s+/','/g")']
-cpp_link_args = ['$(echo ${LDFLAGS} | sed -r "s/\s+/','/g")']
-
-[host_machine]
-system = 'linux'
-cpu_family = '${_MESON_CPU_FAMILY}'
-cpu = '${_MESON_TARGET_CPU}'
-endian = '${_MESON_TARGET_ENDIAN}'
-EOF
-		if [[ $build_helper = *"qemu"* ]]; then
-			sed -e "/\[binaries\]/ a exe_wrapper = '/usr/bin/qemu-${XBPS_TARGET_QEMU_MACHINE}-static'" \
-				-i ${meson_crossfile}
-		fi
-
-		unset _MESON_CPU_FAMILY _MESON_TARGET_CPU _MESON_TARGET_ENDIAN
-	fi
-}
 
 do_configure() {
 	: ${meson_cmd:=meson}
 	: ${meson_builddir:=build}
-	: ${meson_crossfile:=xbps_meson.cross}
+	: ${meson_crossfile:="${XBPS_WRAPPERDIR}/meson/xbps_meson.cross"}
 
 	if [ "$CROSS_BUILD" ]; then
 		configure_args+=" --cross-file=${meson_crossfile}"
diff --git a/common/environment/build-style/meson.sh b/common/environment/build-style/meson.sh
index d5a3c4141f7d9..dbfe93700f691 100644
--- a/common/environment/build-style/meson.sh
+++ b/common/environment/build-style/meson.sh
@@ -1 +1,2 @@
 hostmakedepends+=" meson"
+build_helper+=" meson"

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC, WIP] common/build-helper/meson.sh: new build helper, used by meson build style
  2023-09-18 19:53 [PR PATCH] [RFC, WIP] common/build-helper/meson.sh: new build helper, used by meson build style ahesford
@ 2023-09-18 20:02 ` tornaria
  2023-09-20  3:25 ` tornaria
                   ` (12 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: tornaria @ 2023-09-18 20:02 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 346 bytes --]

New comment by tornaria on void-packages repository

https://github.com/void-linux/void-packages/pull/46117#issuecomment-1724286996

Comment:
An idea to consider: adding a hook in `common/hooks/pre-configure` (or similar) that applies this when build_helper includes meson, etc. similar to `hooks/pre-configure/00-gnu-configure-asneeded.sh` etc.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC, WIP] common/build-helper/meson.sh: new build helper, used by meson build style
  2023-09-18 19:53 [PR PATCH] [RFC, WIP] common/build-helper/meson.sh: new build helper, used by meson build style ahesford
  2023-09-18 20:02 ` tornaria
@ 2023-09-20  3:25 ` tornaria
  2023-09-20 14:46 ` [PR PATCH] [Updated] " ahesford
                   ` (11 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: tornaria @ 2023-09-20  3:25 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 328 bytes --]

New comment by tornaria on void-packages repository

https://github.com/void-linux/void-packages/pull/46117#issuecomment-1726826582

Comment:
Please see my proof of concept in #46109, which seems to be working for `python3-contourpy`. I didn't try the same approach with scipy (or numpy 1.26 which is also moving to meson).



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PR PATCH] [Updated] [RFC, WIP] common/build-helper/meson.sh: new build helper, used by meson build style
  2023-09-18 19:53 [PR PATCH] [RFC, WIP] common/build-helper/meson.sh: new build helper, used by meson build style ahesford
  2023-09-18 20:02 ` tornaria
  2023-09-20  3:25 ` tornaria
@ 2023-09-20 14:46 ` ahesford
  2023-09-20 14:48 ` ahesford
                   ` (10 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: ahesford @ 2023-09-20 14:46 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 2478 bytes --]

There is an updated pull request by ahesford against master on the void-packages repository

https://github.com/ahesford/void-packages meson
https://github.com/void-linux/void-packages/pull/46117

[RFC, WIP] common/build-helper/meson.sh: new build helper, used by meson build style
The `python3-scipy` package now builds with `python3-meson-python`, with some more coming down the pike. The Python build process is necessary to include Python package metadata. For SciPy, this is accomplished by using the `meson` build style to configure a build directory, then overriding `do_build` and `do_install` to build things the PEP517 way (using the pre-configured build directory).

It might be helpful to define a `meson` build helper that can write out the standard cross file for builds, allowing packages like SciPy to use the `python3-pep517` build style with the `meson` helper. There are some issues to be worked out:
1. It seems like the `xbps_meson.cross` is written before `CFLAGS`, *et al.* are properly defined, so this cross file is actually broken. (This is the process by which the `qmake` helper writes its configurations, and they reference `CFLAGS` and others; is the `qmake` helper writing broken configs?)
2. The meson configuration (which would need to happen even with `python3-pep517` plus a `meson` helper) still includes a lot of magic that would have to be brought over to templates. This isn't really easier than the current practice of overriding the one-line `do_build` and `do_install`.

A possible solution would be to define a special-purpose function in the helper, called `vmesoncross` or somesuch, that will only write the configured when called---from a build function where these are properly defined (*e.g.*, `pre_configure`, `do_configure`). We could also define a special `do_configure`-like function in the helper that can be used by the `meson` style to actually do the configuration. This might be a bit ugly, but avoids repetition or violating the typical practice that the actual build functions are only defined in templates or build styles.

A third option is just defining a new `python3-meson` build style that mashes the meson `do_configure` bits from the `meson` style with the `do_build` and `do_install` bits from the `python3-pep517` style.

All of these options are sub-optimal, but I'm not sure which one is least offsensive.

A patch file from https://github.com/void-linux/void-packages/pull/46117.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-meson-46117.patch --]
[-- Type: text/x-diff, Size: 9270 bytes --]

From 8cd6e8ef00680341dd65678e22952bb115aa2e03 Mon Sep 17 00:00:00 2001
From: "Andrew J. Hesford" <ajh@sideband.org>
Date: Mon, 18 Sep 2023 15:40:49 -0400
Subject: [PATCH 1/2] common/build-helper/meson.sh: new build helper, used by
 meson build style

---
 common/build-helper/meson.sh            | 82 ++++++++++++++++++++++++
 common/build-style/meson.sh             | 85 +------------------------
 common/environment/build-style/meson.sh |  1 +
 3 files changed, 84 insertions(+), 84 deletions(-)
 create mode 100644 common/build-helper/meson.sh

diff --git a/common/build-helper/meson.sh b/common/build-helper/meson.sh
new file mode 100644
index 0000000000000..1933306c18a4b
--- /dev/null
+++ b/common/build-helper/meson.sh
@@ -0,0 +1,82 @@
+# This bulid-helper writes a Meson cross-file, allowing other build styles
+# to properly drive cross-builds in Meson when appropriate
+
+if [ "$CROSS_BUILD" ]; then
+	mkdir -p "${XBPS_WRAPPERDIR}/meson"
+
+	_MESON_TARGET_ENDIAN=little
+	# drop the -musl suffix to the target cpu, meson doesn't recognize it
+	_MESON_TARGET_CPU=${XBPS_TARGET_MACHINE/-musl/}
+	case "$XBPS_TARGET_MACHINE" in
+		mips|mips-musl|mipshf-musl)
+			_MESON_TARGET_ENDIAN=big
+			_MESON_CPU_FAMILY=mips
+			;;
+		armv*)
+			_MESON_CPU_FAMILY=arm
+			;;
+		i686*)
+			_MESON_CPU_FAMILY=x86
+			;;
+		ppc64le*)
+			_MESON_CPU_FAMILY=ppc64
+			;;
+		ppc64*)
+			_MESON_TARGET_ENDIAN=big
+			_MESON_CPU_FAMILY=ppc64
+			;;
+		ppcle*)
+			_MESON_CPU_FAMILY=ppc
+			;;
+		ppc*)
+			_MESON_TARGET_ENDIAN=big
+			_MESON_CPU_FAMILY=ppc
+			;;
+		*)
+			# if we reached here that means that the cpu and cpu_family
+			# are the same like 'x86_64' and 'aarch64'
+			_MESON_CPU_FAMILY=${_MESON_TARGET_CPU}
+			;;
+	esac
+
+	# Tell meson to run binaries with qemu if desired
+	_MESON_EXE_WRAPPER=""
+	if [[ "${build_helper}" = *qemu* ]]; then
+		_MESON_EXE_WRAPPER="exe_wrapper = '/usr/bin/qemu-${XBPS_TARGET_QEMU_MACHINE}-static'"
+	fi
+
+	# Record cross-compiling information in cross file.
+	#
+	# CFLAGS, CXXFLAGS and LDFLAGS are not yet available and
+	# will be taken from the environment at configure time.
+	cat > "${XBPS_WRAPPERDIR}/meson/xbps_meson.cross" <<-EOF
+		[binaries]
+		${_MESON_EXE_WRAPPER:-# exe_wrapper is not set}
+		c = '${CC}'
+		cpp = '${CXX}'
+		ar = '${XBPS_CROSS_TRIPLET}-gcc-ar'
+		nm = '${NM}'
+		ld = '${LD}'
+		strip = '${STRIP}'
+		readelf = '${READELF}'
+		objcopy = '${OBJCOPY}'
+		pkgconfig = '${PKG_CONFIG}'
+		rust = ['rustc', '--target', '${RUST_TARGET}' ,'--sysroot', '${XBPS_CROSS_BASE}/usr']
+		g-ir-scanner = '${XBPS_CROSS_BASE}/usr/bin/g-ir-scanner'
+		g-ir-compiler = '${XBPS_CROSS_BASE}/usr/bin/g-ir-compiler'
+		g-ir-generate = '${XBPS_CROSS_BASE}/usr/bin/g-ir-generate'
+		llvm-config = '/usr/bin/llvm-config'
+		cups-config = '${XBPS_CROSS_BASE}/usr/bin/cups-config'
+		
+		[properties]
+		needs_exe_wrapper = true
+		
+		[host_machine]
+		system = 'linux'
+		cpu_family = '${_MESON_CPU_FAMILY}'
+		cpu = '${_MESON_TARGET_CPU}'
+		endian = '${_MESON_TARGET_ENDIAN}'
+		EOF
+
+	unset _MESON_CPU_FAMILY _MESON_TARGET_CPU _MESON_TARGET_ENDIAN _MESON_EXE_WRAPPER
+fi
diff --git a/common/build-style/meson.sh b/common/build-style/meson.sh
index e983c5f42c2f7..5ea2eeda40097 100644
--- a/common/build-style/meson.sh
+++ b/common/build-style/meson.sh
@@ -1,94 +1,11 @@
 #
 # This helper is for templates using meson.
 #
-do_patch() {
-	: ${meson_crossfile:=xbps_meson.cross}
-
-	if [ "$CROSS_BUILD" ]; then
-		_MESON_TARGET_ENDIAN=little
-		# drop the -musl suffix to the target cpu, meson doesn't recognize it
-		_MESON_TARGET_CPU=${XBPS_TARGET_MACHINE/-musl/}
-		case "$XBPS_TARGET_MACHINE" in
-			mips|mips-musl|mipshf-musl)
-				_MESON_TARGET_ENDIAN=big
-				_MESON_CPU_FAMILY=mips
-				;;
-			armv*)
-				_MESON_CPU_FAMILY=arm
-				;;
-			i686*)
-				_MESON_CPU_FAMILY=x86
-				;;
-			ppc64le*)
-				_MESON_CPU_FAMILY=ppc64
-				;;
-			ppc64*)
-				_MESON_TARGET_ENDIAN=big
-				_MESON_CPU_FAMILY=ppc64
-				;;
-			ppcle*)
-				_MESON_CPU_FAMILY=ppc
-				;;
-			ppc*)
-				_MESON_TARGET_ENDIAN=big
-				_MESON_CPU_FAMILY=ppc
-				;;
-			*)
-				# if we reached here that means that the cpu and cpu_family
-				# are the same like 'x86_64' and 'aarch64'
-				_MESON_CPU_FAMILY=${_MESON_TARGET_CPU}
-				;;
-		esac
-
-		# Record cross-compiling information in cross file.
-		# CFLAGS and LDFLAGS must be set as c_args and c_link_args.
-		cat > ${meson_crossfile} <<EOF
-[binaries]
-c = '${CC}'
-cpp = '${CXX}'
-ar = '${XBPS_CROSS_TRIPLET}-gcc-ar'
-nm = '${NM}'
-ld = '${LD}'
-strip = '${STRIP}'
-readelf = '${READELF}'
-objcopy = '${OBJCOPY}'
-pkgconfig = '${PKG_CONFIG}'
-rust = ['rustc', '--target', '${RUST_TARGET}' ,'--sysroot', '${XBPS_CROSS_BASE}/usr']
-g-ir-scanner = '${XBPS_CROSS_BASE}/usr/bin/g-ir-scanner'
-g-ir-compiler = '${XBPS_CROSS_BASE}/usr/bin/g-ir-compiler'
-g-ir-generate = '${XBPS_CROSS_BASE}/usr/bin/g-ir-generate'
-llvm-config = '/usr/bin/llvm-config'
-cups-config = '${XBPS_CROSS_BASE}/usr/bin/cups-config'
-
-[properties]
-needs_exe_wrapper = true
-
-[built-in options]
-c_args = ['$(echo ${CFLAGS} | sed -r "s/\s+/','/g")']
-c_link_args = ['$(echo ${LDFLAGS} | sed -r "s/\s+/','/g")']
-
-cpp_args = ['$(echo ${CXXFLAGS} | sed -r "s/\s+/','/g")']
-cpp_link_args = ['$(echo ${LDFLAGS} | sed -r "s/\s+/','/g")']
-
-[host_machine]
-system = 'linux'
-cpu_family = '${_MESON_CPU_FAMILY}'
-cpu = '${_MESON_TARGET_CPU}'
-endian = '${_MESON_TARGET_ENDIAN}'
-EOF
-		if [[ $build_helper = *"qemu"* ]]; then
-			sed -e "/\[binaries\]/ a exe_wrapper = '/usr/bin/qemu-${XBPS_TARGET_QEMU_MACHINE}-static'" \
-				-i ${meson_crossfile}
-		fi
-
-		unset _MESON_CPU_FAMILY _MESON_TARGET_CPU _MESON_TARGET_ENDIAN
-	fi
-}
 
 do_configure() {
 	: ${meson_cmd:=meson}
 	: ${meson_builddir:=build}
-	: ${meson_crossfile:=xbps_meson.cross}
+	: ${meson_crossfile:="${XBPS_WRAPPERDIR}/meson/xbps_meson.cross"}
 
 	if [ "$CROSS_BUILD" ]; then
 		configure_args+=" --cross-file=${meson_crossfile}"
diff --git a/common/environment/build-style/meson.sh b/common/environment/build-style/meson.sh
index d5a3c4141f7d9..dbfe93700f691 100644
--- a/common/environment/build-style/meson.sh
+++ b/common/environment/build-style/meson.sh
@@ -1 +1,2 @@
 hostmakedepends+=" meson"
+build_helper+=" meson"

From 3a3d66efb87e6fa43fe17c3cd8ac55395eed2a51 Mon Sep 17 00:00:00 2001
From: "Andrew J. Hesford" <ajh@sideband.org>
Date: Wed, 20 Sep 2023 10:45:43 -0400
Subject: [PATCH 2/2] python3-scipy: use new meson helper

---
 srcpkgs/python3-scipy/template | 49 +++++++++++++++-------------------
 1 file changed, 21 insertions(+), 28 deletions(-)

diff --git a/srcpkgs/python3-scipy/template b/srcpkgs/python3-scipy/template
index ba0dd761cdcf5..d2738566c7316 100644
--- a/srcpkgs/python3-scipy/template
+++ b/srcpkgs/python3-scipy/template
@@ -2,9 +2,10 @@
 pkgname=python3-scipy
 version=1.11.2
 revision=1
-build_style=meson
-build_helper="python3"
-configure_args="$(vopt_if openblas "" "-Dblas=blas -Dlapack=lapack")"
+build_style=python3-pep517
+build_helper="meson"
+make_build_args="--no-isolation --wheel
+ $(vopt_if openblas "" "-Csetup-args=-Dblas=blas -Csetup-args=-Dlapack=lapack")"
 hostmakedepends="python3-build python3-installer python3-meson-python
  python3-wheel python3-Cython python3-pybind11 pythran python3-numpy
  gcc-fortran pkg-config"
@@ -22,8 +23,12 @@ make_check="no" # Tests need an installed copy to run and meson makes this tough
 build_options="openblas"
 
 if [ "$CROSS_BUILD" ]; then
+	make_build_args+="
+	 -Csetup-args=--cross-file=${XBPS_WRAPPERDIR}/meson/xbps_meson.cross"
+	 -Csetup-args=--cross-file=${XBPS_WRAPPERDIR}/meson/python.cross
+	"
+
 	_pybind11_dir="${py3_sitelib}/pybind11"
-	configure_args+=" --cross-file=python.cross"
 	export PKG_CONFIG_PATH="${XBPS_CROSS_BASE}/${_pybind11_dir}/share/pkgconfig"
 	# pybind11 uses a path relative to the pkgconfig file to set $prefix,
 	# which causes the wrapper to double-include $XBPS_CROSS_BASE; override
@@ -46,34 +51,22 @@ if [ "$build_option_openblas" ]; then
 	esac
 fi
 
-pre_patch() {
-	if [ "${CROSS_BUILD}" ]; then
-		# Meson can't tolerate $CC with arguments as set by the build helper
-		CC="${XBPS_CROSS_TRIPLET}-gcc"
-		# CXX needs to know where to find Python headers
-		CXXFLAGS+=" -I${XBPS_CROSS_BASE}/${py3_inc}"
-	fi
-}
-
 post_patch() {
 	if [ "$CROSS_BUILD" ]; then
 		local _xpy="${XBPS_CROSS_BASE}/${py3_sitelib}"
-		cat > python.cross <<-EOF
-		[properties]
-		numpy-include-dir = '${_xpy}/numpy/core/include'
-		pythran-include-dir = '${_xpy}/pythran'
-		EOF
+		cat > "${XBPS_WRAPPERDIR}/meson/python.cross" <<-EOF
+			[properties]
+			numpy-include-dir = '${_xpy}/numpy/core/include'
+			pythran-include-dir = '${_xpy}/pythran'
+			EOF
 	fi
 }
 
-do_build() {
-	# Use the build directory already configured by xbps-src for meson
-	python3 -m build --no-isolation --wheel \
-		-Cbuilddir="./build" -Ccompile-args="${makejobs}" .
-}
-
-do_install() {
-	python3 -m installer --destdir "${DESTDIR}" \
-		--no-compile-bytecode dist/*.whl
-	vlicense LICENSE.txt
+pre_build() {
+	if [ "$CROSS_BUILD" ]; then
+		# Meson can't tolerate $CC with arguments as set by the build helper
+		CC="${XBPS_CROSS_TRIPLET}-gcc"
+		# CXX needs to know where to find Python headers
+		CXXFLAGS+=" -I${XBPS_CROSS_BASE}/${py3_inc}"
+	fi
 }

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PR PATCH] [Updated] [RFC, WIP] common/build-helper/meson.sh: new build helper, used by meson build style
  2023-09-18 19:53 [PR PATCH] [RFC, WIP] common/build-helper/meson.sh: new build helper, used by meson build style ahesford
                   ` (2 preceding siblings ...)
  2023-09-20 14:46 ` [PR PATCH] [Updated] " ahesford
@ 2023-09-20 14:48 ` ahesford
  2023-09-20 14:50 ` ahesford
                   ` (9 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: ahesford @ 2023-09-20 14:48 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 2478 bytes --]

There is an updated pull request by ahesford against master on the void-packages repository

https://github.com/ahesford/void-packages meson
https://github.com/void-linux/void-packages/pull/46117

[RFC, WIP] common/build-helper/meson.sh: new build helper, used by meson build style
The `python3-scipy` package now builds with `python3-meson-python`, with some more coming down the pike. The Python build process is necessary to include Python package metadata. For SciPy, this is accomplished by using the `meson` build style to configure a build directory, then overriding `do_build` and `do_install` to build things the PEP517 way (using the pre-configured build directory).

It might be helpful to define a `meson` build helper that can write out the standard cross file for builds, allowing packages like SciPy to use the `python3-pep517` build style with the `meson` helper. There are some issues to be worked out:
1. It seems like the `xbps_meson.cross` is written before `CFLAGS`, *et al.* are properly defined, so this cross file is actually broken. (This is the process by which the `qmake` helper writes its configurations, and they reference `CFLAGS` and others; is the `qmake` helper writing broken configs?)
2. The meson configuration (which would need to happen even with `python3-pep517` plus a `meson` helper) still includes a lot of magic that would have to be brought over to templates. This isn't really easier than the current practice of overriding the one-line `do_build` and `do_install`.

A possible solution would be to define a special-purpose function in the helper, called `vmesoncross` or somesuch, that will only write the configured when called---from a build function where these are properly defined (*e.g.*, `pre_configure`, `do_configure`). We could also define a special `do_configure`-like function in the helper that can be used by the `meson` style to actually do the configuration. This might be a bit ugly, but avoids repetition or violating the typical practice that the actual build functions are only defined in templates or build styles.

A third option is just defining a new `python3-meson` build style that mashes the meson `do_configure` bits from the `meson` style with the `do_build` and `do_install` bits from the `python3-pep517` style.

All of these options are sub-optimal, but I'm not sure which one is least offsensive.

A patch file from https://github.com/void-linux/void-packages/pull/46117.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-meson-46117.patch --]
[-- Type: text/x-diff, Size: 9269 bytes --]

From 8cd6e8ef00680341dd65678e22952bb115aa2e03 Mon Sep 17 00:00:00 2001
From: "Andrew J. Hesford" <ajh@sideband.org>
Date: Mon, 18 Sep 2023 15:40:49 -0400
Subject: [PATCH 1/2] common/build-helper/meson.sh: new build helper, used by
 meson build style

---
 common/build-helper/meson.sh            | 82 ++++++++++++++++++++++++
 common/build-style/meson.sh             | 85 +------------------------
 common/environment/build-style/meson.sh |  1 +
 3 files changed, 84 insertions(+), 84 deletions(-)
 create mode 100644 common/build-helper/meson.sh

diff --git a/common/build-helper/meson.sh b/common/build-helper/meson.sh
new file mode 100644
index 0000000000000..1933306c18a4b
--- /dev/null
+++ b/common/build-helper/meson.sh
@@ -0,0 +1,82 @@
+# This bulid-helper writes a Meson cross-file, allowing other build styles
+# to properly drive cross-builds in Meson when appropriate
+
+if [ "$CROSS_BUILD" ]; then
+	mkdir -p "${XBPS_WRAPPERDIR}/meson"
+
+	_MESON_TARGET_ENDIAN=little
+	# drop the -musl suffix to the target cpu, meson doesn't recognize it
+	_MESON_TARGET_CPU=${XBPS_TARGET_MACHINE/-musl/}
+	case "$XBPS_TARGET_MACHINE" in
+		mips|mips-musl|mipshf-musl)
+			_MESON_TARGET_ENDIAN=big
+			_MESON_CPU_FAMILY=mips
+			;;
+		armv*)
+			_MESON_CPU_FAMILY=arm
+			;;
+		i686*)
+			_MESON_CPU_FAMILY=x86
+			;;
+		ppc64le*)
+			_MESON_CPU_FAMILY=ppc64
+			;;
+		ppc64*)
+			_MESON_TARGET_ENDIAN=big
+			_MESON_CPU_FAMILY=ppc64
+			;;
+		ppcle*)
+			_MESON_CPU_FAMILY=ppc
+			;;
+		ppc*)
+			_MESON_TARGET_ENDIAN=big
+			_MESON_CPU_FAMILY=ppc
+			;;
+		*)
+			# if we reached here that means that the cpu and cpu_family
+			# are the same like 'x86_64' and 'aarch64'
+			_MESON_CPU_FAMILY=${_MESON_TARGET_CPU}
+			;;
+	esac
+
+	# Tell meson to run binaries with qemu if desired
+	_MESON_EXE_WRAPPER=""
+	if [[ "${build_helper}" = *qemu* ]]; then
+		_MESON_EXE_WRAPPER="exe_wrapper = '/usr/bin/qemu-${XBPS_TARGET_QEMU_MACHINE}-static'"
+	fi
+
+	# Record cross-compiling information in cross file.
+	#
+	# CFLAGS, CXXFLAGS and LDFLAGS are not yet available and
+	# will be taken from the environment at configure time.
+	cat > "${XBPS_WRAPPERDIR}/meson/xbps_meson.cross" <<-EOF
+		[binaries]
+		${_MESON_EXE_WRAPPER:-# exe_wrapper is not set}
+		c = '${CC}'
+		cpp = '${CXX}'
+		ar = '${XBPS_CROSS_TRIPLET}-gcc-ar'
+		nm = '${NM}'
+		ld = '${LD}'
+		strip = '${STRIP}'
+		readelf = '${READELF}'
+		objcopy = '${OBJCOPY}'
+		pkgconfig = '${PKG_CONFIG}'
+		rust = ['rustc', '--target', '${RUST_TARGET}' ,'--sysroot', '${XBPS_CROSS_BASE}/usr']
+		g-ir-scanner = '${XBPS_CROSS_BASE}/usr/bin/g-ir-scanner'
+		g-ir-compiler = '${XBPS_CROSS_BASE}/usr/bin/g-ir-compiler'
+		g-ir-generate = '${XBPS_CROSS_BASE}/usr/bin/g-ir-generate'
+		llvm-config = '/usr/bin/llvm-config'
+		cups-config = '${XBPS_CROSS_BASE}/usr/bin/cups-config'
+		
+		[properties]
+		needs_exe_wrapper = true
+		
+		[host_machine]
+		system = 'linux'
+		cpu_family = '${_MESON_CPU_FAMILY}'
+		cpu = '${_MESON_TARGET_CPU}'
+		endian = '${_MESON_TARGET_ENDIAN}'
+		EOF
+
+	unset _MESON_CPU_FAMILY _MESON_TARGET_CPU _MESON_TARGET_ENDIAN _MESON_EXE_WRAPPER
+fi
diff --git a/common/build-style/meson.sh b/common/build-style/meson.sh
index e983c5f42c2f7..5ea2eeda40097 100644
--- a/common/build-style/meson.sh
+++ b/common/build-style/meson.sh
@@ -1,94 +1,11 @@
 #
 # This helper is for templates using meson.
 #
-do_patch() {
-	: ${meson_crossfile:=xbps_meson.cross}
-
-	if [ "$CROSS_BUILD" ]; then
-		_MESON_TARGET_ENDIAN=little
-		# drop the -musl suffix to the target cpu, meson doesn't recognize it
-		_MESON_TARGET_CPU=${XBPS_TARGET_MACHINE/-musl/}
-		case "$XBPS_TARGET_MACHINE" in
-			mips|mips-musl|mipshf-musl)
-				_MESON_TARGET_ENDIAN=big
-				_MESON_CPU_FAMILY=mips
-				;;
-			armv*)
-				_MESON_CPU_FAMILY=arm
-				;;
-			i686*)
-				_MESON_CPU_FAMILY=x86
-				;;
-			ppc64le*)
-				_MESON_CPU_FAMILY=ppc64
-				;;
-			ppc64*)
-				_MESON_TARGET_ENDIAN=big
-				_MESON_CPU_FAMILY=ppc64
-				;;
-			ppcle*)
-				_MESON_CPU_FAMILY=ppc
-				;;
-			ppc*)
-				_MESON_TARGET_ENDIAN=big
-				_MESON_CPU_FAMILY=ppc
-				;;
-			*)
-				# if we reached here that means that the cpu and cpu_family
-				# are the same like 'x86_64' and 'aarch64'
-				_MESON_CPU_FAMILY=${_MESON_TARGET_CPU}
-				;;
-		esac
-
-		# Record cross-compiling information in cross file.
-		# CFLAGS and LDFLAGS must be set as c_args and c_link_args.
-		cat > ${meson_crossfile} <<EOF
-[binaries]
-c = '${CC}'
-cpp = '${CXX}'
-ar = '${XBPS_CROSS_TRIPLET}-gcc-ar'
-nm = '${NM}'
-ld = '${LD}'
-strip = '${STRIP}'
-readelf = '${READELF}'
-objcopy = '${OBJCOPY}'
-pkgconfig = '${PKG_CONFIG}'
-rust = ['rustc', '--target', '${RUST_TARGET}' ,'--sysroot', '${XBPS_CROSS_BASE}/usr']
-g-ir-scanner = '${XBPS_CROSS_BASE}/usr/bin/g-ir-scanner'
-g-ir-compiler = '${XBPS_CROSS_BASE}/usr/bin/g-ir-compiler'
-g-ir-generate = '${XBPS_CROSS_BASE}/usr/bin/g-ir-generate'
-llvm-config = '/usr/bin/llvm-config'
-cups-config = '${XBPS_CROSS_BASE}/usr/bin/cups-config'
-
-[properties]
-needs_exe_wrapper = true
-
-[built-in options]
-c_args = ['$(echo ${CFLAGS} | sed -r "s/\s+/','/g")']
-c_link_args = ['$(echo ${LDFLAGS} | sed -r "s/\s+/','/g")']
-
-cpp_args = ['$(echo ${CXXFLAGS} | sed -r "s/\s+/','/g")']
-cpp_link_args = ['$(echo ${LDFLAGS} | sed -r "s/\s+/','/g")']
-
-[host_machine]
-system = 'linux'
-cpu_family = '${_MESON_CPU_FAMILY}'
-cpu = '${_MESON_TARGET_CPU}'
-endian = '${_MESON_TARGET_ENDIAN}'
-EOF
-		if [[ $build_helper = *"qemu"* ]]; then
-			sed -e "/\[binaries\]/ a exe_wrapper = '/usr/bin/qemu-${XBPS_TARGET_QEMU_MACHINE}-static'" \
-				-i ${meson_crossfile}
-		fi
-
-		unset _MESON_CPU_FAMILY _MESON_TARGET_CPU _MESON_TARGET_ENDIAN
-	fi
-}
 
 do_configure() {
 	: ${meson_cmd:=meson}
 	: ${meson_builddir:=build}
-	: ${meson_crossfile:=xbps_meson.cross}
+	: ${meson_crossfile:="${XBPS_WRAPPERDIR}/meson/xbps_meson.cross"}
 
 	if [ "$CROSS_BUILD" ]; then
 		configure_args+=" --cross-file=${meson_crossfile}"
diff --git a/common/environment/build-style/meson.sh b/common/environment/build-style/meson.sh
index d5a3c4141f7d9..dbfe93700f691 100644
--- a/common/environment/build-style/meson.sh
+++ b/common/environment/build-style/meson.sh
@@ -1 +1,2 @@
 hostmakedepends+=" meson"
+build_helper+=" meson"

From 27a2988d23f0a61f6d9802ffd09b65fc1cde85c3 Mon Sep 17 00:00:00 2001
From: "Andrew J. Hesford" <ajh@sideband.org>
Date: Wed, 20 Sep 2023 10:45:43 -0400
Subject: [PATCH 2/2] python3-scipy: use new meson helper

---
 srcpkgs/python3-scipy/template | 49 +++++++++++++++-------------------
 1 file changed, 21 insertions(+), 28 deletions(-)

diff --git a/srcpkgs/python3-scipy/template b/srcpkgs/python3-scipy/template
index ba0dd761cdcf5..9df3359669acc 100644
--- a/srcpkgs/python3-scipy/template
+++ b/srcpkgs/python3-scipy/template
@@ -2,9 +2,10 @@
 pkgname=python3-scipy
 version=1.11.2
 revision=1
-build_style=meson
-build_helper="python3"
-configure_args="$(vopt_if openblas "" "-Dblas=blas -Dlapack=lapack")"
+build_style=python3-pep517
+build_helper="meson"
+make_build_args="--no-isolation --wheel
+ $(vopt_if openblas "" "-Csetup-args=-Dblas=blas -Csetup-args=-Dlapack=lapack")"
 hostmakedepends="python3-build python3-installer python3-meson-python
  python3-wheel python3-Cython python3-pybind11 pythran python3-numpy
  gcc-fortran pkg-config"
@@ -22,8 +23,12 @@ make_check="no" # Tests need an installed copy to run and meson makes this tough
 build_options="openblas"
 
 if [ "$CROSS_BUILD" ]; then
+	make_build_args+="
+	 -Csetup-args=--cross-file=${XBPS_WRAPPERDIR}/meson/xbps_meson.cross
+	 -Csetup-args=--cross-file=${XBPS_WRAPPERDIR}/meson/python.cross
+	"
+
 	_pybind11_dir="${py3_sitelib}/pybind11"
-	configure_args+=" --cross-file=python.cross"
 	export PKG_CONFIG_PATH="${XBPS_CROSS_BASE}/${_pybind11_dir}/share/pkgconfig"
 	# pybind11 uses a path relative to the pkgconfig file to set $prefix,
 	# which causes the wrapper to double-include $XBPS_CROSS_BASE; override
@@ -46,34 +51,22 @@ if [ "$build_option_openblas" ]; then
 	esac
 fi
 
-pre_patch() {
-	if [ "${CROSS_BUILD}" ]; then
-		# Meson can't tolerate $CC with arguments as set by the build helper
-		CC="${XBPS_CROSS_TRIPLET}-gcc"
-		# CXX needs to know where to find Python headers
-		CXXFLAGS+=" -I${XBPS_CROSS_BASE}/${py3_inc}"
-	fi
-}
-
 post_patch() {
 	if [ "$CROSS_BUILD" ]; then
 		local _xpy="${XBPS_CROSS_BASE}/${py3_sitelib}"
-		cat > python.cross <<-EOF
-		[properties]
-		numpy-include-dir = '${_xpy}/numpy/core/include'
-		pythran-include-dir = '${_xpy}/pythran'
-		EOF
+		cat > "${XBPS_WRAPPERDIR}/meson/python.cross" <<-EOF
+			[properties]
+			numpy-include-dir = '${_xpy}/numpy/core/include'
+			pythran-include-dir = '${_xpy}/pythran'
+			EOF
 	fi
 }
 
-do_build() {
-	# Use the build directory already configured by xbps-src for meson
-	python3 -m build --no-isolation --wheel \
-		-Cbuilddir="./build" -Ccompile-args="${makejobs}" .
-}
-
-do_install() {
-	python3 -m installer --destdir "${DESTDIR}" \
-		--no-compile-bytecode dist/*.whl
-	vlicense LICENSE.txt
+pre_build() {
+	if [ "$CROSS_BUILD" ]; then
+		# Meson can't tolerate $CC with arguments as set by the build helper
+		CC="${XBPS_CROSS_TRIPLET}-gcc"
+		# CXX needs to know where to find Python headers
+		CXXFLAGS+=" -I${XBPS_CROSS_BASE}/${py3_inc}"
+	fi
 }

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PR PATCH] [Updated] [RFC, WIP] common/build-helper/meson.sh: new build helper, used by meson build style
  2023-09-18 19:53 [PR PATCH] [RFC, WIP] common/build-helper/meson.sh: new build helper, used by meson build style ahesford
                   ` (3 preceding siblings ...)
  2023-09-20 14:48 ` ahesford
@ 2023-09-20 14:50 ` ahesford
  2023-09-20 14:54 ` ahesford
                   ` (8 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: ahesford @ 2023-09-20 14:50 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 2478 bytes --]

There is an updated pull request by ahesford against master on the void-packages repository

https://github.com/ahesford/void-packages meson
https://github.com/void-linux/void-packages/pull/46117

[RFC, WIP] common/build-helper/meson.sh: new build helper, used by meson build style
The `python3-scipy` package now builds with `python3-meson-python`, with some more coming down the pike. The Python build process is necessary to include Python package metadata. For SciPy, this is accomplished by using the `meson` build style to configure a build directory, then overriding `do_build` and `do_install` to build things the PEP517 way (using the pre-configured build directory).

It might be helpful to define a `meson` build helper that can write out the standard cross file for builds, allowing packages like SciPy to use the `python3-pep517` build style with the `meson` helper. There are some issues to be worked out:
1. It seems like the `xbps_meson.cross` is written before `CFLAGS`, *et al.* are properly defined, so this cross file is actually broken. (This is the process by which the `qmake` helper writes its configurations, and they reference `CFLAGS` and others; is the `qmake` helper writing broken configs?)
2. The meson configuration (which would need to happen even with `python3-pep517` plus a `meson` helper) still includes a lot of magic that would have to be brought over to templates. This isn't really easier than the current practice of overriding the one-line `do_build` and `do_install`.

A possible solution would be to define a special-purpose function in the helper, called `vmesoncross` or somesuch, that will only write the configured when called---from a build function where these are properly defined (*e.g.*, `pre_configure`, `do_configure`). We could also define a special `do_configure`-like function in the helper that can be used by the `meson` style to actually do the configuration. This might be a bit ugly, but avoids repetition or violating the typical practice that the actual build functions are only defined in templates or build styles.

A third option is just defining a new `python3-meson` build style that mashes the meson `do_configure` bits from the `meson` style with the `do_build` and `do_install` bits from the `python3-pep517` style.

All of these options are sub-optimal, but I'm not sure which one is least offsensive.

A patch file from https://github.com/void-linux/void-packages/pull/46117.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-meson-46117.patch --]
[-- Type: text/x-diff, Size: 9287 bytes --]

From 8cd6e8ef00680341dd65678e22952bb115aa2e03 Mon Sep 17 00:00:00 2001
From: "Andrew J. Hesford" <ajh@sideband.org>
Date: Mon, 18 Sep 2023 15:40:49 -0400
Subject: [PATCH 1/2] common/build-helper/meson.sh: new build helper, used by
 meson build style

---
 common/build-helper/meson.sh            | 82 ++++++++++++++++++++++++
 common/build-style/meson.sh             | 85 +------------------------
 common/environment/build-style/meson.sh |  1 +
 3 files changed, 84 insertions(+), 84 deletions(-)
 create mode 100644 common/build-helper/meson.sh

diff --git a/common/build-helper/meson.sh b/common/build-helper/meson.sh
new file mode 100644
index 0000000000000..1933306c18a4b
--- /dev/null
+++ b/common/build-helper/meson.sh
@@ -0,0 +1,82 @@
+# This bulid-helper writes a Meson cross-file, allowing other build styles
+# to properly drive cross-builds in Meson when appropriate
+
+if [ "$CROSS_BUILD" ]; then
+	mkdir -p "${XBPS_WRAPPERDIR}/meson"
+
+	_MESON_TARGET_ENDIAN=little
+	# drop the -musl suffix to the target cpu, meson doesn't recognize it
+	_MESON_TARGET_CPU=${XBPS_TARGET_MACHINE/-musl/}
+	case "$XBPS_TARGET_MACHINE" in
+		mips|mips-musl|mipshf-musl)
+			_MESON_TARGET_ENDIAN=big
+			_MESON_CPU_FAMILY=mips
+			;;
+		armv*)
+			_MESON_CPU_FAMILY=arm
+			;;
+		i686*)
+			_MESON_CPU_FAMILY=x86
+			;;
+		ppc64le*)
+			_MESON_CPU_FAMILY=ppc64
+			;;
+		ppc64*)
+			_MESON_TARGET_ENDIAN=big
+			_MESON_CPU_FAMILY=ppc64
+			;;
+		ppcle*)
+			_MESON_CPU_FAMILY=ppc
+			;;
+		ppc*)
+			_MESON_TARGET_ENDIAN=big
+			_MESON_CPU_FAMILY=ppc
+			;;
+		*)
+			# if we reached here that means that the cpu and cpu_family
+			# are the same like 'x86_64' and 'aarch64'
+			_MESON_CPU_FAMILY=${_MESON_TARGET_CPU}
+			;;
+	esac
+
+	# Tell meson to run binaries with qemu if desired
+	_MESON_EXE_WRAPPER=""
+	if [[ "${build_helper}" = *qemu* ]]; then
+		_MESON_EXE_WRAPPER="exe_wrapper = '/usr/bin/qemu-${XBPS_TARGET_QEMU_MACHINE}-static'"
+	fi
+
+	# Record cross-compiling information in cross file.
+	#
+	# CFLAGS, CXXFLAGS and LDFLAGS are not yet available and
+	# will be taken from the environment at configure time.
+	cat > "${XBPS_WRAPPERDIR}/meson/xbps_meson.cross" <<-EOF
+		[binaries]
+		${_MESON_EXE_WRAPPER:-# exe_wrapper is not set}
+		c = '${CC}'
+		cpp = '${CXX}'
+		ar = '${XBPS_CROSS_TRIPLET}-gcc-ar'
+		nm = '${NM}'
+		ld = '${LD}'
+		strip = '${STRIP}'
+		readelf = '${READELF}'
+		objcopy = '${OBJCOPY}'
+		pkgconfig = '${PKG_CONFIG}'
+		rust = ['rustc', '--target', '${RUST_TARGET}' ,'--sysroot', '${XBPS_CROSS_BASE}/usr']
+		g-ir-scanner = '${XBPS_CROSS_BASE}/usr/bin/g-ir-scanner'
+		g-ir-compiler = '${XBPS_CROSS_BASE}/usr/bin/g-ir-compiler'
+		g-ir-generate = '${XBPS_CROSS_BASE}/usr/bin/g-ir-generate'
+		llvm-config = '/usr/bin/llvm-config'
+		cups-config = '${XBPS_CROSS_BASE}/usr/bin/cups-config'
+		
+		[properties]
+		needs_exe_wrapper = true
+		
+		[host_machine]
+		system = 'linux'
+		cpu_family = '${_MESON_CPU_FAMILY}'
+		cpu = '${_MESON_TARGET_CPU}'
+		endian = '${_MESON_TARGET_ENDIAN}'
+		EOF
+
+	unset _MESON_CPU_FAMILY _MESON_TARGET_CPU _MESON_TARGET_ENDIAN _MESON_EXE_WRAPPER
+fi
diff --git a/common/build-style/meson.sh b/common/build-style/meson.sh
index e983c5f42c2f7..5ea2eeda40097 100644
--- a/common/build-style/meson.sh
+++ b/common/build-style/meson.sh
@@ -1,94 +1,11 @@
 #
 # This helper is for templates using meson.
 #
-do_patch() {
-	: ${meson_crossfile:=xbps_meson.cross}
-
-	if [ "$CROSS_BUILD" ]; then
-		_MESON_TARGET_ENDIAN=little
-		# drop the -musl suffix to the target cpu, meson doesn't recognize it
-		_MESON_TARGET_CPU=${XBPS_TARGET_MACHINE/-musl/}
-		case "$XBPS_TARGET_MACHINE" in
-			mips|mips-musl|mipshf-musl)
-				_MESON_TARGET_ENDIAN=big
-				_MESON_CPU_FAMILY=mips
-				;;
-			armv*)
-				_MESON_CPU_FAMILY=arm
-				;;
-			i686*)
-				_MESON_CPU_FAMILY=x86
-				;;
-			ppc64le*)
-				_MESON_CPU_FAMILY=ppc64
-				;;
-			ppc64*)
-				_MESON_TARGET_ENDIAN=big
-				_MESON_CPU_FAMILY=ppc64
-				;;
-			ppcle*)
-				_MESON_CPU_FAMILY=ppc
-				;;
-			ppc*)
-				_MESON_TARGET_ENDIAN=big
-				_MESON_CPU_FAMILY=ppc
-				;;
-			*)
-				# if we reached here that means that the cpu and cpu_family
-				# are the same like 'x86_64' and 'aarch64'
-				_MESON_CPU_FAMILY=${_MESON_TARGET_CPU}
-				;;
-		esac
-
-		# Record cross-compiling information in cross file.
-		# CFLAGS and LDFLAGS must be set as c_args and c_link_args.
-		cat > ${meson_crossfile} <<EOF
-[binaries]
-c = '${CC}'
-cpp = '${CXX}'
-ar = '${XBPS_CROSS_TRIPLET}-gcc-ar'
-nm = '${NM}'
-ld = '${LD}'
-strip = '${STRIP}'
-readelf = '${READELF}'
-objcopy = '${OBJCOPY}'
-pkgconfig = '${PKG_CONFIG}'
-rust = ['rustc', '--target', '${RUST_TARGET}' ,'--sysroot', '${XBPS_CROSS_BASE}/usr']
-g-ir-scanner = '${XBPS_CROSS_BASE}/usr/bin/g-ir-scanner'
-g-ir-compiler = '${XBPS_CROSS_BASE}/usr/bin/g-ir-compiler'
-g-ir-generate = '${XBPS_CROSS_BASE}/usr/bin/g-ir-generate'
-llvm-config = '/usr/bin/llvm-config'
-cups-config = '${XBPS_CROSS_BASE}/usr/bin/cups-config'
-
-[properties]
-needs_exe_wrapper = true
-
-[built-in options]
-c_args = ['$(echo ${CFLAGS} | sed -r "s/\s+/','/g")']
-c_link_args = ['$(echo ${LDFLAGS} | sed -r "s/\s+/','/g")']
-
-cpp_args = ['$(echo ${CXXFLAGS} | sed -r "s/\s+/','/g")']
-cpp_link_args = ['$(echo ${LDFLAGS} | sed -r "s/\s+/','/g")']
-
-[host_machine]
-system = 'linux'
-cpu_family = '${_MESON_CPU_FAMILY}'
-cpu = '${_MESON_TARGET_CPU}'
-endian = '${_MESON_TARGET_ENDIAN}'
-EOF
-		if [[ $build_helper = *"qemu"* ]]; then
-			sed -e "/\[binaries\]/ a exe_wrapper = '/usr/bin/qemu-${XBPS_TARGET_QEMU_MACHINE}-static'" \
-				-i ${meson_crossfile}
-		fi
-
-		unset _MESON_CPU_FAMILY _MESON_TARGET_CPU _MESON_TARGET_ENDIAN
-	fi
-}
 
 do_configure() {
 	: ${meson_cmd:=meson}
 	: ${meson_builddir:=build}
-	: ${meson_crossfile:=xbps_meson.cross}
+	: ${meson_crossfile:="${XBPS_WRAPPERDIR}/meson/xbps_meson.cross"}
 
 	if [ "$CROSS_BUILD" ]; then
 		configure_args+=" --cross-file=${meson_crossfile}"
diff --git a/common/environment/build-style/meson.sh b/common/environment/build-style/meson.sh
index d5a3c4141f7d9..dbfe93700f691 100644
--- a/common/environment/build-style/meson.sh
+++ b/common/environment/build-style/meson.sh
@@ -1 +1,2 @@
 hostmakedepends+=" meson"
+build_helper+=" meson"

From 7b9d2832275bb53258173c834c4c52cfb6875846 Mon Sep 17 00:00:00 2001
From: "Andrew J. Hesford" <ajh@sideband.org>
Date: Wed, 20 Sep 2023 10:45:43 -0400
Subject: [PATCH 2/2] python3-scipy: use new meson helper

---
 srcpkgs/python3-scipy/template | 47 ++++++++++++++++------------------
 1 file changed, 22 insertions(+), 25 deletions(-)

diff --git a/srcpkgs/python3-scipy/template b/srcpkgs/python3-scipy/template
index ba0dd761cdcf5..e99919babf3bf 100644
--- a/srcpkgs/python3-scipy/template
+++ b/srcpkgs/python3-scipy/template
@@ -2,9 +2,10 @@
 pkgname=python3-scipy
 version=1.11.2
 revision=1
-build_style=meson
-build_helper="python3"
-configure_args="$(vopt_if openblas "" "-Dblas=blas -Dlapack=lapack")"
+build_style=python3-pep517
+build_helper="meson"
+make_build_args="--no-isolation --wheel
+ $(vopt_if openblas "" "-Csetup-args=-Dblas=blas -Csetup-args=-Dlapack=lapack")"
 hostmakedepends="python3-build python3-installer python3-meson-python
  python3-wheel python3-Cython python3-pybind11 pythran python3-numpy
  gcc-fortran pkg-config"
@@ -22,8 +23,12 @@ make_check="no" # Tests need an installed copy to run and meson makes this tough
 build_options="openblas"
 
 if [ "$CROSS_BUILD" ]; then
+	make_build_args+="
+	 -Csetup-args=--cross-file=${XBPS_WRAPPERDIR}/meson/xbps_meson.cross
+	 -Csetup-args=--cross-file=${XBPS_WRAPPERDIR}/meson/python.cross
+	"
+
 	_pybind11_dir="${py3_sitelib}/pybind11"
-	configure_args+=" --cross-file=python.cross"
 	export PKG_CONFIG_PATH="${XBPS_CROSS_BASE}/${_pybind11_dir}/share/pkgconfig"
 	# pybind11 uses a path relative to the pkgconfig file to set $prefix,
 	# which causes the wrapper to double-include $XBPS_CROSS_BASE; override
@@ -46,34 +51,26 @@ if [ "$build_option_openblas" ]; then
 	esac
 fi
 
-pre_patch() {
-	if [ "${CROSS_BUILD}" ]; then
-		# Meson can't tolerate $CC with arguments as set by the build helper
-		CC="${XBPS_CROSS_TRIPLET}-gcc"
-		# CXX needs to know where to find Python headers
-		CXXFLAGS+=" -I${XBPS_CROSS_BASE}/${py3_inc}"
-	fi
-}
-
 post_patch() {
 	if [ "$CROSS_BUILD" ]; then
 		local _xpy="${XBPS_CROSS_BASE}/${py3_sitelib}"
-		cat > python.cross <<-EOF
-		[properties]
-		numpy-include-dir = '${_xpy}/numpy/core/include'
-		pythran-include-dir = '${_xpy}/pythran'
-		EOF
+		cat > "${XBPS_WRAPPERDIR}/meson/python.cross" <<-EOF
+			[properties]
+			numpy-include-dir = '${_xpy}/numpy/core/include'
+			pythran-include-dir = '${_xpy}/pythran'
+			EOF
 	fi
 }
 
-do_build() {
-	# Use the build directory already configured by xbps-src for meson
-	python3 -m build --no-isolation --wheel \
-		-Cbuilddir="./build" -Ccompile-args="${makejobs}" .
+pre_build() {
+	if [ "$CROSS_BUILD" ]; then
+		# Meson can't tolerate $CC with arguments as set by the build helper
+		CC="${XBPS_CROSS_TRIPLET}-gcc"
+		# CXX needs to know where to find Python headers
+		CXXFLAGS+=" -I${XBPS_CROSS_BASE}/${py3_inc}"
+	fi
 }
 
-do_install() {
-	python3 -m installer --destdir "${DESTDIR}" \
-		--no-compile-bytecode dist/*.whl
+post_install() {
 	vlicense LICENSE.txt
 }

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC, WIP] common/build-helper/meson.sh: new build helper, used by meson build style
  2023-09-18 19:53 [PR PATCH] [RFC, WIP] common/build-helper/meson.sh: new build helper, used by meson build style ahesford
                   ` (4 preceding siblings ...)
  2023-09-20 14:50 ` ahesford
@ 2023-09-20 14:54 ` ahesford
  2023-09-20 15:13 ` [PR PATCH] [Updated] " ahesford
                   ` (7 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: ahesford @ 2023-09-20 14:54 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 829 bytes --]

New comment by ahesford on void-packages repository

https://github.com/void-linux/void-packages/pull/46117#issuecomment-1727894679

Comment:
Alright, it turns out that meson respects `$CFLAGS`, `$LDFLAGS` and `$CXXFLAGS` in the environment at configure time, so we don't need to write them to the cross file; leaving these out produces a valid cross file and lets us customize the flags in templates before `do_configure` is run.

As for re-using `do_configure`, this might not be necessary for the few packages that will be moving to `mesonpy` PEP517 builds in the future, so I'm going to ignore it now.

I've updated `python3-scipy` to use the new helper in conjunction with the `python3-pep517` build style, and will be rebuilding all of the packages with `build_style=meson` to confirm that this doesn't break anything.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PR PATCH] [Updated] [RFC, WIP] common/build-helper/meson.sh: new build helper, used by meson build style
  2023-09-18 19:53 [PR PATCH] [RFC, WIP] common/build-helper/meson.sh: new build helper, used by meson build style ahesford
                   ` (5 preceding siblings ...)
  2023-09-20 14:54 ` ahesford
@ 2023-09-20 15:13 ` ahesford
  2023-09-20 15:16 ` ahesford
                   ` (6 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: ahesford @ 2023-09-20 15:13 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 2478 bytes --]

There is an updated pull request by ahesford against master on the void-packages repository

https://github.com/ahesford/void-packages meson
https://github.com/void-linux/void-packages/pull/46117

[RFC, WIP] common/build-helper/meson.sh: new build helper, used by meson build style
The `python3-scipy` package now builds with `python3-meson-python`, with some more coming down the pike. The Python build process is necessary to include Python package metadata. For SciPy, this is accomplished by using the `meson` build style to configure a build directory, then overriding `do_build` and `do_install` to build things the PEP517 way (using the pre-configured build directory).

It might be helpful to define a `meson` build helper that can write out the standard cross file for builds, allowing packages like SciPy to use the `python3-pep517` build style with the `meson` helper. There are some issues to be worked out:
1. It seems like the `xbps_meson.cross` is written before `CFLAGS`, *et al.* are properly defined, so this cross file is actually broken. (This is the process by which the `qmake` helper writes its configurations, and they reference `CFLAGS` and others; is the `qmake` helper writing broken configs?)
2. The meson configuration (which would need to happen even with `python3-pep517` plus a `meson` helper) still includes a lot of magic that would have to be brought over to templates. This isn't really easier than the current practice of overriding the one-line `do_build` and `do_install`.

A possible solution would be to define a special-purpose function in the helper, called `vmesoncross` or somesuch, that will only write the configured when called---from a build function where these are properly defined (*e.g.*, `pre_configure`, `do_configure`). We could also define a special `do_configure`-like function in the helper that can be used by the `meson` style to actually do the configuration. This might be a bit ugly, but avoids repetition or violating the typical practice that the actual build functions are only defined in templates or build styles.

A third option is just defining a new `python3-meson` build style that mashes the meson `do_configure` bits from the `meson` style with the `do_build` and `do_install` bits from the `python3-pep517` style.

All of these options are sub-optimal, but I'm not sure which one is least offsensive.

A patch file from https://github.com/void-linux/void-packages/pull/46117.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-meson-46117.patch --]
[-- Type: text/x-diff, Size: 11777 bytes --]

From 8cd6e8ef00680341dd65678e22952bb115aa2e03 Mon Sep 17 00:00:00 2001
From: "Andrew J. Hesford" <ajh@sideband.org>
Date: Mon, 18 Sep 2023 15:40:49 -0400
Subject: [PATCH 1/3] common/build-helper/meson.sh: new build helper, used by
 meson build style

---
 common/build-helper/meson.sh            | 82 ++++++++++++++++++++++++
 common/build-style/meson.sh             | 85 +------------------------
 common/environment/build-style/meson.sh |  1 +
 3 files changed, 84 insertions(+), 84 deletions(-)
 create mode 100644 common/build-helper/meson.sh

diff --git a/common/build-helper/meson.sh b/common/build-helper/meson.sh
new file mode 100644
index 0000000000000..1933306c18a4b
--- /dev/null
+++ b/common/build-helper/meson.sh
@@ -0,0 +1,82 @@
+# This bulid-helper writes a Meson cross-file, allowing other build styles
+# to properly drive cross-builds in Meson when appropriate
+
+if [ "$CROSS_BUILD" ]; then
+	mkdir -p "${XBPS_WRAPPERDIR}/meson"
+
+	_MESON_TARGET_ENDIAN=little
+	# drop the -musl suffix to the target cpu, meson doesn't recognize it
+	_MESON_TARGET_CPU=${XBPS_TARGET_MACHINE/-musl/}
+	case "$XBPS_TARGET_MACHINE" in
+		mips|mips-musl|mipshf-musl)
+			_MESON_TARGET_ENDIAN=big
+			_MESON_CPU_FAMILY=mips
+			;;
+		armv*)
+			_MESON_CPU_FAMILY=arm
+			;;
+		i686*)
+			_MESON_CPU_FAMILY=x86
+			;;
+		ppc64le*)
+			_MESON_CPU_FAMILY=ppc64
+			;;
+		ppc64*)
+			_MESON_TARGET_ENDIAN=big
+			_MESON_CPU_FAMILY=ppc64
+			;;
+		ppcle*)
+			_MESON_CPU_FAMILY=ppc
+			;;
+		ppc*)
+			_MESON_TARGET_ENDIAN=big
+			_MESON_CPU_FAMILY=ppc
+			;;
+		*)
+			# if we reached here that means that the cpu and cpu_family
+			# are the same like 'x86_64' and 'aarch64'
+			_MESON_CPU_FAMILY=${_MESON_TARGET_CPU}
+			;;
+	esac
+
+	# Tell meson to run binaries with qemu if desired
+	_MESON_EXE_WRAPPER=""
+	if [[ "${build_helper}" = *qemu* ]]; then
+		_MESON_EXE_WRAPPER="exe_wrapper = '/usr/bin/qemu-${XBPS_TARGET_QEMU_MACHINE}-static'"
+	fi
+
+	# Record cross-compiling information in cross file.
+	#
+	# CFLAGS, CXXFLAGS and LDFLAGS are not yet available and
+	# will be taken from the environment at configure time.
+	cat > "${XBPS_WRAPPERDIR}/meson/xbps_meson.cross" <<-EOF
+		[binaries]
+		${_MESON_EXE_WRAPPER:-# exe_wrapper is not set}
+		c = '${CC}'
+		cpp = '${CXX}'
+		ar = '${XBPS_CROSS_TRIPLET}-gcc-ar'
+		nm = '${NM}'
+		ld = '${LD}'
+		strip = '${STRIP}'
+		readelf = '${READELF}'
+		objcopy = '${OBJCOPY}'
+		pkgconfig = '${PKG_CONFIG}'
+		rust = ['rustc', '--target', '${RUST_TARGET}' ,'--sysroot', '${XBPS_CROSS_BASE}/usr']
+		g-ir-scanner = '${XBPS_CROSS_BASE}/usr/bin/g-ir-scanner'
+		g-ir-compiler = '${XBPS_CROSS_BASE}/usr/bin/g-ir-compiler'
+		g-ir-generate = '${XBPS_CROSS_BASE}/usr/bin/g-ir-generate'
+		llvm-config = '/usr/bin/llvm-config'
+		cups-config = '${XBPS_CROSS_BASE}/usr/bin/cups-config'
+		
+		[properties]
+		needs_exe_wrapper = true
+		
+		[host_machine]
+		system = 'linux'
+		cpu_family = '${_MESON_CPU_FAMILY}'
+		cpu = '${_MESON_TARGET_CPU}'
+		endian = '${_MESON_TARGET_ENDIAN}'
+		EOF
+
+	unset _MESON_CPU_FAMILY _MESON_TARGET_CPU _MESON_TARGET_ENDIAN _MESON_EXE_WRAPPER
+fi
diff --git a/common/build-style/meson.sh b/common/build-style/meson.sh
index e983c5f42c2f7..5ea2eeda40097 100644
--- a/common/build-style/meson.sh
+++ b/common/build-style/meson.sh
@@ -1,94 +1,11 @@
 #
 # This helper is for templates using meson.
 #
-do_patch() {
-	: ${meson_crossfile:=xbps_meson.cross}
-
-	if [ "$CROSS_BUILD" ]; then
-		_MESON_TARGET_ENDIAN=little
-		# drop the -musl suffix to the target cpu, meson doesn't recognize it
-		_MESON_TARGET_CPU=${XBPS_TARGET_MACHINE/-musl/}
-		case "$XBPS_TARGET_MACHINE" in
-			mips|mips-musl|mipshf-musl)
-				_MESON_TARGET_ENDIAN=big
-				_MESON_CPU_FAMILY=mips
-				;;
-			armv*)
-				_MESON_CPU_FAMILY=arm
-				;;
-			i686*)
-				_MESON_CPU_FAMILY=x86
-				;;
-			ppc64le*)
-				_MESON_CPU_FAMILY=ppc64
-				;;
-			ppc64*)
-				_MESON_TARGET_ENDIAN=big
-				_MESON_CPU_FAMILY=ppc64
-				;;
-			ppcle*)
-				_MESON_CPU_FAMILY=ppc
-				;;
-			ppc*)
-				_MESON_TARGET_ENDIAN=big
-				_MESON_CPU_FAMILY=ppc
-				;;
-			*)
-				# if we reached here that means that the cpu and cpu_family
-				# are the same like 'x86_64' and 'aarch64'
-				_MESON_CPU_FAMILY=${_MESON_TARGET_CPU}
-				;;
-		esac
-
-		# Record cross-compiling information in cross file.
-		# CFLAGS and LDFLAGS must be set as c_args and c_link_args.
-		cat > ${meson_crossfile} <<EOF
-[binaries]
-c = '${CC}'
-cpp = '${CXX}'
-ar = '${XBPS_CROSS_TRIPLET}-gcc-ar'
-nm = '${NM}'
-ld = '${LD}'
-strip = '${STRIP}'
-readelf = '${READELF}'
-objcopy = '${OBJCOPY}'
-pkgconfig = '${PKG_CONFIG}'
-rust = ['rustc', '--target', '${RUST_TARGET}' ,'--sysroot', '${XBPS_CROSS_BASE}/usr']
-g-ir-scanner = '${XBPS_CROSS_BASE}/usr/bin/g-ir-scanner'
-g-ir-compiler = '${XBPS_CROSS_BASE}/usr/bin/g-ir-compiler'
-g-ir-generate = '${XBPS_CROSS_BASE}/usr/bin/g-ir-generate'
-llvm-config = '/usr/bin/llvm-config'
-cups-config = '${XBPS_CROSS_BASE}/usr/bin/cups-config'
-
-[properties]
-needs_exe_wrapper = true
-
-[built-in options]
-c_args = ['$(echo ${CFLAGS} | sed -r "s/\s+/','/g")']
-c_link_args = ['$(echo ${LDFLAGS} | sed -r "s/\s+/','/g")']
-
-cpp_args = ['$(echo ${CXXFLAGS} | sed -r "s/\s+/','/g")']
-cpp_link_args = ['$(echo ${LDFLAGS} | sed -r "s/\s+/','/g")']
-
-[host_machine]
-system = 'linux'
-cpu_family = '${_MESON_CPU_FAMILY}'
-cpu = '${_MESON_TARGET_CPU}'
-endian = '${_MESON_TARGET_ENDIAN}'
-EOF
-		if [[ $build_helper = *"qemu"* ]]; then
-			sed -e "/\[binaries\]/ a exe_wrapper = '/usr/bin/qemu-${XBPS_TARGET_QEMU_MACHINE}-static'" \
-				-i ${meson_crossfile}
-		fi
-
-		unset _MESON_CPU_FAMILY _MESON_TARGET_CPU _MESON_TARGET_ENDIAN
-	fi
-}
 
 do_configure() {
 	: ${meson_cmd:=meson}
 	: ${meson_builddir:=build}
-	: ${meson_crossfile:=xbps_meson.cross}
+	: ${meson_crossfile:="${XBPS_WRAPPERDIR}/meson/xbps_meson.cross"}
 
 	if [ "$CROSS_BUILD" ]; then
 		configure_args+=" --cross-file=${meson_crossfile}"
diff --git a/common/environment/build-style/meson.sh b/common/environment/build-style/meson.sh
index d5a3c4141f7d9..dbfe93700f691 100644
--- a/common/environment/build-style/meson.sh
+++ b/common/environment/build-style/meson.sh
@@ -1 +1,2 @@
 hostmakedepends+=" meson"
+build_helper+=" meson"

From 7b9d2832275bb53258173c834c4c52cfb6875846 Mon Sep 17 00:00:00 2001
From: "Andrew J. Hesford" <ajh@sideband.org>
Date: Wed, 20 Sep 2023 10:45:43 -0400
Subject: [PATCH 2/3] python3-scipy: use new meson helper

---
 srcpkgs/python3-scipy/template | 47 ++++++++++++++++------------------
 1 file changed, 22 insertions(+), 25 deletions(-)

diff --git a/srcpkgs/python3-scipy/template b/srcpkgs/python3-scipy/template
index ba0dd761cdcf5..e99919babf3bf 100644
--- a/srcpkgs/python3-scipy/template
+++ b/srcpkgs/python3-scipy/template
@@ -2,9 +2,10 @@
 pkgname=python3-scipy
 version=1.11.2
 revision=1
-build_style=meson
-build_helper="python3"
-configure_args="$(vopt_if openblas "" "-Dblas=blas -Dlapack=lapack")"
+build_style=python3-pep517
+build_helper="meson"
+make_build_args="--no-isolation --wheel
+ $(vopt_if openblas "" "-Csetup-args=-Dblas=blas -Csetup-args=-Dlapack=lapack")"
 hostmakedepends="python3-build python3-installer python3-meson-python
  python3-wheel python3-Cython python3-pybind11 pythran python3-numpy
  gcc-fortran pkg-config"
@@ -22,8 +23,12 @@ make_check="no" # Tests need an installed copy to run and meson makes this tough
 build_options="openblas"
 
 if [ "$CROSS_BUILD" ]; then
+	make_build_args+="
+	 -Csetup-args=--cross-file=${XBPS_WRAPPERDIR}/meson/xbps_meson.cross
+	 -Csetup-args=--cross-file=${XBPS_WRAPPERDIR}/meson/python.cross
+	"
+
 	_pybind11_dir="${py3_sitelib}/pybind11"
-	configure_args+=" --cross-file=python.cross"
 	export PKG_CONFIG_PATH="${XBPS_CROSS_BASE}/${_pybind11_dir}/share/pkgconfig"
 	# pybind11 uses a path relative to the pkgconfig file to set $prefix,
 	# which causes the wrapper to double-include $XBPS_CROSS_BASE; override
@@ -46,34 +51,26 @@ if [ "$build_option_openblas" ]; then
 	esac
 fi
 
-pre_patch() {
-	if [ "${CROSS_BUILD}" ]; then
-		# Meson can't tolerate $CC with arguments as set by the build helper
-		CC="${XBPS_CROSS_TRIPLET}-gcc"
-		# CXX needs to know where to find Python headers
-		CXXFLAGS+=" -I${XBPS_CROSS_BASE}/${py3_inc}"
-	fi
-}
-
 post_patch() {
 	if [ "$CROSS_BUILD" ]; then
 		local _xpy="${XBPS_CROSS_BASE}/${py3_sitelib}"
-		cat > python.cross <<-EOF
-		[properties]
-		numpy-include-dir = '${_xpy}/numpy/core/include'
-		pythran-include-dir = '${_xpy}/pythran'
-		EOF
+		cat > "${XBPS_WRAPPERDIR}/meson/python.cross" <<-EOF
+			[properties]
+			numpy-include-dir = '${_xpy}/numpy/core/include'
+			pythran-include-dir = '${_xpy}/pythran'
+			EOF
 	fi
 }
 
-do_build() {
-	# Use the build directory already configured by xbps-src for meson
-	python3 -m build --no-isolation --wheel \
-		-Cbuilddir="./build" -Ccompile-args="${makejobs}" .
+pre_build() {
+	if [ "$CROSS_BUILD" ]; then
+		# Meson can't tolerate $CC with arguments as set by the build helper
+		CC="${XBPS_CROSS_TRIPLET}-gcc"
+		# CXX needs to know where to find Python headers
+		CXXFLAGS+=" -I${XBPS_CROSS_BASE}/${py3_inc}"
+	fi
 }
 
-do_install() {
-	python3 -m installer --destdir "${DESTDIR}" \
-		--no-compile-bytecode dist/*.whl
+post_install() {
 	vlicense LICENSE.txt
 }

From 52ac7fa1b09b9bf917379a3a38ddd64434234543 Mon Sep 17 00:00:00 2001
From: "Andrew J. Hesford" <ajh@sideband.org>
Date: Wed, 20 Sep 2023 11:13:02 -0400
Subject: [PATCH 3/3] python3-scikit-image: use new meson helper

---
 srcpkgs/python3-scikit-image/template | 34 +++++++++++----------------
 1 file changed, 14 insertions(+), 20 deletions(-)

diff --git a/srcpkgs/python3-scikit-image/template b/srcpkgs/python3-scikit-image/template
index e800ed4f00f6c..b19743e50f37d 100644
--- a/srcpkgs/python3-scikit-image/template
+++ b/srcpkgs/python3-scikit-image/template
@@ -2,8 +2,8 @@
 pkgname=python3-scikit-image
 version=0.21.0
 revision=1
-build_style=meson
-build_helper="python3"
+build_style=python3-pep517
+build_helper="meson"
 hostmakedepends="python3-build python3-installer python3-meson-python
  python3-wheel python3-setuptools python3-packaging python3-Cython pythran
  python3-lazy_loader python3-numpy pkg-config"
@@ -21,22 +21,15 @@ checksum=53a82a9dbd3ed608d2ad3876269a271a7e922b12e228388eac996b508aadd652
 make_check=no
 
 if [ "${CROSS_BUILD}" ]; then
-	configure_args="--cross-file=python.cross"
+	make_build_args+=" --no-isolation --wheel
+	 -Csetup-args=--cross-file=${XBPS_WRAPPERDIR}/meson/xbps_meson.cross
+	 -Csetup-args=--cross-file=${XBPS_WRAPPERDIR}/meson/python.cross"
 fi
 
-pre_patch() {
-	if [ "${CROSS_BUILD}" ]; then
-		# Meson can't tolerate $CC with arguments as set by build helper
-		CC="${XBPS_CROSS_TRIPLET}-gcc"
-		# CXX needs to know where to find Python headers
-		CXXFLAGS+=" -I${XBPS_CROSS_BASE}/${py3_inc}"
-	fi
-}
-
 post_patch() {
 	if [ "${CROSS_BUILD}" ]; then
 		local _xpy="${XBPS_CROSS_BASE}/${py3_sitelib}"
-		cat > python.cross <<-EOF
+		cat > "${XBPS_WRAPPERDIR}/meson/python.cross" <<-EOF
 		[properties]
 		numpy-include-dir = '${_xpy}/numpy/core/include'
 		pythran-include-dir = '${_xpy}/pythran'
@@ -44,14 +37,15 @@ post_patch() {
 	fi
 }
 
-do_build() {
-	# Use the build directory already configured by xbps-src for meson
-	python3 -m build --no-isolation --wheel \
-		-Cbuilddir="./build" -Ccompile-args="${makejobs}" .
+pre_build() {
+	if [ "${CROSS_BUILD}" ]; then
+		# Meson can't tolerate $CC with arguments as set by build helper
+		CC="${XBPS_CROSS_TRIPLET}-gcc"
+		# CXX needs to know where to find Python headers
+		CXXFLAGS+=" -I${XBPS_CROSS_BASE}/${py3_inc}"
+	fi
 }
 
-do_install() {
-	python3 -m installer --destdir "${DESTDIR}" \
-		--no-compile-bytecode dist/*.whl
+post_install() {
 	vlicense LICENSE.txt
 }

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PR PATCH] [Updated] [RFC, WIP] common/build-helper/meson.sh: new build helper, used by meson build style
  2023-09-18 19:53 [PR PATCH] [RFC, WIP] common/build-helper/meson.sh: new build helper, used by meson build style ahesford
                   ` (6 preceding siblings ...)
  2023-09-20 15:13 ` [PR PATCH] [Updated] " ahesford
@ 2023-09-20 15:16 ` ahesford
  2023-09-20 22:16 ` tornaria
                   ` (5 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: ahesford @ 2023-09-20 15:16 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 2478 bytes --]

There is an updated pull request by ahesford against master on the void-packages repository

https://github.com/ahesford/void-packages meson
https://github.com/void-linux/void-packages/pull/46117

[RFC, WIP] common/build-helper/meson.sh: new build helper, used by meson build style
The `python3-scipy` package now builds with `python3-meson-python`, with some more coming down the pike. The Python build process is necessary to include Python package metadata. For SciPy, this is accomplished by using the `meson` build style to configure a build directory, then overriding `do_build` and `do_install` to build things the PEP517 way (using the pre-configured build directory).

It might be helpful to define a `meson` build helper that can write out the standard cross file for builds, allowing packages like SciPy to use the `python3-pep517` build style with the `meson` helper. There are some issues to be worked out:
1. It seems like the `xbps_meson.cross` is written before `CFLAGS`, *et al.* are properly defined, so this cross file is actually broken. (This is the process by which the `qmake` helper writes its configurations, and they reference `CFLAGS` and others; is the `qmake` helper writing broken configs?)
2. The meson configuration (which would need to happen even with `python3-pep517` plus a `meson` helper) still includes a lot of magic that would have to be brought over to templates. This isn't really easier than the current practice of overriding the one-line `do_build` and `do_install`.

A possible solution would be to define a special-purpose function in the helper, called `vmesoncross` or somesuch, that will only write the configured when called---from a build function where these are properly defined (*e.g.*, `pre_configure`, `do_configure`). We could also define a special `do_configure`-like function in the helper that can be used by the `meson` style to actually do the configuration. This might be a bit ugly, but avoids repetition or violating the typical practice that the actual build functions are only defined in templates or build styles.

A third option is just defining a new `python3-meson` build style that mashes the meson `do_configure` bits from the `meson` style with the `do_build` and `do_install` bits from the `python3-pep517` style.

All of these options are sub-optimal, but I'm not sure which one is least offsensive.

A patch file from https://github.com/void-linux/void-packages/pull/46117.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-meson-46117.patch --]
[-- Type: text/x-diff, Size: 11777 bytes --]

From 5dbb797c644dac784e31d29aa1590d2d9a5b20d8 Mon Sep 17 00:00:00 2001
From: "Andrew J. Hesford" <ajh@sideband.org>
Date: Mon, 18 Sep 2023 15:40:49 -0400
Subject: [PATCH 1/3] common/build-helper/meson.sh: new build helper, used by
 meson build style

---
 common/build-helper/meson.sh            | 82 ++++++++++++++++++++++++
 common/build-style/meson.sh             | 85 +------------------------
 common/environment/build-style/meson.sh |  1 +
 3 files changed, 84 insertions(+), 84 deletions(-)
 create mode 100644 common/build-helper/meson.sh

diff --git a/common/build-helper/meson.sh b/common/build-helper/meson.sh
new file mode 100644
index 0000000000000..1933306c18a4b
--- /dev/null
+++ b/common/build-helper/meson.sh
@@ -0,0 +1,82 @@
+# This bulid-helper writes a Meson cross-file, allowing other build styles
+# to properly drive cross-builds in Meson when appropriate
+
+if [ "$CROSS_BUILD" ]; then
+	mkdir -p "${XBPS_WRAPPERDIR}/meson"
+
+	_MESON_TARGET_ENDIAN=little
+	# drop the -musl suffix to the target cpu, meson doesn't recognize it
+	_MESON_TARGET_CPU=${XBPS_TARGET_MACHINE/-musl/}
+	case "$XBPS_TARGET_MACHINE" in
+		mips|mips-musl|mipshf-musl)
+			_MESON_TARGET_ENDIAN=big
+			_MESON_CPU_FAMILY=mips
+			;;
+		armv*)
+			_MESON_CPU_FAMILY=arm
+			;;
+		i686*)
+			_MESON_CPU_FAMILY=x86
+			;;
+		ppc64le*)
+			_MESON_CPU_FAMILY=ppc64
+			;;
+		ppc64*)
+			_MESON_TARGET_ENDIAN=big
+			_MESON_CPU_FAMILY=ppc64
+			;;
+		ppcle*)
+			_MESON_CPU_FAMILY=ppc
+			;;
+		ppc*)
+			_MESON_TARGET_ENDIAN=big
+			_MESON_CPU_FAMILY=ppc
+			;;
+		*)
+			# if we reached here that means that the cpu and cpu_family
+			# are the same like 'x86_64' and 'aarch64'
+			_MESON_CPU_FAMILY=${_MESON_TARGET_CPU}
+			;;
+	esac
+
+	# Tell meson to run binaries with qemu if desired
+	_MESON_EXE_WRAPPER=""
+	if [[ "${build_helper}" = *qemu* ]]; then
+		_MESON_EXE_WRAPPER="exe_wrapper = '/usr/bin/qemu-${XBPS_TARGET_QEMU_MACHINE}-static'"
+	fi
+
+	# Record cross-compiling information in cross file.
+	#
+	# CFLAGS, CXXFLAGS and LDFLAGS are not yet available and
+	# will be taken from the environment at configure time.
+	cat > "${XBPS_WRAPPERDIR}/meson/xbps_meson.cross" <<-EOF
+		[binaries]
+		${_MESON_EXE_WRAPPER:-# exe_wrapper is not set}
+		c = '${CC}'
+		cpp = '${CXX}'
+		ar = '${XBPS_CROSS_TRIPLET}-gcc-ar'
+		nm = '${NM}'
+		ld = '${LD}'
+		strip = '${STRIP}'
+		readelf = '${READELF}'
+		objcopy = '${OBJCOPY}'
+		pkgconfig = '${PKG_CONFIG}'
+		rust = ['rustc', '--target', '${RUST_TARGET}' ,'--sysroot', '${XBPS_CROSS_BASE}/usr']
+		g-ir-scanner = '${XBPS_CROSS_BASE}/usr/bin/g-ir-scanner'
+		g-ir-compiler = '${XBPS_CROSS_BASE}/usr/bin/g-ir-compiler'
+		g-ir-generate = '${XBPS_CROSS_BASE}/usr/bin/g-ir-generate'
+		llvm-config = '/usr/bin/llvm-config'
+		cups-config = '${XBPS_CROSS_BASE}/usr/bin/cups-config'
+		
+		[properties]
+		needs_exe_wrapper = true
+		
+		[host_machine]
+		system = 'linux'
+		cpu_family = '${_MESON_CPU_FAMILY}'
+		cpu = '${_MESON_TARGET_CPU}'
+		endian = '${_MESON_TARGET_ENDIAN}'
+		EOF
+
+	unset _MESON_CPU_FAMILY _MESON_TARGET_CPU _MESON_TARGET_ENDIAN _MESON_EXE_WRAPPER
+fi
diff --git a/common/build-style/meson.sh b/common/build-style/meson.sh
index e983c5f42c2f7..5ea2eeda40097 100644
--- a/common/build-style/meson.sh
+++ b/common/build-style/meson.sh
@@ -1,94 +1,11 @@
 #
 # This helper is for templates using meson.
 #
-do_patch() {
-	: ${meson_crossfile:=xbps_meson.cross}
-
-	if [ "$CROSS_BUILD" ]; then
-		_MESON_TARGET_ENDIAN=little
-		# drop the -musl suffix to the target cpu, meson doesn't recognize it
-		_MESON_TARGET_CPU=${XBPS_TARGET_MACHINE/-musl/}
-		case "$XBPS_TARGET_MACHINE" in
-			mips|mips-musl|mipshf-musl)
-				_MESON_TARGET_ENDIAN=big
-				_MESON_CPU_FAMILY=mips
-				;;
-			armv*)
-				_MESON_CPU_FAMILY=arm
-				;;
-			i686*)
-				_MESON_CPU_FAMILY=x86
-				;;
-			ppc64le*)
-				_MESON_CPU_FAMILY=ppc64
-				;;
-			ppc64*)
-				_MESON_TARGET_ENDIAN=big
-				_MESON_CPU_FAMILY=ppc64
-				;;
-			ppcle*)
-				_MESON_CPU_FAMILY=ppc
-				;;
-			ppc*)
-				_MESON_TARGET_ENDIAN=big
-				_MESON_CPU_FAMILY=ppc
-				;;
-			*)
-				# if we reached here that means that the cpu and cpu_family
-				# are the same like 'x86_64' and 'aarch64'
-				_MESON_CPU_FAMILY=${_MESON_TARGET_CPU}
-				;;
-		esac
-
-		# Record cross-compiling information in cross file.
-		# CFLAGS and LDFLAGS must be set as c_args and c_link_args.
-		cat > ${meson_crossfile} <<EOF
-[binaries]
-c = '${CC}'
-cpp = '${CXX}'
-ar = '${XBPS_CROSS_TRIPLET}-gcc-ar'
-nm = '${NM}'
-ld = '${LD}'
-strip = '${STRIP}'
-readelf = '${READELF}'
-objcopy = '${OBJCOPY}'
-pkgconfig = '${PKG_CONFIG}'
-rust = ['rustc', '--target', '${RUST_TARGET}' ,'--sysroot', '${XBPS_CROSS_BASE}/usr']
-g-ir-scanner = '${XBPS_CROSS_BASE}/usr/bin/g-ir-scanner'
-g-ir-compiler = '${XBPS_CROSS_BASE}/usr/bin/g-ir-compiler'
-g-ir-generate = '${XBPS_CROSS_BASE}/usr/bin/g-ir-generate'
-llvm-config = '/usr/bin/llvm-config'
-cups-config = '${XBPS_CROSS_BASE}/usr/bin/cups-config'
-
-[properties]
-needs_exe_wrapper = true
-
-[built-in options]
-c_args = ['$(echo ${CFLAGS} | sed -r "s/\s+/','/g")']
-c_link_args = ['$(echo ${LDFLAGS} | sed -r "s/\s+/','/g")']
-
-cpp_args = ['$(echo ${CXXFLAGS} | sed -r "s/\s+/','/g")']
-cpp_link_args = ['$(echo ${LDFLAGS} | sed -r "s/\s+/','/g")']
-
-[host_machine]
-system = 'linux'
-cpu_family = '${_MESON_CPU_FAMILY}'
-cpu = '${_MESON_TARGET_CPU}'
-endian = '${_MESON_TARGET_ENDIAN}'
-EOF
-		if [[ $build_helper = *"qemu"* ]]; then
-			sed -e "/\[binaries\]/ a exe_wrapper = '/usr/bin/qemu-${XBPS_TARGET_QEMU_MACHINE}-static'" \
-				-i ${meson_crossfile}
-		fi
-
-		unset _MESON_CPU_FAMILY _MESON_TARGET_CPU _MESON_TARGET_ENDIAN
-	fi
-}
 
 do_configure() {
 	: ${meson_cmd:=meson}
 	: ${meson_builddir:=build}
-	: ${meson_crossfile:=xbps_meson.cross}
+	: ${meson_crossfile:="${XBPS_WRAPPERDIR}/meson/xbps_meson.cross"}
 
 	if [ "$CROSS_BUILD" ]; then
 		configure_args+=" --cross-file=${meson_crossfile}"
diff --git a/common/environment/build-style/meson.sh b/common/environment/build-style/meson.sh
index d5a3c4141f7d9..dbfe93700f691 100644
--- a/common/environment/build-style/meson.sh
+++ b/common/environment/build-style/meson.sh
@@ -1 +1,2 @@
 hostmakedepends+=" meson"
+build_helper+=" meson"

From a640b681dd99188880ee6704c35f9fa9b851f6a3 Mon Sep 17 00:00:00 2001
From: "Andrew J. Hesford" <ajh@sideband.org>
Date: Wed, 20 Sep 2023 10:45:43 -0400
Subject: [PATCH 2/3] python3-scipy: use new meson helper

---
 srcpkgs/python3-scipy/template | 47 ++++++++++++++++------------------
 1 file changed, 22 insertions(+), 25 deletions(-)

diff --git a/srcpkgs/python3-scipy/template b/srcpkgs/python3-scipy/template
index ba0dd761cdcf5..e99919babf3bf 100644
--- a/srcpkgs/python3-scipy/template
+++ b/srcpkgs/python3-scipy/template
@@ -2,9 +2,10 @@
 pkgname=python3-scipy
 version=1.11.2
 revision=1
-build_style=meson
-build_helper="python3"
-configure_args="$(vopt_if openblas "" "-Dblas=blas -Dlapack=lapack")"
+build_style=python3-pep517
+build_helper="meson"
+make_build_args="--no-isolation --wheel
+ $(vopt_if openblas "" "-Csetup-args=-Dblas=blas -Csetup-args=-Dlapack=lapack")"
 hostmakedepends="python3-build python3-installer python3-meson-python
  python3-wheel python3-Cython python3-pybind11 pythran python3-numpy
  gcc-fortran pkg-config"
@@ -22,8 +23,12 @@ make_check="no" # Tests need an installed copy to run and meson makes this tough
 build_options="openblas"
 
 if [ "$CROSS_BUILD" ]; then
+	make_build_args+="
+	 -Csetup-args=--cross-file=${XBPS_WRAPPERDIR}/meson/xbps_meson.cross
+	 -Csetup-args=--cross-file=${XBPS_WRAPPERDIR}/meson/python.cross
+	"
+
 	_pybind11_dir="${py3_sitelib}/pybind11"
-	configure_args+=" --cross-file=python.cross"
 	export PKG_CONFIG_PATH="${XBPS_CROSS_BASE}/${_pybind11_dir}/share/pkgconfig"
 	# pybind11 uses a path relative to the pkgconfig file to set $prefix,
 	# which causes the wrapper to double-include $XBPS_CROSS_BASE; override
@@ -46,34 +51,26 @@ if [ "$build_option_openblas" ]; then
 	esac
 fi
 
-pre_patch() {
-	if [ "${CROSS_BUILD}" ]; then
-		# Meson can't tolerate $CC with arguments as set by the build helper
-		CC="${XBPS_CROSS_TRIPLET}-gcc"
-		# CXX needs to know where to find Python headers
-		CXXFLAGS+=" -I${XBPS_CROSS_BASE}/${py3_inc}"
-	fi
-}
-
 post_patch() {
 	if [ "$CROSS_BUILD" ]; then
 		local _xpy="${XBPS_CROSS_BASE}/${py3_sitelib}"
-		cat > python.cross <<-EOF
-		[properties]
-		numpy-include-dir = '${_xpy}/numpy/core/include'
-		pythran-include-dir = '${_xpy}/pythran'
-		EOF
+		cat > "${XBPS_WRAPPERDIR}/meson/python.cross" <<-EOF
+			[properties]
+			numpy-include-dir = '${_xpy}/numpy/core/include'
+			pythran-include-dir = '${_xpy}/pythran'
+			EOF
 	fi
 }
 
-do_build() {
-	# Use the build directory already configured by xbps-src for meson
-	python3 -m build --no-isolation --wheel \
-		-Cbuilddir="./build" -Ccompile-args="${makejobs}" .
+pre_build() {
+	if [ "$CROSS_BUILD" ]; then
+		# Meson can't tolerate $CC with arguments as set by the build helper
+		CC="${XBPS_CROSS_TRIPLET}-gcc"
+		# CXX needs to know where to find Python headers
+		CXXFLAGS+=" -I${XBPS_CROSS_BASE}/${py3_inc}"
+	fi
 }
 
-do_install() {
-	python3 -m installer --destdir "${DESTDIR}" \
-		--no-compile-bytecode dist/*.whl
+post_install() {
 	vlicense LICENSE.txt
 }

From bedace4ff187239e850e30fbb8169a8c13655033 Mon Sep 17 00:00:00 2001
From: "Andrew J. Hesford" <ajh@sideband.org>
Date: Wed, 20 Sep 2023 11:13:02 -0400
Subject: [PATCH 3/3] python3-scikit-image: use new meson helper

---
 srcpkgs/python3-scikit-image/template | 34 +++++++++++----------------
 1 file changed, 14 insertions(+), 20 deletions(-)

diff --git a/srcpkgs/python3-scikit-image/template b/srcpkgs/python3-scikit-image/template
index e800ed4f00f6c..b19743e50f37d 100644
--- a/srcpkgs/python3-scikit-image/template
+++ b/srcpkgs/python3-scikit-image/template
@@ -2,8 +2,8 @@
 pkgname=python3-scikit-image
 version=0.21.0
 revision=1
-build_style=meson
-build_helper="python3"
+build_style=python3-pep517
+build_helper="meson"
 hostmakedepends="python3-build python3-installer python3-meson-python
  python3-wheel python3-setuptools python3-packaging python3-Cython pythran
  python3-lazy_loader python3-numpy pkg-config"
@@ -21,22 +21,15 @@ checksum=53a82a9dbd3ed608d2ad3876269a271a7e922b12e228388eac996b508aadd652
 make_check=no
 
 if [ "${CROSS_BUILD}" ]; then
-	configure_args="--cross-file=python.cross"
+	make_build_args+=" --no-isolation --wheel
+	 -Csetup-args=--cross-file=${XBPS_WRAPPERDIR}/meson/xbps_meson.cross
+	 -Csetup-args=--cross-file=${XBPS_WRAPPERDIR}/meson/python.cross"
 fi
 
-pre_patch() {
-	if [ "${CROSS_BUILD}" ]; then
-		# Meson can't tolerate $CC with arguments as set by build helper
-		CC="${XBPS_CROSS_TRIPLET}-gcc"
-		# CXX needs to know where to find Python headers
-		CXXFLAGS+=" -I${XBPS_CROSS_BASE}/${py3_inc}"
-	fi
-}
-
 post_patch() {
 	if [ "${CROSS_BUILD}" ]; then
 		local _xpy="${XBPS_CROSS_BASE}/${py3_sitelib}"
-		cat > python.cross <<-EOF
+		cat > "${XBPS_WRAPPERDIR}/meson/python.cross" <<-EOF
 		[properties]
 		numpy-include-dir = '${_xpy}/numpy/core/include'
 		pythran-include-dir = '${_xpy}/pythran'
@@ -44,14 +37,15 @@ post_patch() {
 	fi
 }
 
-do_build() {
-	# Use the build directory already configured by xbps-src for meson
-	python3 -m build --no-isolation --wheel \
-		-Cbuilddir="./build" -Ccompile-args="${makejobs}" .
+pre_build() {
+	if [ "${CROSS_BUILD}" ]; then
+		# Meson can't tolerate $CC with arguments as set by build helper
+		CC="${XBPS_CROSS_TRIPLET}-gcc"
+		# CXX needs to know where to find Python headers
+		CXXFLAGS+=" -I${XBPS_CROSS_BASE}/${py3_inc}"
+	fi
 }
 
-do_install() {
-	python3 -m installer --destdir "${DESTDIR}" \
-		--no-compile-bytecode dist/*.whl
+post_install() {
 	vlicense LICENSE.txt
 }

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC, WIP] common/build-helper/meson.sh: new build helper, used by meson build style
  2023-09-18 19:53 [PR PATCH] [RFC, WIP] common/build-helper/meson.sh: new build helper, used by meson build style ahesford
                   ` (7 preceding siblings ...)
  2023-09-20 15:16 ` ahesford
@ 2023-09-20 22:16 ` tornaria
  2023-09-21  0:36 ` [RFC] " ahesford
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: tornaria @ 2023-09-20 22:16 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 735 bytes --]

New comment by tornaria on void-packages repository

https://github.com/void-linux/void-packages/pull/46117#issuecomment-1728497585

Comment:
Looks nice. I will try it on `python3-contourpy`.

Random thoughts:
1. Would it make sense to set `-Csetup-args=--cross-file=${XBPS_WRAPPERDIR}/meson/xbps_meson.cross` in the `python3-pep517` style (only if using meson helper), or is that "too much magic"?
2. Would it make sense to place the configuration for numpy and 
pythran in `xbps_meson.cross` itself? I assume unused properties are harmless.
3. The helper seems to be called several times at different stages, so the crossfile would be written several times, maybe with different content? Could this be an issue in some case?


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC] common/build-helper/meson.sh: new build helper, used by meson build style
  2023-09-18 19:53 [PR PATCH] [RFC, WIP] common/build-helper/meson.sh: new build helper, used by meson build style ahesford
                   ` (8 preceding siblings ...)
  2023-09-20 22:16 ` tornaria
@ 2023-09-21  0:36 ` ahesford
  2023-09-21  0:50 ` ahesford
                   ` (3 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: ahesford @ 2023-09-21  0:36 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 262 bytes --]

New comment by ahesford on void-packages repository

https://github.com/void-linux/void-packages/pull/46117#issuecomment-1728596415

Comment:
Well I didn't build all of them, but I built a large subset and have no reason to believe this breaks any cross builds.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC] common/build-helper/meson.sh: new build helper, used by meson build style
  2023-09-18 19:53 [PR PATCH] [RFC, WIP] common/build-helper/meson.sh: new build helper, used by meson build style ahesford
                   ` (9 preceding siblings ...)
  2023-09-21  0:36 ` [RFC] " ahesford
@ 2023-09-21  0:50 ` ahesford
  2023-09-21  0:51 ` ahesford
                   ` (2 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: ahesford @ 2023-09-21  0:50 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1464 bytes --]

New comment by ahesford on void-packages repository

https://github.com/void-linux/void-packages/pull/46117#issuecomment-1728605077

Comment:
> 1. Would it make sense to set `-Csetup-args=--cross-file=${XBPS_WRAPPERDIR}/meson/xbps_meson.cross` in the `python3-pep517` style (only if using meson helper), or is that "too much magic"?

I think adding this argument to the PEP517 style is reasonable. It shouldn't be "too much magic" because it confines its manipulations to the actual build functions where this kind of thing is expected.

> 2. Would it make sense to place the configuration for numpy and
>    pythran in `xbps_meson.cross` itself? I assume unused properties are harmless.

This would probably better in the numpy build helper, which can check if the meson helper is also enabled and write a second cross file. We can then add another check in the PEP517 helper to automatically add the second file to the build arguments.

> 3. The helper seems to be called several times at different stages, so the crossfile would be written several times, maybe with different content? Could this be an issue in some case?

it bought about this and decided to follow the precedent of the qmake helper, but we could also add a check to avoid writing the file if it already exists. I'm not sure it matters.

While I'm inclined to adopt the numpy and pep517 improvements, let's consider those in a separate PR after this more general change is merged.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC] common/build-helper/meson.sh: new build helper, used by meson build style
  2023-09-18 19:53 [PR PATCH] [RFC, WIP] common/build-helper/meson.sh: new build helper, used by meson build style ahesford
                   ` (10 preceding siblings ...)
  2023-09-21  0:50 ` ahesford
@ 2023-09-21  0:51 ` ahesford
  2023-09-21 19:28 ` [PR PATCH] [Updated] " ahesford
  2023-09-22 14:17 ` [PR PATCH] [Merged]: " ahesford
  13 siblings, 0 replies; 15+ messages in thread
From: ahesford @ 2023-09-21  0:51 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 1464 bytes --]

New comment by ahesford on void-packages repository

https://github.com/void-linux/void-packages/pull/46117#issuecomment-1728605077

Comment:
> 1. Would it make sense to set `-Csetup-args=--cross-file=${XBPS_WRAPPERDIR}/meson/xbps_meson.cross` in the `python3-pep517` style (only if using meson helper), or is that "too much magic"?

I think adding this argument to the PEP517 style is reasonable. It shouldn't be "too much magic" because it confines its manipulations to the actual build functions where this kind of thing is expected.

> 2. Would it make sense to place the configuration for numpy and
>    pythran in `xbps_meson.cross` itself? I assume unused properties are harmless.

This would probably better in the numpy build helper, which can check if the meson helper is also enabled and write a second cross file. We can then add another check in the PEP517 helper to automatically add the second file to the build arguments.

> 3. The helper seems to be called several times at different stages, so the crossfile would be written several times, maybe with different content? Could this be an issue in some case?

I thought about this and decided to follow the precedent of the qmake helper, but we could also add a check to avoid writing the file if it already exists. I'm not sure it matters.

While I'm inclined to adopt the numpy and pep517 improvements, let's consider those in a separate PR after this more general change is merged.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PR PATCH] [Updated] [RFC] common/build-helper/meson.sh: new build helper, used by meson build style
  2023-09-18 19:53 [PR PATCH] [RFC, WIP] common/build-helper/meson.sh: new build helper, used by meson build style ahesford
                   ` (11 preceding siblings ...)
  2023-09-21  0:51 ` ahesford
@ 2023-09-21 19:28 ` ahesford
  2023-09-22 14:17 ` [PR PATCH] [Merged]: " ahesford
  13 siblings, 0 replies; 15+ messages in thread
From: ahesford @ 2023-09-21 19:28 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 2473 bytes --]

There is an updated pull request by ahesford against master on the void-packages repository

https://github.com/ahesford/void-packages meson
https://github.com/void-linux/void-packages/pull/46117

[RFC] common/build-helper/meson.sh: new build helper, used by meson build style
The `python3-scipy` package now builds with `python3-meson-python`, with some more coming down the pike. The Python build process is necessary to include Python package metadata. For SciPy, this is accomplished by using the `meson` build style to configure a build directory, then overriding `do_build` and `do_install` to build things the PEP517 way (using the pre-configured build directory).

It might be helpful to define a `meson` build helper that can write out the standard cross file for builds, allowing packages like SciPy to use the `python3-pep517` build style with the `meson` helper. There are some issues to be worked out:
1. It seems like the `xbps_meson.cross` is written before `CFLAGS`, *et al.* are properly defined, so this cross file is actually broken. (This is the process by which the `qmake` helper writes its configurations, and they reference `CFLAGS` and others; is the `qmake` helper writing broken configs?)
2. The meson configuration (which would need to happen even with `python3-pep517` plus a `meson` helper) still includes a lot of magic that would have to be brought over to templates. This isn't really easier than the current practice of overriding the one-line `do_build` and `do_install`.

A possible solution would be to define a special-purpose function in the helper, called `vmesoncross` or somesuch, that will only write the configured when called---from a build function where these are properly defined (*e.g.*, `pre_configure`, `do_configure`). We could also define a special `do_configure`-like function in the helper that can be used by the `meson` style to actually do the configuration. This might be a bit ugly, but avoids repetition or violating the typical practice that the actual build functions are only defined in templates or build styles.

A third option is just defining a new `python3-meson` build style that mashes the meson `do_configure` bits from the `meson` style with the `do_build` and `do_install` bits from the `python3-pep517` style.

All of these options are sub-optimal, but I'm not sure which one is least offsensive.

A patch file from https://github.com/void-linux/void-packages/pull/46117.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-meson-46117.patch --]
[-- Type: text/x-diff, Size: 12766 bytes --]

From 64505c00f637f15bb11400c758ab220a67b21a9e Mon Sep 17 00:00:00 2001
From: "Andrew J. Hesford" <ajh@sideband.org>
Date: Mon, 18 Sep 2023 15:40:49 -0400
Subject: [PATCH 1/3] common/build-helper/meson.sh: new build helper, used by
 meson build style

---
 Manual.md                               |  5 ++
 common/build-helper/meson.sh            | 82 ++++++++++++++++++++++++
 common/build-style/meson.sh             | 85 +------------------------
 common/environment/build-style/meson.sh |  1 +
 4 files changed, 89 insertions(+), 84 deletions(-)
 create mode 100644 common/build-helper/meson.sh

diff --git a/Manual.md b/Manual.md
index 0a68f088f6a25..88f9f5243258a 100644
--- a/Manual.md
+++ b/Manual.md
@@ -1079,6 +1079,11 @@ additional paths to be searched when linking target binaries to be introspected.
 `qemu-<target_arch>-static` when running the target binary. You can for example specify
 `GIR_EXTRA_OPTIONS="-strace"` to see a trace of what happens when running that binary.
 
+- `meson` creates a cross file, `${XBPS_WRAPPERDIR}/meson/xbps_meson.cross`, which configures
+meson for cross builds. This is particularly useful for building packages that wrap meson
+invocations (e.g., `python3-pep517` packages that use a meson backend) and is added by default
+for packages that use the `meson` build style.
+
 - `qemu` sets additional variables for the `cmake` and `meson` build styles to allow
 executing cross-compiled binaries inside qemu.
 It sets `CMAKE_CROSSCOMPILING_EMULATOR` for cmake and `exe_wrapper` for meson
diff --git a/common/build-helper/meson.sh b/common/build-helper/meson.sh
new file mode 100644
index 0000000000000..5ac9d2fe1badc
--- /dev/null
+++ b/common/build-helper/meson.sh
@@ -0,0 +1,82 @@
+# This build helper writes a Meson cross-file, allowing other build styles
+# to properly drive cross-builds in Meson when appropriate
+
+if [ -n "$CROSS_BUILD" ]; then
+	mkdir -p "${XBPS_WRAPPERDIR}/meson"
+
+	_MESON_TARGET_ENDIAN=little
+	# drop the -musl suffix to the target cpu, meson doesn't recognize it
+	_MESON_TARGET_CPU=${XBPS_TARGET_MACHINE/-musl/}
+	case "$XBPS_TARGET_MACHINE" in
+		mips|mips-musl|mipshf-musl)
+			_MESON_TARGET_ENDIAN=big
+			_MESON_CPU_FAMILY=mips
+			;;
+		armv*)
+			_MESON_CPU_FAMILY=arm
+			;;
+		i686*)
+			_MESON_CPU_FAMILY=x86
+			;;
+		ppc64le*)
+			_MESON_CPU_FAMILY=ppc64
+			;;
+		ppc64*)
+			_MESON_TARGET_ENDIAN=big
+			_MESON_CPU_FAMILY=ppc64
+			;;
+		ppcle*)
+			_MESON_CPU_FAMILY=ppc
+			;;
+		ppc*)
+			_MESON_TARGET_ENDIAN=big
+			_MESON_CPU_FAMILY=ppc
+			;;
+		*)
+			# if we reached here that means that the cpu and cpu_family
+			# are the same like 'x86_64' and 'aarch64'
+			_MESON_CPU_FAMILY=${_MESON_TARGET_CPU}
+			;;
+	esac
+
+	# Tell meson to run binaries with qemu if desired
+	_MESON_EXE_WRAPPER=""
+	if [[ "${build_helper}" = *qemu* ]]; then
+		_MESON_EXE_WRAPPER="exe_wrapper = '/usr/bin/qemu-${XBPS_TARGET_QEMU_MACHINE}-static'"
+	fi
+
+	# Record cross-compiling information in cross file.
+	#
+	# CFLAGS, CXXFLAGS and LDFLAGS are not yet available and
+	# will be taken from the environment at configure time.
+	cat > "${XBPS_WRAPPERDIR}/meson/xbps_meson.cross" <<-EOF
+		[binaries]
+		${_MESON_EXE_WRAPPER:-# exe_wrapper is not set}
+		c = '${CC}'
+		cpp = '${CXX}'
+		ar = '${XBPS_CROSS_TRIPLET}-gcc-ar'
+		nm = '${NM}'
+		ld = '${LD}'
+		strip = '${STRIP}'
+		readelf = '${READELF}'
+		objcopy = '${OBJCOPY}'
+		pkgconfig = '${PKG_CONFIG}'
+		rust = ['rustc', '--target', '${RUST_TARGET}' ,'--sysroot', '${XBPS_CROSS_BASE}/usr']
+		g-ir-scanner = '${XBPS_CROSS_BASE}/usr/bin/g-ir-scanner'
+		g-ir-compiler = '${XBPS_CROSS_BASE}/usr/bin/g-ir-compiler'
+		g-ir-generate = '${XBPS_CROSS_BASE}/usr/bin/g-ir-generate'
+		llvm-config = '/usr/bin/llvm-config'
+		cups-config = '${XBPS_CROSS_BASE}/usr/bin/cups-config'
+		
+		[properties]
+		needs_exe_wrapper = true
+		
+		[host_machine]
+		system = 'linux'
+		cpu_family = '${_MESON_CPU_FAMILY}'
+		cpu = '${_MESON_TARGET_CPU}'
+		endian = '${_MESON_TARGET_ENDIAN}'
+		EOF
+
+	unset _MESON_CPU_FAMILY _MESON_TARGET_CPU _MESON_TARGET_ENDIAN _MESON_EXE_WRAPPER
+fi
diff --git a/common/build-style/meson.sh b/common/build-style/meson.sh
index e983c5f42c2f7..5ea2eeda40097 100644
--- a/common/build-style/meson.sh
+++ b/common/build-style/meson.sh
@@ -1,94 +1,11 @@
 #
 # This helper is for templates using meson.
 #
-do_patch() {
-	: ${meson_crossfile:=xbps_meson.cross}
-
-	if [ "$CROSS_BUILD" ]; then
-		_MESON_TARGET_ENDIAN=little
-		# drop the -musl suffix to the target cpu, meson doesn't recognize it
-		_MESON_TARGET_CPU=${XBPS_TARGET_MACHINE/-musl/}
-		case "$XBPS_TARGET_MACHINE" in
-			mips|mips-musl|mipshf-musl)
-				_MESON_TARGET_ENDIAN=big
-				_MESON_CPU_FAMILY=mips
-				;;
-			armv*)
-				_MESON_CPU_FAMILY=arm
-				;;
-			i686*)
-				_MESON_CPU_FAMILY=x86
-				;;
-			ppc64le*)
-				_MESON_CPU_FAMILY=ppc64
-				;;
-			ppc64*)
-				_MESON_TARGET_ENDIAN=big
-				_MESON_CPU_FAMILY=ppc64
-				;;
-			ppcle*)
-				_MESON_CPU_FAMILY=ppc
-				;;
-			ppc*)
-				_MESON_TARGET_ENDIAN=big
-				_MESON_CPU_FAMILY=ppc
-				;;
-			*)
-				# if we reached here that means that the cpu and cpu_family
-				# are the same like 'x86_64' and 'aarch64'
-				_MESON_CPU_FAMILY=${_MESON_TARGET_CPU}
-				;;
-		esac
-
-		# Record cross-compiling information in cross file.
-		# CFLAGS and LDFLAGS must be set as c_args and c_link_args.
-		cat > ${meson_crossfile} <<EOF
-[binaries]
-c = '${CC}'
-cpp = '${CXX}'
-ar = '${XBPS_CROSS_TRIPLET}-gcc-ar'
-nm = '${NM}'
-ld = '${LD}'
-strip = '${STRIP}'
-readelf = '${READELF}'
-objcopy = '${OBJCOPY}'
-pkgconfig = '${PKG_CONFIG}'
-rust = ['rustc', '--target', '${RUST_TARGET}' ,'--sysroot', '${XBPS_CROSS_BASE}/usr']
-g-ir-scanner = '${XBPS_CROSS_BASE}/usr/bin/g-ir-scanner'
-g-ir-compiler = '${XBPS_CROSS_BASE}/usr/bin/g-ir-compiler'
-g-ir-generate = '${XBPS_CROSS_BASE}/usr/bin/g-ir-generate'
-llvm-config = '/usr/bin/llvm-config'
-cups-config = '${XBPS_CROSS_BASE}/usr/bin/cups-config'
-
-[properties]
-needs_exe_wrapper = true
-
-[built-in options]
-c_args = ['$(echo ${CFLAGS} | sed -r "s/\s+/','/g")']
-c_link_args = ['$(echo ${LDFLAGS} | sed -r "s/\s+/','/g")']
-
-cpp_args = ['$(echo ${CXXFLAGS} | sed -r "s/\s+/','/g")']
-cpp_link_args = ['$(echo ${LDFLAGS} | sed -r "s/\s+/','/g")']
-
-[host_machine]
-system = 'linux'
-cpu_family = '${_MESON_CPU_FAMILY}'
-cpu = '${_MESON_TARGET_CPU}'
-endian = '${_MESON_TARGET_ENDIAN}'
-EOF
-		if [[ $build_helper = *"qemu"* ]]; then
-			sed -e "/\[binaries\]/ a exe_wrapper = '/usr/bin/qemu-${XBPS_TARGET_QEMU_MACHINE}-static'" \
-				-i ${meson_crossfile}
-		fi
-
-		unset _MESON_CPU_FAMILY _MESON_TARGET_CPU _MESON_TARGET_ENDIAN
-	fi
-}
 
 do_configure() {
 	: ${meson_cmd:=meson}
 	: ${meson_builddir:=build}
-	: ${meson_crossfile:=xbps_meson.cross}
+	: ${meson_crossfile:="${XBPS_WRAPPERDIR}/meson/xbps_meson.cross"}
 
 	if [ "$CROSS_BUILD" ]; then
 		configure_args+=" --cross-file=${meson_crossfile}"
diff --git a/common/environment/build-style/meson.sh b/common/environment/build-style/meson.sh
index d5a3c4141f7d9..dbfe93700f691 100644
--- a/common/environment/build-style/meson.sh
+++ b/common/environment/build-style/meson.sh
@@ -1 +1,2 @@
 hostmakedepends+=" meson"
+build_helper+=" meson"

From c736e23b764ca9a9efeae2d32b67e7db015b2f91 Mon Sep 17 00:00:00 2001
From: "Andrew J. Hesford" <ajh@sideband.org>
Date: Wed, 20 Sep 2023 10:45:43 -0400
Subject: [PATCH 2/3] python3-scipy: use new meson helper

---
 srcpkgs/python3-scipy/template | 47 ++++++++++++++++------------------
 1 file changed, 22 insertions(+), 25 deletions(-)

diff --git a/srcpkgs/python3-scipy/template b/srcpkgs/python3-scipy/template
index ba0dd761cdcf5..e99919babf3bf 100644
--- a/srcpkgs/python3-scipy/template
+++ b/srcpkgs/python3-scipy/template
@@ -2,9 +2,10 @@
 pkgname=python3-scipy
 version=1.11.2
 revision=1
-build_style=meson
-build_helper="python3"
-configure_args="$(vopt_if openblas "" "-Dblas=blas -Dlapack=lapack")"
+build_style=python3-pep517
+build_helper="meson"
+make_build_args="--no-isolation --wheel
+ $(vopt_if openblas "" "-Csetup-args=-Dblas=blas -Csetup-args=-Dlapack=lapack")"
 hostmakedepends="python3-build python3-installer python3-meson-python
  python3-wheel python3-Cython python3-pybind11 pythran python3-numpy
  gcc-fortran pkg-config"
@@ -22,8 +23,12 @@ make_check="no" # Tests need an installed copy to run and meson makes this tough
 build_options="openblas"
 
 if [ "$CROSS_BUILD" ]; then
+	make_build_args+="
+	 -Csetup-args=--cross-file=${XBPS_WRAPPERDIR}/meson/xbps_meson.cross
+	 -Csetup-args=--cross-file=${XBPS_WRAPPERDIR}/meson/python.cross
+	"
+
 	_pybind11_dir="${py3_sitelib}/pybind11"
-	configure_args+=" --cross-file=python.cross"
 	export PKG_CONFIG_PATH="${XBPS_CROSS_BASE}/${_pybind11_dir}/share/pkgconfig"
 	# pybind11 uses a path relative to the pkgconfig file to set $prefix,
 	# which causes the wrapper to double-include $XBPS_CROSS_BASE; override
@@ -46,34 +51,26 @@ if [ "$build_option_openblas" ]; then
 	esac
 fi
 
-pre_patch() {
-	if [ "${CROSS_BUILD}" ]; then
-		# Meson can't tolerate $CC with arguments as set by the build helper
-		CC="${XBPS_CROSS_TRIPLET}-gcc"
-		# CXX needs to know where to find Python headers
-		CXXFLAGS+=" -I${XBPS_CROSS_BASE}/${py3_inc}"
-	fi
-}
-
 post_patch() {
 	if [ "$CROSS_BUILD" ]; then
 		local _xpy="${XBPS_CROSS_BASE}/${py3_sitelib}"
-		cat > python.cross <<-EOF
-		[properties]
-		numpy-include-dir = '${_xpy}/numpy/core/include'
-		pythran-include-dir = '${_xpy}/pythran'
-		EOF
+		cat > "${XBPS_WRAPPERDIR}/meson/python.cross" <<-EOF
+			[properties]
+			numpy-include-dir = '${_xpy}/numpy/core/include'
+			pythran-include-dir = '${_xpy}/pythran'
+			EOF
 	fi
 }
 
-do_build() {
-	# Use the build directory already configured by xbps-src for meson
-	python3 -m build --no-isolation --wheel \
-		-Cbuilddir="./build" -Ccompile-args="${makejobs}" .
+pre_build() {
+	if [ "$CROSS_BUILD" ]; then
+		# Meson can't tolerate $CC with arguments as set by the build helper
+		CC="${XBPS_CROSS_TRIPLET}-gcc"
+		# CXX needs to know where to find Python headers
+		CXXFLAGS+=" -I${XBPS_CROSS_BASE}/${py3_inc}"
+	fi
 }
 
-do_install() {
-	python3 -m installer --destdir "${DESTDIR}" \
-		--no-compile-bytecode dist/*.whl
+post_install() {
 	vlicense LICENSE.txt
 }

From 8126334ab3cb6995ace1d3d76b5660d4e79521fd Mon Sep 17 00:00:00 2001
From: "Andrew J. Hesford" <ajh@sideband.org>
Date: Wed, 20 Sep 2023 11:13:02 -0400
Subject: [PATCH 3/3] python3-scikit-image: use new meson helper

---
 srcpkgs/python3-scikit-image/template | 34 +++++++++++----------------
 1 file changed, 14 insertions(+), 20 deletions(-)

diff --git a/srcpkgs/python3-scikit-image/template b/srcpkgs/python3-scikit-image/template
index e800ed4f00f6c..b19743e50f37d 100644
--- a/srcpkgs/python3-scikit-image/template
+++ b/srcpkgs/python3-scikit-image/template
@@ -2,8 +2,8 @@
 pkgname=python3-scikit-image
 version=0.21.0
 revision=1
-build_style=meson
-build_helper="python3"
+build_style=python3-pep517
+build_helper="meson"
 hostmakedepends="python3-build python3-installer python3-meson-python
  python3-wheel python3-setuptools python3-packaging python3-Cython pythran
  python3-lazy_loader python3-numpy pkg-config"
@@ -21,22 +21,15 @@ checksum=53a82a9dbd3ed608d2ad3876269a271a7e922b12e228388eac996b508aadd652
 make_check=no
 
 if [ "${CROSS_BUILD}" ]; then
-	configure_args="--cross-file=python.cross"
+	make_build_args+=" --no-isolation --wheel
+	 -Csetup-args=--cross-file=${XBPS_WRAPPERDIR}/meson/xbps_meson.cross
+	 -Csetup-args=--cross-file=${XBPS_WRAPPERDIR}/meson/python.cross"
 fi
 
-pre_patch() {
-	if [ "${CROSS_BUILD}" ]; then
-		# Meson can't tolerate $CC with arguments as set by build helper
-		CC="${XBPS_CROSS_TRIPLET}-gcc"
-		# CXX needs to know where to find Python headers
-		CXXFLAGS+=" -I${XBPS_CROSS_BASE}/${py3_inc}"
-	fi
-}
-
 post_patch() {
 	if [ "${CROSS_BUILD}" ]; then
 		local _xpy="${XBPS_CROSS_BASE}/${py3_sitelib}"
-		cat > python.cross <<-EOF
+		cat > "${XBPS_WRAPPERDIR}/meson/python.cross" <<-EOF
 		[properties]
 		numpy-include-dir = '${_xpy}/numpy/core/include'
 		pythran-include-dir = '${_xpy}/pythran'
@@ -44,14 +37,15 @@ post_patch() {
 	fi
 }
 
-do_build() {
-	# Use the build directory already configured by xbps-src for meson
-	python3 -m build --no-isolation --wheel \
-		-Cbuilddir="./build" -Ccompile-args="${makejobs}" .
+pre_build() {
+	if [ "${CROSS_BUILD}" ]; then
+		# Meson can't tolerate $CC with arguments as set by build helper
+		CC="${XBPS_CROSS_TRIPLET}-gcc"
+		# CXX needs to know where to find Python headers
+		CXXFLAGS+=" -I${XBPS_CROSS_BASE}/${py3_inc}"
+	fi
 }
 
-do_install() {
-	python3 -m installer --destdir "${DESTDIR}" \
-		--no-compile-bytecode dist/*.whl
+post_install() {
 	vlicense LICENSE.txt
 }

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PR PATCH] [Merged]: [RFC] common/build-helper/meson.sh: new build helper, used by meson build style
  2023-09-18 19:53 [PR PATCH] [RFC, WIP] common/build-helper/meson.sh: new build helper, used by meson build style ahesford
                   ` (12 preceding siblings ...)
  2023-09-21 19:28 ` [PR PATCH] [Updated] " ahesford
@ 2023-09-22 14:17 ` ahesford
  13 siblings, 0 replies; 15+ messages in thread
From: ahesford @ 2023-09-22 14:17 UTC (permalink / raw)
  To: ml

[-- Attachment #1: Type: text/plain, Size: 2317 bytes --]

There's a merged pull request on the void-packages repository

[RFC] common/build-helper/meson.sh: new build helper, used by meson build style
https://github.com/void-linux/void-packages/pull/46117

Description:
The `python3-scipy` package now builds with `python3-meson-python`, with some more coming down the pike. The Python build process is necessary to include Python package metadata. For SciPy, this is accomplished by using the `meson` build style to configure a build directory, then overriding `do_build` and `do_install` to build things the PEP517 way (using the pre-configured build directory).

It might be helpful to define a `meson` build helper that can write out the standard cross file for builds, allowing packages like SciPy to use the `python3-pep517` build style with the `meson` helper. There are some issues to be worked out:
1. It seems like the `xbps_meson.cross` is written before `CFLAGS`, *et al.* are properly defined, so this cross file is actually broken. (This is the process by which the `qmake` helper writes its configurations, and they reference `CFLAGS` and others; is the `qmake` helper writing broken configs?)
2. The meson configuration (which would need to happen even with `python3-pep517` plus a `meson` helper) still includes a lot of magic that would have to be brought over to templates. This isn't really easier than the current practice of overriding the one-line `do_build` and `do_install`.

A possible solution would be to define a special-purpose function in the helper, called `vmesoncross` or somesuch, that will only write the configured when called---from a build function where these are properly defined (*e.g.*, `pre_configure`, `do_configure`). We could also define a special `do_configure`-like function in the helper that can be used by the `meson` style to actually do the configuration. This might be a bit ugly, but avoids repetition or violating the typical practice that the actual build functions are only defined in templates or build styles.

A third option is just defining a new `python3-meson` build style that mashes the meson `do_configure` bits from the `meson` style with the `do_build` and `do_install` bits from the `python3-pep517` style.

All of these options are sub-optimal, but I'm not sure which one is least offsensive.

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2023-09-22 14:17 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-18 19:53 [PR PATCH] [RFC, WIP] common/build-helper/meson.sh: new build helper, used by meson build style ahesford
2023-09-18 20:02 ` tornaria
2023-09-20  3:25 ` tornaria
2023-09-20 14:46 ` [PR PATCH] [Updated] " ahesford
2023-09-20 14:48 ` ahesford
2023-09-20 14:50 ` ahesford
2023-09-20 14:54 ` ahesford
2023-09-20 15:13 ` [PR PATCH] [Updated] " ahesford
2023-09-20 15:16 ` ahesford
2023-09-20 22:16 ` tornaria
2023-09-21  0:36 ` [RFC] " ahesford
2023-09-21  0:50 ` ahesford
2023-09-21  0:51 ` ahesford
2023-09-21 19:28 ` [PR PATCH] [Updated] " ahesford
2023-09-22 14:17 ` [PR PATCH] [Merged]: " ahesford

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).