From b7ad25b5eca03344c97d988156fdc294953032dc Mon Sep 17 00:00:00 2001 From: core Date: Mon, 26 Jun 2023 23:17:49 -0400 Subject: [PATCH] fix cross compilation with cross --- Cargo.lock | 2 +- Cross.toml | 18 ++++++++++++++++++ nebula-ffi/Cargo.toml | 4 ++-- nebula-ffi/build.rs | 17 +++++++++++++++-- tfclient/Cargo.toml | 7 ------- 5 files changed, 36 insertions(+), 12 deletions(-) create mode 100644 Cross.toml diff --git a/Cargo.lock b/Cargo.lock index e6b777f..6aa746c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2073,7 +2073,7 @@ dependencies = [ [[package]] name = "nebula-ffi" -version = "0.1.1" +version = "0.1.2" dependencies = [ "bindgen", "gobuild", diff --git a/Cross.toml b/Cross.toml new file mode 100644 index 0000000..d613b0e --- /dev/null +++ b/Cross.toml @@ -0,0 +1,18 @@ +# Cross config +[target.aarch64-unknown-linux-musl] +pre-build = [ + "apt-get update && apt-get install --assume-yes wget && wget https://go.dev/dl/go1.20.5.linux-amd64.tar.gz -O /go.tar.gz && tar -C /usr/local -xzf /go.tar.gz && echo \"export PATH=$PATH:/usr/local/go/bin\" >> /etc/profile && touch /go-installed", +] + +[target.aarch64-unknown-linux-musl.env] +volumes = [] +passthrough = ["GOPATH=/tmp/gopath", "GOCACHE=/tmp/gocache"] + +[target.x86_64-unknown-linux-musl] +pre-build = [ + "apt-get update && apt-get install --assume-yes wget && wget https://go.dev/dl/go1.20.5.linux-amd64.tar.gz -O /go.tar.gz && tar -C /usr/local -xzf /go.tar.gz && echo \"export PATH=$PATH:/usr/local/go/bin\" >> /etc/profile && touch /go-installed", +] + +[target.x86_64-unknown-linux-musl] +volumes = [] +passthrough = ["GOPATH=/tmp/gopath", "GOCACHE=/tmp/gocache"] diff --git a/nebula-ffi/Cargo.toml b/nebula-ffi/Cargo.toml index 739288f..118e73a 100644 --- a/nebula-ffi/Cargo.toml +++ b/nebula-ffi/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "nebula-ffi" -version = "0.1.1" +version = "0.1.3" edition = "2021" description = "A Rust wrapper crate for communicating with Nebula via a CGO FFI." license = "GPL-3.0-or-later" @@ -13,4 +13,4 @@ repository = "https://git.e3t.cc/~core/trifid" [build-dependencies] gobuild = "0.1.0-alpha.2" -bindgen = "0.66.1" \ No newline at end of file +bindgen = "0.66.1" diff --git a/nebula-ffi/build.rs b/nebula-ffi/build.rs index fce0147..d3300a4 100644 --- a/nebula-ffi/build.rs +++ b/nebula-ffi/build.rs @@ -1,9 +1,20 @@ use std::env; use std::path::PathBuf; use bindgen::CargoCallbacks; +use std::path::Path; fn main() { - gobuild::Build::new().file("main.go").compile("nebulaffi"); + // Find compiler: if /usr/local/go/bin/go exists, use that + // otherwise, rely on PATH + let compiler; + if Path::new("/usr/local/go/bin/go").exists() { + println!("Using /usr/local/go/bin/go"); + compiler = "/usr/local/go/bin/go"; + } else { + compiler = "go"; + } + + gobuild::Build::new().compiler(compiler).file("main.go").compile("nebulaffi"); let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); @@ -13,6 +24,8 @@ fn main() { println!("cargo:rerun-if-changed=go.sum"); println!("cargo:rerun-if-changed=main.go"); + println!("Bindgen start"); + let bindings = bindgen::Builder::default() .header(out_path.join("libnebulaffi.h").display().to_string()) .parse_callbacks(Box::new(CargoCallbacks)) @@ -23,4 +36,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/Cargo.toml b/tfclient/Cargo.toml index 43b12fc..605709d 100644 --- a/tfclient/Cargo.toml +++ b/tfclient/Cargo.toml @@ -49,10 +49,3 @@ license-file = "LICENSE.txt" maintainer-scripts = "debian/" systemd-units = { enable = false, unit-name = "tfclient@" } -# Cross config -[target.aarch64-unknown-linux-musl] -pre-build = [ - "wget https://go.dev/dl/go1.20.5.linux-arm64.tar.gz -O /go.tar.gz", - "tar -C /usr/local -xzf /go.tar.gz", - "echo \"export PATH=$PATH:/usr/local/go/bin\" >> /etc/profile" -]