@@ -155,10 +155,15 @@ def vendor_rust(
155155 return False
156156
157157 backend = _detect_rust_build_backend (req , pyproject_toml )
158+ rust_root_dir = project_dir
159+ root_cargo_toml = project_dir / "Cargo.toml"
160+ rust_cargo_toml = project_dir / "rust" / "Cargo.toml"
158161 manifests : list [pathlib .Path ] = []
159162 # By default, maturin and setuptools-rust use Cargo.toml from project
160163 # root directory. Projects can specify a different file in optional
161- # "tool.setuptools-rust" or "tool.maturin" entries.
164+ # "tool.setuptools-rust" or "tool.maturin" entries. Maturin also supports
165+ # an alternate src layout with "rust/Cargo.toml" and "rust/.cargo"
166+ # directory, https://www.maturin.rs/project_layout.html#alternate-python-source-directory-src-layout
162167 match backend :
163168 case RustBuildSystem .maturin :
164169 try :
@@ -168,6 +173,13 @@ def vendor_rust(
168173 else :
169174 if "manifest-path" in tool_maturin :
170175 manifests .append (project_dir / tool_maturin ["manifest-path" ])
176+ elif not root_cargo_toml .is_file () and rust_cargo_toml .is_file ():
177+ manifests .append (rust_cargo_toml )
178+ rust_root_dir = rust_cargo_toml .parent .resolve ()
179+ logger .info (
180+ "Use maturin's alternative src layout and alt rust root dir %s" ,
181+ rust_root_dir ,
182+ )
171183 case RustBuildSystem .setuptools_rust :
172184 ext_modules : list [dict [str , typing .Any ]]
173185 try :
@@ -186,7 +198,6 @@ def vendor_rust(
186198
187199 if not manifests :
188200 # check for Cargo.toml in project root
189- root_cargo_toml = project_dir / "Cargo.toml"
190201 if root_cargo_toml .is_file ():
191202 manifests .append (root_cargo_toml )
192203 else :
@@ -199,7 +210,7 @@ def vendor_rust(
199210 logger .debug (f"{ project_dir } has cargo manifests: { the_manifests } " )
200211
201212 vendor_generic_rust_package (
202- req , manifests , project_dir , shrink_vendored = shrink_vendored
213+ req , manifests , rust_root_dir , shrink_vendored = shrink_vendored
203214 )
204215
205216 return True
0 commit comments