libmakepkg: move rust buildenv handling to separate file

This serves as a demonstration for how other languages could drop
in support into libmakepkg.

Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
Allan McRae 2023-01-13 11:10:01 +10:00
parent d35728f924
commit 09e82f01ea
6 changed files with 45 additions and 9 deletions

View file

@ -25,12 +25,13 @@ LIBMAKEPKG_BUILDENV_SH=1
LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
declare -a buildenv_functions build_options
buildenv_vars=('CPPFLAGS' 'CFLAGS' 'CXXFLAGS' 'LDFLAGS' 'MAKEFLAGS' 'CHOST')
for lib in "$LIBRARY/buildenv/"*.sh; do
source "$lib"
done
readonly -a buildenv_functions build_options
readonly -a buildenv_functions buildenv_vars build_options
prepare_buildenv() {
for func in ${buildenv_functions[@]}; do
@ -38,5 +39,5 @@ prepare_buildenv() {
done
# ensure all necessary build variables are exported
export CPPFLAGS CFLAGS CXXFLAGS LDFLAGS RUSTFLAGS MAKEFLAGS CHOST
export ${buildenv_vars[@]}
}

View file

@ -30,6 +30,6 @@ buildenv_functions+=('buildenv_buildflags')
buildenv_buildflags() {
if check_option "buildflags" "n"; then
unset CPPFLAGS CFLAGS DEBUG_CFLAGS CXXFLAGS DEBUG_CXXFLAGS LDFLAGS LTOFLAGS RUSTFLAGS DEBUG_RUSTFLAGS
unset ${buildenv_vars[@]}
fi
}

View file

@ -32,9 +32,7 @@ buildenv_debugflags() {
if check_option "debug" "y" && ! check_option "buildflags" "n"; then
DEBUG_CFLAGS+=" -ffile-prefix-map=$srcdir=${DBGSRCDIR:-/usr/src/debug}/${pkgbase}"
DEBUG_CXXFLAGS+=" -ffile-prefix-map=$srcdir=${DBGSRCDIR:-/usr/src/debug}/${pkgbase}"
DEBUG_RUSTFLAGS+=" --remap-path-prefix=$srcdir=${DBGSRCDIR:-/usr/src/debug}/${pkgbase}"
CFLAGS+=" $DEBUG_CFLAGS"
CXXFLAGS+=" $DEBUG_CXXFLAGS"
RUSTFLAGS+=" $DEBUG_RUSTFLAGS"
fi
}

View file

@ -6,6 +6,7 @@ sources = [
'debugflags.sh.in',
'lto.sh.in',
'makeflags.sh.in',
'rust.sh.in',
]
foreach src : sources

View file

@ -0,0 +1,36 @@
#!/usr/bin/bash
#
# rust.sh - Specify flags for building a package with rust
#
# Copyright (c) 2022 Pacman Development Team <pacman-dev@lists.archlinux.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
[[ -n "$LIBMAKEPKG_BUILDENV_RUST_SH" ]] && return
LIBMAKEPKG_BUILDENV_RUST_SH=1
LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
source "$LIBRARY/util/option.sh"
buildenv_var+=('RUSTFLAGS' 'DEBUG_RUSTFLAGS')
buildenv_functions+=('buildenv_rust')
buildenv_rust() {
if check_option "debug" "y" && ! check_option "buildflags" "n"; then
DEBUG_RUSTFLAGS+=" --remap-path-prefix=$srcdir=${DBGSRCDIR:-/usr/src/debug}/${pkgbase}"
RUSTFLAGS+=" $DEBUG_RUSTFLAGS"
fi
}

View file

@ -32,10 +32,10 @@ lint_config_variables() {
local array=(DLAGENTS VCSCLIENTS BUILDENV OPTIONS INTEGRITY_CHECK MAN_DIRS
DOC_DIRS PURGE_TARGETS COMPRESSGZ COMPRESSBZ2 COMPRESSXZ
COMPRESSLRZ COMPRESSLZO COMPRESSZ)
local string=(CARCH CHOST CPPFLAGS CFLAGS CXXFLAGS RUSTFLAGS LDFLAGS LTOFLAGS
DEBUG_CFLAGS DEBUG_CXXFLAGS DEBUG_RUSTFLAGS DISTCC_HOSTS BUILDDIR
STRIP_BINARIES STRIP_SHARED STRIP_STATIC PKGDEST SRCDEST SRCPKGDEST
LOGDEST PACKAGER GPGKEY PKGEXT SRCEXT)
local string=(CARCH CHOST CPPFLAGS CFLAGS CXXFLAGS LDFLAGS LTOFLAGS DEBUG_CFLAGS
DEBUG_CXXFLAGS DISTCC_HOSTS BUILDDIR STRIP_BINARIES STRIP_SHARED
STRIP_STATIC PKGDEST SRCDEST SRCPKGDEST LOGDEST PACKAGER GPGKEY
PKGEXT SRCEXT)
local i keys ret=0