File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ [workspace ]
2+ members = [
3+ " hv-sys"
4+ ]
Original file line number Diff line number Diff line change 1+ [package ]
2+ name = " hv-sys"
3+ version = " 0.1.0"
4+ edition = " 2018"
5+ description = " Low level Rust binding for Hypervisor Framework generated with bindgen"
6+
7+ [dependencies ]
8+
9+ [build-dependencies ]
10+ bindgen = " 0.58"
Original file line number Diff line number Diff line change 1+ use std:: env;
2+ use std:: path:: PathBuf ;
3+ use std:: process:: Command ;
4+
5+ fn main ( ) {
6+ let out_path = PathBuf :: from ( env:: var ( "OUT_DIR" ) . unwrap ( ) ) ;
7+
8+ bindgen:: builder ( )
9+ . header ( "wrapper.h" )
10+ . clang_arg ( format ! ( "-F{}/System/Library/Frameworks" , show_sdk_path( ) ) ) // -F<directory> Add framework to the search path
11+ . allowlist_function ( "hv_.*" )
12+ . generate ( )
13+ . expect ( "Failed to generate bindings" )
14+ . write_to_file ( out_path. join ( "bindings.rs" ) )
15+ . expect ( "Failed to write bindings file" ) ;
16+ }
17+
18+ /// Execute `xcrun --sdk macosx --show-sdk-path` to locate MacOS SDK
19+ fn show_sdk_path ( ) -> String {
20+ let output = Command :: new ( "xcrun" )
21+ . arg ( "--sdk" )
22+ . arg ( "macosx" )
23+ . arg ( "--show-sdk-path" )
24+ . output ( )
25+ . expect ( "Failed to execute xcrun" ) ;
26+
27+ if !output. stderr . is_empty ( ) {
28+ panic ! ( "ERROR: {}" , String :: from_utf8( output. stderr) . unwrap( ) ) ;
29+ }
30+
31+ let mut path = output. stdout ;
32+
33+ // Remove new line character ('\n' == 0x0A == 10)
34+ if path. ends_with ( & [ 10 ] ) {
35+ path. swap_remove ( path. len ( ) - 1 ) ;
36+ }
37+
38+ String :: from_utf8 ( path) . unwrap ( )
39+ }
Original file line number Diff line number Diff line change 1+ #![ allow( non_upper_case_globals) ]
2+ #![ allow( non_camel_case_types) ]
3+
4+ include ! ( concat!( env!( "OUT_DIR" ) , "/bindings.rs" ) ) ;
Original file line number Diff line number Diff line change 1+ #include "Hypervisor/hv.h"
2+ #include "Hypervisor/hv_vmx.h"
You can’t perform that action at this time.
0 commit comments