From 49aaf19c65a35c37725ead7a438684411b512d6f Mon Sep 17 00:00:00 2001 From: Jeffery To Date: Sat, 23 Sep 2023 00:02:01 +0800 Subject: rust: Install to $(STAGING_DIR)/host This allows rustc/cargo/etc to be called without having to set PATH, as $(STAGING_DIR)/host/bin is already in PATH. This also fixes CARGO_HOME not being set during Host/Configure and Host/Compile. Signed-off-by: Jeffery To --- lang/python/python3-package.mk | 1 - 1 file changed, 1 deletion(-) (limited to 'lang/python/python3-package.mk') diff --git a/lang/python/python3-package.mk b/lang/python/python3-package.mk index 0693d21ee..fcb1d06b3 100644 --- a/lang/python/python3-package.mk +++ b/lang/python/python3-package.mk @@ -47,7 +47,6 @@ PYTHON3_VARS = \ _python_exec_prefix="/usr" \ CARGO_BUILD_TARGET="$(RUSTC_TARGET_ARCH)" \ CARGO_HOME="$(CARGO_HOME)" \ - PATH="$(CARGO_HOME)/bin:$(PATH)" \ PYO3_CROSS_LIB_DIR="$(PYTHON3_LIB_DIR)" \ RUSTFLAGS="$(CARGO_RUSTFLAGS)" -- cgit From 9db7284d589dc8490f8c7dbe56af731fce953eda Mon Sep 17 00:00:00 2001 From: Jeffery To Date: Mon, 25 Sep 2023 11:58:12 +0800 Subject: 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 --- lang/python/python3-host.mk | 2 +- lang/python/python3-package.mk | 6 ++---- lang/rust/rust-host-build.mk | 10 ++++++---- lang/rust/rust-package.mk | 14 +++++--------- lang/rust/rust-values.mk | 13 ++++++++++++- net/netavark/Makefile | 2 +- 6 files changed, 27 insertions(+), 20 deletions(-) (limited to 'lang/python/python3-package.mk') diff --git a/lang/python/python3-host.mk b/lang/python/python3-host.mk index 6ca002587..b233c5679 100644 --- a/lang/python/python3-host.mk +++ b/lang/python/python3-host.mk @@ -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 diff --git a/lang/python/python3-package.mk b/lang/python/python3-package.mk index fcb1d06b3..e4c7bd264 100644 --- a/lang/python/python3-package.mk +++ b/lang/python/python3-package.mk @@ -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 diff --git a/lang/rust/rust-host-build.mk b/lang/rust/rust-host-build.mk index a03df2493..38ce963e0 100644 --- a/lang/rust/rust-host-build.mk +++ b/lang/rust/rust-host-build.mk @@ -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 ; \ ) diff --git a/lang/rust/rust-package.mk b/lang/rust/rust-package.mk index 713d37d5b..6deb859fb 100644 --- a/lang/rust/rust-package.mk +++ b/lang/rust/rust-package.mk @@ -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)),.)" \ diff --git a/lang/rust/rust-values.mk b/lang/rust/rust-values.mk index a0fab6ae1..8f2017af6 100644 --- a/lang/rust/rust-values.mk +++ b/lang/rust/rust-values.mk @@ -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) diff --git a/net/netavark/Makefile b/net/netavark/Makefile index d6d976fc2..9d5c5f405 100644 --- a/net/netavark/Makefile +++ b/net/netavark/Makefile @@ -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 -- cgit From 29ca9797a66f7e4d2ae40d26b91f3d1c2982a744 Mon Sep 17 00:00:00 2001 From: Jeffery To Date: Sun, 8 Oct 2023 20:24:38 +0800 Subject: python-setuptools-rust: Set cargo profile from environment variable This adds a patch (submitted upstream in https://github.com/PyO3/setuptools-rust/pull/364), to read the profile to pass to cargo from an environment variable. This also updates the Python include files to set the environment variable based on values from rust-values.mk. Signed-off-by: Jeffery To --- lang/python/python-setuptools-rust/Makefile | 2 +- ...ETUPTOOLS_RUST_CARGO_PROFILE-env-variable.patch | 48 ++++++++++++++++++++++ lang/python/python3-host.mk | 3 +- lang/python/python3-package.mk | 3 +- 4 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 lang/python/python-setuptools-rust/patches/0001-Allow-profile-to-be-set-by-SETUPTOOLS_RUST_CARGO_PROFILE-env-variable.patch (limited to 'lang/python/python3-package.mk') diff --git a/lang/python/python-setuptools-rust/Makefile b/lang/python/python-setuptools-rust/Makefile index 19325c1fd..00a243bee 100644 --- a/lang/python/python-setuptools-rust/Makefile +++ b/lang/python/python-setuptools-rust/Makefile @@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=python-setuptools-rust PKG_VERSION:=1.7.0 -PKG_RELEASE:=1 +PKG_RELEASE:=2 PYPI_NAME:=setuptools-rust PKG_HASH:=c7100999948235a38ae7e555fe199aa66c253dc384b125f5d85473bf81eae3a3 diff --git a/lang/python/python-setuptools-rust/patches/0001-Allow-profile-to-be-set-by-SETUPTOOLS_RUST_CARGO_PROFILE-env-variable.patch b/lang/python/python-setuptools-rust/patches/0001-Allow-profile-to-be-set-by-SETUPTOOLS_RUST_CARGO_PROFILE-env-variable.patch new file mode 100644 index 000000000..842bc4019 --- /dev/null +++ b/lang/python/python-setuptools-rust/patches/0001-Allow-profile-to-be-set-by-SETUPTOOLS_RUST_CARGO_PROFILE-env-variable.patch @@ -0,0 +1,48 @@ +From b10cab4efeb80abb5a236d651c9ff9355e470527 Mon Sep 17 00:00:00 2001 +From: Jeffery To +Date: Mon, 2 Oct 2023 16:13:51 +0800 +Subject: [PATCH] Allow profile to be set by SETUPTOOLS_RUST_CARGO_PROFILE env + variable + +This allows the profile to be set dynamically, without having to edit +pyproject.toml/setup.py. +--- + setuptools_rust/build.py | 20 ++++++++++++++++---- + 1 file changed, 16 insertions(+), 4 deletions(-) + +--- a/setuptools_rust/build.py ++++ b/setuptools_rust/build.py +@@ -528,10 +528,10 @@ class build_rust(RustCommand): + if target_triple is not None: + args.extend(["--target", target_triple]) + +- if release: +- profile = ext.get_cargo_profile() +- if not profile: +- args.append("--release") ++ ext_profile = ext.get_cargo_profile() ++ env_profile = os.getenv("SETUPTOOLS_RUST_CARGO_PROFILE") ++ if release and not ext_profile and not env_profile: ++ args.append("--release") + + if quiet: + args.append("-q") +@@ -552,6 +552,18 @@ class build_rust(RustCommand): + if ext.args is not None: + args.extend(ext.args) + ++ if env_profile: ++ if ext_profile: ++ args = [p for p in args if not p.startswith("--profile=")] ++ while True: ++ try: ++ index = args.index("--profile") ++ del args[index:index + 2] ++ except ValueError: ++ break ++ ++ args.extend(["--profile", env_profile]) ++ + if ext.cargo_manifest_args is not None: + args.extend(ext.cargo_manifest_args) + diff --git a/lang/python/python3-host.mk b/lang/python/python3-host.mk index b233c5679..3cc20c2ce 100644 --- a/lang/python/python3-host.mk +++ b/lang/python/python3-host.mk @@ -78,7 +78,8 @@ 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_HOST_CONFIG_VARS) + $(CARGO_HOST_CONFIG_VARS) \ + SETUPTOOLS_RUST_CARGO_PROFILE="$(CARGO_HOST_PROFILE)" # $(1) => directory of python script # $(2) => python script and its arguments diff --git a/lang/python/python3-package.mk b/lang/python/python3-package.mk index e4c7bd264..3300f1bea 100644 --- a/lang/python/python3-package.mk +++ b/lang/python/python3-package.mk @@ -46,7 +46,8 @@ PYTHON3_VARS = \ _python_prefix="/usr" \ _python_exec_prefix="/usr" \ $(CARGO_PKG_CONFIG_VARS) \ - PYO3_CROSS_LIB_DIR="$(PYTHON3_LIB_DIR)" + PYO3_CROSS_LIB_DIR="$(PYTHON3_LIB_DIR)" \ + SETUPTOOLS_RUST_CARGO_PROFILE="$(CARGO_PKG_PROFILE)" # $(1) => directory of python script # $(2) => python script and its arguments -- cgit