initial import
This commit is contained in:
commit
4b560fe790
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
/target
|
||||
/Cargo.lock
|
7
Cargo.toml
Normal file
7
Cargo.toml
Normal file
|
@ -0,0 +1,7 @@
|
|||
[package]
|
||||
name = "zephyr-config"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[build-dependencies]
|
||||
bindgen = "0.69.1"
|
42
build.rs
Normal file
42
build.rs
Normal file
|
@ -0,0 +1,42 @@
|
|||
extern crate bindgen;
|
||||
|
||||
use std::{env, path::PathBuf};
|
||||
|
||||
fn main() {
|
||||
let zephyr_sdk_install_dir = PathBuf::from(env::var("ZEPHYR_SDK_INSTALL_DIR").unwrap());
|
||||
|
||||
let bindings = bindgen::Builder::default()
|
||||
// Only use core, as we are in embedded land
|
||||
.use_core()
|
||||
// The input header we would like to generate
|
||||
// bindings for.
|
||||
.header("src/wrapper.h")
|
||||
.clang_args(
|
||||
env::var("TARGET_CFLAGS")
|
||||
.unwrap()
|
||||
.split(' ')
|
||||
.filter(|&el| el != "-mfp16-format=ieee" && el != "-fno-reorder-functions"),
|
||||
)
|
||||
.clang_arg(format!(
|
||||
"-I{}",
|
||||
zephyr_sdk_install_dir
|
||||
.join("arm-zephyr-eabi/arm-zephyr-eabi/sys-include")
|
||||
.to_str()
|
||||
.unwrap()
|
||||
))
|
||||
// only allow CONFIG_ defines
|
||||
.allowlist_item("^CONFIG_.*")
|
||||
// Tell cargo to invalidate the built crate whenever any of the
|
||||
// included header files changed.
|
||||
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
|
||||
// Finish the builder and generate the bindings.
|
||||
.generate()
|
||||
// Unwrap the Result and panic on failure.
|
||||
.expect("Unable to generate bindings");
|
||||
|
||||
// Write the bindings to the $OUT_DIR/bindings.rs file.
|
||||
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
|
||||
bindings
|
||||
.write_to_file(out_path.join("bindings.rs"))
|
||||
.expect("Couldn't write bindings!");
|
||||
}
|
13
src/lib.rs
Normal file
13
src/lib.rs
Normal file
|
@ -0,0 +1,13 @@
|
|||
#![no_std]
|
||||
#![allow(non_upper_case_globals)]
|
||||
#![allow(non_camel_case_types)]
|
||||
#![allow(non_snake_case)]
|
||||
#![allow(dead_code)]
|
||||
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
|
||||
|
||||
pub fn config_str<'a>(var: &'a [u8]) -> &'a str {
|
||||
core::ffi::CStr::from_bytes_until_nul(var)
|
||||
.unwrap()
|
||||
.to_str()
|
||||
.unwrap()
|
||||
}
|
1
src/wrapper.h
Normal file
1
src/wrapper.h
Normal file
|
@ -0,0 +1 @@
|
|||
#include <autoconf.h>
|
Loading…
Reference in a new issue