11//! A collection of helpers to construct artifact names, such as names of dynamic or static
22//! librarys which are target-dependent.
33
4- use crate :: targets:: { is_darwin, is_msvc, is_windows} ;
4+ // FIXME(jieyouxu): convert these to return `PathBuf`s instead of strings!
5+
6+ use crate :: targets:: is_msvc;
57
68/// Construct the static library name based on the target.
79#[ must_use]
@@ -31,41 +33,15 @@ pub fn static_lib_name(name: &str) -> String {
3133/// Construct the dynamic library name based on the target.
3234#[ must_use]
3335pub fn dynamic_lib_name ( name : & str ) -> String {
34- // See tools.mk (irrelevant lines omitted):
35- //
36- // ```makefile
37- // ifeq ($(UNAME),Darwin)
38- // DYLIB = $(TMPDIR)/lib$(1).dylib
39- // else
40- // ifdef IS_WINDOWS
41- // DYLIB = $(TMPDIR)/$(1).dll
42- // else
43- // DYLIB = $(TMPDIR)/lib$(1).so
44- // endif
45- // endif
46- // ```
4736 assert ! ( !name. contains( char :: is_whitespace) , "dynamic library name cannot contain whitespace" ) ;
4837
49- let extension = dynamic_lib_extension ( ) ;
50- if is_darwin ( ) {
51- format ! ( "lib{name}.{extension}" )
52- } else if is_windows ( ) {
53- format ! ( "{name}.{extension}" )
54- } else {
55- format ! ( "lib{name}.{extension}" )
56- }
38+ format ! ( "{}{name}.{}" , std:: env:: consts:: DLL_PREFIX , std:: env:: consts:: DLL_EXTENSION )
5739}
5840
5941/// Construct the dynamic library extension based on the target.
6042#[ must_use]
6143pub fn dynamic_lib_extension ( ) -> & ' static str {
62- if is_darwin ( ) {
63- "dylib"
64- } else if is_windows ( ) {
65- "dll"
66- } else {
67- "so"
68- }
44+ std:: env:: consts:: DLL_EXTENSION
6945}
7046
7147/// Construct the name of a rust library (rlib).
@@ -77,5 +53,5 @@ pub fn rust_lib_name(name: &str) -> String {
7753/// Construct the binary (executable) name based on the target.
7854#[ must_use]
7955pub fn bin_name ( name : & str ) -> String {
80- if is_windows ( ) { format ! ( "{name}.exe" ) } else { name . to_string ( ) }
56+ format ! ( "{name}{}" , std :: env :: consts :: EXE_SUFFIX )
8157}
0 commit comments