Skip to content

Commit 9860b61

Browse files
committed
Initial Setup
1 parent dee05c0 commit 9860b61

File tree

7 files changed

+131
-1
lines changed

7 files changed

+131
-1
lines changed

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ if [[ $1 == CUSTOM_BUILD_FLAGS* ]] || [[ $2 == CUSTOM_BUILD_FLAGS* ]] || [[ $3 =
4646
fi
4747

4848
LINK_TYPE=
49-
CMAKE_OPTS="${CMAKE_OPTS:--DBUILD_SHARED_LIBS=OFF}"
49+
CMAKE_OPTS="${CMAKE_OPTS:-DBUILD_SHARED_LIBS=OFF}"
5050
while getopts "h?vl:D:" opt; do
5151
case "$opt" in
5252
h|\?)

clean-repo.cmd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
git clean -xd -f

wrappers/rust/.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Generated by Cargo
2+
# will have compiled files and executables
3+
debug/
4+
target/
5+
6+
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
7+
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
8+
Cargo.lock
9+
10+
# These are backup files generated by rustfmt
11+
**/*.rs.bk
12+
13+
# MSVC Windows builds of rustc generate these, which store debugging information
14+
*.pdb

wrappers/rust/Cargo.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "msft-client-telemetry"
3+
version = "0.1.0"
4+
edition = "2021"
5+
publish = false
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
9+
10+
[dev-dependencies]
11+
12+
[build-dependencies]
13+
bindgen = "0.65.1"

wrappers/rust/build.cmd

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@echo off
2+
3+
set VSTOOLS_VERSION=vs2019
4+
cd %~dp0
5+
6+
call ..\..\tools\vcvars.cmd
7+
8+
REM ********************************************************************
9+
REM buildgen + rust
10+
REM ********************************************************************
11+
12+
cargo build

wrappers/rust/build.rs

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
extern crate bindgen;
2+
3+
use std::fmt::format;
4+
use std::fs;
5+
use std::env;
6+
use std::path::PathBuf;
7+
8+
use bindgen::CargoCallbacks;
9+
10+
fn main() {
11+
let rust_wrapper_path = env::current_dir().unwrap();
12+
let libdir_path = rust_wrapper_path
13+
.join("..\\..\\lib")
14+
.canonicalize()
15+
.expect("cannot canonicalize lib path");
16+
17+
// This is the path to the `c` headers file.
18+
let headers_path = libdir_path.join("include\\public");
19+
let headers_path_str = headers_path.to_str().expect("Path is not a valid string");
20+
let c_header_path = libdir_path.join("include\\public\\mat.h");
21+
let c_header_path_str = c_header_path.to_str().expect("Path is not a valid string");
22+
23+
// This is the path to the intermediate object file for our library.
24+
let obj_path = libdir_path.join("mat.o");
25+
// This is the path to the static library file.
26+
let lib_path = libdir_path.join("mat.a");
27+
28+
// Tell cargo to look for shared libraries in the specified directory
29+
// println!("cargo:rustc-link-search={}", libdir_path.to_str().unwrap());
30+
31+
// Tell cargo to tell rustc to link our `hello` library. Cargo will
32+
// automatically know it must look for a `libmat.a` file.
33+
// println!("cargo:rustc-link-lib=mat");
34+
35+
// Tell cargo to invalidate the built crate whenever the header changes.
36+
println!("cargo:rerun-if-changed={}", headers_path_str);
37+
38+
// // Run `clang` to compile the `mat.c` file into a `mat.o` object file.
39+
// // Unwrap if it is not possible to spawn the process.
40+
// if !std::process::Command::new("clang")
41+
// .arg("-c")
42+
// .arg("-o")
43+
// .arg(&obj_path)
44+
// .arg(libdir_path.join("hello.c"))
45+
// .output()
46+
// .expect("could not spawn `clang`")
47+
// .status
48+
// .success()
49+
// {
50+
// // Panic if the command was not successful.
51+
// panic!("could not compile object file");
52+
// }
53+
54+
// // Run `ar` to generate the `libhello.a` file from the `hello.o` file.
55+
// // Unwrap if it is not possible to spawn the process.
56+
// if !std::process::Command::new("ar")
57+
// .arg("rcs")
58+
// .arg(lib_path)
59+
// .arg(obj_path)
60+
// .output()
61+
// .expect("could not spawn `ar`")
62+
// .status
63+
// .success()
64+
// {
65+
// // Panic if the command was not successful.
66+
// panic!("could not emit library file");
67+
// }
68+
69+
// The bindgen::Builder is the main entry point
70+
// to bindgen, and lets you build up options for
71+
// the resulting bindings.
72+
let bindings = bindgen::Builder::default()
73+
// The input header we would like to generate
74+
// bindings for.
75+
.header(c_header_path_str)
76+
.clang_arg(format!("-I{}", headers_path_str))
77+
// Tell cargo to invalidate the built crate whenever any of the
78+
// included header files changed.
79+
.parse_callbacks(Box::new(CargoCallbacks))
80+
// Finish the builder and generate the bindings.
81+
.generate()
82+
// Unwrap the Result and panic on failure.
83+
.expect("Unable to generate bindings");
84+
85+
// Write the bindings to the $OUT_DIR/bindings.rs file.
86+
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()).join("bindings.rs");
87+
bindings
88+
.write_to_file(out_path)
89+
.expect("Couldn't write bindings!");
90+
}

wrappers/rust/src/lib.rs

Whitespace-only changes.

0 commit comments

Comments
 (0)