Prechádzať zdrojové kódy

Add Windows build support and general platform support.

parazyd 1 rok pred
rodič
commit
eb411704bd
2 zmenil súbory, kde vykonal 18 pridanie a 9 odobranie
  1. 7 0
      Cargo.toml
  2. 11 9
      build.rs

+ 7 - 0
Cargo.toml

@@ -6,10 +6,14 @@ authors = [
     "Dyne.org Foundation <foundation@dyne.org>",
     "tevador <tevador@gmail.com>",
     "The Monero Project",
+    "The Tari Project",
 ]
 license = "BSD-3-Clause"
 edition = "2021"
 
+[lib]
+crate-type = ["cdylib", "lib"]
+
 [target.'cfg(not(target = "x86_64-unknown-linux-musl"))'.build-dependencies]
 bindgen = "0.71"
  
@@ -23,3 +27,6 @@ libc = "0.2"
 [dev-dependencies]
 anyhow = "1.0"
 hex = "0.4"
+
+[profile.release]
+lto = false

+ 11 - 9
build.rs

@@ -4,7 +4,6 @@ use std::path::PathBuf;
 use std::process::Command;
 
 fn main() {
-    let target = env::var("TARGET").unwrap();
     let n_threads = std::thread::available_parallelism()
         .unwrap()
         .get()
@@ -48,14 +47,17 @@ fn main() {
     );
     println!("cargo:rustc-link-lib=static=randomx");
 
-    if target.contains("apple") {
-        println!("cargo:rustc-link-lib=dylib=c++");
-    } else if target.contains("linux") {
-        println!("cargo:rustc-link-lib=dylib=stdc++");
-    } else if target.contains("freebsd") {
-        println!("cargo:rustc-link-lib=dylib=c++");
-    } else {
-        unimplemented!()
+    let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap_or("linux".to_string());
+    let dylib_name = match target_os.as_str() {
+        "freebsd" | "macos" | "ios" => "c++", // FreeBSD, MacOS, and iOS use "c++",
+        "windows" => "msvcrt",                // Use MSVC runtime on Windows
+        _ => "stdc++",                        // Default for other systems (Linux, etc.)
+    };
+
+    println!("cargo:rustc-link-lib=dylib={}", dylib_name);
+
+    if cfg!(target_os = "windows") {
+        println!("cargo:rustc-link-lib=advapi32");
     }
 
     // The bindgen::Builder is the main entry point