Skip to content

Commit ff6040d

Browse files
committed
feat: Add asset catalog parsing for apple platforms
1 parent e6386a1 commit ff6040d

File tree

7 files changed

+424
-5
lines changed

7 files changed

+424
-5
lines changed

Cargo.lock

Lines changed: 21 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ version = "2.46.0"
66
edition = "2021"
77
rust-version = "1.86"
88

9+
[build-dependencies]
10+
cc = "1.0"
11+
objc = "0.2"
12+
913
[dependencies]
1014
anylog = "0.6.3"
1115
anyhow = { version = "1.0.69", features = ["backtrace"] }

build.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::error::Error;
33
use std::fs::File;
44
use std::io::Write;
55
use std::path::Path;
6+
use std::process::Command;
67

78
fn main() -> Result<(), Box<dyn Error>> {
89
let out_dir = env::var("OUT_DIR").expect("OUT_DIR is set for build scripts");
@@ -29,5 +30,48 @@ fn main() -> Result<(), Box<dyn Error>> {
2930
writeln!(f, "pub const USER_AGENT: &str = \"sentry-cli/{arch}\";")?;
3031
println!("cargo:rerun-if-changed=build.rs\n");
3132

33+
if platform == "darwin" {
34+
println!("cargo:rerun-if-changed=src/apple/AssetCatalogReader.swift");
35+
println!("cargo:rerun-if-changed=src/apple/safeValueForKey.h");
36+
println!("cargo:rerun-if-changed=src/apple/safeValueForKey.m");
37+
// Compile Objective-C
38+
let status = Command::new("clang")
39+
.args([
40+
"src/apple/safeValueForKey.m",
41+
"-c",
42+
"-o",
43+
"safeValueForKey.o",
44+
"-fobjc-arc",
45+
])
46+
.status()
47+
.expect("Failed to compile Objective-C");
48+
49+
assert!(status.success(), "clang failed");
50+
51+
// Compile Swift and link ObjC
52+
let status = Command::new("swiftc")
53+
.args([
54+
"-emit-library",
55+
"-static",
56+
"-o",
57+
"libswiftbridge.a",
58+
"src/apple/AssetCatalogReader.swift",
59+
"safeValueForKey.o",
60+
"-import-objc-header",
61+
"src/apple/safeValueForKey.h",
62+
])
63+
.status()
64+
.expect("Failed to compile Swift");
65+
66+
assert!(status.success(), "swiftc failed");
67+
68+
println!("cargo:rustc-link-search=native=.");
69+
println!("cargo:rustc-link-lib=static=swiftbridge");
70+
71+
println!("cargo:rustc-link-arg=-F");
72+
println!("cargo:rustc-link-arg=/System/Library/PrivateFrameworks");
73+
println!("cargo:rustc-link-lib=framework=CoreUI");
74+
}
75+
3276
Ok(())
3377
}

0 commit comments

Comments
 (0)