@@ -24,7 +24,7 @@ use toolchain::Tool;
2424
2525use crate :: {
2626 cfg:: CfgFlag , utf8_stdout, CargoConfig , CargoFeatures , CargoWorkspace , InvocationLocation ,
27- InvocationStrategy , Package , Sysroot , TargetKind ,
27+ InvocationStrategy , ManifestPath , Package , Sysroot , TargetKind ,
2828} ;
2929
3030/// Output of the build script and proc-macro building steps for a workspace.
@@ -63,7 +63,7 @@ impl WorkspaceBuildScripts {
6363 fn build_command (
6464 config : & CargoConfig ,
6565 allowed_features : & FxHashSet < String > ,
66- workspace_root : & AbsPathBuf ,
66+ manifest_path : & ManifestPath ,
6767 sysroot : Option < & Sysroot > ,
6868 ) -> io:: Result < Command > {
6969 let mut cmd = match config. run_build_script_command . as_deref ( ) {
@@ -79,7 +79,7 @@ impl WorkspaceBuildScripts {
7979 cmd. args ( & config. extra_args ) ;
8080
8181 cmd. arg ( "--manifest-path" ) ;
82- cmd. arg ( workspace_root . join ( "Cargo.toml" ) ) ;
82+ cmd. arg ( manifest_path . as_ref ( ) ) ;
8383
8484 if let Some ( target_dir) = & config. target_dir {
8585 cmd. arg ( "--target-dir" ) . arg ( target_dir) ;
@@ -116,6 +116,10 @@ impl WorkspaceBuildScripts {
116116 }
117117 }
118118
119+ if manifest_path. extension ( ) . map_or ( false , |ext| ext == "rs" ) {
120+ cmd. arg ( "-Zscript" ) ;
121+ }
122+
119123 cmd
120124 }
121125 } ;
@@ -152,37 +156,12 @@ impl WorkspaceBuildScripts {
152156 . as_ref ( ) ;
153157
154158 let allowed_features = workspace. workspace_features ( ) ;
155-
156- match Self :: run_per_ws (
157- Self :: build_command (
158- config,
159- & allowed_features,
160- & workspace. workspace_root ( ) . to_path_buf ( ) ,
161- sysroot,
162- ) ?,
163- workspace,
164- current_dir,
165- progress,
166- ) {
167- Ok ( WorkspaceBuildScripts { error : Some ( error) , .. } )
168- if toolchain. as_ref ( ) . map_or ( false , |it| * it >= RUST_1_75 ) =>
169- {
170- // building build scripts failed, attempt to build with --keep-going so
171- // that we potentially get more build data
172- let mut cmd = Self :: build_command (
173- config,
174- & allowed_features,
175- & workspace. workspace_root ( ) . to_path_buf ( ) ,
176- sysroot,
177- ) ?;
178-
179- cmd. args ( [ "--keep-going" ] ) ;
180- let mut res = Self :: run_per_ws ( cmd, workspace, current_dir, progress) ?;
181- res. error = Some ( error) ;
182- Ok ( res)
183- }
184- res => res,
159+ let mut cmd =
160+ Self :: build_command ( config, & allowed_features, workspace. manifest_path ( ) , sysroot) ?;
161+ if toolchain. as_ref ( ) . map_or ( false , |it| * it >= RUST_1_75 ) {
162+ cmd. args ( [ "--keep-going" ] ) ;
185163 }
164+ Self :: run_per_ws ( cmd, workspace, current_dir, progress)
186165 }
187166
188167 /// Runs the build scripts by invoking the configured command *once*.
@@ -204,7 +183,13 @@ impl WorkspaceBuildScripts {
204183 ) )
205184 }
206185 } ;
207- let cmd = Self :: build_command ( config, & Default :: default ( ) , workspace_root, None ) ?;
186+ let cmd = Self :: build_command (
187+ config,
188+ & Default :: default ( ) ,
189+ // This is not gonna be used anyways, so just construct a dummy here
190+ & ManifestPath :: try_from ( workspace_root. clone ( ) ) . unwrap ( ) ,
191+ None ,
192+ ) ?;
208193 // NB: Cargo.toml could have been modified between `cargo metadata` and
209194 // `cargo check`. We shouldn't assume that package ids we see here are
210195 // exactly those from `config`.
0 commit comments