Skip to content

Commit

Permalink
Fix module map naming
Browse files Browse the repository at this point in the history
  • Loading branch information
alxkzmn committed Nov 25, 2024
1 parent c637be0 commit 0fc77cd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
8 changes: 4 additions & 4 deletions mopro-ffi/src/app_config/android.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub fn build() {

install_ndk();
for arch in target_archs {
build_for_arch(&arch, &build_dir, &bindings_out, &mode);
build_for_arch(arch, &build_dir, &bindings_out, &mode);
}

let uniffi_bindgen_path = {
Expand Down Expand Up @@ -105,11 +105,11 @@ fn build_for_arch(arch: &str, build_dir: &Path, bindings_out: &Path, mode: &str)
}

fn move_bindings(bindings_out: &Path, bindings_dest: &Path) {
if let Ok(info) = fs::metadata(&bindings_dest) {
if let Ok(info) = fs::metadata(bindings_dest) {
if !info.is_dir() {
panic!("bindings directory exists and is not a directory");
}
fs::remove_dir_all(&bindings_dest).expect("Failed to remove bindings directory");
fs::remove_dir_all(bindings_dest).expect("Failed to remove bindings directory");
}
fs::rename(&bindings_out, &bindings_dest).expect("Failed to move bindings into place");
fs::rename(bindings_out, bindings_dest).expect("Failed to move bindings into place");
}
31 changes: 26 additions & 5 deletions mopro-ffi/src/app_config/ios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub fn build() {
std::env::var("CARGO_MANIFEST_DIR").unwrap_or(cwd.to_str().unwrap().to_string());
let build_dir = format!("{}/build", manifest_dir);
let build_dir_path = Path::new(&build_dir);
let work_dir = mktemp_local(&build_dir_path);
let work_dir = mktemp_local(build_dir_path);
let swift_bindings_dir = work_dir.join(Path::new("SwiftBindings"));
let bindings_out = work_dir.join("MoproiOSBindings");
fs::create_dir(&bindings_out).expect("Failed to create bindings out directory");
Expand Down Expand Up @@ -67,7 +67,7 @@ pub fn build() {
}
// now lipo the libraries together
let mut lipo_cmd = Command::new("lipo");
let lib_out = mktemp_local(&build_dir_path).join("libmopro_bindings.a");
let lib_out = mktemp_local(build_dir_path).join("libmopro_bindings.a");
lipo_cmd
.arg("-create")
.arg("-output")
Expand Down Expand Up @@ -111,10 +111,11 @@ pub fn build() {
.expect("uniffi-bindgen errored");

fs::rename(
&swift_bindings_dir.join("mopro.swift"),
&bindings_out.join("mopro.swift"),
swift_bindings_dir.join("mopro.swift"),
bindings_out.join("mopro.swift"),
)
.expect("Failed to move mopro.swift into place");

let out_lib_paths: Vec<PathBuf> = target_archs
.iter()
.map(|v| build_combined_archs(v))
Expand All @@ -136,13 +137,33 @@ pub fn build() {
.unwrap()
.wait()
.unwrap();

// The iOS project expects the module map to be named "module.modulemap",
// but uniffi-bindgen creates "moproFFI.modulemap" by default,
// therefore we need to rename it.
rename_module_map_recursively(&bindings_out);

if let Ok(info) = fs::metadata(&bindings_dest) {
if !info.is_dir() {
panic!("framework directory exists and is not a directory");
}
fs::remove_dir_all(&bindings_dest).expect("Failed to remove framework directory");
}

fs::rename(&bindings_out, &bindings_dest).expect("Failed to move framework into place");
// Copy the mopro.swift file to the output directory
cleanup_tmp_local(&build_dir_path)
cleanup_tmp_local(build_dir_path)
}

fn rename_module_map_recursively(bindings_out: &PathBuf) {
for entry in fs::read_dir(bindings_out).expect("Failed to read bindings out directory") {
let entry = entry.expect("Failed to read entry");
let path = entry.path();
if path.is_file() && path.file_name().unwrap() == "moproFFI.modulemap" {
let dest_path = path.with_file_name("module.modulemap");
fs::rename(&path, &dest_path).expect("Failed to rename module map");
} else if path.is_dir() {
rename_module_map_recursively(&path);
}
}
}

0 comments on commit 0fc77cd

Please sign in to comment.