From ac21e15d7f1f64fbb6adb692a9548d7063501678 Mon Sep 17 00:00:00 2001 From: chrysn Date: Wed, 31 Jan 2024 14:46:04 +0100 Subject: [PATCH] Stop looking into riot-sys's markers All RIOT versions that did not have the expected values there have long been unsupported. --- build.rs | 77 +++++++++++++++++++++------------------------------- src/gcoap.rs | 10 +------ 2 files changed, 32 insertions(+), 55 deletions(-) diff --git a/build.rs b/build.rs index fd09b133..797561ed 100644 --- a/build.rs +++ b/build.rs @@ -23,58 +23,43 @@ fn main() { } } - let mut bindgen_output_file = None; + let bindgen_output_file = env::var("DEP_RIOT_SYS_BINDGEN_OUTPUT_FILE") + .expect("riot-sys did not provide BINDGEN_OUTPUT_FILE"); - for (key, value) in env::vars() { - if let Some(marker) = key.strip_prefix("DEP_RIOT_SYS_MARKER_") { - println!("cargo:rerun-if-env-changed={}", key); - // It appears that they get uppercased in Cargo -- but should be lower-case as in the - // original riot-sys build.rs, especially to not make the cfg statements look weird. - println!("cargo:rustc-cfg=marker_{}", marker.to_lowercase()); - } - if key == "DEP_RIOT_SYS_BINDGEN_OUTPUT_FILE" { - bindgen_output_file = Some(value); - } - } - - if let Some(bindgen_output_file) = bindgen_output_file { - let bindgen_output = std::fs::read_to_string(bindgen_output_file) - .expect("Failed to read BINDGEN_OUTPUT_FILE"); + let bindgen_output = + std::fs::read_to_string(bindgen_output_file).expect("Failed to read BINDGEN_OUTPUT_FILE"); - const BOOLEAN_FLAGS: &[&str] = &[ - // This decides whether or not some fields are populated ... and unlike with other - // structs, the zeroed default is not a good solution here. (It'd kind of work, but - // it'd produce incorrect debug output). - "CONFIG_AUTO_INIT_ENABLE_DEBUG", - ]; + const BOOLEAN_FLAGS: &[&str] = &[ + // This decides whether or not some fields are populated ... and unlike with other + // structs, the zeroed default is not a good solution here. (It'd kind of work, but + // it'd produce incorrect debug output). + "CONFIG_AUTO_INIT_ENABLE_DEBUG", + ]; - let parsed = syn::parse_file(&bindgen_output).expect("Failed to parse bindgen output"); - for item in &parsed.items { - if let syn::Item::Const(const_) = item { - // It's the easiest way to get something we can `contains`... - let ident = const_.ident.to_string(); - if BOOLEAN_FLAGS.contains(&ident.as_str()) { - if let syn::Expr::Lit(syn::ExprLit { - lit: syn::Lit::Int(litint), - .. - }) = &*const_.expr - { - let value: usize = litint - .base10_parse() - .expect("Identifier is integer literal but not parsable"); - if value != 0 { - println!("cargo:rustc-cfg=marker_{}", ident.to_lowercase()); - } - continue; + let parsed = syn::parse_file(&bindgen_output).expect("Failed to parse bindgen output"); + for item in &parsed.items { + if let syn::Item::Const(const_) = item { + // It's the easiest way to get something we can `contains`... + let ident = const_.ident.to_string(); + if BOOLEAN_FLAGS.contains(&ident.as_str()) { + if let syn::Expr::Lit(syn::ExprLit { + lit: syn::Lit::Int(litint), + .. + }) = &*const_.expr + { + let value: usize = litint + .base10_parse() + .expect("Identifier is integer literal but not parsable"); + if value != 0 { + println!("cargo:rustc-cfg=marker_{}", ident.to_lowercase()); } - panic!( - "Found {} but it's not the literal const it was expected to be", - ident - ); + continue; } + panic!( + "Found {} but it's not the literal const it was expected to be", + ident + ); } } - } else { - println!("cargo:warning=Old riot-sys did not provide BINDGEN_OUTPUT_FILE, assuming it's an old RIOT version"); } } diff --git a/src/gcoap.rs b/src/gcoap.rs index 66188374..c42b1a76 100644 --- a/src/gcoap.rs +++ b/src/gcoap.rs @@ -7,11 +7,6 @@ use riot_sys::{coap_optpos_t, coap_pkt_t, gcoap_listener_t}; use riot_sys::coap_resource_t; -#[cfg(marker_coap_request_ctx_t)] -type HandlerArg4 = riot_sys::coap_request_ctx_t; -#[cfg(not(marker_coap_request_ctx_t))] -type HandlerArg4 = libc::c_void; - /// Give the caller a way of registering Gcoap handlers into the global Gcoap registry inside a /// callback. When the callback terminates, the registered handlers are deregistered again, /// theoretically allowing the registration of non-'static handlers. @@ -177,14 +172,11 @@ where pkt: *mut coap_pkt_t, buf: *mut u8, len: u32, - context: *mut HandlerArg4, + context: *mut riot_sys::coap_request_ctx_t, ) -> i32 { - #[cfg(marker_coap_request_ctx_t)] /* The remaining information in the request_ctx is inaccessible through the CoAP handler * API as it is now */ let h = riot_sys::coap_request_ctx_get_context(context) as *mut H; - #[cfg(not(marker_coap_request_ctx_t))] - let h = context as *mut H; let h = &mut *h; let mut pb = PacketBuffer {