Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support customized UDL file. #253

Merged
merged 7 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions cli/src/template/init/build.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
use std::path::Path;

fn main() {
// CIRCOM_TEMPLATE
// This is writing the UDL file which defines the functions exposed
// to your app. We have pre-generated this file for you
// This file must be written to ./src
std::fs::write("./src/mopro.udl", mopro_ffi::app_config::UDL).expect("Failed to write UDL");
// to your app. We have pre-generated this file for you.
// Feel free to modify it to suit your needs.
let udl_path = Path::new("src/mopro.udl");
if !udl_path.exists() {
std::fs::write(udl_path, mopro_ffi::app_config::UDL).expect("Failed to write UDL");
}
// Finally initialize uniffi and build the scaffolding into the
// rust binary
uniffi::generate_scaffolding("./src/mopro.udl").unwrap();
uniffi::generate_scaffolding(udl_path.to_str().unwrap()).unwrap();
}
12 changes: 8 additions & 4 deletions docs/docs/setup/rust-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,29 @@ Now you should copy your wasm and zkey files somewhere in the project folder. Fo
:::info
Download example multiplier2 wasm and zkey here:

- [multiplier2.wasm](https://github.com/zkmopro/mopro/raw/ae88356e680ac4d785183267d6147167fabe071c/test-vectors/circom/multiplier2.wasm)
- [multiplier2_final.zkey](https://github.com/zkmopro/mopro/raw/ae88356e680ac4d785183267d6147167fabe071c/test-vectors/circom/multiplier2_final.zkey)
- [multiplier2.wasm](https://github.com/zkmopro/mopro/raw/ae88356e680ac4d785183267d6147167fabe071c/test-vectors/circom/multiplier2.wasm)
- [multiplier2_final.zkey](https://github.com/zkmopro/mopro/raw/ae88356e680ac4d785183267d6147167fabe071c/test-vectors/circom/multiplier2_final.zkey)

:::

Now we need to add 4 rust files. First we'll add `build.rs` in the main project folder. This file should contain the following:

```rust
use std::path::Path;
fn main() {
// We're going to transpile the wasm witness generators to C
// Change this to where you put your zkeys and wasm files
rust_witness::transpile::transpile_wasm("./test-vectors/circom".to_string());
// This is writing the UDL file which defines the functions exposed
// to your app. We have pre-generated this file for you
// This file must be written to ./src
std::fs::write("./src/mopro.udl", mopro_ffi::app_config::UDL).expect("Failed to write UDL");
let udl_path = Path::new("src/mopro.udl");
if !udl_path.exists() {
std::fs::write(udl_path, mopro_ffi::app_config::UDL).expect("Failed to write UDL");
}
// Finally initialize uniffi and build the scaffolding into the
// rust binary
uniffi::generate_scaffolding("./src/mopro.udl").unwrap();
uniffi::generate_scaffolding(udl_path.to_str().unwrap()).unwrap();
}
```

Expand Down
Loading
Loading