Statically link Monero

Closes https://github.com/serai-dex/serai/issues/11.
This commit is contained in:
Luke Parker 2022-07-07 14:13:24 -04:00
parent 7d13be5797
commit 6c76458063
No known key found for this signature in database
GPG key ID: F9F1386DB1E119B6
2 changed files with 55 additions and 34 deletions

View file

@ -6,6 +6,9 @@ license = "MIT"
authors = ["Luke Parker <lukeparker5132@gmail.com>"]
edition = "2021"
[build-dependencies]
cc = "1.0"
[dependencies]
hex-literal = "0.3"
lazy_static = "1"

View file

@ -1,6 +1,4 @@
use std::process::Command;
use std::env;
use std::path::Path;
use std::{env, path::Path, process::Command};
fn main() {
if !Command::new("git").args(&["submodule", "update", "--init", "--recursive"]).status().unwrap().success() {
@ -19,11 +17,6 @@ fn main() {
// 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("cmake").args(&["cmake", "-DCMAKE_BUILD_TYPE=Release", "-DBUILD_SHARED_LIBS=1", "."])
.current_dir(&Path::new("c/monero")).status().unwrap().success() {
panic!("cmake failed to generate Monero's build scripts");
}
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");
@ -44,47 +37,72 @@ fn main() {
&env::consts::DLL_EXTENSION
)
).exists() {
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()
];
for (folder, lib) in [
("common", "common"),
("crypto", "cncrypto"),
("crypto/wallet", "wallet-crypto"),
("cryptonote_basic", "cryptonote_basic"),
("cryptonote_basic", "cryptonote_format_utils_basic"),
("", "version"),
("device", "device"),
("ringct", "ringct_basic"),
("ringct", "ringct")
] {
if !Command::new("cp").args(&[
&format!(
"c/monero/src/{}/{}{}.{}",
paths.push(
format!(
"c/monero/build/release/src/{}/{}{}.a",
folder,
&env::consts::DLL_PREFIX,
lib,
&env::consts::DLL_EXTENSION
),
out_dir
]).status().unwrap().success() {
panic!("Failed to cp {}", lib);
lib
)
);
}
for path in paths {
if !Command::new("cp").args(&[&path, out_dir]).status().unwrap().success() {
panic!("Failed to cp {}", path);
}
}
}
println!("cargo:rerun-if-changed=c/wrapper.cpp");
if !Command::new("g++").args(&[
"-O3", "-Wall", "-shared", "-std=c++14", "-fPIC",
"-Imonero/contrib/epee/include", "-Imonero/src",
"wrapper.cpp", "-o", &format!(
"{}/{}wrapper.{}",
out_dir,
&env::consts::DLL_PREFIX,
&env::consts::DLL_EXTENSION
),
&format!("-L{}", out_dir),
"-ldevice", "-lringct_basic", "-lringct"
]).current_dir(&Path::new("c")).status().unwrap().success() {
panic!("g++ failed to build the wrapper");
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");
}
println!("cargo:rustc-link-search={}", out_dir);
println!("cargo:rustc-link-lib=cncrypto");
println!("cargo:rustc-link-lib=device");
println!("cargo:rustc-link-lib=ringct_basic");
println!("cargo:rustc-link-lib=ringct");
println!("cargo:rustc-link-lib=wrapper");
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");
}