2022-07-07 18:13:24 +00:00
|
|
|
use std::{env, path::Path, process::Command};
|
2022-04-22 01:36:18 +00:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
if !Command::new("git").args(&["submodule", "update", "--init", "--recursive"]).status().unwrap().success() {
|
|
|
|
panic!("git failed to init submodules");
|
|
|
|
}
|
|
|
|
|
|
|
|
if !Command ::new("mkdir").args(&["-p", ".build"])
|
|
|
|
.current_dir(&Path::new("c")).status().unwrap().success() {
|
|
|
|
panic!("failed to create a directory to track build progress");
|
|
|
|
}
|
|
|
|
|
|
|
|
let out_dir = &env::var("OUT_DIR").unwrap();
|
|
|
|
|
|
|
|
// Use a file to signal if Monero was already built, as that should never be rebuilt
|
|
|
|
// If the signaling file was deleted, run this script again to rebuild Monero though
|
|
|
|
// TODO: Move this signaling file into OUT_DIR once Monero is built statically successfully
|
|
|
|
println!("cargo:rerun-if-changed=c/.build/monero");
|
|
|
|
if !Path::new("c/.build/monero").exists() {
|
|
|
|
if !Command::new("make").arg(format!("-j{}", &env::var("THREADS").unwrap_or("2".to_string())))
|
|
|
|
.current_dir(&Path::new("c/monero")).status().unwrap().success() {
|
|
|
|
panic!("make failed to build Monero. Please check your dependencies");
|
|
|
|
}
|
|
|
|
|
2022-04-23 07:59:21 +00:00
|
|
|
if !Command::new("touch").arg("monero")
|
|
|
|
.current_dir(&Path::new("c/.build")).status().unwrap().success() {
|
|
|
|
panic!("failed to create a file to label Monero as built");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
println!("cargo:rerun-if-env-changed=OUT_DIR");
|
|
|
|
if !Path::new(
|
|
|
|
&format!(
|
2022-04-27 04:09:25 +00:00
|
|
|
"{}/{}cncrypto.{}",
|
|
|
|
out_dir,
|
2022-04-23 07:59:21 +00:00
|
|
|
&env::consts::DLL_PREFIX,
|
|
|
|
&env::consts::DLL_EXTENSION
|
|
|
|
)
|
|
|
|
).exists() {
|
2022-07-07 18:13:24 +00:00
|
|
|
let mut paths = vec![
|
|
|
|
"c/monero/build/release/contrib/epee/src/libepee.a".to_string(),
|
|
|
|
"c/monero/build/release/external/easylogging++/libeasylogging.a".to_string(),
|
|
|
|
"c/monero/build/release/external/randomx/librandomx.a".to_string()
|
|
|
|
];
|
|
|
|
|
2022-04-27 02:59:20 +00:00
|
|
|
for (folder, lib) in [
|
2022-07-07 18:13:24 +00:00
|
|
|
("common", "common"),
|
2022-04-27 02:59:20 +00:00
|
|
|
("crypto", "cncrypto"),
|
2022-07-07 18:13:24 +00:00
|
|
|
("crypto/wallet", "wallet-crypto"),
|
|
|
|
("cryptonote_basic", "cryptonote_basic"),
|
|
|
|
("cryptonote_basic", "cryptonote_format_utils_basic"),
|
|
|
|
("", "version"),
|
2022-04-27 02:59:20 +00:00
|
|
|
("device", "device"),
|
|
|
|
("ringct", "ringct_basic"),
|
|
|
|
("ringct", "ringct")
|
|
|
|
] {
|
2022-07-07 18:13:24 +00:00
|
|
|
paths.push(
|
|
|
|
format!(
|
|
|
|
"c/monero/build/release/src/{}/{}{}.a",
|
2022-04-27 02:59:20 +00:00
|
|
|
folder,
|
|
|
|
&env::consts::DLL_PREFIX,
|
2022-07-07 18:13:24 +00:00
|
|
|
lib
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
for path in paths {
|
|
|
|
if !Command::new("cp").args(&[&path, out_dir]).status().unwrap().success() {
|
|
|
|
panic!("Failed to cp {}", path);
|
2022-04-27 02:59:20 +00:00
|
|
|
}
|
2022-04-22 01:36:18 +00:00
|
|
|
}
|
2022-04-28 02:49:18 +00:00
|
|
|
}
|
2022-04-22 01:36:18 +00:00
|
|
|
|
2022-05-22 05:56:17 +00:00
|
|
|
println!("cargo:rerun-if-changed=c/wrapper.cpp");
|
2022-07-07 18:13:24 +00:00
|
|
|
if !Path::new(&format!("{}/{}wrapper.a", out_dir, &env::consts::DLL_PREFIX)).exists() {
|
|
|
|
cc::Build::new()
|
|
|
|
.file("c/wrapper.cpp")
|
|
|
|
.cpp(true)
|
|
|
|
.warnings(false)
|
|
|
|
.include("c/monero/contrib/epee/include")
|
|
|
|
.include("c/monero/src")
|
|
|
|
.compile("wrapper");
|
2022-04-22 01:36:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
println!("cargo:rustc-link-search={}", out_dir);
|
|
|
|
println!("cargo:rustc-link-lib=wrapper");
|
2022-07-07 18:13:24 +00:00
|
|
|
println!("cargo:rustc-link-lib=ringct");
|
|
|
|
println!("cargo:rustc-link-lib=ringct_basic");
|
|
|
|
println!("cargo:rustc-link-lib=device");
|
|
|
|
println!("cargo:rustc-link-lib=cryptonote_basic");
|
|
|
|
println!("cargo:rustc-link-lib=cncrypto");
|
|
|
|
println!("cargo:rustc-link-lib=cryptonote_format_utils_basic");
|
|
|
|
println!("cargo:rustc-link-lib=version");
|
|
|
|
println!("cargo:rustc-link-lib=wallet-crypto");
|
|
|
|
println!("cargo:rustc-link-lib=easylogging");
|
|
|
|
println!("cargo:rustc-link-lib=epee");
|
|
|
|
println!("cargo:rustc-link-lib=common");
|
|
|
|
println!("cargo:rustc-link-lib=randomx");
|
|
|
|
println!("cargo:rustc-link-lib=unbound");
|
|
|
|
println!("cargo:rustc-link-lib=sodium");
|
|
|
|
println!("cargo:rustc-link-lib=boost_system");
|
|
|
|
println!("cargo:rustc-link-lib=boost_thread");
|
|
|
|
println!("cargo:rustc-link-lib=boost_filesystem");
|
|
|
|
println!("cargo:rustc-link-lib=hidapi-hidraw");
|
|
|
|
println!("cargo:rustc-link-lib=stdc++");
|
|
|
|
|
|
|
|
println!("cargo:rustc-link-arg=-zmuldefs");
|
2022-04-22 01:36:18 +00:00
|
|
|
}
|