Skip to content

Conversation

@bitwalker
Copy link
Collaborator

@bitwalker bitwalker commented Dec 12, 2025

Bumping the toolchain and Rust edition to pick up some nice changes in latest stable and 2024 edition, as well as to finally be able to get rid of the old hashbrown hack we needed to have in place. I've updated our dependencies as well and removed some unused ones that I found.

The main issue I encountered was that something in how Rust is compiling our programs causes an extra object file for the program to be emitted with some kind of default/stub implementation of the #[alloc_error_handler] required for no-std crates that link against liballoc. The problem is that these stubs have incorrect signatures, and this causes rust-lld to raise an error because it cannot unify the actual implementation defined in liballoc, with the stub implementation. The solution ends up being to define our own #[alloc_error_handler] in the crate itself, but this isn't ideal, as it requires activation of alloc_error_handler feature, which we cannot hide with other boilerplate emitted by our proc-macro infra.

We'll have to try and dig in deeper to understand what is actually going on there, but for now I've simply modified everything with the workaround above.

Note that -Zbuild-std-features=panic_immediate_abort was removed, it is now an actual panic type that can be activated with panic = "immediate-abort" or -Cpanic=immediate-abort. Use in Cargo.toml is still behind a nightly Cargo feature called panic-immediate-abort, but we're emitting -Cpanic=immediate-abort via RUSTFLAGS, so we don't actually need to use it via Cargo anyway.

@greenhat
Copy link
Contributor

There is also https://github.com/0xMiden/project-template that needs to be updated as well.

…_handler

It appears that Rust for the wasm32-* targets now emits a second object
file containing stub definitions for the default #[alloc_error_handler]
that is defined by liballoc/libstd (the implementations are different
depending on whether a crate is #![no_std] or not). The problem is that
the signature of these stubs does not match the signature of the actual
definitions, i.e. it is `fn() -> !` rather than `fn(core::alloc::Layout)
-> !`. Because these stubs are fed to rust-lld, we get conflicting
symbol errors due to the stub definition conflicting with the actual
definition in liballoc.

It isn't clear to me why this second object file is emitted by Rust, nor
why the signature is wrong. My assumption is that it has something to do
with the fact that we're producing a `cdylib` artifact, or perhaps due
to our use of `cargo -Zbuild-std` (more likely), but I wasn't able to
confirm either option.

Regardless, the fix appears to be to ensure that we define our own
`#[alloc_error_handler]` with the correct signature in the crate being
compiled. This ensures that only one definition is present, ours, and
makes the conflict go away. The downside of this (currently), is that it
also requires activation of `#[feature(alloc_error_handler)]`, which
cannot be hidden by our proc-macro machinery that hides boilerplate.

My hope is that we can figure out the actual underlying issue here, or a
fix is shipped in a new nightly and we can make this workaround go away.
When an empty template path was given to `cargo miden new`, it would
generate using a template from a different repo (project-template) than
our other templates (from the rust-templates repo). Local overrides of
the template sources would only work for rust-templates, and would cause
any use of project-template templates to fail with an error.

This fixes up the handling of local template overrides, and allows
overriding both rust-templates and project-template template sources.
@greenhat
Copy link
Contributor

greenhat commented Dec 16, 2025

I reverted 0xMiden/project-template#12 because it breaks the cargo miden new for the released cargo-miden and we have users now. I made 0xMiden/project-template#14 with the same changes instead and added the v0.6 git tag. Then, I made #821 to this branch where I added the git tag to the cargo miden new command. So it fetches the Miden project template from the v0.6 git tag. After we make the next compiler release the 0xMiden/project-template#14 will be safe to merge.

The test_all_templates_and_examples test still fails EDIT: when compiling the integration test in the Miden project template from the 0xMiden/project-template#14 using the cargo-miden from this branch. We need to fix it before merging this PR.

TLDR; merge #821 to this branch, don't merge 0xMiden/project-template#14 yet.

fix: use git tag for new Miden project template (`cargo miden new`)
@bitwalker bitwalker merged commit 9223f1d into next Dec 16, 2025
14 of 15 checks passed
@bitwalker bitwalker deleted the bitwalker/toolchain-1.94 branch December 16, 2025 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants