Auto merge of #125031 - Oneirical:dynamic-libs, r=jieyouxu · rust-lang/rust@9e7aff7 (original) (raw)
`@@ -40,12 +40,17 @@ pub fn target() -> String {
`
40
40
``
41
41
`/// Check if target is windows-like.
`
42
42
`pub fn is_windows() -> bool {
`
43
``
`-
env::var_os("IS_WINDOWS").is_some()
`
``
43
`+
target().contains("windows")
`
44
44
`}
`
45
45
``
46
46
`/// Check if target uses msvc.
`
47
47
`pub fn is_msvc() -> bool {
`
48
``
`-
env::var_os("IS_MSVC").is_some()
`
``
48
`+
target().contains("msvc")
`
``
49
`+
}
`
``
50
+
``
51
`+
/// Check if target uses macOS.
`
``
52
`+
pub fn is_darwin() -> bool {
`
``
53
`+
target().contains("darwin")
`
49
54
`}
`
50
55
``
51
56
`` /// Construct a path to a static library under $TMPDIR
given the library name. This will return a
``
`@@ -82,9 +87,47 @@ pub fn static_lib_name(name: &str) -> String {
`
82
87
`// endif
`
83
88
`// endif
`
84
89
```` // ```
`85`
``
`-
assert!(!name.contains(char::is_whitespace), "name cannot contain whitespace");
`
``
`90`
`+
assert!(!name.contains(char::is_whitespace), "static library name cannot contain whitespace");
`
``
`91`
`+`
``
`92`
`+
if is_msvc() { format!("{name}.lib") } else { format!("lib{name}.a") }
`
``
`93`
`+
}
`
``
`94`
`+`
``
`95`
`` +
/// Construct a path to a dynamic library under `$TMPDIR` given the library name. This will return a
``
``
`96`
`` +
/// path with `$TMPDIR` joined with platform-and-compiler-specific library name.
``
``
`97`
`+
pub fn dynamic_lib(name: &str) -> PathBuf {
`
``
`98`
`+
tmp_dir().join(dynamic_lib_name(name))
`
``
`99`
`+
}
`
``
`100`
`+`
``
`101`
`+
/// Construct the dynamic library name based on the platform.
`
``
`102`
`+
pub fn dynamic_lib_name(name: &str) -> String {
`
``
`103`
`+
// See tools.mk (irrelevant lines omitted):
`
``
`104`
`+
//
`
``
`105`
```` +
// ```makefile
``
106
`+
// ifeq ($(UNAME),Darwin)
`
``
107
`+
// DYLIB = (TMPDIR)/lib(TMPDIR)/lib(TMPDIR)/lib(1).dylib
`
``
108
`+
// else
`
``
109
`+
// ifdef IS_WINDOWS
`
``
110
`+
// DYLIB = (TMPDIR)/(TMPDIR)/(TMPDIR)/(1).dll
`
``
111
`+
// else
`
``
112
`+
// DYLIB = (TMPDIR)/lib(TMPDIR)/lib(TMPDIR)/lib(1).so
`
``
113
`+
// endif
`
``
114
`+
// endif
`
``
115
// ```
``
116
`+
assert!(!name.contains(char::is_whitespace), "dynamic library name cannot contain whitespace");
`
``
117
+
``
118
`+
if is_darwin() {
`
``
119
`+
format!("lib{name}.dylib")
`
``
120
`+
} else if is_windows() {
`
``
121
`+
format!("{name}.dll")
`
``
122
`+
} else {
`
``
123
`+
format!("lib{name}.so")
`
``
124
`+
}
`
``
125
`+
}
`
86
126
``
87
``
`-
if target().contains("msvc") { format!("{name}.lib") } else { format!("lib{name}.a") }
`
``
127
`` +
/// Construct a path to a rust library (rlib) under $TMPDIR
given the library name. This will return a
``
``
128
`` +
/// path with $TMPDIR
joined with the library name.
``
``
129
`+
pub fn rust_lib(name: &str) -> PathBuf {
`
``
130
`+
tmp_dir().join(format!("lib{name}.rlib"))
`
88
131
`}
`
89
132
``
90
133
`/// Construct the binary name based on platform.
`