dynamically link to provide more options for more platforms

This commit is contained in:
c0repwn3r 2023-07-12 10:32:19 -04:00
parent 8ce7bb0857
commit 40ce3efe3c
Signed by: core
GPG Key ID: FDBF740DADDCEECF
2 changed files with 10 additions and 24 deletions

View File

@ -1,18 +1,23 @@
use std::env; use std::env;
use std::path::PathBuf; use std::path::PathBuf;
use bindgen::CargoCallbacks; use bindgen::CargoCallbacks;
use gobuild::BuildMode;
fn main() { fn main() {
gobuild::Build::new().file("main.go").compile("nebulaffi"); gobuild::Build::new().buildmode(BuildMode::CShared).file("main.go").compile("nebulaffi");
println!("Go compile success");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
println!("cargo:rustc-link-search={}", out_path.display()); println!("cargo:rustc-link-search={}", out_path.display());
println!("cargo:rustc-link-lib=static=nebulaffi"); println!("cargo:rustc-link-lib=dylib=nebulaffi");
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");
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("libnebulaffi.h").display().to_string())
.parse_callbacks(Box::new(CargoCallbacks)) .parse_callbacks(Box::new(CargoCallbacks))
@ -23,4 +28,4 @@ fn main() {
bindings bindings
.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!");
} }

View File

@ -25,19 +25,13 @@ pub mod timerworker;
pub mod util; pub mod util;
use crate::config::load_config; use crate::config::load_config;
use clap::{ArgAction, Parser, Subcommand}; use clap::{Parser, Subcommand};
use log::{error, info}; use log::{error, info};
use simple_logger::SimpleLogger; use simple_logger::SimpleLogger;
#[derive(Parser)] #[derive(Parser)]
#[command(author = "c0repwn3r", version, about, long_about = None)] #[command(author = "c0repwn3r", version, about, long_about = None)]
#[clap(disable_version_flag = true)]
struct Cli { struct Cli {
#[arg(short = 'v', long = "version", action = ArgAction::SetTrue)]
#[clap(global = true)]
/// Print the tfclient version, as well as the trifid-pki version and the version of the embedded nebula and nebula-cert binaries
version: bool,
#[command(subcommand)] #[command(subcommand)]
subcommand: Commands, subcommand: Commands,
} }
@ -75,13 +69,8 @@ enum Commands {
fn main() { fn main() {
SimpleLogger::new().init().unwrap(); SimpleLogger::new().init().unwrap();
let args = Cli::parse(); let args = Cli::parse();
if args.version {
print_version();
}
match args.subcommand { match args.subcommand {
Commands::Run { name, server } => { Commands::Run { name, server } => {
daemon::daemon_main(name, server); daemon::daemon_main(name, server);
@ -121,12 +110,4 @@ fn main() {
}; };
} }
} }
} }
fn print_version() {
println!(
"tfclient v{} linked to trifid-pki v{}",
env!("CARGO_PKG_VERSION"),
trifid_pki::TRIFID_PKI_VERSION
);
}