1
1
//! A collection of helpers to construct artifact names, such as names of dynamic or static
2
- //! librarys which are target-dependent.
3
-
4
- // FIXME(jieyouxu): convert these to return `PathBuf`s instead of strings!
2
+ //! libraries which are target-dependent.
5
3
4
+ use crate :: target;
6
5
use crate :: targets:: is_msvc;
7
6
8
7
/// Construct the static library name based on the target.
8
+ #[ track_caller]
9
9
#[ must_use]
10
10
pub fn static_lib_name ( name : & str ) -> String {
11
11
assert ! ( !name. contains( char :: is_whitespace) , "static library name cannot contain whitespace" ) ;
@@ -14,15 +14,34 @@ pub fn static_lib_name(name: &str) -> String {
14
14
}
15
15
16
16
/// Construct the dynamic library name based on the target.
17
+ #[ track_caller]
17
18
#[ must_use]
18
19
pub fn dynamic_lib_name ( name : & str ) -> String {
19
20
assert ! ( !name. contains( char :: is_whitespace) , "dynamic library name cannot contain whitespace" ) ;
20
21
21
- format ! ( "{}{name}.{}" , std:: env:: consts:: DLL_PREFIX , std:: env:: consts:: DLL_EXTENSION )
22
+ format ! ( "{}{name}.{}" , dynamic_lib_prefix( ) , dynamic_lib_extension( ) )
23
+ }
24
+
25
+ fn dynamic_lib_prefix ( ) -> & ' static str {
26
+ if target ( ) . contains ( "windows" ) { "" } else { "lib" }
22
27
}
23
28
24
- /// Construct the name of the import library for the dynamic library, exclusive to MSVC and
25
- /// accepted by link.exe.
29
+ /// Construct the dynamic library extension based on the target.
30
+ #[ must_use]
31
+ pub fn dynamic_lib_extension ( ) -> & ' static str {
32
+ let target = target ( ) ;
33
+
34
+ if target. contains ( "apple" ) {
35
+ "dylib"
36
+ } else if target. contains ( "windows" ) {
37
+ "dll"
38
+ } else {
39
+ "so"
40
+ }
41
+ }
42
+
43
+ /// Construct the name of the import library for the dynamic library, exclusive to MSVC and accepted
44
+ /// by link.exe.
26
45
#[ track_caller]
27
46
#[ must_use]
28
47
pub fn msvc_import_dynamic_lib_name ( name : & str ) -> String {
@@ -32,20 +51,28 @@ pub fn msvc_import_dynamic_lib_name(name: &str) -> String {
32
51
format ! ( "{name}.dll.lib" )
33
52
}
34
53
35
- /// Construct the dynamic library extension based on the target.
36
- #[ must_use]
37
- pub fn dynamic_lib_extension ( ) -> & ' static str {
38
- std:: env:: consts:: DLL_EXTENSION
39
- }
40
-
41
54
/// Construct the name of a rust library (rlib).
55
+ #[ track_caller]
42
56
#[ must_use]
43
57
pub fn rust_lib_name ( name : & str ) -> String {
44
58
format ! ( "lib{name}.rlib" )
45
59
}
46
60
47
61
/// Construct the binary (executable) name based on the target.
62
+ #[ track_caller]
48
63
#[ must_use]
49
64
pub fn bin_name ( name : & str ) -> String {
50
- format ! ( "{name}{}" , std:: env:: consts:: EXE_SUFFIX )
65
+ let target = target ( ) ;
66
+
67
+ if target. contains ( "windows" ) {
68
+ format ! ( "{name}.exe" )
69
+ } else if target. contains ( "uefi" ) {
70
+ format ! ( "{name}.efi" )
71
+ } else if target. contains ( "wasm" ) {
72
+ format ! ( "{name}.wasm" )
73
+ } else if target. contains ( "nvptx" ) {
74
+ format ! ( "{name}.ptx" )
75
+ } else {
76
+ name. to_string ( )
77
+ }
51
78
}
0 commit comments