Skip to content

Commit 8e17918

Browse files
author
Charlie Friend
committed
Rework build script, create cpp-client-telemetry-sys crate
1 parent 736409a commit 8e17918

File tree

8 files changed

+103
-116363
lines changed

8 files changed

+103
-116363
lines changed

wrappers/rust/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[workspace]
22
resolver = "2"
33

4-
members = ["oneds-telemetry", "telemetry-sample"]
4+
members = ["cpp-client-telemetry-sys", "oneds-telemetry", "telemetry-sample"]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "cpp-client-telemetry-sys"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
9+
10+
[build-dependencies]
11+
bindgen = { version = "0.65.1", features = ["experimental"] }
12+
subprocess = "0.2.9"
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
use std::env;
2+
use std::fs;
3+
use std::path::PathBuf;
4+
use subprocess::Exec;
5+
6+
static PROJECT_ROOT: &str = "../../../";
7+
8+
fn write_bindings(header_path: &PathBuf) {
9+
let header_path_string = String::from(header_path.to_string_lossy());
10+
11+
// The bindgen::Builder is the main entry point
12+
// to bindgen, and lets you build up options for
13+
// the resulting bindings.
14+
let bindings = bindgen::Builder::default()
15+
// The input header we would like to generate
16+
// bindings for.
17+
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
18+
.rust_target(bindgen::RustTarget::Stable_1_68)
19+
// .raw_line("#![allow(non_upper_case_globals)]")
20+
// .raw_line("#![allow(non_camel_case_types)]")
21+
// .raw_line("#![allow(non_snake_case)]")
22+
.header(&header_path_string)
23+
.allowlist_file(&header_path_string)
24+
.c_naming(false)
25+
.blocklist_type("struct_IMAGE_TLS_DIRECTORY")
26+
.blocklist_type("struct_PIMAGE_TLS_DIRECTORY")
27+
.blocklist_type("struct_IMAGE_TLS_DIRECTORY64")
28+
.blocklist_type("struct_PIMAGE_TLS_DIRECTORY64")
29+
.blocklist_type("struct__IMAGE_TLS_DIRECTORY64")
30+
.blocklist_type("IMAGE_TLS_DIRECTORY")
31+
.blocklist_type("PIMAGE_TLS_DIRECTORY")
32+
.blocklist_type("IMAGE_TLS_DIRECTORY64")
33+
.blocklist_type("PIMAGE_TLS_DIRECTORY64")
34+
.blocklist_type("_IMAGE_TLS_DIRECTORY64")
35+
.allowlist_type("evt_.*")
36+
.allowlist_function("evt_.*")
37+
.allowlist_var("evt_.*")
38+
.allowlist_recursively(false)
39+
.layout_tests(false)
40+
.merge_extern_blocks(true)
41+
// Tell cargo to invalidate the built crate whenever any of the
42+
// included header files changed.
43+
// .wrap_static_fns(true)
44+
// Finish the builder and generate the bindings.
45+
.generate()
46+
// Unwrap the Result and panic on failure.
47+
.expect("Unable to generate bindings");
48+
49+
// // Write the bindings to the $OUT_DIR/bindings.rs file.
50+
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
51+
bindings
52+
.write_to_file(out_path.join("bindings.rs"))
53+
.expect("Couldn't write bindings!");
54+
}
55+
56+
fn main() {
57+
// Tell cargo to look for shared libraries in the specified directory
58+
println!("cargo:rustc-link-search=../lib");
59+
60+
// TODO use clang crate instead of invoking CLI directly
61+
let header_out = Exec::cmd("clang")
62+
.arg("-E")
63+
.arg(PathBuf::from(PROJECT_ROOT).join("lib/include/public/mat.h"))
64+
.arg("-D")
65+
.arg("HAVE_DYNAMIC_C_LIB")
66+
.capture()
67+
.expect("Failed to open clang process")
68+
.stdout_str();
69+
70+
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
71+
let mat_out_path = out_dir.join("mat.out.h");
72+
73+
fs::write(&mat_out_path, header_out).unwrap();
74+
75+
write_bindings(&mat_out_path);
76+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
pub fn add(left: usize, right: usize) -> usize {
2+
left + right
3+
}
4+
5+
#[cfg(test)]
6+
mod tests {
7+
use super::*;
8+
9+
#[test]
10+
fn it_works() {
11+
let result = add(2, 2);
12+
assert_eq!(result, 4);
13+
}
14+
}

wrappers/rust/include/build-header.cmd

Lines changed: 0 additions & 1 deletion
This file was deleted.

wrappers/rust/include/ctmacros.hpp

Lines changed: 0 additions & 130 deletions
This file was deleted.

0 commit comments

Comments
 (0)