@@ -94,14 +94,31 @@ pub fn source_root() -> PathBuf {
94
94
}
95
95
96
96
/// Creates a new symlink to a path on the filesystem, adjusting for Windows or Unix.
97
+ #[ cfg( target_family = "windows" ) ]
97
98
pub 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 ( ) ;
104
115
}
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
+ ) ) ;
105
122
}
106
123
107
124
/// Construct the static library name based on the platform.
@@ -125,11 +142,7 @@ pub fn static_lib_name(name: &str) -> String {
125
142
// ```
126
143
assert ! ( !name. contains( char :: is_whitespace) , "static library name cannot contain whitespace" ) ;
127
144
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" ) }
133
146
}
134
147
135
148
/// Construct the dynamic library name based on the platform.
@@ -176,11 +189,7 @@ pub fn rust_lib_name(name: &str) -> String {
176
189
177
190
/// Construct the binary name based on platform.
178
191
pub 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 ( ) }
184
193
}
185
194
186
195
/// Return the current working directory.
0 commit comments