@@ -250,7 +250,7 @@ struct ComponentLdArgs {
250
250
251
251
/// Where to place the component output.
252
252
#[ clap( short, long) ]
253
- output : Option < PathBuf > ,
253
+ output : PathBuf ,
254
254
255
255
/// Print verbose output.
256
256
#[ clap( long) ]
@@ -522,17 +522,29 @@ impl App {
522
522
let mut cmd = self . lld ( ) ;
523
523
let linker = cmd. get_program ( ) . to_owned ( ) ;
524
524
525
- let lld_output =
526
- tempfile:: NamedTempFile :: new ( ) . context ( "failed to create temp output file" ) ?;
525
+ // If a temporary output is needed make sure it has the same file name
526
+ // as the output of our command itself since LLD will embed this file
527
+ // name in the name section of the output.
528
+ let temp_dir = match self . component . output . parent ( ) {
529
+ Some ( parent) => tempfile:: TempDir :: new_in ( parent) ?,
530
+ None => tempfile:: TempDir :: new ( ) ?,
531
+ } ;
532
+ let temp_output = match self . component . output . file_name ( ) {
533
+ Some ( name) => temp_dir. path ( ) . join ( name) ,
534
+ None => bail ! (
535
+ "output of {:?} does not have a file name" ,
536
+ self . component. output
537
+ ) ,
538
+ } ;
527
539
528
540
// Shared libraries don't get wit-component run below so place the
529
541
// output directly at the desired output location. Otherwise output to a
530
542
// temporary location for wit-component to read and then the real output
531
543
// is created after wit-component runs.
532
544
if self . skip_wit_component ( ) {
533
- cmd. arg ( "-o" ) . arg ( self . component . output . as_ref ( ) . unwrap ( ) ) ;
545
+ cmd. arg ( "-o" ) . arg ( & self . component . output ) ;
534
546
} else {
535
- cmd. arg ( "-o" ) . arg ( lld_output . path ( ) ) ;
547
+ cmd. arg ( "-o" ) . arg ( & temp_output ) ;
536
548
}
537
549
538
550
if self . component . verbose {
@@ -555,8 +567,8 @@ impl App {
555
567
wasi_preview1_component_adapter_provider:: WASI_SNAPSHOT_PREVIEW1_COMMAND_ADAPTER ;
556
568
let proxy_adapter =
557
569
wasi_preview1_component_adapter_provider:: WASI_SNAPSHOT_PREVIEW1_PROXY_ADAPTER ;
558
- let mut core_module = std:: fs:: read ( lld_output . path ( ) )
559
- . with_context ( || format ! ( "failed to read {linker:?} output" ) ) ?;
570
+ let mut core_module = std:: fs:: read ( & temp_output )
571
+ . with_context ( || format ! ( "failed to read {linker:?} output: {temp_output:?} " ) ) ?;
560
572
561
573
// Inspect the output module to see if it's a command or reactor.
562
574
let mut exports_start = false ;
@@ -636,8 +648,10 @@ impl App {
636
648
637
649
let component = encoder. encode ( ) . context ( "failed to encode component" ) ?;
638
650
639
- std:: fs:: write ( self . component . output . as_ref ( ) . unwrap ( ) , & component)
640
- . context ( "failed to write output file" ) ?;
651
+ std:: fs:: write ( & self . component . output , & component) . context ( format ! (
652
+ "failed to write output file: {:?}" ,
653
+ self . component. output
654
+ ) ) ?;
641
655
642
656
Ok ( ( ) )
643
657
}
0 commit comments