From 151c328ade7df863dbd638f24eb94e3e93b86fba Mon Sep 17 00:00:00 2001 From: Boris Astardzhiev Date: Mon, 6 Jun 2022 11:23:47 +0300 Subject: [PATCH] Pass BINDGEN_TARGET env to instruct what target bindgen is built for. --- libuci-sys/build.rs | 4 ++++ libuci-sys/src/lib.rs | 2 ++ 2 files changed, 6 insertions(+) diff --git a/libuci-sys/build.rs b/libuci-sys/build.rs index 6b75c59..1a8516c 100644 --- a/libuci-sys/build.rs +++ b/libuci-sys/build.rs @@ -17,6 +17,10 @@ fn main() { } let mut builder = bindgen::Builder::default(); + // if BINDGEN_TARGET is set it instructs the target bindgen is built for + if let Ok(bindgen_target) = env::var("BINDGEN_TARGET") { + builder = builder.clang_arg(format!("--target={}", bindgen_target)); + } // if UCI_DIR is present, use it to look for the header file and precompiled libs if let Ok(uci_dir) = env::var("UCI_DIR") { diff --git a/libuci-sys/src/lib.rs b/libuci-sys/src/lib.rs index 7d0b8c3..1894820 100644 --- a/libuci-sys/src/lib.rs +++ b/libuci-sys/src/lib.rs @@ -15,6 +15,8 @@ //! If building inside the OpenWRT SDK with OpenWRT's UCI package set the environment variable //! `UCI_DIR=$(STAGING_DIR)/usr` using the corresponding Makefile. //! rust-uci will automatically use the headers and libraries for the target system. +//! When crosscompiling it may be useful to set BINDGEN_TARGET to instruct what +//! target bindgen is built for. //! //! ## Vendored //!