Index | Thread | Search

From:
Andrew Kloet <andrew@kloet.net>
Subject:
cargo.port.mk: separate libtest argument namespace
To:
tech@openbsd.org
Date:
Wed, 05 Aug 2026 11:41:12 -0400

Download raw body.

Thread
  • Andrew Kloet:

    cargo.port.mk: separate libtest argument namespace

Hello tech@

In net/arti I'd like to ignore a few tests that are expected to fail by
passing libtest arguments, for example:

MODCARGO_TEST_ARGS = -- --skip example_test

The `--` separator is required because `--skip` is a libtest option, not
a Cargo option [1]. With the current cargo.port.mk this cannot be done
when MODCARGO_FEATURES is also defined:

# User arguments for cargo targets.
MODCARGO_BUILD_ARGS ?=
MODCARGO_INSTALL_ARGS ?=
MODCARGO_TEST_ARGS ?=

# Manage crate features.
.if !empty(MODCARGO_FEATURES)
MODCARGO_BUILD_ARGS +=          --features='${MODCARGO_FEATURES}'
MODCARGO_INSTALL_ARGS +=        --features='${MODCARGO_FEATURES}'
MODCARGO_TEST_ARGS +=           --features='${MODCARGO_FEATURES}'
.endif

.if ${MODCARGO_NO_DEFAULT_FEATURES:L} == "yes"
MODCARGO_BUILD_ARGS +=          --no-default-features
MODCARGO_INSTALL_ARGS +=        --no-default-features
MODCARGO_TEST_ARGS +=           --no-default-features
.endif

cargo.port.mk appends `--features` and `--no-default-features` to
MODCARGO_TEST_ARGS. If MODCARGO_TEST_ARGS already contains `--`, those
options end up after the separator and are passed to libtest instead of
Cargo.

In brief: `MODCARGO_TEST_ARGS` is used for two different argument
namespaces: Cargo arguments and libtest arguments. There is currently
no way to pass arguments to libtest without also causing subsequent
Cargo arguments added by `cargo.port.mk` to be passed to libtest.

I propose that another variable, MODCARGO_LIBTEST_ARGS, be added.

[1] https://dirname.github.io/rust-std-doc/cargo/commands/cargo-test.html

Andrew

diff --git a/devel/cargo/cargo.port.mk b/devel/cargo/cargo.port.mk
index 0d63b67e6..a18d06d13 100644
--- a/devel/cargo/cargo.port.mk
+++ b/devel/cargo/cargo.port.mk
@@ -334,6 +334,7 @@ MODCARGO_CARGO_RUN = \
 MODCARGO_BUILD_ARGS ?=
 MODCARGO_INSTALL_ARGS ?=
 MODCARGO_TEST_ARGS ?=
+MODCARGO_LIBTEST_ARGS ?=
 
 # Manage crate features.
 .if !empty(MODCARGO_FEATURES)
@@ -396,7 +397,9 @@ MODCARGO_TEST_TARGET = \
 	${MODCARGO_CARGO_RUN} test \
 		--manifest-path ${MODCARGO_CARGOTOML} \
 		--release \
-		${MODCARGO_TEST_ARGS} ;
+		${MODCARGO_TEST_ARGS} \
+		-- \
+		${MODCARGO_LIBTEST_ARGS} ;
 
 .if !target(do-test) && ${MODCARGO_TEST:L} == "yes"
 do-test:

 diff --git a/share/man/man5/cargo-module.5 b/share/man/man5/cargo-module.5
index 0c49e377a..ae7ecabd3 100644
--- a/share/man/man5/cargo-module.5
+++ b/share/man/man5/cargo-module.5
@@ -185,6 +185,8 @@ Defaults to
 .It Ev MODCARGO_TEST_ARGS
 Additional arguments passed to
 .Cm cargo test .
+.It Ev MODCARGO_LIBTEST_ARGS
+Additional arguments passed to libtest.
 .It Ev MODCARGO_CARGO_BIN
 Path to the
 .Xr cargo 1