@@ -201,10 +201,10 @@ fn main() {
201201 cmd. args ( & components) ;
202202
203203 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
208208 } else if Path :: new ( lib) . exists ( ) {
209209 // On MSVC llvm-config will print the full name to libraries, but
210210 // we're only interested in the name part
@@ -241,17 +241,17 @@ fn main() {
241241 cmd. arg ( llvm_link_arg) . arg ( "--ldflags" ) ;
242242 for lib in output ( & mut cmd) . split_whitespace ( ) {
243243 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) ) ;
248248 }
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 ) ;
255255 }
256256 }
257257
@@ -262,10 +262,10 @@ fn main() {
262262 let llvm_linker_flags = tracked_env_var_os ( "LLVM_LINKER_FLAGS" ) ;
263263 if let Some ( s) = llvm_linker_flags {
264264 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 ) ;
269269 }
270270 }
271271 }
0 commit comments