Skip to content

Conversation

greenhat
Copy link
Contributor

@greenhat greenhat commented Aug 28, 2025

Close #532
Close #531
Close #341

Corresponding template repo PR - 0xMiden/rust-templates#20

Changes in this PR:

  • Add lowering for Rust “linker stubs” (functions whose body is just unreachable) to MASM calls. Stubs are identified by fully qualified MASM symbol names.
  • Remove legacy Wasm CM import rewriting: imports of intrinsics/SDK/stdlib are now expected to flow through linker stubs rather than Wasm CM imports.
  • SDK sys crates: retarget extern link names to canonical MASM symbols. Provide unreachable stubs exporting those symbols; add build.rs to emit small static archives. Allocator now links to intrinsics::mem::heap_base; adds its own unreachable stub + build.rs archive.

Note: I recommend reviewing this PR per commit. Keep in mind that initially I did one big stub library linking in cargo-miden and then moved it to the build.rs in the relevant crates with bindings.

TODO:

  • path the abs path of the rlib in rustc-link-lib=static=[PATH]

@greenhat
Copy link
Contributor Author

@bitwalker I've tried with add_asset as an example. I'm pretty sure it should all work out. Let me know if I missed something.

…g from

the `cargo-miden` to the `miden-stdlib-sys`, `miden-base-sys` and `miden-sdk-alloc` crates build.rs build script.
@greenhat greenhat force-pushed the greenhat/i532-undefined-stub branch from 1688716 to 23a1345 Compare September 5, 2025 11:16
@greenhat greenhat marked this pull request as ready for review September 5, 2025 15:06
@greenhat greenhat requested a review from bitwalker September 5, 2025 15:06
@greenhat greenhat marked this pull request as draft September 8, 2025 15:22
@greenhat
Copy link
Contributor Author

greenhat commented Sep 9, 2025

@bitwalker I've tried putting the absolute path in cargo:rustc-link-lib= and got:

= note: "wasm-component-ld" "-flavor" "wasm" "--export" "miden:counter-contract/[email protected]#get-count" "--export" "miden:counter-contract/[email protected]#increment-count" "-z" "stack-size=1048576" "--stack-first" "--allow-undefined" "--no-demangle" "<2 object files omitted>" "/Users/green/src/miden/compiler/target/wasm32-wasip2/release/deps/{libwit_bindgen_rt-16ff1bd05fdeee75,libmiden-20facf7236ffc3a2,libmiden_sdk_alloc-6d1aad4ffaeee370,libmiden_base-3d0244c6049bc738,libmiden_base_sys-77d5e9ccdd08b24c,libmiden_stdlib_sys-05e41bc6bf31c083,liballoc-183a8ae8f4dddade,libcore-0f8b392b2a22cb35,libcompiler_builtins-bcac1ff194d77167}.rlib" "-l" "wit_bindgen_cabi_realloc0_28_0" "-l" "/Users/green/src/miden/compiler/target/wasm32-wasip2/release/build/miden-base-sys-57d0d33cd85a9b78/out/miden_base_sys_stubs.rlib" "-L" "/Users/green/src/miden/compiler/target/wasm32-wasip2/release/build/miden-stdlib-sys-f0725d73fbde8b3a/out" "-L" "/Users/green/src/miden/compiler/target/wasm32-wasip2/release/build/miden-sdk-alloc-ba2bef2eebd34832/out" "-L" "/Users/green/src/miden/compiler/target/wasm32-wasip2/release/build/wit-bindgen-rt-80618d9455efd17a/out" "-L" "<sysroot>/lib/rustlib/wasm32-wasip2/lib/self-contained" "-o" "/Users/green/src/miden/compiler/target/wasm32-wasip2/release/deps/counter_contract.wasm" "--gc-sections" "--no-entry" "-O2" "--strip-debug"
= note: some arguments are omitted. use --verbose to show all linker arguments
= note: rust-lld: error: unable to find library -l/Users/green/src/miden/compiler/target/wasm32-wasip2/release/build/miden-base-sys-57d0d33cd85a9b78/out/miden_base_sys_stubs.rlib
error: failed to invoke LLD: exit status: 1

Disabling cargo:rustc-link-search=native= does not help. I'm out of ideas.

@greenhat greenhat marked this pull request as ready for review September 9, 2025 06:38
@greenhat
Copy link
Contributor Author

@bitwalker WARNING: When this PR is merged the new miden crate will break the users projects due to the new project templates using miden dependency specifying only git and not version. We need to either do #628 before merging this PR or publish a new version v0.4.2 of the compiler ASAP after we merge it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant