@@ -305,6 +305,12 @@ impl CargoWorkspace {
305305 . collect ( ) ,
306306 ) ;
307307 }
308+ // The manifest is a rust file, so this means its a script manifest
309+ if cargo_toml. extension ( ) . is_some_and ( |ext| ext == "rs" ) {
310+ // Deliberately don't set up RUSTC_BOOTSTRAP or a nightly override here, the user should
311+ // opt into it themselves.
312+ other_options. push ( "-Zscript" . to_owned ( ) ) ;
313+ }
308314 meta. other_options ( other_options) ;
309315
310316 // FIXME: Fetching metadata is a slow process, as it might require
@@ -373,11 +379,12 @@ impl CargoWorkspace {
373379 let is_local = source. is_none ( ) ;
374380 let is_member = ws_members. contains ( & id) ;
375381
382+ let manifest = AbsPathBuf :: assert ( manifest_path) ;
376383 let pkg = packages. alloc ( PackageData {
377384 id : id. repr . clone ( ) ,
378385 name,
379386 version,
380- manifest : AbsPathBuf :: assert ( manifest_path ) . try_into ( ) . unwrap ( ) ,
387+ manifest : manifest . clone ( ) . try_into ( ) . unwrap ( ) ,
381388 targets : Vec :: new ( ) ,
382389 is_local,
383390 is_member,
@@ -400,11 +407,22 @@ impl CargoWorkspace {
400407 for meta_tgt in meta_targets {
401408 let cargo_metadata:: Target { name, kind, required_features, src_path, .. } =
402409 meta_tgt;
410+ let kind = TargetKind :: new ( & kind) ;
403411 let tgt = targets. alloc ( TargetData {
404412 package : pkg,
405413 name,
406- root : AbsPathBuf :: assert ( src_path) ,
407- kind : TargetKind :: new ( & kind) ,
414+ root : if kind == TargetKind :: Bin
415+ && manifest. extension ( ) . is_some_and ( |ext| ext == "rs" )
416+ {
417+ // cargo strips the script part of a cargo script away and places the
418+ // modified manifest file into a special target dir which is then used as
419+ // the source path. We don't want that, we want the original here so map it
420+ // back
421+ manifest. clone ( )
422+ } else {
423+ AbsPathBuf :: assert ( src_path)
424+ } ,
425+ kind,
408426 required_features,
409427 } ) ;
410428 pkg_data. targets . push ( tgt) ;
0 commit comments