Sitelet https://github.com/zkmopro/mopro/commit/f3a1c6546348db33491af69a1d0a702e2dcdf206
Skip to content

Commit f3a1c65

Browse files
authored
fix: remove unused ubrn WASM scaffolding (#727)
* fix: remove unused ubrn WASM scaffolding * correctly formatted rust code
1 parent a2ccb0c commit f3a1c65

3 files changed

Lines changed: 27 additions & 18 deletions

File tree

‎cli/src/build/react_native_noir.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use anyhow::Context;
1818
use mopro_ffi::app_config::android::AndroidBindingsParams;
1919
use mopro_ffi::app_config::constants::Mode;
2020
use mopro_ffi::app_config::project_name_from_toml;
21+
use mopro_ffi::app_config::react_native::remove_unrequested_wasm_stubs;
2122
use std::fs;
2223
use std::path::{Path, PathBuf};
2324
use std::process::Command;
@@ -77,6 +78,8 @@ pub fn build(
7778
bindgen_lib.display()
7879
);
7980
}
81+
82+
remove_unrequested_wasm_stubs(bindings_dir)?;
8083
Ok(())
8184
}
8285

‎cli/src/create/react_native.rs‎

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ use crate::style::print_green_bold;
77

88
use anyhow::{Context, Error, Result};
99
use mopro_ffi::app_config::constants::{REACT_NATIVE_APP_DIR, REACT_NATIVE_BINDINGS_DIR};
10-
use mopro_ffi::app_config::react_native::patch_gradle_properties_architectures;
10+
use mopro_ffi::app_config::react_native::{
11+
patch_gradle_properties_architectures, remove_unrequested_wasm_stubs,
12+
};
1113
use std::{fs, path::PathBuf};
1214

1315
pub struct ReactNative;
@@ -39,7 +41,7 @@ impl Create for ReactNative {
3941
react_native_bindings_dir.as_ref().unwrap(),
4042
&mopro_module_dir,
4143
)?;
42-
remove_stale_web_entrypoint(&mopro_module_dir)?;
44+
remove_unrequested_wasm_stubs(&mopro_module_dir)?;
4345

4446
let assets_dir = target_dir.join("assets/keys");
4547
fs::remove_dir_all(&assets_dir)?;
@@ -87,19 +89,3 @@ impl Create for ReactNative {
8789
print_footer_message();
8890
}
8991
}
90-
91-
/// The downloaded `zkmopro/react-native-app` scaffold ships a static
92-
/// `src/index.web.ts` (for optional web/wasm support) that imports from
93-
/// `./generated/wasm-bindgen/index.js` and `index_bg.wasm`. `mopro build` never
94-
/// generates that `generated/wasm-bindgen` directory — React Native builds only
95-
/// target iOS/Android — so the file is always a dangling reference. Since
96-
/// `copy_dir` only overwrites files present in the built bindings dir, it can't
97-
/// remove this pre-existing one; left in place, it breaks `npm install`'s
98-
/// `prepare: bob build` step (`tsc` fails to resolve the missing module).
99-
fn remove_stale_web_entrypoint(mopro_module_dir: &std::path::Path) -> Result<()> {
100-
let index_web_ts = mopro_module_dir.join("src").join("index.web.ts");
101-
if index_web_ts.exists() {
102-
fs::remove_file(&index_web_ts)?;
103-
}
104-
Ok(())
105-
}

‎mopro-ffi/src/app_config/react_native.rs‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,3 +318,23 @@ pub fn patch_gradle_properties_architectures(
318318
.with_context(|| format!("Failed to patch {:?}", gradle_properties_path))?;
319319
Ok(())
320320
}
321+
322+
/// Remove leftover WASM scaffolding that `uniffi-bindgen-react-native generate all`
323+
/// writes into the React Native bindings dir (`src/index.web.ts` and `rust_modules/wasm/`).
324+
///
325+
/// Mopro's React Native path only targets iOS/Android. `generate all` with no
326+
/// platform still emits ubrn's web templates, but never runs wasm-pack, so
327+
/// `src/generated/wasm-bindgen/` is missing. Left in place, `src/index.web.ts`
328+
/// is a dangling import and `bob build` / `tsc` fails.
329+
pub fn remove_unrequested_wasm_stubs(bindings_dir: &Path) -> anyhow::Result<()> {
330+
let index_web_file = bindings_dir.join("src").join("index.web.ts");
331+
if index_web_file.exists() {
332+
fs::remove_file(&index_web_file)?;
333+
}
334+
335+
let wasm_crate = bindings_dir.join("rust_modules").join("wasm");
336+
if wasm_crate.exists() {
337+
fs::remove_dir_all(&wasm_crate)?;
338+
}
339+
Ok(())
340+
}

0 commit comments

Comments
 (0)