Skip to content

Commit

Permalink
Initial swiftpm support
Browse files Browse the repository at this point in the history
  • Loading branch information
junepark678 committed Aug 12, 2024
1 parent 03ad744 commit 464fb69
Showing 1 changed file with 0 additions and 58 deletions.
58 changes: 0 additions & 58 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,62 +28,4 @@ fn main() {

swift_bridge_build::parse_bridges(bridges)
.write_all_concatenated(OUT_DIR, env!("CARGO_PKG_NAME"));

// move the generated headers/Swift out of the crate directory
let crate_dir = format!("{OUT_DIR}{}", env!("CARGO_PKG_NAME"));
for path in std::fs::read_dir(&crate_dir).unwrap() {
let path = path
.unwrap()
.path()
.file_name()
.unwrap()
.to_str()
.unwrap()
.to_string();
std::fs::rename(format!("{crate_dir}/{path}"), format!("{OUT_DIR}{path}")).unwrap();
}
std::fs::remove_dir(crate_dir).unwrap();

for path in std::fs::read_dir(OUT_DIR).unwrap() {
let path = path
.unwrap()
.path()
.file_name()
.unwrap()
.to_str()
.unwrap()
.to_string();
let out_path = format!("{OUT_DIR}{path}");

// remove duplicate lines from minimuxer.h (see https://github.com/chinedufn/swift-bridge/issues/207)
if path.ends_with(&format!("{}.h", env!("CARGO_PKG_NAME"))) {
let input = std::fs::read_to_string(&out_path)
.unwrap()
// sometimes swift-bridge won't add a newline after defintions
.replace(";typedef", ";\ntypedef");
let mut output: Vec<String> = vec![];
for line in input.split('\n') {
let line = line.to_owned();
if !output.contains(&line) || line.is_empty() || line.starts_with("//") {
output.push(line);
}
}
std::fs::write(out_path, output.join("\n")).unwrap();
// Add our custom things to minimuxer.swift
} else if path.ends_with("minimuxer.swift") {
let input = std::fs::read_to_string(&out_path).unwrap();
std::fs::write(
out_path,
format!(
"{input}
// tell Swift the MinimuxerError enum can be thrown
// TODO: do this through swift-bridge instead of manually
extension MinimuxerError: Error {{}}
"
),
)
.unwrap();
}
}
}

0 comments on commit 464fb69

Please sign in to comment.