diff --git a/cargo.eclass b/cargo.eclass index 6f7ffdb..5c7c9f4 100644 --- a/cargo.eclass +++ b/cargo.eclass @@ -23,7 +23,7 @@ esac inherit multiprocessing -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" @@ -154,6 +154,24 @@ cargo_gen_config() { [[ "${NOCOLOR}" = true || "${NOCOLOR}" = yes ]] && echo "color = 'never'" >> "${ECARGO_HOME}/config" } +# @FUNCTION: cargo_feature +# @DESCRIPTION: +# Enable a crate feature +cargo_feature() { + if ! [ -z ${1} ]; then + CARGO_FEATURES="${1},${CARGO_FEATURES}" + fi +} + +# @FUNCTION: cargo_src_configure +# @DESCRIPTION: +# Apply the selected features +cargo_src_configure() { + if ! [ -z "${CARGO_FEATURES}" ]; then + CARGO_FEATURES="--no-default-features --features ${CARGO_FEATURES}" + fi +} + # @FUNCTION: cargo_src_compile # @DESCRIPTION: # Build the package using cargo build @@ -162,7 +180,7 @@ cargo_src_compile() { export CARGO_HOME="${ECARGO_HOME}" - cargo build $(usex debug "" --release) "$@" \ + cargo build $(usex debug "" --release) ${CARGO_FEATURES} "$@" \ || die "cargo build failed" } @@ -173,7 +191,7 @@ cargo_src_install() { debug-print-function ${FUNCNAME} "$@" cargo install --path ${CARGO_INSTALL_PATH} \ - --root="${ED}/usr" $(usex debug --debug "") "$@" \ + --root="${ED}/usr" $(usex debug --debug "") ${CARGO_FEATURES} "$@" \ || die "cargo install failed" rm -f "${ED}/usr/.crates.toml" rm -f "${ED}/usr/.crates2.json" @@ -187,7 +205,7 @@ cargo_src_install() { cargo_src_test() { debug-print-function ${FUNCNAME} "$@" - cargo test $(usex debug "" --release) "$@" \ + cargo test $(usex debug "" --release) ${CARGO_FEATURES} "$@" \ || die "cargo test failed" }