aboutsummaryrefslogtreecommitdiff
path: root/lang/python
diff options
context:
space:
mode:
authorJeffery To <jeffery.to@gmail.com>2023-10-08 20:24:38 +0800
committerJeffery To <jeffery.to@gmail.com>2023-10-11 15:50:24 +0800
commit29ca9797a66f7e4d2ae40d26b91f3d1c2982a744 (patch)
treeefcd6638efde591c3656720f9fc35af8f8d66490 /lang/python
parent8bf2725f9be82eec0849cc5efe77bedeb0a693a0 (diff)
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 <jeffery.to@gmail.com>
Diffstat (limited to 'lang/python')
-rw-r--r--lang/python/python-setuptools-rust/Makefile2
-rw-r--r--lang/python/python-setuptools-rust/patches/0001-Allow-profile-to-be-set-by-SETUPTOOLS_RUST_CARGO_PROFILE-env-variable.patch48
-rw-r--r--lang/python/python3-host.mk3
-rw-r--r--lang/python/python3-package.mk3
4 files changed, 53 insertions, 3 deletions
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 <jeffery.to@gmail.com>
+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