Skip to content

Commit 1356ce1

Browse files
committed
Merge branch 'simplify-bindings'
2 parents a64ade7 + 9f566d1 commit 1356ce1

File tree

7 files changed

+666
-358
lines changed

7 files changed

+666
-358
lines changed

generate_bindings.sh

Lines changed: 94 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,66 @@
22

33
# Always have the latest version of bindgen and rustfmt installed before using this script
44

5+
set -eu
6+
57
export DYLD_LIBRARY_PATH=$(rustc +stable --print sysroot)/lib
68

79
SDK_VERSION=`xcodebuild -sdk macosx -version SDKVersion`
810
SDK_PATH=`xcodebuild -sdk macosx -version Path`
911
FRAMEWORK_PATH="$SDK_PATH/System/Library/Frameworks/"
10-
HEADER_PATH="$FRAMEWORK_PATH/SystemConfiguration.framework/Headers/SCDynamicStore.h"
1112

12-
BINDING_PATH="./system-configuration-sys/src/dynamic_store.rs"
13+
PREFERENCES_HEADER_PATH="$FRAMEWORK_PATH/SystemConfiguration.framework/Headers/SCPreferences.h"
14+
DYNAMIC_STORE_HEADER_PATH="$FRAMEWORK_PATH/SystemConfiguration.framework/Headers/SCDynamicStore.h"
15+
NETWORK_CONFIGURATION_HEADER_PATH="$FRAMEWORK_PATH/SystemConfiguration.framework/Headers/SCNetworkConfiguration.h"
16+
17+
PREFERENCES_BINDING_PATH="./system-configuration-sys/src/preferences.rs"
18+
DYNAMIC_STORE_BINDING_PATH="./system-configuration-sys/src/dynamic_store.rs"
19+
NETWORK_CONFIGURATION_BINDING_PATH="./system-configuration-sys/src/network_configuration.rs"
1320

1421
BINDGEN_VERSION=`bindgen --version`
1522

1623
echo "Using macOS SDK at: $SDK_PATH"
1724
echo "Using $BINDGEN_VERSION"
1825
echo ""
1926

20-
echo "Generating bindings for $HEADER_PATH"
27+
echo "Generating bindings for $PREFERENCES_HEADER_PATH"
28+
bindgen \
29+
--no-doc-comments \
30+
--whitelist-function "SCPreferences.*" \
31+
--blacklist-type "(__)?CF.*" \
32+
--blacklist-type "Boolean" \
33+
--blacklist-type "dispatch_queue_[ts]" \
34+
--blacklist-type "(AuthorizationOpaqueRef|__SCPreferences)" \
35+
--raw-line "// Generated using:" \
36+
--raw-line "// $BINDGEN_VERSION" \
37+
--raw-line "// macOS SDK $SDK_VERSION." \
38+
--raw-line "" \
39+
--raw-line "use core_foundation_sys::array::CFArrayRef;" \
40+
--raw-line "use core_foundation_sys::base::{Boolean, CFIndex, CFAllocatorRef, CFTypeID};" \
41+
--raw-line "use core_foundation_sys::data::CFDataRef;" \
42+
--raw-line "use core_foundation_sys::string::CFStringRef;" \
43+
--raw-line "use core_foundation_sys::propertylist::CFPropertyListRef;" \
44+
--raw-line "use core_foundation_sys::runloop::CFRunLoopRef;" \
45+
--raw-line "" \
46+
--raw-line "use dispatch_queue_t;" \
47+
--raw-line "use libc::c_void;" \
48+
--raw-line "" \
49+
--raw-line "pub type AuthorizationOpaqueRef = c_void;" \
50+
--raw-line "pub type __SCPreferences = c_void;" \
51+
-o $PREFERENCES_BINDING_PATH \
52+
$PREFERENCES_HEADER_PATH -- \
53+
-I$SDK_PATH/usr/include \
54+
-F$FRAMEWORK_PATH
55+
56+
rustfmt $PREFERENCES_BINDING_PATH
57+
58+
echo ""
59+
echo ""
60+
echo "Generating bindings for $DYNAMIC_STORE_HEADER_PATH"
61+
sleep 2
62+
2163
bindgen \
64+
--no-doc-comments \
2265
--whitelist-function "SCDynamicStore.*" \
2366
--whitelist-var "kSCDynamicStore.*" \
2467
--blacklist-type "(__)?CF.*" \
@@ -35,11 +78,54 @@ bindgen \
3578
--raw-line "use core_foundation_sys::propertylist::CFPropertyListRef;" \
3679
--raw-line "use core_foundation_sys::runloop::CFRunLoopSourceRef;" \
3780
--raw-line "" \
38-
--raw-line "/// This is a temporary solution." \
39-
--raw-line "pub type dispatch_queue_t = *mut ::std::os::raw::c_void;" \
40-
-o $BINDING_PATH \
41-
$HEADER_PATH -- \
81+
--raw-line "use dispatch_queue_t;" \
82+
-o $DYNAMIC_STORE_BINDING_PATH \
83+
$DYNAMIC_STORE_HEADER_PATH -- \
84+
-I$SDK_PATH/usr/include \
85+
-F$FRAMEWORK_PATH
86+
87+
rustfmt $DYNAMIC_STORE_BINDING_PATH
88+
89+
echo ""
90+
echo ""
91+
echo "Generating bindings for $NETWORK_CONFIGURATION_HEADER_PATH"
92+
sleep 2
93+
94+
bindgen \
95+
--no-doc-comments \
96+
--whitelist-function "SCNetwork.*" \
97+
--whitelist-function "SCBondInterface.*" \
98+
--whitelist-var "kSC(NetworkInterface|BondStatus).*" \
99+
--blacklist-type "dispatch_queue_[ts]" \
100+
--blacklist-type "(__)?CF.*" \
101+
--blacklist-type "__SC.*" \
102+
--blacklist-type "Boolean" \
103+
--blacklist-type "(sockaddr|socklen_t|sa_family_t|__darwin_socklen_t|__uint.*_t)" \
104+
--blacklist-type "(__)?SCPreferences.*" \
105+
--raw-line "// Generated using:" \
106+
--raw-line "// $BINDGEN_VERSION" \
107+
--raw-line "// macOS SDK $SDK_VERSION." \
108+
--raw-line "" \
109+
--raw-line "use core_foundation_sys::array::CFArrayRef;" \
110+
--raw-line "use core_foundation_sys::base::{Boolean, CFIndex, CFAllocatorRef, CFTypeID};" \
111+
--raw-line "use core_foundation_sys::string::CFStringRef;" \
112+
--raw-line "use core_foundation_sys::dictionary::CFDictionaryRef;" \
113+
--raw-line "use core_foundation_sys::runloop::CFRunLoopRef;" \
114+
--raw-line "" \
115+
--raw-line "use dispatch_queue_t;" \
116+
--raw-line "use libc::{c_void, c_char, c_int, sockaddr};" \
117+
--raw-line "use preferences::SCPreferencesRef;" \
118+
--raw-line "" \
119+
--raw-line "pub type __SCNetworkReachability = c_void;" \
120+
--raw-line "pub type __SCNetworkConnection = c_void;" \
121+
--raw-line "pub type __SCNetworkInterface = c_void;" \
122+
--raw-line "pub type __SCBondStatus = c_void;" \
123+
--raw-line "pub type __SCNetworkProtocol = c_void;" \
124+
--raw-line "pub type __SCNetworkService = c_void;" \
125+
--raw-line "pub type __SCNetworkSet = c_void;" \
126+
-o $NETWORK_CONFIGURATION_BINDING_PATH \
127+
$NETWORK_CONFIGURATION_HEADER_PATH -- \
42128
-I$SDK_PATH/usr/include \
43129
-F$FRAMEWORK_PATH
44130

45-
rustfmt $BINDING_PATH
131+
rustfmt $NETWORK_CONFIGURATION_BINDING_PATH

system-configuration-sys/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ license = "MIT/Apache-2.0"
1010

1111
[dependencies]
1212
core-foundation-sys = "0.5"
13+
libc = "0.2"

0 commit comments

Comments
 (0)