@@ -3,7 +3,7 @@ use std::path::{Path, PathBuf};
3
3
use path_absolutize:: Absolutize ;
4
4
5
5
#[ cfg( target_os = "macos" ) ]
6
- fn macos_res_path ( ) -> PathBuf {
6
+ fn platform_res_path ( ) -> Option < PathBuf > {
7
7
use objc:: { runtime:: Object , * } ;
8
8
use std:: ffi:: CStr ;
9
9
use std:: os:: unix:: ffi:: OsStringExt ;
@@ -17,20 +17,22 @@ fn macos_res_path() -> PathBuf {
17
17
CStr :: from_ptr ( resource_path) . to_bytes ( ) . to_vec ( )
18
18
} ) ;
19
19
let resource_path = PathBuf :: from ( OsString :: from_vec ( resource_path) ) ;
20
- resource_path
20
+ Some ( resource_path)
21
21
}
22
22
23
+ #[ cfg( not( target_os = "macos" ) ) ]
24
+ fn platform_res_path ( ) -> Option < PathBuf > {
25
+ None
26
+ }
27
+
28
+
23
29
unsafe extern "C" fn node_start ( napi_reg_func : * mut c_void ) -> i32 {
24
30
nodejs:: run_raw ( napi_reg_func)
25
31
}
26
32
27
33
pub unsafe fn main ( ) -> i32 {
28
34
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 ( ) ) ;
34
36
35
37
let embedder_path_file = res_path. join ( "nodejs_embedder" ) ;
36
38
let dylib_path = std:: fs:: read_to_string ( embedder_path_file) . unwrap ( ) ;
0 commit comments