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() {
|
2022-07-15 05:26:07 +00:00
|
|
|
if !Command::new("git")
|
|
|
|
.args(&["submodule", "update", "--init", "--recursive"])
|
|
|
|
.status()
|
|
|
|
.unwrap()
|
|
|
|
.success()
|
|
|
|
{
|
2022-04-22 01:36:18 +00:00
|
|
|
panic!("git failed to init submodules");
|
|
|
|
}
|
|
|
|
|
2022-07-15 05:26:07 +00:00
|
|
|
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");
|
2022-04-22 01:36:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
println!("cargo:rerun-if-changed=c/.build/monero");
|
|
|
|
if !Path::new("c/.build/monero").exists() {
|
2022-07-22 16:31:29 +00:00
|
|
|
if !Command::new("mkdir")
|
|
|
|
.args(&["-p", "build/release"])
|
2022-07-15 05:26:07 +00:00
|
|
|
.current_dir(&Path::new("c/monero"))
|
|
|
|
.status()
|
|
|
|
.unwrap()
|
|
|
|
.success()
|
2022-07-22 16:31:29 +00:00
|
|
|
{
|
|
|
|
panic!("failed to mkdir");
|
|
|
|
}
|
|
|
|
|
|
|
|
if !Command::new("cmake")
|
|
|
|
.args(&[
|
|
|
|
"-D",
|
|
|
|
&format!("ARCH={}", &env::var("ARCH").unwrap_or_else(|_| "native".to_string())),
|
|
|
|
"-D",
|
|
|
|
"BUILD_TESTS=OFF",
|
|
|
|
"-D",
|
|
|
|
"CMAKE_BUILD_TYPE=Release",
|
|
|
|
"../..",
|
|
|
|
])
|
|
|
|
.current_dir(&Path::new("c/monero/build/release"))
|
|
|
|
.status()
|
|
|
|
.unwrap()
|
|
|
|
.success()
|
|
|
|
{
|
|
|
|
panic!("failed to call cmake. Please check your dependencies");
|
|
|
|
}
|
|
|
|
|
|
|
|
if !Command::new("make")
|
|
|
|
.arg(format!("-j{}", &env::var("THREADS").unwrap_or_else(|_| "2".to_string())))
|
|
|
|
.current_dir(&Path::new("c/monero/build/release"))
|
|
|
|
.status()
|
|
|
|
.unwrap()
|
|
|
|
.success()
|
2022-07-15 05:26:07 +00:00
|
|
|
{
|
|
|
|
panic!("make failed to build Monero. Please check your dependencies");
|
2022-04-22 01:36:18 +00:00
|
|
|
}
|
|
|
|
|
2022-07-15 05:26:07 +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");
|
2022-04-23 07:59:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-10 01:51:39 +00:00
|
|
|
println!("cargo:rerun-if-changed=c/wrapper.cpp");
|
2022-07-15 05:26:07 +00:00
|
|
|
#[rustfmt::skip]
|
2022-07-10 01:51:39 +00:00
|
|
|
cc::Build::new()
|
|
|
|
.static_flag(true)
|
|
|
|
.warnings(false)
|
|
|
|
.extra_warnings(false)
|
|
|
|
.flag("-Wno-deprecated-declarations")
|
2022-07-07 18:13:24 +00:00
|
|
|
|
2022-07-10 01:51:39 +00:00
|
|
|
.include("c/monero/external/supercop/include")
|
|
|
|
.include("c/monero/contrib/epee/include")
|
|
|
|
.include("c/monero/src")
|
|
|
|
.include("c/monero/build/release/generated_include")
|
2022-07-07 18:13:24 +00:00
|
|
|
|
2022-07-10 01:51:39 +00:00
|
|
|
.define("AUTO_INITIALIZE_EASYLOGGINGPP", None)
|
|
|
|
.include("c/monero/external/easylogging++")
|
|
|
|
.file("c/monero/external/easylogging++/easylogging++.cc")
|
2022-04-22 01:36:18 +00:00
|
|
|
|
2022-07-10 01:51:39 +00:00
|
|
|
.file("c/monero/src/common/aligned.c")
|
|
|
|
.file("c/monero/src/common/perf_timer.cpp")
|
|
|
|
|
|
|
|
.include("c/monero/src/crypto")
|
|
|
|
.file("c/monero/src/crypto/crypto-ops-data.c")
|
|
|
|
.file("c/monero/src/crypto/crypto-ops.c")
|
|
|
|
.file("c/monero/src/crypto/keccak.c")
|
|
|
|
.file("c/monero/src/crypto/hash.c")
|
|
|
|
|
|
|
|
.include("c/monero/src/device")
|
|
|
|
.file("c/monero/src/device/device_default.cpp")
|
|
|
|
|
|
|
|
.include("c/monero/src/ringct")
|
|
|
|
.file("c/monero/src/ringct/rctCryptoOps.c")
|
|
|
|
.file("c/monero/src/ringct/rctTypes.cpp")
|
|
|
|
.file("c/monero/src/ringct/rctOps.cpp")
|
|
|
|
.file("c/monero/src/ringct/multiexp.cc")
|
|
|
|
.file("c/monero/src/ringct/bulletproofs.cc")
|
|
|
|
.file("c/monero/src/ringct/rctSigs.cpp")
|
|
|
|
|
|
|
|
.file("c/wrapper.cpp")
|
|
|
|
.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=stdc++");
|
2022-04-22 01:36:18 +00:00
|
|
|
}
|