forked from Noxmore/egui_system_theme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
66 lines (53 loc) · 1.97 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#[cfg(not(all(feature = "dynamic-mac-colors", target_os = "macos")))]
fn main() {}
#[cfg(all(feature = "dynamic-mac-colors", target_os = "macos"))]
fn main() {
use std::io::Write;
use std::process::Command;
let _ = std::fs::create_dir("./swift_bridge");
let bridging_header = std::fs::File::create("./swift_bridge/bridging-header.h");
let _ = match bridging_header {
Ok(mut f) => f.write_all(
r#"
#ifndef BRIDGING_HEADER_H
#define BRIDGING_HEADER_H
#import "./SwiftBridgeCore.h"
#import "./egui_system_theme/egui_system_theme.h"
#endif BRIDGING_HEADER_H
"#
.as_bytes(),
),
Err(_) => Ok(()),
};
// 1. Use `swift-bridge-build` to generate Swift/C FFI glue.
// You can also use the `swift-bridge` CLI.
let bridge_files = vec!["src/macos/dynamic.rs"];
swift_bridge_build::parse_bridges(bridge_files)
.write_all_concatenated("./swift_bridge", "egui_system_theme");
// 2. Compile Swift library
let mut cmd = Command::new("swiftc");
cmd.arg("-emit-library")
.arg("-static")
.arg("-module-name")
.arg("swift_colors")
.arg("-import-objc-header")
.arg("./swift_bridge/bridging-header.h")
.arg("./src/macos/colors.swift")
.arg("./swift_bridge/egui_system_theme/egui_system_theme.swift")
.arg("./swift_bridge/SwiftBridgeCore.swift");
if std::env::var("PROFILE").unwrap() == "release" {
cmd.args(["-c", "release"]);
}
// 3. Link to Swift library
println!("cargo:rustc-link-lib=static=swift_colors");
println!("cargo:rustc-link-search=./");
let exit_status = cmd.spawn().unwrap().wait_with_output().unwrap();
assert!(exit_status.status.success(),
r#"
Stderr: {}
Stdout: {}
"#,
String::from_utf8(exit_status.stderr).unwrap(),
String::from_utf8(exit_status.stdout).unwrap(),
);
}