From b72b52cc63e4ffd9ae43db59e380a8be7dcbb16c Mon Sep 17 00:00:00 2001 From: Denys Zadorozhnyi Date: Fri, 7 Feb 2025 17:39:18 +0200 Subject: [PATCH 1/3] chore: add fibonacci sequence example --- Cargo.toml | 1 + examples/fibonacci/.gitignore | 1 + examples/fibonacci/Cargo.lock | 38 ++++++++++++++++++++++++++ examples/fibonacci/Cargo.toml | 36 ++++++++++++++++++++++++ examples/fibonacci/README.md | 21 ++++++++++++++ examples/fibonacci/inputs.toml | 2 ++ examples/fibonacci/rust-toolchain.toml | 5 ++++ examples/fibonacci/src/lib.rs | 37 +++++++++++++++++++++++++ 8 files changed, 141 insertions(+) create mode 100644 examples/fibonacci/.gitignore create mode 100644 examples/fibonacci/Cargo.lock create mode 100644 examples/fibonacci/Cargo.toml create mode 100644 examples/fibonacci/README.md create mode 100644 examples/fibonacci/inputs.toml create mode 100644 examples/fibonacci/rust-toolchain.toml create mode 100644 examples/fibonacci/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index 85c2a2ad..598bab76 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,6 +26,7 @@ exclude = [ "tests/rust-apps/fib", "tests/rust-apps-wasm", "cargo-ext/tests/data", + "examples", ] [workspace.package] diff --git a/examples/fibonacci/.gitignore b/examples/fibonacci/.gitignore new file mode 100644 index 00000000..c41cc9e3 --- /dev/null +++ b/examples/fibonacci/.gitignore @@ -0,0 +1 @@ +/target \ No newline at end of file diff --git a/examples/fibonacci/Cargo.lock b/examples/fibonacci/Cargo.lock new file mode 100644 index 00000000..0f6f3b61 --- /dev/null +++ b/examples/fibonacci/Cargo.lock @@ -0,0 +1,38 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "fibonacci" +version = "0.1.0" +dependencies = [ + "miden", +] + +[[package]] +name = "miden" +version = "0.0.7" +source = "git+https://github.com/0xPolygonMiden/compiler#8aa89ff73021253520694904304f99f1f53d4b9a" +dependencies = [ + "miden-base-sys", + "miden-sdk-alloc", + "miden-stdlib-sys", +] + +[[package]] +name = "miden-base-sys" +version = "0.0.7" +source = "git+https://github.com/0xPolygonMiden/compiler#8aa89ff73021253520694904304f99f1f53d4b9a" +dependencies = [ + "miden-stdlib-sys", +] + +[[package]] +name = "miden-sdk-alloc" +version = "0.0.7" +source = "git+https://github.com/0xPolygonMiden/compiler#8aa89ff73021253520694904304f99f1f53d4b9a" + +[[package]] +name = "miden-stdlib-sys" +version = "0.0.7" +source = "git+https://github.com/0xPolygonMiden/compiler#8aa89ff73021253520694904304f99f1f53d4b9a" diff --git a/examples/fibonacci/Cargo.toml b/examples/fibonacci/Cargo.toml new file mode 100644 index 00000000..cc9db5ca --- /dev/null +++ b/examples/fibonacci/Cargo.toml @@ -0,0 +1,36 @@ +[package] +name = "fibonacci" +version = "0.1.0" +edition = "2021" + +[lib] +# Build this crate as a self-contained, C-style dynamic library +# This is required to emit the proper Wasm module type +crate-type = ["cdylib"] + +[dependencies] +# Miden SDK consists of a stdlib (intrinsic functions for VM ops, stdlib functions and types) +# and transaction kernel API for the Miden rollup + +miden = { git = "https://github.com/0xPolygonMiden/compiler" } + + +[profile.release] +# optimize the output for size +opt-level = "z" +# Explicitly disable panic infrastructure on Wasm, as +# there is no proper support for them anyway, and it +# ensures that panics do not pull in a bunch of standard +# library code unintentionally +panic = "abort" + +[profile.dev] +# Explicitly disable panic infrastructure on Wasm, as +# there is no proper support for them anyway, and it +# ensures that panics do not pull in a bunch of standard +# library code unintentionally +panic = "abort" +opt-level = 1 +debug-assertions = false +overflow-checks = false +debug = true diff --git a/examples/fibonacci/README.md b/examples/fibonacci/README.md new file mode 100644 index 00000000..87c44a0f --- /dev/null +++ b/examples/fibonacci/README.md @@ -0,0 +1,21 @@ +# fibonacci + +## Useful commands + +`fibonacci` is built using the [Miden compiler](https://github.com/0xPolygonMiden/compiler). + +`cargo miden` is a `cargo` cargo extension. Check out its [documentation](https://0xpolygonmiden.github.io/compiler/usage/cargo-miden/#compiling-to-miden-assembly) +for more details on how to build and run the compiled programs. + +## Compile + +```bash +cargo miden build --release +``` + +## Run + +```bash +midenc run target/miden/release/fibonacci.masp --inputs inputs.toml +``` + diff --git a/examples/fibonacci/inputs.toml b/examples/fibonacci/inputs.toml new file mode 100644 index 00000000..07b3e8cf --- /dev/null +++ b/examples/fibonacci/inputs.toml @@ -0,0 +1,2 @@ +[inputs] +stack = [25] diff --git a/examples/fibonacci/rust-toolchain.toml b/examples/fibonacci/rust-toolchain.toml new file mode 100644 index 00000000..6f66019d --- /dev/null +++ b/examples/fibonacci/rust-toolchain.toml @@ -0,0 +1,5 @@ +[toolchain] +channel = "nightly-2025-01-16" +components = ["rustfmt", "rust-src"] +targets = ["wasm32-wasi"] +profile = "minimal" diff --git a/examples/fibonacci/src/lib.rs b/examples/fibonacci/src/lib.rs new file mode 100644 index 00000000..f3436a91 --- /dev/null +++ b/examples/fibonacci/src/lib.rs @@ -0,0 +1,37 @@ +// Do not link against libstd (i.e. anything defined in `std::`) +#![no_std] + +// However, we could still use some standard library types while +// remaining no-std compatible, if we uncommented the following lines: +// +// extern crate alloc; +// use alloc::vec::Vec; + +// // Global allocator to use heap memory in no-std environment +// #[global_allocator] +// static ALLOC: BumpAlloc = miden::BumpAlloc::new(); + +// Required for no-std crates +#[panic_handler] +fn my_panic(_info: &core::panic::PanicInfo) -> ! { + loop {} +} + +// Pass up to 16 u32 inputs as entrypoint function parameters. +// The output is temporarely limited to 1 u32 value +// +// NOTE: +// The name of the entrypoint function is expected to be `entrypoint`. Do not remove the +// `#[no_mangle]` attribute, otherwise, the rustc will mangle the name and it'll not be recognized +// by the Miden compiler. +#[no_mangle] +pub fn entrypoint(n: u32) -> u32 { + let mut a = 0; + let mut b = 1; + for _ in 0..n { + let c = a + b; + a = b; + b = c; + } + a +} From 481120d0f3e93fa5917282e0526c1a9a80160744 Mon Sep 17 00:00:00 2001 From: Denys Zadorozhnyi Date: Mon, 10 Feb 2025 09:42:59 +0200 Subject: [PATCH 2/3] test: add the integration test for `examples/fibonacci`, remove `fib` test in `apps` integration tests --- Cargo.lock | 5 -- tests/integration/Cargo.toml | 1 - tests/integration/expected/examples/fib.hir | 32 +++++++++ .../expected/{ => examples}/fib.masm | 4 +- .../expected/{ => examples}/fib.wat | 10 +-- tests/integration/expected/fib.hir | 39 ----------- tests/integration/expected/fib_hir2.hir | 40 ----------- tests/integration/expected/fib_hir2.wat | 39 ----------- tests/integration/src/rust_masm_tests/apps.rs | 66 ------------------- .../src/rust_masm_tests/examples.rs | 50 ++++++++++++++ tests/integration/src/rust_masm_tests/mod.rs | 1 + tests/rust-apps-wasm/fib/Cargo.lock | 30 --------- tests/rust-apps-wasm/fib/Cargo.toml | 15 ----- tests/rust-apps-wasm/fib/src/lib.rs | 13 ---- tests/rust-apps/fib/Cargo.lock | 7 -- tests/rust-apps/fib/Cargo.toml | 8 --- tests/rust-apps/fib/src/lib.rs | 13 ---- 17 files changed, 88 insertions(+), 285 deletions(-) create mode 100644 tests/integration/expected/examples/fib.hir rename tests/integration/expected/{ => examples}/fib.masm (89%) rename tests/integration/expected/{ => examples}/fib.wat (69%) delete mode 100644 tests/integration/expected/fib.hir delete mode 100644 tests/integration/expected/fib_hir2.hir delete mode 100644 tests/integration/expected/fib_hir2.wat create mode 100644 tests/integration/src/rust_masm_tests/examples.rs delete mode 100644 tests/rust-apps-wasm/fib/Cargo.lock delete mode 100644 tests/rust-apps-wasm/fib/Cargo.toml delete mode 100644 tests/rust-apps-wasm/fib/src/lib.rs delete mode 100644 tests/rust-apps/fib/Cargo.lock delete mode 100644 tests/rust-apps/fib/Cargo.toml delete mode 100644 tests/rust-apps/fib/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 7ef7eb9a..14145295 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3101,7 +3101,6 @@ dependencies = [ "log", "miden-assembly", "miden-core", - "miden-integration-tests-rust-fib", "miden-package", "miden-processor", "miden-stdlib", @@ -3120,10 +3119,6 @@ dependencies = [ "wasmprinter", ] -[[package]] -name = "miden-integration-tests-rust-fib" -version = "0.0.0" - [[package]] name = "miden-miette" version = "7.1.1" diff --git a/tests/integration/Cargo.toml b/tests/integration/Cargo.toml index deaaa17a..9715e7ba 100644 --- a/tests/integration/Cargo.toml +++ b/tests/integration/Cargo.toml @@ -45,4 +45,3 @@ blake3.workspace = true concat-idents = "1.1" env_logger.workspace = true miden-core.workspace = true -miden-integration-tests-rust-fib = { path = "../rust-apps/fib" } diff --git a/tests/integration/expected/examples/fib.hir b/tests/integration/expected/examples/fib.hir new file mode 100644 index 00000000..210cb9d2 --- /dev/null +++ b/tests/integration/expected/examples/fib.hir @@ -0,0 +1,32 @@ +builtin.component #[name = #root] #[namespace = #root_ns] #[version = 1.0.0] #[visibility = public] { + + builtin.module #[name = #fibonacci] #[visibility = public] { + + builtin.function public @entrypoint(v0: i32) -> i32 { + ^block3(v0: i32): + v2 = hir.constant 0 : i32; + v3 = hir.constant 0 : i32; + v4 = hir.constant 1 : i32; + hir.br block5 v4, v0, v3; + ^block4(v1: i32): + + ^block5(v6: i32, v7: i32, v10: i32): + v8 = hir.constant 0 : i32; + v9 = hir.neq v7, v8 : i1; + hir.cond_br block7, block8 v9; + ^block6(v5: i32): + + ^block7: + v11 = hir.constant -1 : i32; + v12 = hir.add v7, v11 : i32 #[overflow = wrapping]; + v13 = hir.add v10, v6 : i32 #[overflow = wrapping]; + hir.br block5 v13, v12, v6; + ^block8: + hir.ret v10; + }; + builtin.global_variable #[name = #__stack_pointer] #[ty = i32] #[visibility = private] { + + hir.ret_imm #[value = 1048576]; + }; + }; +}; \ No newline at end of file diff --git a/tests/integration/expected/fib.masm b/tests/integration/expected/examples/fib.masm similarity index 89% rename from tests/integration/expected/fib.masm rename to tests/integration/expected/examples/fib.masm index 6096c201..5dd92a94 100644 --- a/tests/integration/expected/fib.masm +++ b/tests/integration/expected/examples/fib.masm @@ -1,6 +1,6 @@ -# mod miden_integration_tests_rust_fib_wasm +# mod fibonacci -export.fib +export.entrypoint push.0 push.1 movup.2 diff --git a/tests/integration/expected/fib.wat b/tests/integration/expected/examples/fib.wat similarity index 69% rename from tests/integration/expected/fib.wat rename to tests/integration/expected/examples/fib.wat index 580653ea..1a30a110 100644 --- a/tests/integration/expected/fib.wat +++ b/tests/integration/expected/examples/fib.wat @@ -1,6 +1,6 @@ -(module $miden_integration_tests_rust_fib_wasm.wasm +(module $fibonacci.wasm (type (;0;) (func (param i32) (result i32))) - (func $fib (;0;) (type 0) (param i32) (result i32) + (func $entrypoint (;0;) (type 0) (param i32) (result i32) (local i32 i32 i32) i32.const 0 local.set 1 @@ -30,10 +30,6 @@ ) (memory (;0;) 16) (global $__stack_pointer (;0;) (mut i32) i32.const 1048576) - (global (;1;) i32 i32.const 1048576) - (global (;2;) i32 i32.const 1048576) (export "memory" (memory 0)) - (export "fib" (func $fib)) - (export "__data_end" (global 1)) - (export "__heap_base" (global 2)) + (export "entrypoint" (func $entrypoint)) ) \ No newline at end of file diff --git a/tests/integration/expected/fib.hir b/tests/integration/expected/fib.hir deleted file mode 100644 index e4d11080..00000000 --- a/tests/integration/expected/fib.hir +++ /dev/null @@ -1,39 +0,0 @@ -(component - ;; Modules - (module #miden_integration_tests_rust_fib_wasm - ;; Constants - (const (id 0) 0x00100000) - - ;; Global Variables - (global (export #__stack_pointer) (id 0) (type i32) (const 0)) - (global (export #gv1) (id 1) (type i32) (const 0)) - (global (export #gv2) (id 2) (type i32) (const 0)) - - ;; Functions - (func (export #fib) (param i32) (result i32) - (block 0 (param v0 i32) - (let (v2 i32) (const.i32 0)) - (let (v3 i32) (const.i32 0)) - (let (v4 i32) (const.i32 1)) - (br (block 2 v4 v0 v3))) - - (block 1 (param v1 i32)) - - (block 2 (param v6 i32) (param v7 i32) (param v9 i32) - (let (v8 i1) (neq v7 0)) - (condbr v8 (block 4) (block 5))) - - (block 3 (param v5 i32)) - - (block 4 - (let (v10 i32) (const.i32 -1)) - (let (v11 i32) (add.wrapping v7 v10)) - (let (v12 i32) (add.wrapping v9 v6)) - (br (block 2 v12 v11 v6))) - - (block 5 - (ret v9)) - ) - ) - -) diff --git a/tests/integration/expected/fib_hir2.hir b/tests/integration/expected/fib_hir2.hir deleted file mode 100644 index 6266e345..00000000 --- a/tests/integration/expected/fib_hir2.hir +++ /dev/null @@ -1,40 +0,0 @@ -builtin.component #[name = #root] #[namespace = #root_ns] #[version = 1.0.0] #[visibility = public] { - - builtin.module #[name = #miden_integration_tests_rust_fib_wasm] #[visibility = public] { - - builtin.function public @fib(v0: i32) -> i32 { - ^block5(v0: i32): - v2 = hir.constant 0 : i32; - v3 = hir.constant 0 : i32; - v4 = hir.constant 1 : i32; - hir.br block7 v4, v0, v3; - ^block6(v1: i32): - - ^block7(v6: i32, v7: i32, v10: i32): - v8 = hir.constant 0 : i32; - v9 = hir.neq v7, v8 : i1; - hir.cond_br block9, block10 v9; - ^block8(v5: i32): - - ^block9: - v11 = hir.constant -1 : i32; - v12 = hir.add v7, v11 : i32 #[overflow = wrapping]; - v13 = hir.add v10, v6 : i32 #[overflow = wrapping]; - hir.br block7 v13, v12, v6; - ^block10: - hir.ret v10; - }; - builtin.global_variable #[name = #__stack_pointer] #[ty = i32] #[visibility = private] { - - hir.ret_imm #[value = 1048576]; - }; - builtin.global_variable #[name = #gv1] #[ty = i32] #[visibility = public] { - - hir.ret_imm #[value = 1048576]; - }; - builtin.global_variable #[name = #gv2] #[ty = i32] #[visibility = public] { - - hir.ret_imm #[value = 1048576]; - }; - }; -}; \ No newline at end of file diff --git a/tests/integration/expected/fib_hir2.wat b/tests/integration/expected/fib_hir2.wat deleted file mode 100644 index 580653ea..00000000 --- a/tests/integration/expected/fib_hir2.wat +++ /dev/null @@ -1,39 +0,0 @@ -(module $miden_integration_tests_rust_fib_wasm.wasm - (type (;0;) (func (param i32) (result i32))) - (func $fib (;0;) (type 0) (param i32) (result i32) - (local i32 i32 i32) - i32.const 0 - local.set 1 - i32.const 1 - local.set 2 - loop (result i32) ;; label = @1 - local.get 2 - local.set 3 - block ;; label = @2 - local.get 0 - br_if 0 (;@2;) - local.get 1 - return - end - local.get 0 - i32.const -1 - i32.add - local.set 0 - local.get 1 - local.get 3 - i32.add - local.set 2 - local.get 3 - local.set 1 - br 0 (;@1;) - end - ) - (memory (;0;) 16) - (global $__stack_pointer (;0;) (mut i32) i32.const 1048576) - (global (;1;) i32 i32.const 1048576) - (global (;2;) i32 i32.const 1048576) - (export "memory" (memory 0)) - (export "fib" (func $fib)) - (export "__data_end" (global 1)) - (export "__heap_base" (global 2)) -) \ No newline at end of file diff --git a/tests/integration/src/rust_masm_tests/apps.rs b/tests/integration/src/rust_masm_tests/apps.rs index 09982f74..da078a8f 100644 --- a/tests/integration/src/rust_masm_tests/apps.rs +++ b/tests/integration/src/rust_masm_tests/apps.rs @@ -8,72 +8,6 @@ use proptest::{prelude::*, test_runner::TestRunner}; use crate::{cargo_proj::project, CompilerTest, CompilerTestBuilder}; -#[test] -fn fib() { - let mut test = - CompilerTest::rust_source_cargo("fib", "miden_integration_tests_rust_fib_wasm", "fib"); - // Test expected compilation artifacts - test.expect_wasm(expect_file!["../../expected/fib.wat"]); - test.expect_ir(expect_file!["../../expected/fib.hir"]); - test.expect_masm(expect_file!["../../expected/fib.masm"]); - // let ir_masm = test.ir_masm_program(); - let package = test.compiled_package(); - - // Run the Rust and compiled MASM code against a bunch of random inputs and compare the results - TestRunner::default() - .run(&(1u32..30), move |a| { - let rust_out = miden_integration_tests_rust_fib::fib(a); - let mut args = Vec::::default(); - PushToStack::try_push(&a, &mut args); - - let exec = Executor::for_package(&package, args, &test.session) - .map_err(|err| TestCaseError::fail(err.to_string()))?; - let output: u32 = exec.execute_into(&package.unwrap_program(), &test.session); - dbg!(output); - prop_assert_eq!(rust_out, output); - // args.reverse(); - // let emul_out: u32 = - // execute_emulator(ir_masm.clone(), &args).first().unwrap().clone().into(); - // prop_assert_eq!(rust_out, emul_out); - Ok(()) - }) - .unwrap(); -} - -#[test] -fn fib_hir2() { - let mut test = CompilerTest::rust_source_cargo("fib", "fib_hir2", "fib"); - let artifact_name = test.artifact_name().to_string(); - test.expect_wasm(expect_file![format!("../../expected/{artifact_name}.wat")]); - test.expect_ir2(expect_file![format!("../../expected/{artifact_name}.hir")]); - - /* - test.expect_masm(expect_file!["../../expected/fib.masm"]); - // let ir_masm = test.ir_masm_program(); - let package = test.compiled_package(); - - // Run the Rust and compiled MASM code against a bunch of random inputs and compare the results - TestRunner::default() - .run(&(1u32..30), move |a| { - let rust_out = miden_integration_tests_rust_fib::fib(a); - let mut args = Vec::::default(); - PushToStack::try_push(&a, &mut args); - - let exec = Executor::for_package(&package, args, &test.session) - .map_err(|err| TestCaseError::fail(err.to_string()))?; - let output: u32 = exec.execute_into(&package.unwrap_program(), &test.session); - dbg!(output); - prop_assert_eq!(rust_out, output); - // args.reverse(); - // let emul_out: u32 = - // execute_emulator(ir_masm.clone(), &args).first().unwrap().clone().into(); - // prop_assert_eq!(rust_out, emul_out); - Ok(()) - }) - .unwrap(); - */ -} - #[test] fn function_call_hir2() { let name = "function_call_hir2"; diff --git a/tests/integration/src/rust_masm_tests/examples.rs b/tests/integration/src/rust_masm_tests/examples.rs new file mode 100644 index 00000000..f6a59648 --- /dev/null +++ b/tests/integration/src/rust_masm_tests/examples.rs @@ -0,0 +1,50 @@ +use std::collections::VecDeque; + +use expect_test::expect_file; +use midenc_debug::{Executor, PopFromStack, PushToStack}; +use midenc_frontend_wasm::WasmTranslationConfig; +use midenc_hir::Felt; +use proptest::{prelude::*, test_runner::TestRunner}; + +use crate::{cargo_proj::project, CompilerTest, CompilerTestBuilder}; + +#[test] +fn fibonacci() { + fn expected_fib(n: u32) -> u32 { + let mut a = 0; + let mut b = 1; + for _ in 0..n { + let c = a + b; + a = b; + b = c; + } + a + } + + let config = WasmTranslationConfig::default(); + let mut test = CompilerTest::rust_source_cargo_miden( + "../../examples/fibonacci", + config, + ["--entrypoint=fibonacci::entrypoint".into()], + ); + test.expect_wasm(expect_file!["../../expected/examples/fib.wat"]); + test.expect_ir2(expect_file!["../../expected/examples/fib.hir"]); + test.expect_masm(expect_file!["../../expected/examples/fib.masm"]); + let package = test.compiled_package(); + + // Run the Rust and compiled MASM code against a bunch of random inputs and compare the results + TestRunner::default() + .run(&(1u32..30), move |a| { + let rust_out = expected_fib(a); + let mut args = Vec::::default(); + PushToStack::try_push(&a, &mut args); + + let exec = Executor::for_package(&package, args, &test.session) + .map_err(|err| TestCaseError::fail(err.to_string()))?; + let output: u32 = exec.execute_into(&package.unwrap_program(), &test.session); + dbg!(output); + prop_assert_eq!(rust_out, output); + Ok(()) + }) + .unwrap(); +} diff --git a/tests/integration/src/rust_masm_tests/mod.rs b/tests/integration/src/rust_masm_tests/mod.rs index 4089cfce..d70297aa 100644 --- a/tests/integration/src/rust_masm_tests/mod.rs +++ b/tests/integration/src/rust_masm_tests/mod.rs @@ -12,6 +12,7 @@ use crate::execute_emulator; mod abi_transform; mod apps; +mod examples; mod instructions; mod intrinsics; mod rust_sdk; diff --git a/tests/rust-apps-wasm/fib/Cargo.lock b/tests/rust-apps-wasm/fib/Cargo.lock deleted file mode 100644 index bc2f3262..00000000 --- a/tests/rust-apps-wasm/fib/Cargo.lock +++ /dev/null @@ -1,30 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "dlmalloc" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "203540e710bfadb90e5e29930baf5d10270cec1f43ab34f46f78b147b2de715a" -dependencies = [ - "libc", -] - -[[package]] -name = "libc" -version = "0.2.149" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" - -[[package]] -name = "miden-integration-tests-rust-fib" -version = "0.0.0" - -[[package]] -name = "miden-integration-tests-rust-fib-wasm" -version = "0.0.0" -dependencies = [ - "dlmalloc", - "miden-integration-tests-rust-fib", -] diff --git a/tests/rust-apps-wasm/fib/Cargo.toml b/tests/rust-apps-wasm/fib/Cargo.toml deleted file mode 100644 index b975b3f1..00000000 --- a/tests/rust-apps-wasm/fib/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "miden-integration-tests-rust-fib-wasm" -version = "0.0.0" -edition = "2021" - -[lib] -crate-type = ["cdylib"] - -[dependencies] -dlmalloc = { version = "0.2.4", features = ["global"] } -miden-integration-tests-rust-fib = { path = "../../rust-apps/fib" } - -[profile.release] -opt-level = "z" -debug = true diff --git a/tests/rust-apps-wasm/fib/src/lib.rs b/tests/rust-apps-wasm/fib/src/lib.rs deleted file mode 100644 index 357025f8..00000000 --- a/tests/rust-apps-wasm/fib/src/lib.rs +++ /dev/null @@ -1,13 +0,0 @@ -#![no_std] - -#[global_allocator] -static A: dlmalloc::GlobalDlmalloc = dlmalloc::GlobalDlmalloc; - -#[panic_handler] -fn my_panic(_info: &core::panic::PanicInfo) -> ! { - loop {} -} - -pub fn fib(n: u32) -> u32 { - miden_integration_tests_rust_fib::fib(n) -} diff --git a/tests/rust-apps/fib/Cargo.lock b/tests/rust-apps/fib/Cargo.lock deleted file mode 100644 index 0f3629b8..00000000 --- a/tests/rust-apps/fib/Cargo.lock +++ /dev/null @@ -1,7 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 4 - -[[package]] -name = "miden-integration-tests-rust-fib" -version = "0.0.0" diff --git a/tests/rust-apps/fib/Cargo.toml b/tests/rust-apps/fib/Cargo.toml deleted file mode 100644 index 8f815bf3..00000000 --- a/tests/rust-apps/fib/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "miden-integration-tests-rust-fib" -version = "0.0.0" -edition = "2021" -publish = false - -[profile.release] -debug = true diff --git a/tests/rust-apps/fib/src/lib.rs b/tests/rust-apps/fib/src/lib.rs deleted file mode 100644 index d63aefa7..00000000 --- a/tests/rust-apps/fib/src/lib.rs +++ /dev/null @@ -1,13 +0,0 @@ -#![no_std] - -#[no_mangle] -pub fn fib(n: u32) -> u32 { - let mut a = 0; - let mut b = 1; - for _ in 0..n { - let c = a + b; - a = b; - b = c; - } - a -} From 8d13fe4fbe72c0667da94a7d96ed6061ef46a690 Mon Sep 17 00:00:00 2001 From: Denys Zadorozhnyi Date: Mon, 10 Feb 2025 14:03:50 +0200 Subject: [PATCH 3/3] docs: link examples in the book --- docs/usage/cargo-miden.md | 6 ++++-- examples/README.md | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 examples/README.md diff --git a/docs/usage/cargo-miden.md b/docs/usage/cargo-miden.md index 2981872d..e1b05f53 100644 --- a/docs/usage/cargo-miden.md +++ b/docs/usage/cargo-miden.md @@ -58,7 +58,7 @@ As there is no panic infrastructure, `panic = "abort"` is set, and the panic han to use the native WebAssembly `unreachable` intrinsic, so the compiler will strip out all of the usual panic formatting code. -### Compiling to Miden package +## Compiling to Miden package Now that you've created your project, compiling it to Miden package is as easy as running the following command from the root of the project directory: @@ -70,7 +70,7 @@ cargo miden build --release This will emit the compiled artifacts to `target/miden/release/foo.masp`. -### Running a compiled Miden VM program +## Running a compiled Miden VM program !!! warning @@ -88,4 +88,6 @@ See `midenc run --help` for the inputs file format. +## Examples +Check out the [examples](https://github.com/0xPolygonMiden/compiler/tree/next/examples) for some `cargo-miden` project examples. diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 00000000..1071c1ba --- /dev/null +++ b/examples/README.md @@ -0,0 +1,6 @@ +# Rust program examples + +These examples are built using `cargo-miden`. + +`cargo miden` is a `cargo` cargo extension. Check out its [documentation](https://0xpolygonmiden.github.io/compiler/usage/cargo-miden/#compiling-to-miden-assembly) +for more details on how to build and run the compiled programs.