File tree Expand file tree Collapse file tree 2 files changed +25
-2
lines changed
Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -221,7 +221,18 @@ def build_extension(
221221 # Find the shared library that cargo hopefully produced and copy
222222 # it into the build directory as if it were produced by build_ext.
223223
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 )
225236 dylib_paths = []
226237
227238 if ext ._uses_exec_binding ():
@@ -462,7 +473,9 @@ def _cargo_args(
462473 args .extend (["--target" , target_triple ])
463474
464475 if release :
465- args .append ("--release" )
476+ profile = ext .get_cargo_profile ()
477+ if not profile :
478+ args .append ("--release" )
466479
467480 if quiet :
468481 args .append ("-q" )
Original file line number Diff line number Diff line change @@ -170,6 +170,16 @@ def get_rust_version(self) -> Optional[SimpleSpec]: # type: ignore[no-any-unimp
170170 "Can not parse rust compiler version: %s" , self .rust_version
171171 )
172172
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+ return None
180+ except IndexError :
181+ raise DistutilsSetupError ("Can not parse cargo profile from %s" , args )
182+
173183 def entry_points (self ) -> List [str ]:
174184 entry_points = []
175185 if self .script and self .binding == Binding .Exec :
You can’t perform that action at this time.
0 commit comments