summaryrefslogtreecommitdiff
path: root/sof_sys/generator
diff options
context:
space:
mode:
Diffstat (limited to 'sof_sys/generator')
-rw-r--r--sof_sys/generator/.gitignore1
-rw-r--r--sof_sys/generator/Cargo.toml6
-rw-r--r--sof_sys/generator/README.md1
-rw-r--r--sof_sys/generator/src/main.rs42
-rw-r--r--sof_sys/generator/wrapper.h5
5 files changed, 55 insertions, 0 deletions
diff --git a/sof_sys/generator/.gitignore b/sof_sys/generator/.gitignore
new file mode 100644
index 00000000..03314f77
--- /dev/null
+++ b/sof_sys/generator/.gitignore
@@ -0,0 +1 @@
+Cargo.lock
diff --git a/sof_sys/generator/Cargo.toml b/sof_sys/generator/Cargo.toml
new file mode 100644
index 00000000..672d41da
--- /dev/null
+++ b/sof_sys/generator/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "generator"
+version = "0.1.0"
+authors = ["The Chromium OS Authors"]
+[dependencies]
+bindgen = "0.43.0"
diff --git a/sof_sys/generator/README.md b/sof_sys/generator/README.md
new file mode 100644
index 00000000..3e2ca771
--- /dev/null
+++ b/sof_sys/generator/README.md
@@ -0,0 +1 @@
+Use `cargo run` to generate rust bindings at sof_sys/src/bindings.rs
diff --git a/sof_sys/generator/src/main.rs b/sof_sys/generator/src/main.rs
new file mode 100644
index 00000000..60f0102d
--- /dev/null
+++ b/sof_sys/generator/src/main.rs
@@ -0,0 +1,42 @@
+// Copyright 2020 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+extern crate bindgen;
+
+use std::fs::File;
+use std::io::Write;
+use std::path::PathBuf;
+
+fn main() {
+ let bindings = bindgen::Builder::default()
+ .header("wrapper.h")
+ .derive_debug(false)
+ .clang_arg("-I../../../sound-open-firmware-private/src/include")
+ .whitelist_type("sof_abi_hdr")
+ .whitelist_type("sof_ipc_ctrl_cmd")
+ .generate()
+ .expect("Unable to generate bindings");
+
+ let header = b"// Copyright 2020 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+/*
+ * generated from files in sound-open-firmware-private/src/include:
+ * kernel/header.h
+ * ipc/control.h
+ */
+
+";
+
+ // Write the bindings to the $OUT_DIR/bindings.rs file.
+ let out_path = PathBuf::from("../src").join("bindings.rs");
+
+ let mut output_file =
+ File::create(&out_path).expect(&format!("Couldn't create {:?}", out_path));
+ output_file
+ .write_all(header)
+ .expect("Couldn't write header");
+ output_file
+ .write_all(bindings.to_string().as_bytes())
+ .expect("Couldn't write bindings");
+}
diff --git a/sof_sys/generator/wrapper.h b/sof_sys/generator/wrapper.h
new file mode 100644
index 00000000..5bac0f57
--- /dev/null
+++ b/sof_sys/generator/wrapper.h
@@ -0,0 +1,5 @@
+// Copyright 2021 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+#include <kernel/header.h>
+#include <ipc/control.h>