run_make_support/artifact_names.rs
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!
5
6use crate::targets::is_msvc;
7
8/// Construct the static library name based on the target.
9#[must_use]
10pub fn static_lib_name(name: &str) -> String {
11 assert!(!name.contains(char::is_whitespace), "static library name cannot contain whitespace");
12
13 if is_msvc() { format!("{name}.lib") } else { format!("lib{name}.a") }
14}
15
16/// Construct the dynamic library name based on the target.
17#[must_use]
18pub fn dynamic_lib_name(name: &str) -> String {
19 assert!(!name.contains(char::is_whitespace), "dynamic library name cannot contain whitespace");
20
21 format!("{}{name}.{}", std::env::consts::DLL_PREFIX, std::env::consts::DLL_EXTENSION)
22}
23
24/// Construct the name of the import library for the dynamic library, exclusive to MSVC and
25/// accepted by link.exe.
26#[track_caller]
27#[must_use]
28pub fn msvc_import_dynamic_lib_name(name: &str) -> String {
29 assert!(is_msvc(), "this function is exclusive to MSVC");
30 assert!(!name.contains(char::is_whitespace), "import library name cannot contain whitespace");
31
32 format!("{name}.dll.lib")
33}
34
35/// Construct the dynamic library extension based on the target.
36#[must_use]
37pub fn dynamic_lib_extension() -> &'static str {
38 std::env::consts::DLL_EXTENSION
39}
40
41/// Construct the name of a rust library (rlib).
42#[must_use]
43pub fn rust_lib_name(name: &str) -> String {
44 format!("lib{name}.rlib")
45}
46
47/// Construct the binary (executable) name based on the target.
48#[must_use]
49pub fn bin_name(name: &str) -> String {
50 format!("{name}{}", std::env::consts::EXE_SUFFIX)
51}