Skip to content

Commit aa2dc7c

Browse files
committed
new helper functions and rename
1 parent c1400ca commit aa2dc7c

File tree

5 files changed

+22
-11
lines changed

5 files changed

+22
-11
lines changed

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,17 @@ pub fn target() -> String {
4040

4141
/// Check if target is windows-like.
4242
pub fn is_windows() -> bool {
43-
env::var_os("IS_WINDOWS").is_some()
43+
target().contains("windows")
4444
}
4545

4646
/// Check if target uses msvc.
4747
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")
4954
}
5055

5156
/// Construct a path to a static library under `$TMPDIR` given the library name. This will return a
@@ -84,7 +89,7 @@ pub fn static_lib_name(name: &str) -> String {
8489
// ```
8590
assert!(!name.contains(char::is_whitespace), "static library name cannot contain whitespace");
8691

87-
if target().contains("msvc") { format!("{name}.lib") } else { format!("lib{name}.a") }
92+
if is_msvc() { format!("{name}.lib") } else { format!("lib{name}.a") }
8893
}
8994

9095
/// Construct a path to a dynamic library under `$TMPDIR` given the library name. This will return a
@@ -110,15 +115,21 @@ pub fn dynamic_lib_name(name: &str) -> String {
110115
// ```
111116
assert!(!name.contains(char::is_whitespace), "dynamic library name cannot contain whitespace");
112117

113-
if target().contains("darwin") {
118+
if is_darwin() {
114119
format!("lib{name}.dylib")
115-
} else if target().contains("windows") {
120+
} else if is_windows() {
116121
format!("{name}.dll")
117122
} else {
118123
format!("lib{name}.so")
119124
}
120125
}
121126

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"))
131+
}
132+
122133
/// Construct the binary name based on platform.
123134
pub fn bin_name(name: &str) -> String {
124135
if is_windows() { format!("{name}.exe") } else { name.to_string() }

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl Rustc {
9191
self
9292
}
9393

94-
/// Specify path to the output file.
94+
/// Specify path to the output file. Equivalent to `-o`` in rustc.
9595
pub fn output<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
9696
self.cmd.arg("-o");
9797
self.cmd.arg(path.as_ref());
@@ -150,7 +150,7 @@ impl Rustc {
150150
self
151151
}
152152

153-
/// Add a directory to the library search path.
153+
/// Add a directory to the library search path. Equivalent to `-L`` in rustc.
154154
pub fn library_search_path<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
155155
self.cmd.arg("-L");
156156
self.cmd.arg(path.as_ref());

tests/run-make/issue-11908/rmake.rs renamed to tests/run-make/same-lib-two-locations-no-panic/rmake.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@
1111

1212
//@ ignore-cross-compile
1313

14-
use run_make_support::{dynamic_lib, rustc, tmp_dir};
14+
use run_make_support::{dynamic_lib, rust_lib, rustc, tmp_dir};
1515
use std::fs;
1616

1717
fn main() {
1818
let tmp_dir_other = tmp_dir().join("other");
1919

2020
fs::create_dir(&tmp_dir_other);
21-
rustc().input("foo.rs").crate_type("dylib").codegen_option("prefer-dynamic").run();
21+
rustc().input("foo.rs").crate_type("dylib").prefer_dynamic().run();
2222
fs::rename(dynamic_lib("foo"), &tmp_dir_other);
23-
rustc().input("foo.rs").crate_type("dylib").codegen_option("prefer-dynamic").run();
23+
rustc().input("foo.rs").crate_type("dylib").prefer_dynamic().run();
2424
rustc().input("bar.rs").library_search_path(&tmp_dir_other).run();
2525
fs::remove_dir_all(tmp_dir());
2626

2727
fs::create_dir_all(&tmp_dir_other);
2828
rustc().input("foo.rs").crate_type("rlib").run();
29-
fs::rename(tmp_dir().join("libfoo.rlib"), &tmp_dir_other);
29+
fs::rename(rust_lib("foo"), &tmp_dir_other);
3030
rustc().input("foo.rs").crate_type("rlib").run();
3131
rustc().input("bar.rs").library_search_path(tmp_dir_other).run();
3232
}

0 commit comments

Comments
 (0)