fix cross compilation with cross

This commit is contained in:
core 2023-06-26 23:17:49 -04:00
parent acb956a28d
commit b7ad25b5ec
Signed by: core
GPG Key ID: FDBF740DADDCEECF
5 changed files with 36 additions and 12 deletions

2
Cargo.lock generated
View File

@ -2073,7 +2073,7 @@ dependencies = [
[[package]]
name = "nebula-ffi"
version = "0.1.1"
version = "0.1.2"
dependencies = [
"bindgen",
"gobuild",

18
Cross.toml Normal file
View File

@ -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"]

View File

@ -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"

View File

@ -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))

View File

@ -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"
]