File tree Expand file tree Collapse file tree 3 files changed +36
-2
lines changed Expand file tree Collapse file tree 3 files changed +36
-2
lines changed Original file line number Diff line number Diff line change 3
3
## Unreleased
4
4
### Added
5
5
- Add support for ` kebab-case ` executable names. [ #205 ] ( https://github.com/PyO3/setuptools-rust/pull/205 )
6
+ - Add support for custom cargo profiles. [ #216 ] ( https://github.com/PyO3/setuptools-rust/pull/216 )
6
7
7
8
## 1.1.2 (2021-12-05)
8
9
### Changed
Original file line number Diff line number Diff line change @@ -221,7 +221,18 @@ def build_extension(
221
221
# Find the shared library that cargo hopefully produced and copy
222
222
# it into the build directory as if it were produced by build_ext.
223
223
224
- artifacts_dir = os .path .join (target_dir , "debug" if debug else "release" )
224
+ profile = ext .get_cargo_profile ()
225
+ if profile :
226
+ # https://doc.rust-lang.org/cargo/reference/profiles.html
227
+ if profile in {"dev" , "test" }:
228
+ profile_dir = "debug"
229
+ elif profile == "bench" :
230
+ profile_dir = "release"
231
+ else :
232
+ profile_dir = profile
233
+ else :
234
+ profile_dir = "debug" if debug else "release"
235
+ artifacts_dir = os .path .join (target_dir , profile_dir )
225
236
dylib_paths = []
226
237
227
238
if ext ._uses_exec_binding ():
@@ -462,7 +473,9 @@ def _cargo_args(
462
473
args .extend (["--target" , target_triple ])
463
474
464
475
if release :
465
- args .append ("--release" )
476
+ profile = ext .get_cargo_profile ()
477
+ if not profile :
478
+ args .append ("--release" )
466
479
467
480
if quiet :
468
481
args .append ("-q" )
Original file line number Diff line number Diff line change @@ -170,6 +170,26 @@ def get_rust_version(self) -> Optional[SimpleSpec]: # type: ignore[no-any-unimp
170
170
"Can not parse rust compiler version: %s" , self .rust_version
171
171
)
172
172
173
+ def get_cargo_profile (self ) -> Optional [str ]:
174
+ args = self .args or []
175
+ try :
176
+ index = args .index ("--profile" )
177
+ return args [index + 1 ]
178
+ except ValueError :
179
+ pass
180
+ except IndexError :
181
+ raise DistutilsSetupError ("Can not parse cargo profile from %s" , args )
182
+
183
+ # Handle `--profile=<profile>`
184
+ profile_args = [p for p in args if p .startswith ("--profile=" )]
185
+ if profile_args :
186
+ profile = profile_args [0 ].split ("=" , 1 )[1 ]
187
+ if not profile :
188
+ raise DistutilsSetupError ("Can not parse cargo profile from %s" , args )
189
+ return profile
190
+ else :
191
+ return None
192
+
173
193
def entry_points (self ) -> List [str ]:
174
194
entry_points = []
175
195
if self .script and self .binding == Binding .Exec :
You can’t perform that action at this time.
0 commit comments