Skip to content

Commit 615b97d

Browse files
jefferytograysky2
authored andcommitted
python-setuptools-rust: Set cargo profile from environment variable
This adds a patch (submitted upstream in PyO3/setuptools-rust#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>
1 parent 04d22db commit 615b97d

File tree

4 files changed

+53
-3
lines changed

4 files changed

+53
-3
lines changed

lang/python/python-setuptools-rust/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
99

1010
PKG_NAME:=python-setuptools-rust
1111
PKG_VERSION:=1.7.0
12-
PKG_RELEASE:=1
12+
PKG_RELEASE:=2
1313

1414
PYPI_NAME:=setuptools-rust
1515
PKG_HASH:=c7100999948235a38ae7e555fe199aa66c253dc384b125f5d85473bf81eae3a3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
From b10cab4efeb80abb5a236d651c9ff9355e470527 Mon Sep 17 00:00:00 2001
2+
From: Jeffery To <jeffery.to@gmail.com>
3+
Date: Mon, 2 Oct 2023 16:13:51 +0800
4+
Subject: [PATCH] Allow profile to be set by SETUPTOOLS_RUST_CARGO_PROFILE env
5+
variable
6+
7+
This allows the profile to be set dynamically, without having to edit
8+
pyproject.toml/setup.py.
9+
---
10+
setuptools_rust/build.py | 20 ++++++++++++++++----
11+
1 file changed, 16 insertions(+), 4 deletions(-)
12+
13+
--- a/setuptools_rust/build.py
14+
+++ b/setuptools_rust/build.py
15+
@@ -528,10 +528,10 @@ class build_rust(RustCommand):
16+
if target_triple is not None:
17+
args.extend(["--target", target_triple])
18+
19+
- if release:
20+
- profile = ext.get_cargo_profile()
21+
- if not profile:
22+
- args.append("--release")
23+
+ ext_profile = ext.get_cargo_profile()
24+
+ env_profile = os.getenv("SETUPTOOLS_RUST_CARGO_PROFILE")
25+
+ if release and not ext_profile and not env_profile:
26+
+ args.append("--release")
27+
28+
if quiet:
29+
args.append("-q")
30+
@@ -552,6 +552,18 @@ class build_rust(RustCommand):
31+
if ext.args is not None:
32+
args.extend(ext.args)
33+
34+
+ if env_profile:
35+
+ if ext_profile:
36+
+ args = [p for p in args if not p.startswith("--profile=")]
37+
+ while True:
38+
+ try:
39+
+ index = args.index("--profile")
40+
+ del args[index:index + 2]
41+
+ except ValueError:
42+
+ break
43+
+
44+
+ args.extend(["--profile", env_profile])
45+
+
46+
if ext.cargo_manifest_args is not None:
47+
args.extend(ext.cargo_manifest_args)
48+

lang/python/python3-host.mk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ HOST_PYTHON3_VARS = \
7878
CFLAGS="$(HOST_CFLAGS)" \
7979
CPPFLAGS="$(HOST_CPPFLAGS) -I$(HOST_PYTHON3_INC_DIR)" \
8080
LDFLAGS="$(HOST_LDFLAGS) -lpython$(PYTHON3_VERSION) -Wl$(comma)-rpath$(comma)$(STAGING_DIR_HOSTPKG)/lib" \
81-
$(CARGO_HOST_CONFIG_VARS)
81+
$(CARGO_HOST_CONFIG_VARS) \
82+
SETUPTOOLS_RUST_CARGO_PROFILE="$(CARGO_HOST_PROFILE)"
8283

8384
# $(1) => directory of python script
8485
# $(2) => python script and its arguments

lang/python/python3-package.mk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ PYTHON3_VARS = \
4646
_python_prefix="/usr" \
4747
_python_exec_prefix="/usr" \
4848
$(CARGO_PKG_CONFIG_VARS) \
49-
PYO3_CROSS_LIB_DIR="$(PYTHON3_LIB_DIR)"
49+
PYO3_CROSS_LIB_DIR="$(PYTHON3_LIB_DIR)" \
50+
SETUPTOOLS_RUST_CARGO_PROFILE="$(CARGO_PKG_PROFILE)"
5051

5152
# $(1) => directory of python script
5253
# $(2) => python script and its arguments

0 commit comments

Comments
 (0)