diff mbox series

package/pkg-cargo: add HOST_* variables for target build

Message ID 20260225124832.3969166-1-slaveze@smartandconnective.com
State Handled Elsewhere
Headers show
Series package/pkg-cargo: add HOST_* variables for target build | expand

Commit Message

Sebastien LAVEZE Feb. 25, 2026, 12:48 p.m. UTC
From: Sebastien Laveze <slaveze@smartandconnective.com>

Cargo builds both host (build.rs) and target in the same build stage.

Host-side build scripts (build.rs) using cc-rs resolve tools/flags through
HOST_* before falling back to unprefixed variables. Without HOST_* set, they
can incorrectly pick target compiler/flags and fail in mixed-bitness setups
(e.g. 64-bit host with 32-bit target).

https://docs.rs/cc/1.2.55/cc/#external-configuration-via-environment-variables

Signed-off-by: Sebastien Laveze <slaveze@smartandconnective.com>
---
 package/pkg-cargo.mk | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/package/pkg-cargo.mk b/package/pkg-cargo.mk
index 47a6353f25..a3c7436a1b 100644
--- a/package/pkg-cargo.mk
+++ b/package/pkg-cargo.mk
@@ -51,7 +51,19 @@  PKG_CARGO_ENV = \
 	CARGO_TARGET_APPLIES_TO_HOST="false" \
 	CARGO_BUILD_TARGET="$(RUSTC_TARGET_NAME)" \
 	CARGO_HOST_RUSTFLAGS="$(addprefix -C link-args=,$(HOST_LDFLAGS))" \
-	CARGO_TARGET_$(call UPPERCASE,$(RUSTC_TARGET_NAME))_LINKER=$(notdir $(TARGET_CROSS))gcc
+	CARGO_TARGET_$(call UPPERCASE,$(RUSTC_TARGET_NAME))_LINKER=$(notdir $(TARGET_CROSS))gcc \
+	HOST_AR="$(HOSTAR)" \
+	HOST_AS="$(HOSTAS)" \
+	HOST_CC="$(HOSTCC)" \
+	HOST_CXX="$(HOSTCXX)" \
+	HOST_CPP="$(HOSTCPP)" \
+	HOST_LD="$(HOSTLD)" \
+	HOST_NM="$(HOSTNM)" \
+	HOST_RANLIB="$(HOSTRANLIB)" \
+	HOST_PKG_CONFIG_SYSROOT_DIR="/" \
+	HOST_PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 \
+	HOST_PKG_CONFIG_ALLOW_SYSTEM_LIBS=1 \
+	HOST_PKG_CONFIG_LIBDIR="$(HOST_DIR)/lib/pkgconfig:$(HOST_DIR)/share/pkgconfig"
 
 # We always set both CARGO_PROFILE_DEV and CARGO_PROFILE_RELEASE
 # as we are unable to select a build profile using the environment.