diff --git a/.cargo/config b/.cargo/config new file mode 100644 index 0000000..d96c875 --- /dev/null +++ b/.cargo/config @@ -0,0 +1,4 @@ +[target.x86_64-unknown-linux-gnu] +rustflags = [ + "-C", "link-arg=-Wl,-rpath,$ORIGIN", +] diff --git a/Cargo.toml b/Cargo.toml index 495524c..b089f0c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,5 +12,9 @@ lto = true # Enables link to optimizations opt-level = "z" # Optimize for binary size strip = true # Remove debug symbols +[[bin]] +name = "harmony_link_client" +path = "src/main.rs" + [dependencies] -libloading = "0.8.0" +libloading = "0.8.0" \ No newline at end of file diff --git a/Resources/harmony_link_core.dll b/Resources/harmony_link_core.dll index 405578c..1e5e310 100644 Binary files a/Resources/harmony_link_core.dll and b/Resources/harmony_link_core.dll differ diff --git a/Resources/libharmony_link_core.so b/Resources/libharmony_link_core.so new file mode 100644 index 0000000..c4a3640 Binary files /dev/null and b/Resources/libharmony_link_core.so differ diff --git a/build.rs b/build.rs index b18a54e..7ad538e 100644 --- a/build.rs +++ b/build.rs @@ -29,4 +29,7 @@ fn main() { fs::copy(&path, &dest_path).expect("copy failed"); } } + + println!("cargo:rustc-env=RUSTFLAGS=-C link-arg=-Wl,-rpath,$ORIGIN"); + println!("cargo:rerun-if-changed=src/main.rs"); } diff --git a/src/main.rs b/src/main.rs index 9446346..23ba0c3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,20 @@ extern crate libloading; fn main() { - let lib = unsafe { match libloading::Library::new("harmony_link_core.dll") { + // Use `cfg!` macro to detect OS + let lib_path = if cfg!(target_os = "windows") { + "harmony_link_core.dll" + } else if cfg!(target_os = "linux") { + "libharmony_link_core.so" + } else { + eprintln!("Unsupported OS"); + return; + }; + + let lib = unsafe { match libloading::Library::new(lib_path) { Ok(lib) => lib, Err(err) => { - eprintln!("Error loading DLL: {}", err); + eprintln!("Error loading dynamic library: {}", err); return; }, } @@ -14,7 +24,7 @@ fn main() { let func: libloading::Symbol = match lib.get(b"start") { Ok(func) => func, Err(err) => { - eprintln!("Error finding function in DLL: {}", err); + eprintln!("Error finding function in dynamic library: {}", err); return; } };