Skip to content

Commit 122586c

Browse files
committed
Merge branch 'commit-generated-bindings'
2 parents df96c5c + 736e785 commit 122586c

File tree

9 files changed

+489
-54
lines changed

9 files changed

+489
-54
lines changed

generate_bindings.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
--blacklist-type "dispatch_queue_[ts]" \
27+
--raw-line "// Generated using:" \
28+
--raw-line "// $BINDGEN_VERSION" \
29+
--raw-line "// macOS SDK $SDK_VERSION." \
30+
--raw-line "" \
31+
--raw-line "use core_foundation_sys::array::CFArrayRef;" \
32+
--raw-line "use core_foundation_sys::base::{Boolean, CFIndex, CFAllocatorRef, CFTypeID};" \
33+
--raw-line "use core_foundation_sys::string::CFStringRef;" \
34+
--raw-line "use core_foundation_sys::dictionary::CFDictionaryRef;" \
35+
--raw-line "use core_foundation_sys::propertylist::CFPropertyListRef;" \
36+
--raw-line "use core_foundation_sys::runloop::CFRunLoopSourceRef;" \
37+
--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 -- \
42+
-I$SDK_PATH/usr/include \
43+
-F$FRAMEWORK_PATH
44+
45+
rustfmt $BINDING_PATH

system-configuration-sys/Cargo.toml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,11 @@
22
name = "system-configuration-sys"
33
version = "0.1.0"
44
authors = ["Mullvad VPN <admin@mullvad.net>", "Linus Färnstrand <linus@mullvad.net>", "Andrej Mihajlov <and@mullvad.net>"]
5-
description = "Low level bindings to System Configuration framework for macOS"
5+
description = "Low level bindings to SystemConfiguration framework for macOS"
66
keywords = ["macos", "system", "configuration", "bindings"]
7-
categories = ["api-bindings", "external-ffi-bindings"]
7+
categories = ["external-ffi-bindings", "os::macos-apis"]
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
}

0 commit comments

Comments
 (0)