@@ -305,6 +305,12 @@ impl CargoWorkspace {
305
305
. collect ( ) ,
306
306
) ;
307
307
}
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
+ }
308
314
meta. other_options ( other_options) ;
309
315
310
316
// FIXME: Fetching metadata is a slow process, as it might require
@@ -373,11 +379,12 @@ impl CargoWorkspace {
373
379
let is_local = source. is_none ( ) ;
374
380
let is_member = ws_members. contains ( & id) ;
375
381
382
+ let manifest = AbsPathBuf :: assert ( manifest_path) ;
376
383
let pkg = packages. alloc ( PackageData {
377
384
id : id. repr . clone ( ) ,
378
385
name,
379
386
version,
380
- manifest : AbsPathBuf :: assert ( manifest_path ) . try_into ( ) . unwrap ( ) ,
387
+ manifest : manifest . clone ( ) . try_into ( ) . unwrap ( ) ,
381
388
targets : Vec :: new ( ) ,
382
389
is_local,
383
390
is_member,
@@ -400,11 +407,22 @@ impl CargoWorkspace {
400
407
for meta_tgt in meta_targets {
401
408
let cargo_metadata:: Target { name, kind, required_features, src_path, .. } =
402
409
meta_tgt;
410
+ let kind = TargetKind :: new ( & kind) ;
403
411
let tgt = targets. alloc ( TargetData {
404
412
package : pkg,
405
413
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,
408
426
required_features,
409
427
} ) ;
410
428
pkg_data. targets . push ( tgt) ;
0 commit comments