@@ -94,14 +94,31 @@ pub fn source_root() -> PathBuf {
9494}
9595
9696/// Creates a new symlink to a path on the filesystem, adjusting for Windows or Unix.
97+ #[ cfg( target_family = "windows" ) ]
9798pub fn create_symlink < P : AsRef < Path > , Q : AsRef < Path > > ( original : P , link : Q ) {
98- if is_windows ( ) {
99- use std:: os:: windows:: fs;
100- fs:: symlink_file ( original, link) . unwrap ( ) ;
101- } else {
102- use std:: os:: unix:: fs;
103- fs:: symlink ( original, link) . unwrap ( ) ;
99+ if link. as_ref ( ) . exists ( ) {
100+ std:: fs:: remove_dir ( link. as_ref ( ) ) . unwrap ( ) ;
101+ }
102+ use std:: os:: windows:: fs;
103+ fs:: symlink_file ( original. as_ref ( ) , link. as_ref ( ) ) . expect ( & format ! (
104+ "failed to create symlink {:?} for {:?}" ,
105+ link. as_ref( ) . display( ) ,
106+ original. as_ref( ) . display( ) ,
107+ ) ) ;
108+ }
109+
110+ /// Creates a new symlink to a path on the filesystem, adjusting for Windows or Unix.
111+ #[ cfg( target_family = "unix" ) ]
112+ pub fn create_symlink < P : AsRef < Path > , Q : AsRef < Path > > ( original : P , link : Q ) {
113+ if link. as_ref ( ) . exists ( ) {
114+ std:: fs:: remove_dir ( link. as_ref ( ) ) . unwrap ( ) ;
104115 }
116+ use std:: os:: unix:: fs;
117+ fs:: symlink ( original. as_ref ( ) , link. as_ref ( ) ) . expect ( & format ! (
118+ "failed to create symlink {:?} for {:?}" ,
119+ link. as_ref( ) . display( ) ,
120+ original. as_ref( ) . display( ) ,
121+ ) ) ;
105122}
106123
107124/// Construct the static library name based on the platform.
@@ -125,11 +142,7 @@ pub fn static_lib_name(name: &str) -> String {
125142 // ```
126143 assert ! ( !name. contains( char :: is_whitespace) , "static library name cannot contain whitespace" ) ;
127144
128- if is_msvc ( ) {
129- format ! ( "{name}.lib" )
130- } else {
131- format ! ( "lib{name}.a" )
132- }
145+ if is_msvc ( ) { format ! ( "{name}.lib" ) } else { format ! ( "lib{name}.a" ) }
133146}
134147
135148/// Construct the dynamic library name based on the platform.
@@ -176,11 +189,7 @@ pub fn rust_lib_name(name: &str) -> String {
176189
177190/// Construct the binary name based on platform.
178191pub fn bin_name ( name : & str ) -> String {
179- if is_windows ( ) {
180- format ! ( "{name}.exe" )
181- } else {
182- name. to_string ( )
183- }
192+ if is_windows ( ) { format ! ( "{name}.exe" ) } else { name. to_string ( ) }
184193}
185194
186195/// Return the current working directory.
0 commit comments