rust: Consolidate cargo environment variables

This consolidates all environment variables for cargo into:

* CARGO_HOST_CONFIG_VARS / CARGO_PKG_CONFIG_VARS

  These contain all cargo-specific environment variables, i.e. without
  "common" variables like CC.

* CARGO_HOST_VARS / CARGO_PKG_VARS (renamed from CARGO_VARS)

  These contain all environment variables to be passed to cargo.

This also:

* Set the CARGO_BUILD_TARGET environment variable instead of using the
  --target command-line option

* Update Python include files to use CARGO_HOST_CONFIG_VARS /
  CARGO_PKG_CONFIG_VARS

Signed-off-by: Jeffery To <jeffery.to@gmail.com>
This commit is contained in:
Jeffery To 2023-09-25 11:58:12 +08:00
parent 853c9c9e86
commit 9db7284d58
No known key found for this signature in database
GPG Key ID: C616D9E719E868E4
6 changed files with 27 additions and 20 deletions

View File

@ -78,7 +78,7 @@ HOST_PYTHON3_VARS = \
CFLAGS="$(HOST_CFLAGS)" \
CPPFLAGS="$(HOST_CPPFLAGS) -I$(HOST_PYTHON3_INC_DIR)" \
LDFLAGS="$(HOST_LDFLAGS) -lpython$(PYTHON3_VERSION) -Wl$(comma)-rpath$(comma)$(STAGING_DIR_HOSTPKG)/lib" \
CARGO_HOME="$(CARGO_HOME)"
$(CARGO_HOST_CONFIG_VARS)
# $(1) => directory of python script
# $(2) => python script and its arguments

View File

@ -45,10 +45,8 @@ PYTHON3_VARS = \
_python_sysroot="$(STAGING_DIR)" \
_python_prefix="/usr" \
_python_exec_prefix="/usr" \
CARGO_BUILD_TARGET="$(RUSTC_TARGET_ARCH)" \
CARGO_HOME="$(CARGO_HOME)" \
PYO3_CROSS_LIB_DIR="$(PYTHON3_LIB_DIR)" \
RUSTFLAGS="$(CARGO_RUSTFLAGS)"
$(CARGO_PKG_CONFIG_VARS) \
PYO3_CROSS_LIB_DIR="$(PYTHON3_LIB_DIR)"
# $(1) => directory of python script
# $(2) => python script and its arguments

View File

@ -15,13 +15,16 @@ ifeq ($(origin RUST_INCLUDE_DIR),undefined)
endif
include $(RUST_INCLUDE_DIR)/rust-values.mk
CARGO_HOST_VARS= \
$(CARGO_HOST_CONFIG_VARS) \
CC=$(HOSTCC_NOCACHE)
# $(1) path to the package (optional)
# $(2) additional arguments to cargo (optional)
define Host/Compile/Cargo
( \
cd $(HOST_BUILD_DIR) ; \
CARGO_HOME=$(CARGO_HOME) \
CC=$(HOSTCC_NOCACHE) \
$(CARGO_HOST_VARS) \
cargo install -v \
--profile $(CARGO_HOST_PROFILE) \
$(if $(RUST_HOST_FEATURES),--features "$(RUST_HOST_FEATURES)") \
@ -33,8 +36,7 @@ endef
define Host/Uninstall/Cargo
( \
cd $(HOST_BUILD_DIR) ; \
CARGO_HOME=$(CARGO_HOME) \
CC=$(HOSTCC_NOCACHE) \
$(CARGO_HOST_VARS) \
cargo uninstall -v \
--root $(HOST_INSTALL_DIR) || true ; \
)

View File

@ -15,22 +15,18 @@ ifeq ($(origin RUST_INCLUDE_DIR),undefined)
endif
include $(RUST_INCLUDE_DIR)/rust-values.mk
CARGO_PKG_VARS= \
$(CARGO_PKG_CONFIG_VARS) \
CC=$(HOSTCC_NOCACHE)
# $(1) path to the package (optional)
# $(2) additional arguments to cargo (optional)
define Build/Compile/Cargo
( \
cd $(PKG_BUILD_DIR) ; \
CARGO_HOME=$(CARGO_HOME) \
CARGO_PROFILE_RELEASE_OPT_LEVEL=s \
CARGO_TARGET_$(subst -,_,$(call toupper,$(RUSTC_TARGET_ARCH)))_LINKER=$(TARGET_CC_NOCACHE) \
TARGET_CFLAGS="$(TARGET_CFLAGS) $(RUSTC_CFLAGS)" \
TARGET_CC=$(TARGET_CC_NOCACHE) \
CC=$(HOSTCC_NOCACHE) \
RUSTFLAGS="$(CARGO_RUSTFLAGS)" \
$(CARGO_VARS) \
$(CARGO_PKG_VARS) \
cargo install -v \
--profile $(CARGO_PKG_PROFILE) \
--target $(RUSTC_TARGET_ARCH) \
$(if $(strip $(RUST_PKG_FEATURES)),--features "$(strip $(RUST_PKG_FEATURES))") \
--root $(PKG_INSTALL_DIR) \
--path "$(if $(strip $(1)),$(strip $(1)),.)" \

View File

@ -6,7 +6,6 @@
RUSTC_HOST_SUFFIX:=$(word 4, $(subst -, ,$(GNU_HOST_NAME)))
RUSTC_HOST_ARCH:=$(HOST_ARCH)-unknown-linux-$(RUSTC_HOST_SUFFIX)
CARGO_HOME:=$(DL_DIR)/cargo
CARGO_VARS?=
ifeq ($(CONFIG_USE_MUSL),y)
# Force linking of the SSP library for musl
@ -63,6 +62,18 @@ endif
# Support only a subset for now.
RUST_ARCH_DEPENDS:=@(aarch64||arm||i386||i686||mips||mipsel||mips64||mips64el||mipsel||powerpc64||riscv64||x86_64)
CARGO_HOST_CONFIG_VARS= \
CARGO_HOME=$(CARGO_HOME)
CARGO_HOST_PROFILE:=release
CARGO_PKG_CONFIG_VARS= \
CARGO_BUILD_TARGET=$(RUSTC_TARGET_ARCH) \
CARGO_HOME=$(CARGO_HOME) \
CARGO_PROFILE_RELEASE_OPT_LEVEL=s \
CARGO_TARGET_$(subst -,_,$(call toupper,$(RUSTC_TARGET_ARCH)))_LINKER=$(TARGET_CC_NOCACHE) \
RUSTFLAGS="$(CARGO_RUSTFLAGS)" \
TARGET_CC=$(TARGET_CC_NOCACHE) \
TARGET_CFLAGS="$(TARGET_CFLAGS) $(RUSTC_CFLAGS)"
CARGO_PKG_PROFILE:=$(if $(CONFIG_DEBUG),dev,release)

View File

@ -36,7 +36,7 @@ define Package/netavark/conffiles
/etc/config/netavark
endef
CARGO_VARS += \
CARGO_PKG_VARS += \
PROTOC=$(STAGING_DIR_HOSTPKG)/bin/protoc
define Package/netavark/install