1
1
use std:: env;
2
+ use std:: fs;
2
3
use std:: path:: PathBuf ;
4
+ use subprocess:: Exec ;
3
5
4
6
static PROJECT_ROOT : & str = "../../../" ;
5
7
8
+ fn copy_static_libs ( ) {
9
+ // TODO add compatibility for x86 and ARM
10
+ let cpp_project_out = PathBuf :: from ( PROJECT_ROOT ) . join ( "Solutions/out/Release/x64" ) ;
11
+ let out_dir = PathBuf :: from ( env:: var ( "OUT_DIR" ) . unwrap ( ) ) ;
12
+
13
+ std:: fs:: copy ( cpp_project_out. join ( "win32-lib/ClientTelemetry.lib" ) , PathBuf :: from ( & out_dir) . join ( "ClientTelemetry.lib" ) )
14
+ . expect ( "Failed to copy ClientTelemetry lib" ) ;
15
+ std:: fs:: copy ( cpp_project_out. join ( "sqlite/sqlite.lib" ) , out_dir. join ( "sqlite.lib" ) )
16
+ . expect ( "Failed to copy sqlite native library" ) ;
17
+ std:: fs:: copy ( cpp_project_out. join ( "zlib/zlib.lib" ) , out_dir. join ( "zlib.lib" ) )
18
+ . expect ( "Failed to copy zlib native library" ) ;
19
+
20
+ // Tell cargo to look for shared libraries in the specified directory
21
+ println ! ( "cargo:rustc-link-search={}" , out_dir. display( ) ) ;
22
+ println ! ( "cargo:rustc-link-lib=ClientTelemetry" ) ;
23
+ println ! ( "cargo:rustc-link-lib=wininet" ) ;
24
+ println ! ( "cargo:rustc-link-lib=crypt32" ) ;
25
+ println ! ( "cargo:rustc-link-lib=sqlite" ) ;
26
+ println ! ( "cargo:rustc-link-lib=zlib" ) ;
27
+ }
28
+
6
29
fn write_bindings ( ) {
30
+ // Precompile header with the appropriate preprocessor options
31
+ let mat_h_location = PathBuf :: from ( PROJECT_ROOT ) . join ( "lib/include/public/mat.h" ) ;
32
+ println ! ( "cargo:rerun-if-changed={}" , mat_h_location. to_string_lossy( ) ) ;
33
+
34
+ // TODO use clang crate instead of invoking CLI directly
35
+ let header_out = Exec :: cmd ( "clang" )
36
+ . arg ( "-E" )
37
+ . arg ( mat_h_location)
38
+ . arg ( "-D" )
39
+ . arg ( "MATSDK_STATIC_LIB=1" )
40
+ . capture ( )
41
+ . expect ( "Failed to open clang process" )
42
+ . stdout_str ( ) ;
43
+
44
+ let out_dir = PathBuf :: from ( env:: var ( "OUT_DIR" ) . unwrap ( ) ) ;
45
+ let mat_out_path = out_dir. join ( "mat.out.h" ) ;
46
+
47
+ fs:: write ( & mat_out_path, header_out) . unwrap ( ) ;
48
+
7
49
// The bindgen::Builder is the main entry point
8
50
// to bindgen, and lets you build up options for
9
51
// the resulting bindings.
@@ -15,17 +57,11 @@ fn write_bindings() {
15
57
// .raw_line("#![allow(non_upper_case_globals)]")
16
58
// .raw_line("#![allow(non_camel_case_types)]")
17
59
// .raw_line("#![allow(non_snake_case)]")
18
- . clang_arg ( format ! ( "-I{}" , PathBuf :: from( PROJECT_ROOT ) . join( "lib/include" ) . display( ) ) )
19
- . header ( "./include/wrapper.hpp" )
20
- //.enable_cxx_namespaces()
21
- . allowlist_type ( "Microsoft::Applications::Events::LogManagerProvider" )
22
- . allowlist_recursively ( true )
23
- // STL types must be marked as 'opaque' as bindgen can't handle the internals of these types.
24
- . opaque_type ( "std::(.*)" )
25
- //.blocklist_function("std::*")
26
- // Tell cargo to invalidate the built crate whenever any of the
27
- // included header files changed.
28
- // .wrap_static_fns(true)
60
+ //.clang_arg(format!("-I{}", PathBuf::from(PROJECT_ROOT).join("lib/include").display()))
61
+ . header ( PathBuf :: from ( out_dir) . join ( "mat.out.h" ) . to_string_lossy ( ) )
62
+ . allowlist_type ( "evt_.*" )
63
+ . allowlist_function ( "evt_.*" )
64
+ . allowlist_var ( "evt_.*" )
29
65
// Finish the builder and generate the bindings.
30
66
. generate ( )
31
67
// Unwrap the Result and panic on failure.
@@ -39,31 +75,6 @@ fn write_bindings() {
39
75
}
40
76
41
77
fn main ( ) {
42
- let mat_h_location = PathBuf :: from ( PROJECT_ROOT ) . join ( "lib/include/public/mat.h" ) ;
43
- println ! ( "cargo:rerun-if-changed={}" , mat_h_location. to_string_lossy( ) ) ;
44
-
45
- let out_dir = env:: var ( "OUT_DIR" ) . unwrap ( ) ;
46
- std:: fs:: copy ( "../lib/ClientTelemetry.lib" , PathBuf :: from ( & out_dir) . join ( "ClientTelemetry.lib" ) )
47
- . expect ( "Failed to copy native ClientTelemetry lib" ) ;
48
-
49
- // Tell cargo to look for shared libraries in the specified directory
50
- println ! ( "cargo:rustc-link-search=native={}" , out_dir) ;
51
- println ! ( "cargo:rustc-link-lib=ClientTelemetry" ) ;
52
-
53
- // // TODO use clang crate instead of invoking CLI directly
54
- // let header_out = Exec::cmd("clang")
55
- // .arg("-E")
56
- // .arg(mat_h_location)
57
- // .arg("-D")
58
- // .arg("HAVE_DYNAMIC_C_LIB")
59
- // .capture()
60
- // .expect("Failed to open clang process")
61
- // .stdout_str();
62
-
63
- // let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
64
- // let mat_out_path = out_dir.join("mat.out.h");
65
-
66
- // fs::write(&mat_out_path, header_out).unwrap();
67
-
68
78
write_bindings ( ) ;
79
+ copy_static_libs ( ) ;
69
80
}
0 commit comments