@@ -201,10 +201,10 @@ fn main() {
201
201
cmd. args ( & components) ;
202
202
203
203
for lib in output ( & mut cmd) . split_whitespace ( ) {
204
- let name = if lib. starts_with ( "-l" ) {
205
- & lib [ 2 .. ]
206
- } else if lib. starts_with ( '-' ) {
207
- & lib [ 1 .. ]
204
+ let name = if let Some ( stripped ) = lib. strip_prefix ( "-l" ) {
205
+ stripped
206
+ } else if let Some ( stripped ) = lib. strip_prefix ( '-' ) {
207
+ stripped
208
208
} else if Path :: new ( lib) . exists ( ) {
209
209
// On MSVC llvm-config will print the full name to libraries, but
210
210
// we're only interested in the name part
@@ -241,17 +241,17 @@ fn main() {
241
241
cmd. arg ( llvm_link_arg) . arg ( "--ldflags" ) ;
242
242
for lib in output ( & mut cmd) . split_whitespace ( ) {
243
243
if is_crossed {
244
- if lib. starts_with ( "-LIBPATH:" ) {
245
- println ! ( "cargo:rustc-link-search=native={}" , lib [ 9 .. ] . replace( & host, & target) ) ;
246
- } else if lib. starts_with ( "-L" ) {
247
- println ! ( "cargo:rustc-link-search=native={}" , lib [ 2 .. ] . replace( & host, & target) ) ;
244
+ if let Some ( stripped ) = lib. strip_prefix ( "-LIBPATH:" ) {
245
+ println ! ( "cargo:rustc-link-search=native={}" , stripped . replace( & host, & target) ) ;
246
+ } else if let Some ( stripped ) = lib. strip_prefix ( "-L" ) {
247
+ println ! ( "cargo:rustc-link-search=native={}" , stripped . replace( & host, & target) ) ;
248
248
}
249
- } else if lib. starts_with ( "-LIBPATH:" ) {
250
- println ! ( "cargo:rustc-link-search=native={}" , & lib [ 9 .. ] ) ;
251
- } else if lib. starts_with ( "-l" ) {
252
- println ! ( "cargo:rustc-link-lib={}" , & lib [ 2 .. ] ) ;
253
- } else if lib. starts_with ( "-L" ) {
254
- println ! ( "cargo:rustc-link-search=native={}" , & lib [ 2 .. ] ) ;
249
+ } else if let Some ( stripped ) = lib. strip_prefix ( "-LIBPATH:" ) {
250
+ println ! ( "cargo:rustc-link-search=native={}" , stripped ) ;
251
+ } else if let Some ( stripped ) = lib. strip_prefix ( "-l" ) {
252
+ println ! ( "cargo:rustc-link-lib={}" , stripped ) ;
253
+ } else if let Some ( stripped ) = lib. strip_prefix ( "-L" ) {
254
+ println ! ( "cargo:rustc-link-search=native={}" , stripped ) ;
255
255
}
256
256
}
257
257
@@ -262,10 +262,10 @@ fn main() {
262
262
let llvm_linker_flags = tracked_env_var_os ( "LLVM_LINKER_FLAGS" ) ;
263
263
if let Some ( s) = llvm_linker_flags {
264
264
for lib in s. into_string ( ) . unwrap ( ) . split_whitespace ( ) {
265
- if lib. starts_with ( "-l" ) {
266
- println ! ( "cargo:rustc-link-lib={}" , & lib [ 2 .. ] ) ;
267
- } else if lib. starts_with ( "-L" ) {
268
- println ! ( "cargo:rustc-link-search=native={}" , & lib [ 2 .. ] ) ;
265
+ if let Some ( stripped ) = lib. strip_prefix ( "-l" ) {
266
+ println ! ( "cargo:rustc-link-lib={}" , stripped ) ;
267
+ } else if let Some ( stripped ) = lib. strip_prefix ( "-L" ) {
268
+ println ! ( "cargo:rustc-link-search=native={}" , stripped ) ;
269
269
}
270
270
}
271
271
}
0 commit comments