Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] common/build-helper/meson.sh: new build helper, used by meson build style #46117

Merged
merged 3 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
82 changes: 82 additions & 0 deletions common/build-helper/meson.sh
Original file line number Diff line number Diff line change
@@ -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
85 changes: 1 addition & 84 deletions common/build-style/meson.sh
Original file line number Diff line number Diff line change
@@ -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}"
Expand Down
1 change: 1 addition & 0 deletions common/environment/build-style/meson.sh
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
hostmakedepends+=" meson"
build_helper+=" meson"
34 changes: 14 additions & 20 deletions srcpkgs/python3-scikit-image/template
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -21,37 +21,31 @@ 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'
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 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
}
47 changes: 22 additions & 25 deletions srcpkgs/python3-scipy/template
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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
}
Loading