termux / termux-packages

A package build system for Termux.
https://termux.dev
Other
12.65k stars 2.91k forks source link

build system: rust compiler for meson? #20517

Open knyipab opened 4 weeks ago

knyipab commented 4 weeks ago

Currently, it seems that building rust-dependent package with meson is not so feasible with the existing build script. Someone may test below build script. Grateful for devs adding support to rust for meson.

TERMUX_PKG_HOMEPAGE=https://gitlab.freedesktop.org/pipewire/helvum
TERMUX_PKG_DESCRIPTION="A GTK patchbay for pipewire. "
TERMUX_PKG_LICENSE="GPL-3.0"
TERMUX_PKG_MAINTAINER="@termux"
TERMUX_PKG_VERSION="0.5.1"
TERMUX_PKG_SRCURL="https://gitlab.freedesktop.org/pipewire/helvum/-/archive/${TERMUX_PKG_VERSION}/helvum-${TERMUX_PKG_VERSION}.tar.bz2"
TERMUX_PKG_SHA256=d4f5cc0c3a70a91edfc816f12a10426dadd9ca74ea82662e2df5e6c4eb31d8ca
TERMUX_PKG_DEPENDS="gdk-pixbuf, glib, graphene, gtk4, hicolor-icon-theme, libadwaita, libcairo, pipewire, pango"
TERMUX_PKG_BUILD_DEPENDS="appstream-glib"
TERMUX_PKG_AUTO_UPDATE=true

termux_step_configure() {
    termux_setup_meson
    termux_setup_rust

    local _meson_buildtype="minsize"
    local _meson_stripflag="--strip"
    if [ "$TERMUX_DEBUG_BUILD" = "true" ]; then
        _meson_buildtype="debug"
        _meson_stripflag=
    fi

    CC=gcc CXX=g++ CFLAGS= CXXFLAGS= CPPFLAGS= LDFLAGS= $TERMUX_MESON \
        setup \
        $TERMUX_PKG_SRCDIR \
        $TERMUX_PKG_BUILDDIR \
        --$(test "${TERMUX_PKG_MESON_NATIVE}" = "true" && echo "native-file" || echo "cross-file") $TERMUX_MESON_CROSSFILE \
        --prefix $TERMUX_PREFIX \
        --libdir lib \
        --buildtype ${_meson_buildtype} \
        ${_meson_stripflag} \
        $TERMUX_PKG_EXTRA_CONFIGURE_ARGS \
        || (termux_step_configure_meson_failure_hook && false)
}

And it prompts error:

../src/meson.build:1:0: ERROR: 'rust' compiler binary not defined in cross or native file

Attempt

I also tried to copy termux_setup_meson and patch with rust registration in CROSSFILE:

echo "rust = '${HOME}/.cargo/bin/rustc'" >> $TERMUX_MESON_CROSSFILE

but it prompts:

meson.build:1:0: ERROR: Rust compiler /home/builder/.cargo/bin/rustc -C linker=x86_64-linux-android-clang cannot compile programs.

This issue is cross-compiling-specific

As a POC, this on-device build action works: https://github.com/knyipab/tur/actions/runs/9526259153

truboxl commented 5 days ago

Seems to work after changing to

sed -i "s|cmake = 'cmake'|cmake = 'cmake'\nrust = ['rustc', '--target', 'aarch64-linux-android', '-L', '${TERMUX_PREFIX}/lib']|" "$TERMUX_MESON_CROSSFILE"

I suppose each arch needs to have separate meson file.

Edit: only progress up to a point before ld complains incompatible. Need further investigation.

Biswa96 commented 11 hours ago

This kind of feature is probably required for neocmakelsp 0.7.8. It uses meson to build rust program.