change the nebula-ffi build process to be more compatible with other platforms [nebula-ffi/1.7.2, tfclient/0.2.6]
This commit is contained in:
parent
27bf92d2cd
commit
e519700530
|
@ -1568,15 +1568,6 @@ dependencies = [
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "gobuild"
|
|
||||||
version = "0.1.0-alpha.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "71e156a4ddbf3deb5e8116946c111413bd9a5679bdc1536c78a60618a7a9ac9e"
|
|
||||||
dependencies = [
|
|
||||||
"cc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "h2"
|
name = "h2"
|
||||||
version = "0.3.21"
|
version = "0.3.21"
|
||||||
|
@ -2078,10 +2069,10 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nebula-ffi"
|
name = "nebula-ffi"
|
||||||
version = "0.2.0"
|
version = "1.7.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bindgen",
|
"bindgen",
|
||||||
"gobuild",
|
"cc",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -3607,7 +3598,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tfclient"
|
name = "tfclient"
|
||||||
version = "0.2.5"
|
version = "0.2.6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64 0.21.4",
|
"base64 0.21.4",
|
||||||
"base64-serde",
|
"base64-serde",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "nebula-ffi"
|
name = "nebula-ffi"
|
||||||
version = "0.2.0"
|
version = "1.7.2"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "A Rust wrapper crate for communicating with Nebula via a CGO FFI."
|
description = "A Rust wrapper crate for communicating with Nebula via a CGO FFI."
|
||||||
license = "GPL-3.0-or-later"
|
license = "GPL-3.0-or-later"
|
||||||
|
@ -12,5 +12,5 @@ repository = "https://git.e3t.cc/~core/trifid"
|
||||||
|
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
gobuild = "0.1.0-alpha.2"
|
|
||||||
bindgen = "0.68.1"
|
bindgen = "0.68.1"
|
||||||
|
cc = "1"
|
|
@ -1,27 +1,61 @@
|
||||||
use std::env;
|
use std::{env, process};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use bindgen::CargoCallbacks;
|
use bindgen::CargoCallbacks;
|
||||||
use gobuild::BuildMode;
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// Find compiler: if /usr/local/go/bin/go exists, use that
|
|
||||||
// otherwise, rely on PATH
|
// Find compiler:
|
||||||
let compiler = if Path::new("/usr/local/go/bin/go").exists() {
|
// 1. GOC
|
||||||
println!("Using /usr/local/go/bin/go");
|
// 2. /usr/local/go/bin/go
|
||||||
"/usr/local/go/bin/go"
|
// 3. system "go"
|
||||||
} else {
|
|
||||||
"go"
|
let compiler = match env::var("GOC") {
|
||||||
|
Ok(c) => c,
|
||||||
|
Err(_) => {
|
||||||
|
if Path::new("/usr/local/go/bin/go").exists() {
|
||||||
|
"/usr/local/go/bin/go".to_string()
|
||||||
|
} else {
|
||||||
|
"go".to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
gobuild::Build::new().compiler(compiler).buildmode(BuildMode::CArchive).file("main.go").compile("nebulaffi");
|
println!("using go compiler {}", compiler);
|
||||||
|
|
||||||
|
//gobuild::Build::new().compiler(compiler).buildmode(BuildMode::CArchive).file("main.go").compile("nebulaffi");
|
||||||
|
|
||||||
|
let c_compiler = cc::Build::new().try_get_compiler().unwrap();
|
||||||
|
|
||||||
|
let out_dir = env::var("OUT_DIR").unwrap();
|
||||||
|
let out_path = PathBuf::from(out_dir);
|
||||||
|
let out_file = LIBRARY_PREFIX.to_owned() + "nebula" + LIBRARY_EXTENSION;
|
||||||
|
let out = out_path.join(out_file);
|
||||||
|
|
||||||
|
let mut command = process::Command::new(compiler);
|
||||||
|
command.args(["build", "-buildmode", "c-archive", "-o", out.display().to_string().as_str(), "main.go"]);
|
||||||
|
command.env("CGO_ENABLED", "1");
|
||||||
|
command.env("CC", c_compiler.path());
|
||||||
|
command.env("GOARCH", goarch());
|
||||||
|
command.env("GOOS", goos());
|
||||||
|
println!("running go compile command: {:?}", command);
|
||||||
|
|
||||||
|
let mut child = command.spawn().unwrap();
|
||||||
|
let status = child.wait().unwrap();
|
||||||
|
println!("{}", status);
|
||||||
|
|
||||||
|
if !status.success() {
|
||||||
|
panic!("`{:?}` exited with status code {}", command, status);
|
||||||
|
}
|
||||||
|
|
||||||
println!("Go compile success");
|
println!("Go compile success");
|
||||||
|
|
||||||
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
|
println!("cargo:rustc-link-lib=static=nebula");
|
||||||
|
println!("cargo:rustc-link-search=native={}", env::var("OUT_DIR").unwrap());
|
||||||
|
|
||||||
println!("cargo:rustc-link-search={}", out_path.display());
|
//let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
|
||||||
println!("cargo:rustc-link-lib=dylib=nebulaffi");
|
|
||||||
|
//println!("cargo:rustc-link-search={}", out_path.display());
|
||||||
println!("cargo:rerun-if-changed=go.mod");
|
println!("cargo:rerun-if-changed=go.mod");
|
||||||
println!("cargo:rerun-if-changed=go.sum");
|
println!("cargo:rerun-if-changed=go.sum");
|
||||||
println!("cargo:rerun-if-changed=main.go");
|
println!("cargo:rerun-if-changed=main.go");
|
||||||
|
@ -29,7 +63,7 @@ fn main() {
|
||||||
println!("Generating bindings");
|
println!("Generating bindings");
|
||||||
|
|
||||||
let bindings = bindgen::Builder::default()
|
let bindings = bindgen::Builder::default()
|
||||||
.header(out_path.join("libnebulaffi.h").display().to_string())
|
.header(out_path.join("libnebula.h").display().to_string())
|
||||||
.parse_callbacks(Box::new(CargoCallbacks))
|
.parse_callbacks(Box::new(CargoCallbacks))
|
||||||
.generate()
|
.generate()
|
||||||
.expect("Error generating CFFI bindings");
|
.expect("Error generating CFFI bindings");
|
||||||
|
@ -39,3 +73,40 @@ fn main() {
|
||||||
.write_to_file(out_path.join("bindings.rs"))
|
.write_to_file(out_path.join("bindings.rs"))
|
||||||
.expect("Couldn't write bindings!");
|
.expect("Couldn't write bindings!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(target_family = "unix")]
|
||||||
|
const LIBRARY_EXTENSION: & str = ".a";
|
||||||
|
#[cfg(target_family = "unix")]
|
||||||
|
const LIBRARY_PREFIX: & str = "lib";
|
||||||
|
|
||||||
|
#[cfg(target_family = "windows")]
|
||||||
|
const LIBRARY_EXTENSION: &str = ".lib";
|
||||||
|
#[cfg(target_family = "windows")]
|
||||||
|
const LIBRARY_PREFIX: &str = "";
|
||||||
|
|
||||||
|
fn goarch() -> String {
|
||||||
|
match env::var("CARGO_CFG_TARGET_ARCH").unwrap().as_str() {
|
||||||
|
"x86" => "386",
|
||||||
|
"x86_64" => "amd64",
|
||||||
|
"mips" => "mips",
|
||||||
|
"powerpc" => "ppc",
|
||||||
|
"powerpc64" => "ppc64",
|
||||||
|
"arm" => "arm",
|
||||||
|
"aarch64" => "arm64",
|
||||||
|
arch => panic!("unsupported architecture {arch}")
|
||||||
|
}.to_string()
|
||||||
|
}
|
||||||
|
fn goos() -> String {
|
||||||
|
match env::var("CARGO_CFG_TARGET_OS").unwrap().as_str() {
|
||||||
|
"windows" => "windows",
|
||||||
|
"macos" => "darwin",
|
||||||
|
"ios" => "darwin",
|
||||||
|
"linux" => "linux",
|
||||||
|
"android" => "android",
|
||||||
|
"freebsd" => "freebsd",
|
||||||
|
"dragonfly" => "dragonfly",
|
||||||
|
"openbsd" => "openbsd",
|
||||||
|
"netbsd" => "netbsd",
|
||||||
|
os => panic!("unsupported operating system {os}")
|
||||||
|
}.to_string()
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "tfclient"
|
name = "tfclient"
|
||||||
version = "0.2.5"
|
version = "0.2.6"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "An open-source reimplementation of a Defined Networking-compatible client"
|
description = "An open-source reimplementation of a Defined Networking-compatible client"
|
||||||
license = "GPL-3.0-or-later"
|
license = "GPL-3.0-or-later"
|
||||||
|
@ -30,7 +30,7 @@ ipnet = "2.7"
|
||||||
base64-serde = "0.7"
|
base64-serde = "0.7"
|
||||||
dnapi-rs = { version = "0.2", path = "../dnapi-rs" }
|
dnapi-rs = { version = "0.2", path = "../dnapi-rs" }
|
||||||
serde_yaml = "0.9"
|
serde_yaml = "0.9"
|
||||||
nebula-ffi = { version = "0.2", path = "../nebula-ffi", optional = true }
|
nebula-ffi = { version = "1.7.2", path = "../nebula-ffi", optional = true }
|
||||||
[package.metadata.deb]
|
[package.metadata.deb]
|
||||||
maintainer = "c0repwn3r <core@e3t.cc>"
|
maintainer = "c0repwn3r <core@e3t.cc>"
|
||||||
copyright = "e3team <admin@e3t.cc>"
|
copyright = "e3team <admin@e3t.cc>"
|
||||||
|
|
Loading…
Reference in New Issue