Skip to content

Commit

Permalink
Allow cargo profile to be set by CARGO_PROFILE environment variable
Browse files Browse the repository at this point in the history
This allows the profile to be set dynamically, without having to edit
pyproject.toml/setup.py.
  • Loading branch information
jefferyto committed Oct 3, 2023
1 parent 67946fa commit 77a0d61
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions setuptools_rust/build.py
Expand Up @@ -517,10 +517,10 @@ def _cargo_args(
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("CARGO_PROFILE")
if release and not ext_profile and not env_profile:
args.append("--release")

if quiet:
args.append("-q")
Expand All @@ -541,6 +541,18 @@ def _cargo_args(
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)

Expand Down

0 comments on commit 77a0d61

Please sign in to comment.