tech-pkg archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[PATCH] Cargo build product directory: CARGO_TARGET_DIR
By default, cargo puts build products in ${WRKSRC}/target/release, and
some do-install recipes use this, e.g. textproc/dbcat:
do-install:
${INSTALL_PROGRAM} ${WRKSRC}/target/release/dbcat ${DESTDIR}${PREFIX}/bin
When cross-building, though, the build product will go instead by
default in ${WRKSRC}/target/${RUST_ARCH}/release.
To enable packages to gracefully handle both native and cross builds,
I'd like to add a new variable CARGO_TARGET_DIR which is
${WRKSRC}/target/release in native builds and
${WRKSRC}/target/${RUST_ARCH}/release in cross builds, so if this
recipe is rewritten as the following then it works in both cases:
do-install:
${INSTALL_PROGRAM} ${CARGO_TARGET_DIR}/dbcat ${DESTDIR}${PREFIX}/bin
I picked the name CARGO_TARGET_DIR because it more or less matches the
(shorter) environment variable that cargo already uses for this:
https://web.archive.org/web/20250118203056/https://doc.rust-lang.org/cargo/reference/config.html#buildtarget-dir
This variable is defined by the system for use by packages, not
settable by packages. I'm separating out this commit from the rest of
the changes to do Rust cross-builds because it's about the cargo.mk
interface contract with packages and is independent of the rest of the
cross-build changes.
(I also have variants of this patch queued up for pkgsrc-wip to
rust181 through rust184.)
As an alternative, we could instead arrange the cross-build logic to
specify ${WRKSRC}/target/release but I don't know what other
consequences that might have. And I think naming CARGO_TARGET_DIR
will assist in future changes like that if we want anyway.
OK?
From ec9bedcb1f96b9b387caed291134bf3736de0529 Mon Sep 17 00:00:00 2001
From: Taylor R Campbell <riastradh%NetBSD.org@localhost>
Date: Sat, 11 Jan 2025 09:01:53 +0000
Subject: [PATCH] lang/rust/cargo.mk: New variable CARGO_TARGET_DIR.
This is where cargo puts its build products. Packages can use this,
e.g., for do-install recipes that install executables into
${PREFIX}/bin.
This variable is useful because for native builds it is
${WRKSRC}/target/release, but for cross builds (once supported) it
will have to be ${WRKSRC}/target/${RUST_ARCH}/release instead.
---
lang/rust/cargo.mk | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/lang/rust/cargo.mk b/lang/rust/cargo.mk
index 5a3ed0cf8306..7dbc30f57aed 100644
--- a/lang/rust/cargo.mk
+++ b/lang/rust/cargo.mk
@@ -82,6 +82,13 @@ DEFAULT_CARGO_ARGS= --offline -j${_MAKE_JOBS_N} \
CARGO_ARGS?= build --release ${DEFAULT_CARGO_ARGS}
CARGO_INSTALL_ARGS?= install --path . --root ${DESTDIR}${PREFIX} ${DEFAULT_CARGO_ARGS}
+# Note: Cargo uses the word `target' both for the cross-compilation
+# tuple (architecture/vendor/OS) and for the directory where build
+# products go. The name CARGO_TARGET_DIR (or CARGO_BUILD_TARGET_DIR)
+# is what cargo uses for the directory of build products.
+CARGO_TARGET_SUBDIR= target/release
+CARGO_TARGET_DIR= ${WRKSRC}/${CARGO_TARGET_SUBDIR}
+
MAKE_ENV+= RUSTFLAGS=${RUSTFLAGS:Q}
ALL_ENV+= CARGO_HOME=${WRKDIR}
Home |
Main Index |
Thread Index |
Old Index