-
Notifications
You must be signed in to change notification settings - Fork 34
Description
The build script uses device-mapper-sys for the dm version detection. The dependency is declared here.
What happens, is that the TARGET is set to the host target - the machine that is used for building. The result is that bindgen in the device-mapper-sys build script uses the hosts dm-ioctl.h header in instead of the one (probably) in the cross toolchain in use. If the headers differ a wrong version is detected. In my case accidently 441 is assumed but the later build fails because a DM_GET_TARGET_VERSION_CMD is missing because during the later cross build TARGET is correct.
I verified with a rustc:warning in the device-mapper-sys build script:
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
use std::{env::var, path::PathBuf};
use bindgen::Builder;
fn main() {
println!("cargo:warning={:?}", std::env::var("TARGET"));
let bindings = Builder::default()
.header("dm-ioctl.h")
.derive_debug(true)
.derive_default(true)
.generate()
.expect("Could not generate bindings");
let mut bindings_path = PathBuf::from(var("OUT_DIR").unwrap());
bindings_path.push("bindings.rs");
bindings
.write_to_file(&bindings_path)
.expect("Could not write bindings to file");
}Then a random cross compile reveals:
# cargo check --target aarch64-linux-android
Checking bitflags v1.3.2
Checking cfg-if v1.0.0
Checking lazy_static v1.4.0
Compiling libc v0.2.137
Compiling serde v1.0.147
Compiling semver v1.0.14
Compiling memoffset v0.6.5
Compiling devicemapper-sys v0.1.3 (/home/felix/devicemapper-rs/devicemapper-rs-sys)
warning: Ok("x86_64-unknown-linux-gnu")
Compiling devicemapper v0.32.2 (/home/felix/devicemapper-rs)
The following warnings were emitted during compilation:
warning: Ok("aarch64-linux-android")
...
A solution must tell the build script in the dependency (device-mapper-sys) that TARGET is something different. This is the classic "build script is not cross compiled problem".