Driver compilation Issue

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: ()',
stack backtrace:
0: rust_begin_unwind
at /rustc/04caa632dd10c2bf64b69524c7f9c4c30a436877/library/std/src/
1: core::panicking::panic_fmt
at /rustc/04caa632dd10c2bf64b69524c7f9c4c30a436877/library/core/src/
2: core::option::expect_none_failed
at /rustc/04caa632dd10c2bf64b69524c7f9c4c30a436877/library/core/src/
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/
4: build_script_build::main
at ./
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/
note: Some details are omitted, run with RUST_BACKTRACE=full for a verbose backtrace.

My 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] = &[
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()
.clang_arg(format!("--target={}", target));

let output = String::from_utf8(


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());

builder = builder.header("src/bindgen_helper.h");

builder = builder.whitelist_type(t);
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());
.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?


I don't know if this is what's causing your problem, but these lines


don't execute anything, they just build up a Command and then throw it away. If you want to run the command and ignore its output and exit status you can do

    let _ = Command::new("make")

Please use code blocks instead of quote blocks.

1 Like

Thanks for the reply!

I kept exploring possible causes. Seems like the linux-headers have some files missing.

Anyway, I comment some parts and there is a new error around.

thread 'main' panicked at 'libclang error;
possible causes include:

  • Invalid flag syntax`
  • Unrecognized flags
  • Invalid flag arguments
  • File I/O errors
  • Host vs. target architecture mismatch
    If you encounter an error missing from this list, please file an issue or a PR!

How do I format in code style? Thanks!

It's in the pinned post, on the main page of this forum.

Since the pinned posts have a tendency to disappear after having been marked read, here's a link:

Hi guys!

Well, my problem was fixed changing the clang compiler. Seems like the one that I had installed, was a version that have some kind of conflict. So I'm using clang-11 and this was working fine until today.

Now, without change a thing in my repo, I'm facing this issue:

Finished dev [unoptimized + debuginfo] target(s) in 0.34s
ld -r -o /path/to/my/dir/hello-world/hello_world.rust.o --whole-archive /path/to/my/dir/hello-world/target/x86_64-linux-kernel/debug/libhello_world.a
  LD [M]  /path/to/my/dir/hello-world/helloworld.o
  MODPOST /path/to/my/dir/hello-world/Module.symvers
/path/to/my/dir/hello-world/.hello_world.rust.o.cmd: No such file or directory
make[2]: *** [scripts/Makefile.modpost:111: /path/to/my/dir/hello-world/Module.symvers] Error 1
make[1]: *** [Makefile:1693: modules] Error 2
make[1]: se sale del directorio '/usr/src/linux-headers-5.8.0-43-generic'
make: *** [Makefile:9: all] Error 2

Funny thing is my configuration was working few days ago. And today, it doesn't work anymore.

Some suggestions?

Btw, I updated nightly version. There is a new build from yesteday (2021-02-12). Do you know if this could be the issue?


Seem like a need the file


Just creating it with touch command, works.