Skip to content

Commit

Permalink
Refactor build.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
chrysn committed Jan 31, 2024
1 parent 0248e7d commit c69e3d4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ riot-rs-core = { version = "< 0.2.0", optional = true }

[build-dependencies]
bindgen = "^0.64"
shlex = "^1.3"
serde_json = "1"
serde = { version = "1", features = [ "derive" ] }
regex = "1"
Expand Down
24 changes: 10 additions & 14 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
extern crate bindgen;
extern crate shlex;

use bindgen::builder;
use std::env;
Expand All @@ -9,9 +8,6 @@ use std::path::PathBuf;
use serde_json::json;

fn main() {
let cc;
let mut cflags;

#[cfg(not(feature = "riot-rs"))]
if env::var("BUILDING_RIOT_RS").is_ok() {
println!("");
Expand Down Expand Up @@ -117,19 +113,19 @@ fn main() {
consensus_cflag_groups = Some(cflag_groups);
}
}
cc = consensus_cc
let cc = consensus_cc
.expect("Entries are present in compile_commands.json")
.to_string();
cflags = shlex::try_join(consensus_cflag_groups.unwrap().iter().flatten().map(|s| *s))
.expect("Input is not expected to contain NUL characters");

println!("cargo:rerun-if-changed=riot-bindgen.h");

let cflags = shlex::split(&cflags).expect("Odd shell escaping in RIOT_CFLAGS");
let cflags: Vec<String> = cflags
.into_iter()
.filter(|x| {
match x.as_ref() {
let cflags: Vec<&str> = consensus_cflag_groups
.unwrap()
.iter()
.flatten()
.map(|v| *v)
.filter(|&x| {
match x {
// These will be in riotbuild.h as well, and better there because bindgen emits
// consts for data from files but not from defines (?)
x if x.starts_with("-D") => false,
Expand Down Expand Up @@ -339,9 +335,9 @@ fn main() {
panic!("riot-sys only accepts clang style CFLAGS. RIOT can produce them using the compile_commands tool even when using a non-clang compiler, such as GCC.");
};

let arguments: Vec<_> = core::iter::once("any-cc".to_string())
let arguments: Vec<_> = core::iter::once("any-cc")
.chain(cflags.into_iter())
.chain(core::iter::once(c2rust_infile.to_string()))
.chain(core::iter::once(c2rust_infile))
.collect();
let compile_commands = json!([{
"arguments": arguments,
Expand Down

0 comments on commit c69e3d4

Please sign in to comment.