Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"[toml]": {
"editor.formatOnSave": false
},
"[markdown]": {
"editor.formatOnSave": false
},
"rust-analyzer.rustfmt.extraArgs": [
"+nightly"
],
"rust-analyzer.check.allTargets": false,
//"rust-analyzer.check.noDefaultFeatures": true,
//"rust-analyzer.cargo.noDefaultFeatures": true,
"rust-analyzer.showUnlinkedFileNotification": false,
// Uncomment the target of your chip.
// "rust-analyzer.cargo.target": "thumbv6m-none-eabi",
//"rust-analyzer.cargo.target": "thumbv7m-none-eabi",
"rust-analyzer.cargo.target": "thumbv7em-none-eabi",
//"rust-analyzer.cargo.target": "thumbv7em-none-eabihf",
// "rust-analyzer.cargo.target": "thumbv8m.main-none-eabihf",
"rust-analyzer.cargo.features": [],
"rust-analyzer.linkedProjects": [
"stm32-bindings-gen/Cargo.toml",
"build/stm32-bindings/Cargo.toml"
],
}
1 change: 1 addition & 0 deletions stm32-bindings-gen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ serde = { version = "1.0.157", features = [ "derive" ] }
serde_json = "1.0.94"
proc-macro2 = "1.0.52"
bindgen = "0.72.1"
tempfile = "3.23.0"
63 changes: 3 additions & 60 deletions stm32-bindings-gen/res/build.rs
Original file line number Diff line number Diff line change
@@ -1,69 +1,12 @@
// use std::env;
// #[cfg(feature = "rt")]
// use std::path::PathBuf;
//
// enum GetOneError {
// None,
// Multiple,
// }
//
// trait IteratorExt: Iterator {
// fn get_one(self) -> Result<Self::Item, GetOneError>;
// }
//
// impl<T: Iterator> IteratorExt for T {
// fn get_one(mut self) -> Result<Self::Item, GetOneError> {
// match self.next() {
// None => Err(GetOneError::None),
// Some(res) => match self.next() {
// Some(_) => Err(GetOneError::Multiple),
// None => Ok(res),
// },
// }
// }
// }
use std::env;
use std::path::PathBuf;

fn main() {
let crate_dir = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap());

println!(
"cargo:rustc-link-search=native={}",
crate_dir.join("src/lib")
crate_dir.join("src/lib").to_str().unwrap()
);
println!("cargo:rustc-link-lib=static=wba_mac_lib");

// #[cfg(feature = "rt")]
// let crate_dir = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap());
//
// let chip_core_name = match env::vars()
// .map(|(a, _)| a)
// .filter(|x| x.starts_with("CARGO_FEATURE_STM32"))
// .get_one()
// {
// Ok(x) => x,
// Err(GetOneError::None) => panic!("No stm32xx Cargo feature enabled"),
// Err(GetOneError::Multiple) => panic!("Multiple stm32xx Cargo features enabled"),
// }
// .strip_prefix("CARGO_FEATURE_")
// .unwrap()
// .to_ascii_lowercase()
// .replace('_', "-");
//
// #[cfg(feature = "rt")]
// println!(
// "cargo:rustc-link-search={}/src/chips/{}",
// crate_dir.display(),
// chip_core_name,
// );
//
// println!(
// "cargo:rustc-env=STM32_METAPAC_PAC_PATH=chips/{}/pac.rs",
// chip_core_name
// );
// println!(
// "cargo:rustc-env=STM32_METAPAC_METADATA_PATH=chips/{}/metadata.rs",
// chip_core_name
// );
//
// println!("cargo:rerun-if-changed=build.rs");
}
1 change: 1 addition & 0 deletions stm32-bindings-gen/res/src/bindings/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod wpan_wba;
13 changes: 1 addition & 12 deletions stm32-bindings-gen/res/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,4 @@
#![allow(non_camel_case_types)]
#![doc(html_no_source)]

mod generated {

mod std {
pub mod os {
pub mod raw {
pub type c_uint = u32;
}
}
}

// core::include!(core::concat!(core::env!("OUT_DIR"), "/bindings.rs"));
}
mod bindings;
36 changes: 35 additions & 1 deletion stm32-bindings-gen/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use std::io::Write;
use std::{fs, path::PathBuf};
use tempfile::NamedTempFile;

pub struct Options {
pub out_dir: PathBuf,
Expand All @@ -15,9 +17,20 @@ impl Gen {
}

pub fn run_gen(&mut self) {
let _ = fs::remove_dir_all(self.opts.out_dir.clone());
fs::create_dir_all(self.opts.out_dir.join("src/bindings")).unwrap();
fs::create_dir_all(self.opts.out_dir.join("src/lib")).unwrap();

// Create a named temporary file
let mut header = NamedTempFile::new().unwrap();

// Write some data to the first handle
header
.write_all(include_bytes!("../inc/wpan-wba.h"))
.unwrap();

header.reopen().unwrap();

// The bindgen::Builder is the main entry point
// to bindgen, and lets you build up options for
// the resulting bindings.
Expand All @@ -34,10 +47,20 @@ impl Gen {
// Unwrap the Result and panic on failure.
.expect("Unable to generate bindings");

let out_path = self.opts.out_dir.join("src/bindings/wpan_wba.rs");

bindings
.write_to_file(self.opts.out_dir.join("src/bindings/wpan-wba.rs"))
.write_to_file(&out_path)
.expect("Couldn't write bindings!");

let file_contents = fs::read_to_string(&out_path).unwrap();
let file_contents = file_contents
.replace("::std::mem::", "::core::mem::")
.replace("::std::os::raw::", "::core::ffi::")
.replace("::std::option::", "::core::option::");

fs::write(&out_path, file_contents).unwrap();

// copy misc files
fs::copy(
self.opts
Expand All @@ -51,6 +74,11 @@ impl Gen {
include_bytes!("../res/README.md"),
)
.unwrap();
fs::write(
self.opts.out_dir.join("Cargo.toml"),
include_bytes!("../res/Cargo.toml"),
)
.unwrap();
fs::write(
self.opts.out_dir.join("build.rs"),
include_bytes!("../res/build.rs"),
Expand All @@ -61,5 +89,11 @@ impl Gen {
include_bytes!("../res/src/lib.rs"),
)
.unwrap();

fs::write(
self.opts.out_dir.join("src/bindings/mod.rs"),
include_bytes!("../res/src/bindings/mod.rs"),
)
.unwrap();
}
}