forked from cardano-community/cncli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
49 lines (43 loc) · 1.46 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use std::process::Command;
macro_rules! ok (($expression:expr) => ($expression.unwrap()));
macro_rules! log {
($fmt:expr) => (println!(concat!("cncli/build.rs:{}: ", $fmt), line!()));
($fmt:expr, $($arg:tt)*) => (println!(concat!("cncli/build.rs:{}: ", $fmt),
line!(), $($arg)*));
}
fn main() {
// Build and link IOHK libsodium
run("git", |command| {
command
.arg("submodule")
.arg("update")
.arg("--init")
.arg("--recursive")
.arg("--force")
});
// Build libsodium automatically (as part of rust build)
#[cfg(not(feature = "libsodium-sys"))]
{
let libsodium = autotools::Config::new("contrib/libsodium/").reconf("-vfi").build();
println!("cargo:rustc-link-search=native={}", libsodium.join("lib").display());
println!("cargo:rustc-link-lib=static=sodium");
}
// Link with libsodium system library
#[cfg(feature = "libsodium-sys")]
{
pkg_config::Config::new().probe("libsodium").unwrap();
}
println!("cargo:return-if-changed=build.rs");
}
fn run<F>(name: &str, mut configure: F)
where
F: FnMut(&mut Command) -> &mut Command,
{
let mut command = Command::new(name);
let configured = configure(&mut command);
log!("Executing {:?}", configured);
if !ok!(configured.status()).success() {
panic!("failed to execute {:?}", configured);
}
log!("Command {:?} finished successfully", configured);
}