Skip to content

Commit 5d89a28

Browse files
committed
Fix res_path on non-mac platforms
1 parent 07b2a66 commit 5d89a28

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

nodejs-embedded/src/lib.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::path::{Path, PathBuf};
33
use path_absolutize::Absolutize;
44

55
#[cfg(target_os = "macos")]
6-
fn macos_res_path() -> PathBuf {
6+
fn platform_res_path() -> Option<PathBuf> {
77
use objc::{runtime::Object, *};
88
use std::ffi::CStr;
99
use std::os::unix::ffi::OsStringExt;
@@ -17,20 +17,22 @@ fn macos_res_path() -> PathBuf {
1717
CStr::from_ptr(resource_path).to_bytes().to_vec()
1818
});
1919
let resource_path = PathBuf::from(OsString::from_vec(resource_path));
20-
resource_path
20+
Some(resource_path)
2121
}
2222

23+
#[cfg(not(target_os = "macos"))]
24+
fn platform_res_path() -> Option<PathBuf> {
25+
None
26+
}
27+
28+
2329
unsafe extern "C" fn node_start(napi_reg_func: *mut c_void) -> i32 {
2430
nodejs::run_raw(napi_reg_func)
2531
}
2632

2733
pub unsafe fn main() -> i32 {
2834
let exec_dir = std::env::current_exe().unwrap().parent().unwrap().to_path_buf();
29-
30-
#[cfg(target_os = "macos")]
31-
let res_path = macos_res_path();
32-
#[cfg(not(target_os = "macos"))]
33-
let res_path = exec_dir.clone();
35+
let res_path = platform_res_path().unwrap_or_else(|| exec_dir.clone());
3436

3537
let embedder_path_file = res_path.join("nodejs_embedder");
3638
let dylib_path = std::fs::read_to_string(embedder_path_file).unwrap();

0 commit comments

Comments
 (0)