842bc401928d604744ed4b58b73b6a1db76e3790
[openwrt-packages.git] /
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  
git clone https://git.99rst.org/PROJECT