File tree Expand file tree Collapse file tree 7 files changed +68
-2
lines changed
rustc_error_messages/locales/en-US
src/test/ui/native-library-link-flags Expand file tree Collapse file tree 7 files changed +68
-2
lines changed Original file line number Diff line number Diff line change @@ -165,6 +165,8 @@ metadata_failed_write_error =
165165metadata_missing_native_library =
166166 could not find native static library `{ $libname } `, perhaps an -L flag is missing?
167167
168+ metadata_only_provide_library_name = only provide the library name `{ $suggested_name } `, not the full filename
169+
168170metadata_failed_create_tempdir =
169171 couldn't create a temp dir: { $err }
170172
Original file line number Diff line number Diff line change @@ -372,7 +372,41 @@ pub struct FailedWriteError {
372372#[ derive( Diagnostic ) ]
373373#[ diag( metadata:: missing_native_library) ]
374374pub struct MissingNativeLibrary < ' a > {
375- pub libname : & ' a str ,
375+ libname : & ' a str ,
376+ #[ subdiagnostic]
377+ suggest_name : Option < SuggestLibraryName < ' a > > ,
378+ }
379+
380+ impl < ' a > MissingNativeLibrary < ' a > {
381+ pub fn new ( libname : & ' a str , verbatim : bool ) -> Self {
382+ // if it looks like the user has provided a complete filename rather just the bare lib name,
383+ // then provide a note that they might want to try trimming the name
384+ let suggested_name = if !verbatim {
385+ if let Some ( libname) = libname. strip_prefix ( "lib" ) && let Some ( libname) = libname. strip_suffix ( ".a" ) {
386+ // this is a unix style filename so trim prefix & suffix
387+ Some ( libname)
388+ } else if let Some ( libname) = libname. strip_suffix ( ".lib" ) {
389+ // this is a Windows style filename so just trim the suffix
390+ Some ( libname)
391+ } else {
392+ None
393+ }
394+ } else {
395+ None
396+ } ;
397+
398+ Self {
399+ libname,
400+ suggest_name : suggested_name
401+ . map ( |suggested_name| SuggestLibraryName { suggested_name } ) ,
402+ }
403+ }
404+ }
405+
406+ #[ derive( Subdiagnostic ) ]
407+ #[ help( metadata:: only_provide_library_name) ]
408+ pub struct SuggestLibraryName < ' a > {
409+ suggested_name : & ' a str ,
376410}
377411
378412#[ derive( Diagnostic ) ]
Original file line number Diff line number Diff line change @@ -52,7 +52,7 @@ pub fn find_native_static_library(
5252 }
5353 }
5454
55- sess. emit_fatal ( MissingNativeLibrary { libname : name } ) ;
55+ sess. emit_fatal ( MissingNativeLibrary :: new ( name, verbatim . unwrap_or ( false ) ) ) ;
5656}
5757
5858fn find_bundled_library (
Original file line number Diff line number Diff line change 1+ // build-fail
2+ // compile-flags: --crate-type rlib
3+ // error-pattern: could not find native static library `libfoo.a`
4+ // error-pattern: only provide the library name `foo`, not the full filename
5+
6+ #[ link( name = "libfoo.a" , kind = "static" ) ]
7+ extern { }
8+
9+ pub fn main ( ) { }
Original file line number Diff line number Diff line change 1+ error: could not find native static library `libfoo.a`, perhaps an -L flag is missing?
2+ |
3+ = help: only provide the library name `foo`, not the full filename
4+
5+ error: aborting due to previous error
6+
Original file line number Diff line number Diff line change 1+ // build-fail
2+ // compile-flags: --crate-type rlib
3+ // error-pattern: could not find native static library `bar.lib`
4+ // error-pattern: only provide the library name `bar`, not the full filename
5+
6+ #[ link( name = "bar.lib" , kind = "static" ) ]
7+ extern { }
8+
9+ pub fn main ( ) { }
Original file line number Diff line number Diff line change 1+ error: could not find native static library `bar.lib`, perhaps an -L flag is missing?
2+ |
3+ = help: only provide the library name `bar`, not the full filename
4+
5+ error: aborting due to previous error
6+
You can’t perform that action at this time.
0 commit comments