cross-platform nebula build process
/ build (push) Successful in 2m0s Details
/ build_x64 (push) Successful in 10m4s Details
/ build_arm64 (push) Successful in 3m47s Details

This commit is contained in:
core 2023-10-09 20:12:44 -04:00
parent 7d1bdf07e0
commit ae990cf977
Signed by: core
GPG Key ID: FDBF740DADDCEECF
2 changed files with 24 additions and 5 deletions

View File

@ -33,7 +33,7 @@ fn main() {
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.args(["build", "-buildmode", link_type().as_str(), "-o", out.display().to_string().as_str(), "main.go"]);
command.env("CGO_ENABLED", "1");
command.env("CC", c_compiler.path());
command.env("GOARCH", goarch());
@ -50,7 +50,7 @@ fn main() {
println!("Go compile success");
println!("cargo:rustc-link-lib=static=nebula");
print_link();
println!("cargo:rustc-link-search=native={}", env::var("OUT_DIR").unwrap());
//let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
@ -63,7 +63,7 @@ fn main() {
println!("Generating bindings");
let bindings = bindgen::Builder::default()
.header(out_path.join("libnebula.h").display().to_string())
.header(out_path.join(LIBRARY_PREFIX.to_owned() + "nebula.h").display().to_string())
.parse_callbacks(Box::new(CargoCallbacks))
.generate()
.expect("Error generating CFFI bindings");
@ -80,7 +80,7 @@ const LIBRARY_EXTENSION: & str = ".a";
const LIBRARY_PREFIX: & str = "lib";
#[cfg(target_family = "windows")]
const LIBRARY_EXTENSION: &str = ".lib";
const LIBRARY_EXTENSION: &str = ".dll";
#[cfg(target_family = "windows")]
const LIBRARY_PREFIX: &str = "";
@ -109,4 +109,21 @@ fn goos() -> String {
"netbsd" => "netbsd",
os => panic!("unsupported operating system {os}")
}.to_string()
}
}
#[cfg(target_family = "unix")]
fn print_link() {
println!("cargo:rustc-link-lib=static=nebula");
}
#[cfg(target_family = "unix")]
fn link_type() -> String {
"c-archive".to_string()
}
#[cfg(target_family = "windows")]
fn print_link() {
println!("cargo:rustc-link-lib=dylib=nebula");
}
#[cfg(target_family = "windows")]
fn link_type() -> String {
"c-shared".to_string()
}

View File

@ -124,6 +124,8 @@ fn handle_client(
) -> Result<(), io::Error> {
info!("Handling connection from {}", stream.peer_addr()?);
stream.set_nonblocking(false)?;
let mut client = Client {
state: ClientState::WaitHello,
reader: BufReader::new(&stream),