vpncloud/build.rs

45 lines
2.0 KiB
Rust
Raw Normal View History

2017-07-22 14:49:53 +00:00
// VpnCloud - Peer-to-Peer VPN
// Copyright (C) 2015-2017 Dennis Schwerdel
// This software is licensed under GPL-3 or newer (see LICENSE.md)
2015-11-19 15:34:20 +00:00
extern crate gcc;
2015-11-30 16:27:50 +00:00
extern crate pkg_config;
2015-11-19 15:34:20 +00:00
use std::process::Command;
use std::path::PathBuf;
2016-04-12 07:20:47 +00:00
use std::env;
use std::fs;
2015-11-19 15:34:20 +00:00
fn main() {
2017-01-07 14:09:40 +00:00
gcc::Config::new().file("src/c/tuntap.c").include("src").compile("libtuntap.a");
if cfg!(feature = "system-libsodium") {
pkg_config::Config::new().atleast_version("1.0.8").probe("libsodium").expect("Libsodium >= 1.0.8 missing");
return
} else {
let target = env::var("TARGET").unwrap();
let dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
let libsodium_dir = dir.join("libsodium");
let libsodium_target_dir = dir.join("target/sodium-build").join(&target);
let libsodium_target_file = libsodium_target_dir.join("libsodium.a");
if ! libsodium_target_file.exists() {
fs::create_dir_all(&libsodium_target_dir).unwrap();
Command::new("make").arg("clean").current_dir(&libsodium_dir).status().unwrap();
Command::new("sh").arg("autogen.sh").current_dir(&libsodium_dir).status().unwrap();
let mut args = vec!["configure", "--host", &target];
if target.starts_with("i686-") {
args.extend(vec!["CFLAGS=-m32", "CXXFLAGS=-m32", "LDFLAGS=-m32"]);
}
if target.ends_with("-musl") {
args.extend(vec!["CC=musl-gcc"]);
}
if target == "arm-unknown-linux-gnueabihf" || target == "armv7-unknown-linux-gnueabihf" {
args.extend(vec!["CC=arm-linux-gnueabihf-gcc"]);
}
Command::new("sh").args(&args).current_dir(&libsodium_dir).status().unwrap();
Command::new("make").current_dir(&libsodium_dir).status().unwrap();
fs::copy(libsodium_dir.join("src/libsodium/.libs/libsodium.a"), libsodium_target_file).unwrap();
}
2017-01-07 14:09:40 +00:00
println!("cargo:rustc-link-search={}", libsodium_target_dir.to_str().unwrap());
}
2015-11-21 16:06:57 +00:00
}