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
7 This allows the profile to be set dynamically, without having to edit
8 pyproject.toml/setup.py.
10 setuptools_rust/build.py | 20 ++++++++++++++++----
11 1 file changed, 16 insertions(+), 4 deletions(-)
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])
20 - profile = ext.get_cargo_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")
30 @@ -552,6 +552,18 @@ class build_rust(RustCommand):
31 if ext.args is not None:
36 + args = [p for p in args if not p.startswith("--profile=")]
39 + index = args.index("--profile")
40 + del args[index:index + 2]
44 + args.extend(["--profile", env_profile])
46 if ext.cargo_manifest_args is not None:
47 args.extend(ext.cargo_manifest_args)