Skip to content

Commit

Permalink
Generate libbluetooth bindings in OUT_DIR
Browse files Browse the repository at this point in the history
  • Loading branch information
cesmec committed Apr 21, 2024
1 parent d913b0d commit 92bc0c7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 15 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
/target
bindings.rs
16 changes: 2 additions & 14 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
use std::fs::OpenOptions;
use std::io::Write;
use std::path::PathBuf;

fn main() {
let out_path = PathBuf::from("src/native/linux/bindings.rs");

let mut bindings_file = OpenOptions::new()
.create(true)
.write(true)
.truncate(true)
.open(out_path)
.unwrap();

if cfg!(target_os = "linux") {
const HEADER_FILE: &str = "src/native/linux/bluetooth_linux.h";
println!("cargo:rerun-if-changed={HEADER_FILE}");
Expand All @@ -22,10 +11,9 @@ fn main() {
.generate()
.expect("Failed to generate bindings for libbluetooth");

bindings_file.write_all(b"#![allow(warnings)]\n\n").unwrap();

let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());
bindings
.write(Box::new(bindings_file))
.write_to_file(out_dir.join("bindings.rs"))
.expect("Failed to write bindings for libbluetooth");

println!("cargo:rustc-link-lib=bluetooth");
Expand Down
3 changes: 3 additions & 0 deletions src/native/linux/bindings.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#![allow(warnings)]

include!(concat!(env!("OUT_DIR"), "/bindings.rs"));

0 comments on commit 92bc0c7

Please sign in to comment.