mirror of
https://github.com/bitwarden/browser
synced 2026-01-03 00:53:23 +00:00
replace swift logic with objc
This commit is contained in:
@@ -1,54 +1,8 @@
|
||||
#[cfg(target_os = "macos")]
|
||||
fn main() {
|
||||
use std::process::Command;
|
||||
|
||||
use glob::glob;
|
||||
|
||||
let out_dir = std::env::var("OUT_DIR").expect("env var OUT_DIR is invalid or not set");
|
||||
|
||||
// Compile Swift files FIRST (generates Bitwarden-Swift.h for browser_access.m)
|
||||
let swift_files: Vec<String> = glob("src/native/**/*.swift")
|
||||
.expect("Failed to read Swift glob pattern")
|
||||
.filter_map(Result::ok)
|
||||
.filter_map(|p| {
|
||||
println!("cargo::rerun-if-changed={}", p.display());
|
||||
p.to_str().map(|s| s.to_string())
|
||||
})
|
||||
.collect();
|
||||
|
||||
if !swift_files.is_empty() {
|
||||
// Compile Swift into a static library
|
||||
let status = Command::new("swiftc")
|
||||
.args([
|
||||
"-emit-library",
|
||||
"-static",
|
||||
"-module-name",
|
||||
"Bitwarden",
|
||||
"-import-objc-header",
|
||||
"src/native/bridging-header.h",
|
||||
"-emit-objc-header-path",
|
||||
&format!("{}/Bitwarden-Swift.h", out_dir),
|
||||
"-o",
|
||||
&format!("{}/libbitwarden_swift.a", out_dir),
|
||||
])
|
||||
.args(&swift_files)
|
||||
.status()
|
||||
.expect("Failed to compile Swift code");
|
||||
|
||||
if !status.success() {
|
||||
panic!("Swift compilation failed");
|
||||
}
|
||||
|
||||
// Tell cargo to link the Swift library
|
||||
println!("cargo:rustc-link-search=native={}", out_dir);
|
||||
println!("cargo:rustc-link-lib=static=bitwarden_swift");
|
||||
|
||||
// Link required Swift/Foundation frameworks
|
||||
println!("cargo:rustc-link-lib=framework=Foundation");
|
||||
println!("cargo:rustc-link-lib=framework=AppKit");
|
||||
}
|
||||
|
||||
// Compile Objective-C files (Bitwarden-Swift.h exists now)
|
||||
// Compile Objective-C files
|
||||
let mut builder = cc::Build::new();
|
||||
|
||||
// Compile all .m files in the src/native directory
|
||||
@@ -59,9 +13,12 @@ fn main() {
|
||||
}
|
||||
|
||||
builder
|
||||
.include(&out_dir) // Add OUT_DIR to include path so Bitwarden-Swift.h can be found
|
||||
.flag("-fobjc-arc") // Enable Auto Reference Counting (ARC)
|
||||
.compile("objc_code");
|
||||
|
||||
// Link required frameworks
|
||||
println!("cargo:rustc-link-lib=framework=Foundation");
|
||||
println!("cargo:rustc-link-lib=framework=AppKit");
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
|
||||
Reference in New Issue
Block a user