Skip to content

fix: Update proc-macro2 usage for latest nightly#3663

Merged
acheroncrypto merged 8 commits into
otter-sec:masterfrom
cryptopapi997:fix-proc-macro-2
Apr 17, 2025
Merged

fix: Update proc-macro2 usage for latest nightly#3663
acheroncrypto merged 8 commits into
otter-sec:masterfrom
cryptopapi997:fix-proc-macro-2

Conversation

@cryptopapi997
Copy link
Copy Markdown
Contributor

@cryptopapi997 cryptopapi997 commented Apr 16, 2025

As of nightly-2025-04-16, SourceFile and the methods around it don't exist anymore, so anyone updating rust or installing rust won't be able to compile the idl anymore. proc-macro2 already updated, this PR updates anchor accordingly. Note that this will require users to update to the latest nightly (and will break users with an older nightly). Idk if this counts as a breaking change since it only affects nightly...

Fixes #3662

@cryptopapi997 cryptopapi997 changed the title Update proc-macro for latest nightly Update proc-macro2 usage for latest nightly Apr 16, 2025
@cryptopapi997 cryptopapi997 changed the title Update proc-macro2 usage for latest nightly Update proc-macro2 usage for latest nightly Apr 16, 2025
@cryptopapi997 cryptopapi997 changed the title Update proc-macro2 usage for latest nightly fix: Update proc-macro2 usage for latest nightly Apr 16, 2025
Comment thread lang/syn/src/idl/defined.rs Outdated
@tobaccorico
Copy link
Copy Markdown

as far as I can tell it also affects stable, not only nightly (at least on my local build)

@kingmanas
Copy link
Copy Markdown

Replace the respective error line with

📁 File:

defined.rs

📝 Line 499:

let source_path = proc_macro2::Span::call_site().file();

@Rayato159
Copy link
Copy Markdown

I'm facing this problem too even though I use stable version of rustc.

@RealAyyo
Copy link
Copy Markdown

RealAyyo commented Apr 16, 2025

same. Not only nightly

@acheroncrypto acheroncrypto added idl related to the IDL, either program or client side fix Bug fix PR labels Apr 16, 2025
Copy link
Copy Markdown
Collaborator

@acheroncrypto acheroncrypto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick fix.

We're also planning to make the IDL generation use the stable compiler by default and make code that required nightly optional via a CLI flag to avoid issues like this one. It sounds like these methods will be stabilized (as mentioned in rust-lang/rust#139671), so we might be able to avoid nightly completely when that happens.

Related: There is an open issue (rust-lang/rust#139903) regarding the naming of local_file.

Comment thread lang/syn/src/idl/defined.rs Outdated
@hryer
Copy link
Copy Markdown

hryer commented Apr 16, 2025

Is anything that I can help maybe?, I need this fix ASAP. Also, I want to tell the CI failed

no method named `source_file` found for struct `proc_macro2::Span` in the current scope
   --> /home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/anchor-syn-0.31.0/src/idl/defined.rs:499:66
    |
499 |                 let source_path = proc_macro2::Span::call_site().source_file().path();
    |                                                                  ^^^^^^^^^^^ method not found in `Span`

@jacobcreech
Copy link
Copy Markdown
Collaborator

@hryer we're waiting on the update and I'll check into the CI

@andreisilviudragnea
Copy link
Copy Markdown
Contributor

Hello. Is this going to be released as a hotfix for Anchor v0.31.0?

@quanghuynguyen1902
Copy link
Copy Markdown

Please fix it ASAP.

@moribus-single
Copy link
Copy Markdown

having the same issue
even in the new empty anchor project

@tobaccorico
Copy link
Copy Markdown

having the same issue even in the new empty anchor project

this is the temporary fix that worked best for me:
https://solana.stackexchange.com/a/21560/39751

@conceitodigital
Copy link
Copy Markdown

Facing the same issue.

@romeoscript
Copy link
Copy Markdown

source_path

i can't find this file , where would i locate it ?

@iamramtin
Copy link
Copy Markdown

Using anchor build --no-idl works as a temporary workaround (tested on Anchor v0.30.1)

@romeoscript
Copy link
Copy Markdown

Using anchor build --no-idl works as a temporary workaround (tested on Anchor v0.30.1)

so how do i generate IDL for frontend use ?

Copy link
Copy Markdown
Collaborator

@acheroncrypto acheroncrypto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're most likely going to make a patch release for this issue. Thanks for the fix and also responsiveness!

@acheroncrypto acheroncrypto merged commit 54d5396 into otter-sec:master Apr 17, 2025
48 of 52 checks passed
@cryptopapi997 cryptopapi997 deleted the fix-proc-macro-2 branch April 17, 2025 21:32
@adama789
Copy link
Copy Markdown

Hi, how to pull these changes? Will it be released in anchor 0.31.1?

@Vinayapr23
Copy link
Copy Markdown

Vinayapr23 commented Apr 18, 2025

How will these changes be reflected? In anchor 0.31.1 ?
So what to do with current 0.31.0 in the meantime

@stevensanborn
Copy link
Copy Markdown

anchor-cli 0.31.0
rustc 1.88.0-nightly (191df20fc 2025-04-18)
adding to cargo toml worked for me :
proc-macro2 = { version = "1.0.95"}

@tofuwu-dev
Copy link
Copy Markdown

Is it fixed?

@0xJamesBong
Copy link
Copy Markdown

So what's the solution?

@Vinayapr23
Copy link
Copy Markdown

So what's the solution?

Update to anchor 0.31.1 which was released today

@tofuwu-dev
Copy link
Copy Markdown

So what's the solution?

Update to anchor 0.31.1 which was released today

please check the issue, I figured out the issue yesterday but today I am facing a new issue
#3676 (comment)

@0xm4ud
Copy link
Copy Markdown

0xm4ud commented Apr 21, 2025

@hryer this line: let source_path = proc_macro2::Span::call_site().source_file().path();
into this: let source_path = proc_macro2::Span::call_site().file().to_string();

@cryptopapi997
Copy link
Copy Markdown
Contributor Author

For anyone still runing into this issue:

Make sure you're using

  • anchor v0.31.1
  • latest rust nightly
  • proc_macro2 v0.1.95 in your cargo.lock

@rotcan
Copy link
Copy Markdown

rotcan commented Apr 21, 2025

Getting below error while using

  • anchor v0.31.1
  • rust nightly-2025-04-21
  • proc_macro2 v0.1.95

Error

no method named file found for reference &proc_macro::Span in the current scope
|
465 | Span::Compiler(s) => s.file(),
| ^^^^ method not found in &Span

error[E0599]: no method named local_file found for reference &proc_macro::Span in the current scope
|
473 | Span::Compiler(s) => s.local_file(),
| ^^^^^^^^^^ method not found in &Span

@0xm4ud
Copy link
Copy Markdown

0xm4ud commented Apr 21, 2025

@rotcan

Getting below error while using

  • anchor v0.31.1
  • rust nightly-2025-04-21
  • proc_macro2 v0.1.95

Error

no method named file found for reference &proc_macro::Span in the current scope | 465 | Span::Compiler(s) => s.file(), | ^^^^ method not found in &Span

error[E0599]: no method named local_file found for reference &proc_macro::Span in the current scope | 473 | Span::Compiler(s) => s.local_file(), | ^^^^^^^^^^ method not found in &Span

have you tried reverting proc_macro2 v0.1.95 to proc_macro2 v0.1.94?

@rotcan
Copy link
Copy Markdown

rotcan commented Apr 21, 2025

Hi @0xm4ud ,

@rotcan

Getting below error while using

  • anchor v0.31.1
  • rust nightly-2025-04-21
  • proc_macro2 v0.1.95

Error
no method named file found for reference &proc_macro::Span in the current scope | 465 | Span::Compiler(s) => s.file(), | ^^^^ method not found in &Span
error[E0599]: no method named local_file found for reference &proc_macro::Span in the current scope | 473 | Span::Compiler(s) => s.local_file(), | ^^^^^^^^^^ method not found in &Span

have you tried reverting proc_macro2 v0.1.95 to proc_macro2 v0.1.94?

With below configuration

  • anchor v0.31.1
  • rust nightly - 2025-04-21
  • proc_macro2 v0.1.94
  • solana - 2.1.4

I am getting this error

no method named file found for struct proc_macro2::Span in the current scope
--> /.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/anchor-syn-0.31.1/src/idl/defined.rs:501:22
|
500 | let source_path = proc_macro2::Span::call_site()
| ______________-
501 | | .file()
| | -^^^^ method not found in Span
| |
|
|

@0xm4ud
Copy link
Copy Markdown

0xm4ud commented Apr 21, 2025

@rotcan I saw that error this morning. What I did was: cargo update -p proc-macro2, rustup override set 1.81, which solved it for me.
btw I'm not running nightly.

@rotcan
Copy link
Copy Markdown

rotcan commented Apr 21, 2025

@0xm4ud , still getting same error with below setting :(

  • anchor 0.31.1
  • rust- 1.81
  • proc_macro2 v0.1.94
  • solana - 2.1.4

no method named file found for struct proc_macro2::Span in the current scope
--> /.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/anchor-syn-0.31.1/src/idl/defined.rs:501:22
|
500 | let source_path = proc_macro2::Span::call_site()
| ______________-
501 | | .file()
| | -^^^^ method not found in Span
| |
|

@0xm4ud
Copy link
Copy Markdown

0xm4ud commented Apr 21, 2025

@rotcan hmm.. cargo update -p proc-macro2 should've changed/updated your proc-macro2 version, but by your post I see still is 1.94, try removing the lib /proc-macro2-1.0.94/directory and running cargo update -p proc-macro2 again.
Clean the project as well, and cargo clean before building it again.
Updating proc-macro2 v1.0.94 -> v1.0.95

@rotcan
Copy link
Copy Markdown

rotcan commented Apr 21, 2025

@0xm4ud Got it working thanks. I deleted proc-macro2-1.0.94 & 95 directory and anchor-syn-0.31.1 directory in cargo registry. Then ran rustup update.
Following config worked
rustup - 2025-04-21 nightly
anchor - 0.31.1
solana - 2.14.0
proc-macro2 - 1.0.95

@jgur-psyops
Copy link
Copy Markdown

Was confused by people saying you need nightly rust.

You don't need to be using nightly in your workspace, but you DO need to update your nightly because anchor idl generation uses it. Make sure you have run rustup update and your rustc 1.88.0-nightly in the resulting list is up to date. Your toolchain can be 1.81.0 or 1.79 stable without issue.

@el-tumero
Copy link
Copy Markdown

this works for me:

  • anchor - 0.31.1
  • solana - 2.1.0
  • proc-macro2 - 1.0.95
  • rust - 1.81.0

Copy link
Copy Markdown

@Dustin4444 Dustin4444 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otter-0x4ka5h pushed a commit to Otter-0x4ka5h/anchor that referenced this pull request Mar 25, 2026
JonasjJonas added a commit to JonasjJonas/norvia that referenced this pull request Apr 26, 2026
Splits the mint flow into two on-chain instructions to support the Bonsol
callback signing model (where the prover PDA — not the user authority —
signs the mint):

  1. init_lote(): permissionless reservation of LoteAccount, called by
     the client BEFORE submitting the proof request to Bonsol. Binds
     the lote to the expected execution_account PDA derived from the
     execute_v1 args.
  2. mint_from_proof(): refactored to be a true Bonsol callback handler.
     Validates execution_request via vendored handle_callback (key,
     owner=Bonsol, signer, image_id), then populates the pre-reserved
     lote and mints the 3 assets.

Account changes:
- LoteAccount: +execution_account (Pubkey), +is_minted (bool)
- MintFromProof accounts: removed init/payer/authority/system_program,
  added execution_request (UncheckedAccount). 13 -> 9 boxed fields.
- New InitLote accounts struct (cpa, lote, payer, system_program).

Other:
- Add IMAGE_ID_HEX const + #[cfg(test)] cross-validation with IMAGE_ID
- Add MRV_OUTPUT_SIZE / CALLBACK_PAYLOAD_SIZE constants for host-runner
  to construct the callback_instruction_prefix correctly
- New errors: AlreadyMinted, PeriodoMismatch
- Drop orphan helper output_bytes_extract_periodo
- bonsol_callback.rs: silence dead_code warning on input_digest field
  (reserved for future audit-trail use)

Validation:
- cargo build-sbf: clean (~325KB, 9 boxed accounts in MintFromProof)
- cargo test --lib: 3 host-side tests pass

KNOWN ISSUE: anchor test fails to build IDL due to anchor-syn 0.30.1
hard-dependency on proc_macro::SourceFile (removed from rustc) combined
with proc-macro2 1.0.94 unable to compile on modern toolchains. This is
the upstream bug fixed in anchor 0.31.1 (PR otter-sec/anchor#3663),
not backported to 0.30.1. Confirmed unfixable by Rust version pinning:
no Rust version satisfies both edition2024 (cargo deps) and proc_macro::
SourceFile availability simultaneously.

TS tests are deferred to end-to-end devnet integration (Stage 6 of the
hackathon roadmap), where init_lote and the callback path are exercised
against a real Bonsol prover. Plan: stay on Anchor 0.30.1 through the
hackathon submission, evaluate upgrade to 0.31.x post-MVP.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Bug fix PR idl related to the IDL, either program or client side

Projects

None yet

Development

Successfully merging this pull request may close these issues.

error[E0599]: no method named source_file found for struct proc_macro2::Span in the current scope