File tree 7 files changed +68
-2
lines changed
rustc_error_messages/locales/en-US
src/test/ui/native-library-link-flags
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 =
165
165
metadata_missing_native_library =
166
166
could not find native static library `{ $libname } `, perhaps an -L flag is missing?
167
167
168
+ metadata_only_provide_library_name = only provide the library name `{ $suggested_name } `, not the full filename
169
+
168
170
metadata_failed_create_tempdir =
169
171
couldn't create a temp dir: { $err }
170
172
Original file line number Diff line number Diff line change @@ -372,7 +372,41 @@ pub struct FailedWriteError {
372
372
#[ derive( Diagnostic ) ]
373
373
#[ diag( metadata:: missing_native_library) ]
374
374
pub 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 ,
376
410
}
377
411
378
412
#[ derive( Diagnostic ) ]
Original file line number Diff line number Diff line change @@ -52,7 +52,7 @@ pub fn find_native_static_library(
52
52
}
53
53
}
54
54
55
- sess. emit_fatal ( MissingNativeLibrary { libname : name } ) ;
55
+ sess. emit_fatal ( MissingNativeLibrary :: new ( name, verbatim . unwrap_or ( false ) ) ) ;
56
56
}
57
57
58
58
fn 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