Skip to content

Commit 64a35a1

Browse files
committed
Move bindgen invocation from build.rs to generate_bindings.sh
1 parent df96c5c commit 64a35a1

File tree

5 files changed

+43
-48
lines changed

5 files changed

+43
-48
lines changed

generate_bindings.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env bash
2+
3+
# Always have the latest version of bindgen and rustfmt installed before using this script
4+
5+
export DYLD_LIBRARY_PATH=$(rustc +stable --print sysroot)/lib
6+
7+
SDK_VERSION=`xcodebuild -sdk macosx -version SDKVersion`
8+
SDK_PATH=`xcodebuild -sdk macosx -version Path`
9+
FRAMEWORK_PATH="$SDK_PATH/System/Library/Frameworks/"
10+
HEADER_PATH="$FRAMEWORK_PATH/SystemConfiguration.framework/Headers/SCDynamicStore.h"
11+
12+
BINDING_PATH="./system-configuration-sys/src/dynamic_store.rs"
13+
14+
BINDGEN_VERSION=`bindgen --version`
15+
16+
echo "Using macOS SDK at: $SDK_PATH"
17+
echo "Using $BINDGEN_VERSION"
18+
echo ""
19+
20+
echo "Generating bindings for $HEADER_PATH"
21+
bindgen \
22+
--whitelist-function "SCDynamicStore.*" \
23+
--whitelist-var "kSCDynamicStore.*" \
24+
--blacklist-type "(__)?CF.*" \
25+
--blacklist-type "Boolean" \
26+
--raw-line "// Generated using:" \
27+
--raw-line "// $BINDGEN_VERSION" \
28+
--raw-line "// macOS SDK $SDK_VERSION." \
29+
--raw-line "" \
30+
--raw-line "use core_foundation_sys::array::CFArrayRef;" \
31+
--raw-line "use core_foundation_sys::base::{Boolean, CFIndex, CFAllocatorRef, CFTypeID};" \
32+
--raw-line "use core_foundation_sys::string::CFStringRef;" \
33+
--raw-line "use core_foundation_sys::dictionary::CFDictionaryRef;" \
34+
--raw-line "use core_foundation_sys::propertylist::CFPropertyListRef;" \
35+
--raw-line "use core_foundation_sys::runloop::CFRunLoopSourceRef;" \
36+
-o $BINDING_PATH \
37+
$HEADER_PATH -- \
38+
-I$SDK_PATH/usr/include \
39+
-F$FRAMEWORK_PATH
40+
41+
rustfmt $BINDING_PATH

system-configuration-sys/Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ keywords = ["macos", "system", "configuration", "bindings"]
77
categories = ["api-bindings", "external-ffi-bindings"]
88
repository = "https://github.com/mullvad/system-configuration-rs"
99
license = "MIT/Apache-2.0"
10-
build = "build.rs"
1110

1211
[dependencies]
1312
core-foundation-sys = "0.5"
14-
15-
[build-dependencies]
16-
bindgen = "0.31"

system-configuration-sys/build.rs

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,49 +6,8 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9-
extern crate bindgen;
10-
11-
use std::env;
12-
use std::path::Path;
13-
use std::process::Command;
14-
use std::str;
15-
169
fn main() {
1710
if std::env::var("TARGET").unwrap().contains("-apple") {
1811
println!("cargo:rustc-link-lib=framework=SystemConfiguration");
1912
}
20-
21-
let out_dir = env::var("OUT_DIR").expect("OUT_DIR missing from environment");
22-
let sdk_path = get_macos_sdk_path();
23-
let framework_path = format!("{}/System/Library/Frameworks/", sdk_path);
24-
let sc_header_dir = format!("{}/SystemConfiguration.framework/Headers/", framework_path);
25-
26-
let sc_header_path = format!("{}/SCDynamicStore.h", sc_header_dir);
27-
let _ = bindgen::builder()
28-
.header(sc_header_path)
29-
.clang_arg(format!("-I{}/usr/include", sdk_path))
30-
.clang_arg(format!("-F{}", framework_path))
31-
.whitelist_function("SCDynamicStore.*")
32-
.whitelist_var("kSCDynamicStore.*")
33-
.blacklist_type("(__)?CF.*")
34-
.blacklist_type("Boolean")
35-
.raw_line("use core_foundation_sys::array::CFArrayRef;")
36-
.raw_line("use core_foundation_sys::base::{Boolean, CFIndex, CFAllocatorRef, CFTypeID};")
37-
.raw_line("use core_foundation_sys::string::CFStringRef;")
38-
.raw_line("use core_foundation_sys::dictionary::CFDictionaryRef;")
39-
.raw_line("use core_foundation_sys::propertylist::CFPropertyListRef;")
40-
.raw_line("use core_foundation_sys::runloop::CFRunLoopSourceRef;")
41-
.generate()
42-
.expect("Unable to generate bindings")
43-
.write_to_file(Path::new(&out_dir).join("SCDynamicStore.rs"))
44-
.expect("Unable to write SCDynamicStore.rs");
45-
}
46-
47-
fn get_macos_sdk_path() -> String {
48-
let output = Command::new("xcodebuild")
49-
.args(&["-sdk", "macosx", "Path", "-version"])
50-
.output()
51-
.expect("Unable to get macOS SDK path with \"xcodebuild\"");
52-
let stdout = str::from_utf8(&output.stdout).expect("xcodebuild did not print valid utf-8");
53-
stdout.trim().to_owned()
5413
}

system-configuration-sys/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,4 @@
1212

1313
extern crate core_foundation_sys;
1414

15-
pub mod dynamic_store {
16-
include!(concat!(env!("OUT_DIR"), "/SCDynamicStore.rs"));
17-
}
15+
pub mod dynamic_store;

system-configuration/src/bin/watch_dns.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ fn main() {
3131
.next()
3232
.expect("Give service uuid as first argument");
3333
let service_path = CFString::from(&format!("State:/Network/Service/{}/DNS", service_id)[..]);
34+
println!("Watching {}", service_path);
3435

3536
let watch_keys = CFArray::from_CFTypes(&[service_path.clone()]);
3637
let watch_patterns: CFArray<CFString> = CFArray::from_CFTypes(&[]);

0 commit comments

Comments
 (0)