Hi guys!
I'm new in Rust and in the device drivers in particular. I'm following some examples for a device driver in Rust but I'm facing a problem that cannot understand completely.
This is my error:
thread 'main' panicked at 'Unable to generate bindings: ()', build.rs:86:39
stack backtrace:
0: rust_begin_unwind
at /rustc/04caa632dd10c2bf64b69524c7f9c4c30a436877/library/std/src/panicking.rs:493:5
1: core::panicking::panic_fmt
at /rustc/04caa632dd10c2bf64b69524c7f9c4c30a436877/library/core/src/panicking.rs:92:14
2: core::option::expect_none_failed
at /rustc/04caa632dd10c2bf64b69524c7f9c4c30a436877/library/core/src/option.rs:1300:5
3: core::result::Result<T,E>::expect
at /home/kuni/snap/rustup/common/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/result.rs:997:23
4: build_script_build::main
at ./build.rs:86:20
5: core::ops::function::FnOnce::call_once
at /home/kuni/snap/rustup/common/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:227:5
note: Some details are omitted, run withRUST_BACKTRACE=full
for a verbose backtrace.
My build.rs file is this:
extern crate bindgen;
extern crate cc;
extern crate shlex;use std::env;
use std::path::PathBuf;
use std::process::Command;const INCLUDED_TYPES: &[&str] = &["file_operations", "ctl_table", "spinlock_t", "mutex", "usb_driver", "usb_device_id", "driver_info"];
const INCLUDED_FUNCTIONS: &[&str] = &[
"__register_chrdev",
"__unregister_chrdev",
"_copy_to_user",
"register_sysctl",
"unregister_sysctl_table",
"proc_dointvec_minmax",
"spin_lock",
"usbnet_probe",
"usbnet_disconnect",
"usb_register_driver",
"usb_deregister",
"usbnet_get_endpoints",
"of_get_mac_address",
"skb_pull",
"skb_push",
"skb_trim",
"skb_clone",
"usbnet_skb_return",
"usbnet_read_cmd",
"call_usermodehelper",
"schedule",
//"__purge_module",
//"__rust_delete_module",
];
const INCLUDED_VARS: &[&str] = &["__this_module", "THIS_MODULE"];
fn main() {
let target = env::var("TARGET").unwrap();
println!("Target={}", target);
let mut builder = bindgen::Builder::default()
.use_core()
.ctypes_prefix("c_types")
.no_copy(".*")
.derive_default(true)
.rustfmt_bindings(true)
.clang_arg(format!("--target={}", target));let output = String::from_utf8(
Command::new("make")
.arg("-C")
.arg("kernel-cflags-finder")
.arg("-s")
.output()
.unwrap()
.stdout,
)
.unwrap();Command::new("make")
.arg("-C")
.arg("kernel-cflags-finder")
.arg("clean");println!("get output:{}", output);
// These three arguments are not supported by clang
// output = output.replace("-mapcs", "");
// output = output.replace("-mno-sched-prolog", "");
// output = output.replace("-mno-thumb-interwork", "");for arg in shlex::split(&output).unwrap() {
builder = builder.clang_arg(arg.to_string());
}println!("cargo:rerun-if-changed=src/bindgen_helper.h");
builder = builder.header("src/bindgen_helper.h");for t in INCLUDED_TYPES {
builder = builder.whitelist_type(t);
}
for f in INCLUDED_FUNCTIONS {
builder = builder.whitelist_function(f);
}
for v in INCLUDED_VARS {
builder = builder.whitelist_var(v);
}
let bindings = builder.generate().expect("Unable to generate bindings");let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}
The line tha fails is this
let bindings = builder.generate().expect("Unable to generate bindings");
I'm working on Ubuntu 20.04. Have installed clang, llvm-dev, llvm , libclang-dev, xbuild, nightly toolchain.
Can some help me where to look up in order to understand this error better?
Thanks!