From 40ce3efe3ce4d611eaca585427eba442d9c17084 Mon Sep 17 00:00:00 2001 From: c0repwn3r Date: Wed, 12 Jul 2023 10:32:19 -0400 Subject: [PATCH] dynamically link to provide more options for more platforms --- nebula-ffi/build.rs | 11 ++++++++--- tfclient/src/main.rs | 23 ++--------------------- 2 files changed, 10 insertions(+), 24 deletions(-) diff --git a/nebula-ffi/build.rs b/nebula-ffi/build.rs index fce0147..4f6178c 100644 --- a/nebula-ffi/build.rs +++ b/nebula-ffi/build.rs @@ -1,18 +1,23 @@ use std::env; use std::path::PathBuf; use bindgen::CargoCallbacks; +use gobuild::BuildMode; 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()); 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.sum"); println!("cargo:rerun-if-changed=main.go"); + println!("Generating bindings"); + let bindings = bindgen::Builder::default() .header(out_path.join("libnebulaffi.h").display().to_string()) .parse_callbacks(Box::new(CargoCallbacks)) @@ -23,4 +28,4 @@ fn main() { bindings .write_to_file(out_path.join("bindings.rs")) .expect("Couldn't write bindings!"); -} \ No newline at end of file +} diff --git a/tfclient/src/main.rs b/tfclient/src/main.rs index 51c42a0..cc4a6d6 100644 --- a/tfclient/src/main.rs +++ b/tfclient/src/main.rs @@ -25,19 +25,13 @@ pub mod timerworker; pub mod util; use crate::config::load_config; -use clap::{ArgAction, Parser, Subcommand}; +use clap::{Parser, Subcommand}; use log::{error, info}; use simple_logger::SimpleLogger; #[derive(Parser)] #[command(author = "c0repwn3r", version, about, long_about = None)] -#[clap(disable_version_flag = true)] 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)] subcommand: Commands, } @@ -75,13 +69,8 @@ enum Commands { fn main() { SimpleLogger::new().init().unwrap(); - let args = Cli::parse(); - if args.version { - print_version(); - } - match args.subcommand { Commands::Run { 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 - ); -} +} \ No newline at end of file