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

Commit d80a02a

Browse files
committed
fixup
1 parent 4523a35 commit d80a02a

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

crates/libm-cdylib/src/macros.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ macro_rules! export {
4747
c_format_s = c_format_s
4848
);
4949

50-
let src = &format!("../../target/{}.c", stringify!($id));
51-
let bin = &format!("../../target/{}", stringify!($id));
52-
let src_path = std::path::Path::new(src);
53-
let bin_path = std::path::Path::new(bin);
50+
let target_dir = target_dir();
51+
eprintln!("target dir: {}", target_dir.display());
52+
let src_path = target_dir.clone().join(format!("{}.c", stringify!($id)));
53+
let bin_path = target_dir.clone().join(format!("{}", stringify!($id)));
5454
write_to_file(&src_path, &ctest);
5555

5656
// We now compile the C program into an executable, make sure

crates/libm-cdylib/src/test_utils.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,29 +51,22 @@ where
5151
let mut cmd = process::Command::new(path);
5252

5353
// Find the cdylib - we just support standard locations for now.
54-
let target_dir = if let Ok(dir) = std::env::var("CARGO_TARGET_DIR") {
55-
std::path::PathBuf::from(&dir)
56-
} else {
57-
Path::new("../../target").into()
58-
};
59-
let libm_path = target_dir.join(Path::new(if cfg!(release_profile) {
54+
let libm_path = target_dir().join(if cfg!(release_profile) {
6055
"release"
6156
} else {
6257
"debug"
63-
}));
58+
});
6459

6560
// Replace libm at runtime
6661
if cfg!(target_os = "macos") {
67-
let lib_name = format!("liblibm.{}", "dylib");
68-
let lib_path = libm_path.join(Path::new(&lib_name));
62+
let lib_path = libm_path.join("liblibm.dylib");
6963
// for debugging:
7064
// cmd.env("DYLD_PRINT_LIBRARIES", "1");
7165
// cmd.env("X", "1");
7266
cmd.env("DYLD_FORCE_FLAT_NAMESPACE", "1");
7367
cmd.env("DYLD_INSERT_LIBRARIES", lib_path.display().to_string());
7468
} else if cfg!(target_os = "linux") {
75-
let lib_name = format!("liblibm.{}", "so");
76-
let lib_path = libm_path.join(Path::new(&lib_name));
69+
let lib_path = libm_path.join("liblibm.so");
7770
cmd.env("LD_PRELOAD", lib_path.display().to_string());
7871
}
7972
// Run the binary:
@@ -140,3 +133,11 @@ pub(crate) fn ctype_and_printf_format_specifier(x: &str) -> (&str, &str) {
140133
_ => panic!("unknown type: {}", x),
141134
}
142135
}
136+
137+
pub(crate) fn target_dir() -> std::path::PathBuf {
138+
if let Ok(dir) = std::env::var("CARGO_TARGET_DIR") {
139+
std::path::PathBuf::from(&dir)
140+
} else {
141+
Path::new("../../target").into()
142+
}
143+
}

0 commit comments

Comments
 (0)