Skip to content

Commit 54dfa50

Browse files
committed
Change bindings inclusion
This works around the go to definition feature of rust-analyzer, which otherwise just goes to the `include!` line. When `#[path = concat!(env!(...), ...)]` works (issue rust-lang/rust#87681), we should switch to that.
1 parent 76888db commit 54dfa50

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
/target
33
/Cargo.lock
44
**/*.rs.bk
5+
/src/bindings.rs

sdk_build_support/main.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -369,23 +369,19 @@ pub fn build(build_env: &BuildEnv) -> Result<()> {
369369

370370
// Generate bindings.
371371
let header_file = path_buf![&manifest_dir, "src", "include", "esp-idf", "bindings.h"];
372+
let bindings_file = path_buf![&manifest_dir, "src", "bindings.rs"];
372373
bindgen::builder()
373374
.header(format!("{}", header_file.display()))
374-
.ctypes_prefix("c_types")
375+
.ctypes_prefix("crate::c_types")
375376
.blocklist_function("(_)?strtold(_r)?")
376377
.clang_args(clang_args)
377378
.use_core()
378379
.detect_include_paths(false)
379380
.derive_default(true)
380381
.layout_tests(false)
381-
.raw_line("#![allow(broken_intra_doc_links)]")
382-
.raw_line("#![allow(non_upper_case_globals)]")
383-
.raw_line("#![allow(non_camel_case_types)]")
384-
.raw_line("#![allow(non_snake_case)]")
385-
.raw_line("use crate::c_types;")
386382
.generate()
387383
.or_else(|_| bail!("Failed to generate bindings."))?
388-
.write_to_file(out_dir.join("bindings.rs"))
384+
.write_to_file(bindings_file)
389385
.context("Could not write the generated bindings to file.")?;
390386

391387
// Create archive of all libraries and write linker args to file.

src/lib.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,18 @@ mod alloc;
1010
mod panic;
1111
mod pthread_rwlock;
1212

13+
#[allow(broken_intra_doc_links)]
14+
#[allow(non_upper_case_globals)]
15+
#[allow(non_camel_case_types)]
16+
#[allow(non_snake_case)]
17+
mod bindings;
18+
1319
// ESP-IDF current stable version (4.3) has atomics for ESP32S2, but not for ESP32C3
1420
// The ESP-IDF master branch has atomics for both
1521
#[cfg(all(esp32c3, not(feature = "espidf_master")))]
1622
mod atomics_esp32c3;
1723

24+
pub use bindings::*;
1825
pub use error::*;
1926
pub use mutex::EspMutex;
2027

@@ -54,6 +61,4 @@ pub mod c_types {
5461
pub type c_ulong = u32;
5562
pub type c_longlong = i64;
5663
pub type c_ulonglong = u64;
57-
}
58-
59-
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
64+
}

0 commit comments

Comments
 (0)