summaryrefslogtreecommitdiff
path: root/eclass/cargo.eclass
diff options
context:
space:
mode:
authorV3n3RiX <venerix@redcorelinux.org>2020-09-23 10:22:15 +0100
committerV3n3RiX <venerix@redcorelinux.org>2020-09-23 10:22:15 +0100
commit8b4ace9c50842c5b83401ea7b179dcab940387e1 (patch)
tree230f3135ceaace633cf93e9838b185c4a6664c2e /eclass/cargo.eclass
parent9ee6d97c2883d42f204a533a8bc1f4562df778fb (diff)
gentoo resync : 23.09.2020
Diffstat (limited to 'eclass/cargo.eclass')
-rw-r--r--eclass/cargo.eclass103
1 files changed, 87 insertions, 16 deletions
diff --git a/eclass/cargo.eclass b/eclass/cargo.eclass
index ccbf87aa9a6c..6d341601a112 100644
--- a/eclass/cargo.eclass
+++ b/eclass/cargo.eclass
@@ -22,17 +22,29 @@ esac
inherit multiprocessing toolchain-funcs
-EXPORT_FUNCTIONS src_unpack src_compile src_install src_test
+EXPORT_FUNCTIONS src_unpack src_configure src_compile src_install src_test
IUSE="${IUSE} debug"
ECARGO_HOME="${WORKDIR}/cargo_home"
ECARGO_VENDOR="${ECARGO_HOME}/gentoo"
-# @ECLASS-VARIABLE: CARGO_INSTALL_PATH
+# @VARIABLE: myfeatures
+# @DEFAULT_UNSET
# @DESCRIPTION:
-# Allows overriding the default cwd to run cargo install from
-: ${CARGO_INSTALL_PATH:=.}
+# Optional cargo features defined as bash array.
+# Should be defined before calling cargo_src_configure().
+#
+# Example package that has x11 and wayland as features, and disables default.
+# @CODE
+# src_configure() {
+# local myfeatures=(
+# $(usex X x11 '')
+# $(usev wayland)
+# )
+# cargo_src_configure --no-default-features
+# }
+# @CODE
# @FUNCTION: cargo_crate_uris
# @DESCRIPTION:
@@ -112,6 +124,7 @@ cargo_live_src_unpack() {
mkdir -p "${S}" || die
pushd "${S}" > /dev/null || die
+ # need to specify CARGO_HOME before cargo_gen_config fired
CARGO_HOME="${ECARGO_HOME}" cargo fetch || die
CARGO_HOME="${ECARGO_HOME}" cargo vendor "${ECARGO_VENDOR}" || die
popd > /dev/null || die
@@ -151,6 +164,56 @@ cargo_gen_config() {
EOF
# honor NOCOLOR setting
[[ "${NOCOLOR}" = true || "${NOCOLOR}" = yes ]] && echo "color = 'never'" >> "${ECARGO_HOME}/config"
+
+ export CARGO_HOME="${ECARGO_HOME}"
+}
+
+# @FUNCTION: cargo_src_configure
+# @DESCRIPTION:
+# Configure cargo package features and arguments.
+# Extra positional arguments supplied to this function
+# will be passed to cargo in all phases.
+# Make sure all cargo subcommands support flags passed here.
+#
+# Example for package that explicitly builds only 'baz' binary and
+# enables 'barfeature' and optional 'foo' feature.
+# will pass '--features barfeature --features foo --bin baz'
+# in src_{compile,test,install}
+#
+# @CODE
+# src_configure() {
+# local myfeatures=(
+# barfeature
+# $(usev foo)
+# )
+# cargo_src_configure --bin baz
+# }
+# @CODE
+#
+# In some cases crates may need '--no-default-features' option,
+# as there is no way to disable single feature, except disabling all.
+# It can be passed directly to cargo_src_configure().
+
+cargo_src_configure() {
+ debug-print-function ${FUNCNAME} "$@"
+
+ [[ -z ${myfeatures} ]] && declare -a myfeatures=()
+ local myfeaturestype=$(declare -p myfeatures 2>&-)
+ if [[ "${myfeaturestype}" != "declare -a myfeatures="* ]]; then
+ die "myfeatures must be declared as array"
+ fi
+
+ # transform array from simple feature list
+ # to multiple cargo args:
+ # --features feature1 --features feature2 ...
+ # this format is chosen because 2 other methods of
+ # listing features (space OR comma separated) require
+ # more fiddling with strings we'd like to avoid here.
+ myfeatures=( ${myfeatures[@]/#/--features } )
+
+ readonly ECARGO_ARGS=( ${myfeatures[@]} ${@} ${ECARGO_EXTRA_ARGS} )
+
+ [[ ${ECARGO_ARGS[@]} ]] && einfo "Configured with: ${ECARGO_ARGS[@]}"
}
# @FUNCTION: cargo_src_compile
@@ -159,25 +222,32 @@ cargo_gen_config() {
cargo_src_compile() {
debug-print-function ${FUNCNAME} "$@"
- export CARGO_HOME="${ECARGO_HOME}"
+ tc-export AR CC CXX
- tc-export AR CC
-
- cargo build $(usex debug "" --release) "$@" \
- || die "cargo build failed"
+ set -- cargo build $(usex debug "" --release) ${ECARGO_ARGS[@]} "$@"
+ einfo "${@}"
+ "${@}" || die "cargo build failed"
}
# @FUNCTION: cargo_src_install
# @DESCRIPTION:
# Installs the binaries generated by cargo
+# In come case workspaces need alternative --path parameter
+# default is '--path ./' if nothing specified.
+# '--path ./somedir' can be passed directly to cargo_src_install()
+
cargo_src_install() {
debug-print-function ${FUNCNAME} "$@"
- cargo install --path ${CARGO_INSTALL_PATH} \
- --root="${ED}/usr" $(usex debug --debug "") "$@" \
- || die "cargo install failed"
- rm -f "${ED}/usr/.crates.toml"
- rm -f "${ED}/usr/.crates2.json"
+ set -- cargo install $(has --path ${@} || echo --path ./) \
+ --root "${ED}/usr" \
+ $(usex debug --debug "") \
+ ${ECARGO_ARGS[@]} "$@"
+ einfo "${@}"
+ "${@}" || die "cargo install failed"
+
+ rm -f "${ED}/usr/.crates.toml" || die
+ rm -f "${ED}/usr/.crates2.json" || die
[ -d "${S}/man" ] && doman "${S}/man" || return 0
}
@@ -188,8 +258,9 @@ cargo_src_install() {
cargo_src_test() {
debug-print-function ${FUNCNAME} "$@"
- cargo test $(usex debug "" --release) "$@" \
- || die "cargo test failed"
+ set -- cargo test $(usex debug "" --release) ${ECARGO_ARGS[@]} "$@"
+ einfo "${@}"
+ "${@}" || die "cargo test failed"
}
fi