Skip to content

Commit a6e82c2

Browse files
authored
Merge pull request #364 from jefferyto/cargo-profile-env-var
Allow profile to be set by SETUPTOOLS_RUST_CARGO_PROFILE env variable
2 parents c9dcdbf + 8489360 commit a6e82c2

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
- Drop support for Python 3.7. [#357](https://github.com/PyO3/setuptools-rust/pull/357)
66
- Remove direct imports from `pkg_resources`. [#359](https://github.com/PyO3/setuptools-rust/pull/359)
77

8+
### Added
9+
- Add support for setting a custom cargo profile with the `SETUPTOOLS_RUST_CARGO_PROFILE` environment variable. [#364](https://github.com/PyO3/setuptools-rust/pull/364)
10+
811
## 1.7.0 (2023-08-22)
912
### Packaging
1013
- Remove direct imports from `distutils`. [#336](https://github.com/PyO3/setuptools-rust/pull/336)

setuptools_rust/build.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -517,10 +517,10 @@ def _cargo_args(
517517
if target_triple is not None:
518518
args.extend(["--target", target_triple])
519519

520-
if release:
521-
profile = ext.get_cargo_profile()
522-
if not profile:
523-
args.append("--release")
520+
ext_profile = ext.get_cargo_profile()
521+
env_profile = os.getenv("SETUPTOOLS_RUST_CARGO_PROFILE")
522+
if release and not ext_profile and not env_profile:
523+
args.append("--release")
524524

525525
if quiet:
526526
args.append("-q")
@@ -541,6 +541,18 @@ def _cargo_args(
541541
if ext.args is not None:
542542
args.extend(ext.args)
543543

544+
if env_profile:
545+
if ext_profile:
546+
args = [p for p in args if not p.startswith("--profile=")]
547+
while True:
548+
try:
549+
index = args.index("--profile")
550+
del args[index : index + 2]
551+
except ValueError:
552+
break
553+
554+
args.extend(["--profile", env_profile])
555+
544556
if ext.cargo_manifest_args is not None:
545557
args.extend(ext.cargo_manifest_args)
546558

0 commit comments

Comments
 (0)