Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit e1af0b8

Browse files
committed
run_make_support: move artifact name helpers into artifact_names module
1 parent 7c70651 commit e1af0b8

File tree

2 files changed

+87
-76
lines changed

2 files changed

+87
-76
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
//! A collection of helpers to construct artifact names, such as names of dynamic or static
2+
//! librarys which are target-dependent.
3+
4+
use crate::targets::{is_darwin, is_msvc, is_windows};
5+
6+
/// Construct the static library name based on the target.
7+
#[must_use]
8+
pub fn static_lib_name(name: &str) -> String {
9+
// See tools.mk (irrelevant lines omitted):
10+
//
11+
// ```makefile
12+
// ifeq ($(UNAME),Darwin)
13+
// STATICLIB = $(TMPDIR)/lib$(1).a
14+
// else
15+
// ifdef IS_WINDOWS
16+
// ifdef IS_MSVC
17+
// STATICLIB = $(TMPDIR)/$(1).lib
18+
// else
19+
// STATICLIB = $(TMPDIR)/lib$(1).a
20+
// endif
21+
// else
22+
// STATICLIB = $(TMPDIR)/lib$(1).a
23+
// endif
24+
// endif
25+
// ```
26+
assert!(!name.contains(char::is_whitespace), "static library name cannot contain whitespace");
27+
28+
if is_msvc() { format!("{name}.lib") } else { format!("lib{name}.a") }
29+
}
30+
31+
/// Construct the dynamic library name based on the target.
32+
#[must_use]
33+
pub 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+
// ```
47+
assert!(!name.contains(char::is_whitespace), "dynamic library name cannot contain whitespace");
48+
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+
}
57+
}
58+
59+
/// Construct the dynamic library extension based on the target.
60+
#[must_use]
61+
pub fn dynamic_lib_extension() -> &'static str {
62+
if is_darwin() {
63+
"dylib"
64+
} else if is_windows() {
65+
"dll"
66+
} else {
67+
"so"
68+
}
69+
}
70+
71+
/// Construct the name of a rust library (rlib).
72+
#[must_use]
73+
pub fn rust_lib_name(name: &str) -> String {
74+
format!("lib{name}.rlib")
75+
}
76+
77+
/// Construct the binary (executable) name based on the target.
78+
#[must_use]
79+
pub fn bin_name(name: &str) -> String {
80+
if is_windows() { format!("{name}.exe") } else { name.to_string() }
81+
}

src/tools/run-make-support/src/lib.rs

Lines changed: 6 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ mod command;
77
mod macros;
88

99
pub mod ar;
10+
pub mod artifact_names;
1011
pub mod diff;
1112
pub mod env_checked;
1213
pub mod external_deps;
@@ -61,6 +62,11 @@ pub use run::{cmd, run, run_fail, run_with_args};
6162
/// Helpers for checking target information.
6263
pub use targets::{is_darwin, is_msvc, is_windows, target, uname};
6364

65+
/// Helpers for building names of output artifacts that are potentially target-specific.
66+
pub use artifact_names::{
67+
bin_name, dynamic_lib_extension, dynamic_lib_name, rust_lib_name, static_lib_name,
68+
};
69+
6470
use command::{Command, CompletedProcess};
6571

6672
/// Returns the path for a local test file.
@@ -102,82 +108,6 @@ pub fn create_symlink<P: AsRef<Path>, Q: AsRef<Path>>(original: P, link: Q) {
102108
));
103109
}
104110

105-
/// Construct the static library name based on the platform.
106-
#[must_use]
107-
pub fn static_lib_name(name: &str) -> String {
108-
// See tools.mk (irrelevant lines omitted):
109-
//
110-
// ```makefile
111-
// ifeq ($(UNAME),Darwin)
112-
// STATICLIB = $(TMPDIR)/lib$(1).a
113-
// else
114-
// ifdef IS_WINDOWS
115-
// ifdef IS_MSVC
116-
// STATICLIB = $(TMPDIR)/$(1).lib
117-
// else
118-
// STATICLIB = $(TMPDIR)/lib$(1).a
119-
// endif
120-
// else
121-
// STATICLIB = $(TMPDIR)/lib$(1).a
122-
// endif
123-
// endif
124-
// ```
125-
assert!(!name.contains(char::is_whitespace), "static library name cannot contain whitespace");
126-
127-
if is_msvc() { format!("{name}.lib") } else { format!("lib{name}.a") }
128-
}
129-
130-
/// Construct the dynamic library name based on the platform.
131-
#[must_use]
132-
pub fn dynamic_lib_name(name: &str) -> String {
133-
// See tools.mk (irrelevant lines omitted):
134-
//
135-
// ```makefile
136-
// ifeq ($(UNAME),Darwin)
137-
// DYLIB = $(TMPDIR)/lib$(1).dylib
138-
// else
139-
// ifdef IS_WINDOWS
140-
// DYLIB = $(TMPDIR)/$(1).dll
141-
// else
142-
// DYLIB = $(TMPDIR)/lib$(1).so
143-
// endif
144-
// endif
145-
// ```
146-
assert!(!name.contains(char::is_whitespace), "dynamic library name cannot contain whitespace");
147-
148-
let extension = dynamic_lib_extension();
149-
if is_darwin() {
150-
format!("lib{name}.{extension}")
151-
} else if is_windows() {
152-
format!("{name}.{extension}")
153-
} else {
154-
format!("lib{name}.{extension}")
155-
}
156-
}
157-
158-
#[must_use]
159-
pub fn dynamic_lib_extension() -> &'static str {
160-
if is_darwin() {
161-
"dylib"
162-
} else if is_windows() {
163-
"dll"
164-
} else {
165-
"so"
166-
}
167-
}
168-
169-
/// Generate the name a rust library (rlib) would have.
170-
#[must_use]
171-
pub fn rust_lib_name(name: &str) -> String {
172-
format!("lib{name}.rlib")
173-
}
174-
175-
/// Construct the binary name based on platform.
176-
#[must_use]
177-
pub fn bin_name(name: &str) -> String {
178-
if is_windows() { format!("{name}.exe") } else { name.to_string() }
179-
}
180-
181111
/// Return the current working directory.
182112
#[must_use]
183113
pub fn cwd() -> PathBuf {

0 commit comments

Comments
 (0)