@@ -17,6 +17,7 @@ mod diagnostics;
17
17
use diagnostics:: { Diagnostic , GeneratedError } ;
18
18
19
19
pub mod dir;
20
+ use dir:: INCLUDE_VERB ;
20
21
21
22
mod dependencies;
22
23
pub use dependencies:: Interface ;
@@ -630,49 +631,28 @@ impl CxxQtBuilder {
630
631
}
631
632
}
632
633
633
- fn symlink_directory ( target : impl AsRef < Path > , link : impl AsRef < Path > ) -> std:: io:: Result < ( ) > {
634
- #[ cfg( unix) ]
635
- let result = std:: os:: unix:: fs:: symlink ( target, link) ;
636
-
637
- #[ cfg( windows) ]
638
- let result = std:: os:: windows:: fs:: symlink_dir ( target, link) ;
639
-
640
- // TODO: If it's neither unix nor windows, we should probably just deep-copy the
641
- // dependency headers into our own include directory.
642
- #[ cfg( not( any( unix, windows) ) ) ]
643
- panic ! ( "Cxx-Qt-build: Unsupported platform! Only unix and windows are currently supported! Please file a bug report in the CXX-Qt repository." ) ;
644
-
645
- result
646
- }
647
-
648
634
// A dependency can specify which of its own include paths it wants to export.
649
- // Set up each of these exported include paths as symlinks in our own include directory.
635
+ // Set up each of these exported include paths as symlinks in our own include directory,
636
+ // or deep copy the files if the platform does not support symlinks.
650
637
fn include_dependency ( & mut self , dependency : & Dependency ) {
638
+ let header_root = dir:: header_root ( ) ;
639
+ let dependency_root = dependency. path . join ( "include" ) ;
651
640
for include_prefix in & dependency. manifest . exported_include_prefixes {
652
641
// setup include directory
653
- let target = dependency. path . join ( "include" ) . join ( include_prefix) ;
654
-
655
- let symlink = dir:: header_root ( ) . join ( include_prefix) ;
656
- if symlink. exists ( ) {
657
- // Two dependencies may be reexporting the same shared dependency, which will
658
- // result in conflicting symlinks.
659
- // Try detecting this by resolving the symlinks and checking whether this leads us
660
- // to the same paths. If so, it's the same include path for the same prefix, which
661
- // is fine.
662
- let symlink =
663
- std:: fs:: canonicalize ( symlink) . expect ( "Failed to canonicalize symlink!" ) ;
664
- let target =
665
- std:: fs:: canonicalize ( target) . expect ( "Failed to canonicalize symlink target!" ) ;
666
- if symlink != target {
642
+ let source = dependency_root. join ( include_prefix) ;
643
+ let dest = header_root. join ( include_prefix) ;
644
+
645
+ match dir:: symlink_or_copy_directory ( source, dest) {
646
+ Ok ( true ) => ( ) ,
647
+ Ok ( false ) => {
667
648
panic ! (
668
649
"Conflicting include_prefixes for {include_prefix}!\n Dependency {dep_name} conflicts with existing include path" ,
669
650
dep_name = dependency. manifest. name,
670
651
) ;
671
652
}
672
- } else {
673
- Self :: symlink_directory ( target, symlink) . unwrap_or_else ( |_| {
674
- panic ! ( "Could not create symlink for include_prefix {include_prefix}!" )
675
- } ) ;
653
+ Err ( e) => {
654
+ panic ! ( "Could not {INCLUDE_VERB} for include_prefix {include_prefix}: {e:?}" ) ;
655
+ }
676
656
}
677
657
}
678
658
}
@@ -1019,17 +999,18 @@ impl CxxQtBuilder {
1019
999
}
1020
1000
1021
1001
fn write_interface_include_dirs ( & self ) {
1022
- if let Some ( interface) = & self . public_interface {
1023
- for ( header_dir, symlink) in & interface. exported_include_directories {
1024
- Self :: symlink_directory ( header_dir, dir:: header_root ( ) . join ( symlink) )
1025
- . unwrap_or_else ( |_| {
1026
- panic ! (
1027
- "Failed to create symlink `{}` for export_include_directory: {}" ,
1028
- symlink,
1029
- header_dir. to_string_lossy( )
1030
- )
1031
- } ) ;
1032
- }
1002
+ let Some ( interface) = & self . public_interface else {
1003
+ return ;
1004
+ } ;
1005
+ let header_root = dir:: header_root ( ) ;
1006
+ for ( header_dir, dest) in & interface. exported_include_directories {
1007
+ let dest_dir = header_root. join ( dest) ;
1008
+ if let Err ( e) = dir:: symlink_or_copy_directory ( header_dir, dest_dir) {
1009
+ panic ! (
1010
+ "Failed to {INCLUDE_VERB} `{dest}` for export_include_directory `{dir_name}`: {e:?}" ,
1011
+ dir_name = header_dir. to_string_lossy( )
1012
+ )
1013
+ } ;
1033
1014
}
1034
1015
}
1035
1016
0 commit comments