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

Unsupported proc macro punctuation character while rendering device from svd #863

Closed
Alan-JH opened this issue Oct 8, 2024 · 3 comments · Fixed by #864
Closed

Unsupported proc macro punctuation character while rendering device from svd #863

Alan-JH opened this issue Oct 8, 2024 · 3 comments · Fixed by #864

Comments

@Alan-JH
Copy link

Alan-JH commented Oct 8, 2024

I've been trying to generate crates from svd for S32K3 processors, but svd2rust errors while rendering the device. Here is the command and output:

$ svd2rust -i S32K344_M7.svd
[INFO  svd2rust] Parsing device from SVD file
[INFO  svd2rust] Rendering device
thread 'main' panicked at /home/alan/.cargo/registry/src/index.crates.io-6f17d22bba15001f/proc-macro2-1.0.87/src/lib.rs:847:13:
unsupported proc macro punctuation character '{'
stack backtrace:
   0:     0x56d31bfb10f5 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h1b9dad2a88e955ff
   1:     0x56d31bfd4efb - core::fmt::write::h4b5a1270214bc4a7
   2:     0x56d31bfaef4f - std::io::Write::write_fmt::hd04af345a50c312d
   3:     0x56d31bfb2241 - std::panicking::default_hook::{{closure}}::h96ab15e9936be7ed
   4:     0x56d31bfb1f1c - std::panicking::default_hook::h3cacb9c27561ad33
   5:     0x56d31bfb28a1 - std::panicking::rust_panic_with_hook::hfe205f6954b2c97b
   6:     0x56d31bfb2707 - std::panicking::begin_panic_handler::{{closure}}::h6cb44b3a50f28c44
   7:     0x56d31bfb15b9 - std::sys::backtrace::__rust_end_short_backtrace::hf1c1f2a92799bb0e
   8:     0x56d31bfb2394 - rust_begin_unwind
   9:     0x56d31bb33e23 - core::panicking::panic_fmt::h3d8fc78294164da7
  10:     0x56d31bf7aac7 - proc_macro2::Punct::new::ha98fcb302f38a7f8
  11:     0x56d31bcc1d53 - svd2rust::generate::register::render_register_mod::h984d025f9b4ff5bf
  12:     0x56d31bcbfc2d - svd2rust::generate::register::render::h50dd757fecc731d8
  13:     0x56d31bcf53fc - svd2rust::generate::peripheral::render_ercs::h49ca57539bc0198b
  14:     0x56d31bce63fe - svd2rust::generate::peripheral::render::hf621df3c5ab9d684
  15:     0x56d31bc2fa0d - svd2rust::generate::device::render::h7ad2eee6726a060c
  16:     0x56d31bb48caa - svd2rust::run::ha72c8b7caa53a83f
  17:     0x56d31bb4b56d - svd2rust::main::h707855b15b260831
  18:     0x56d31bb61f33 - std::sys::backtrace::__rust_begin_short_backtrace::h1766bca47e196873
  19:     0x56d31bb5e299 - std::rt::lang_start::{{closure}}::hdc4d91e205a6d325
  20:     0x56d31bfa8dc0 - std::rt::lang_start_internal::h5e7c81cecd7f0954
  21:     0x56d31bb4b695 - main
  22:     0x72d777029d90 - __libc_start_call_main
                               at ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
  23:     0x72d777029e40 - __libc_start_main_impl
                               at ./csu/../csu/libc-start.c:392:3
  24:     0x56d31bb34635 - _start
  25:                0x0 - <unknown>

I'm new to rust, so I don't have much of an idea of how to troubleshoot, but I also tried a couple other SVD files and had the same error output:
S32K144.svd from s32k-rust/s32k144.rs (which was generated using svd2rust)
stm32f411.svd from tinygo-org/stm32-svd

svd2rust was installed using cargo and is version 0.33.4

@burrbull
Copy link
Member

burrbull commented Oct 8, 2024

Looks like issue with new proc-macro.
Try to install with:

cargo install svd2rust --locked

@Alan-JH
Copy link
Author

Alan-JH commented Oct 8, 2024

That solved it, thanks!

@Alan-JH Alan-JH closed this as completed Oct 8, 2024
@jannic
Copy link
Member

jannic commented Oct 8, 2024

While --locked helped to work around this issue for now, I think this is actually a bug in svd2rust.

The change in proc-macro2 that triggered this issue was https://github.com/dtolnay/proc-macro2/pull/471.
One might argue that this is a breaking change and should therefore not be in a bugfix release of proc-macro2. But the way svd2rust uses Punct was actually forbidden by the documentation before:

The ch argument must be a valid punctuation character permitted by the language, otherwise the function will panic.

      let open: Punct = Punct::new(ch: '{', Spacing::Alone);
      let close: Punct = Punct::new(ch: '}', Spacing::Alone);

These braces are clearly not punctuation characters but delimiters:
https://doc.rust-lang.org/reference/tokens.html#punctuation
https://doc.rust-lang.org/reference/tokens.html#delimiters

So svd2rust should probably use proc_macro2::Group(Delimiter::Brace, ...) instead. Unfortunately, that requires restructuring the code in render_register_mod_debug: https://github.com/rust-embedded/svd2rust/blob/master/src/generate/register.rs#L476

@jannic jannic reopened this Oct 8, 2024
rmsyn added a commit to rmsyn/svd2rust that referenced this issue Oct 9, 2024
Uses `proc_macro2::Group` for token streams delimited with braces.

Resolves: rust-embedded#863
rmsyn added a commit to rmsyn/svd2rust that referenced this issue Oct 9, 2024
Uses `proc_macro2::Group` for token streams delimited with braces.

Resolves: rust-embedded#863
rmsyn added a commit to rmsyn/svd2rust that referenced this issue Oct 9, 2024
Uses `proc_macro2::Group` for token streams delimited with braces.

Resolves: rust-embedded#863
rmsyn added a commit to rmsyn/svd2rust that referenced this issue Oct 10, 2024
Uses `proc_macro2::Group` for token streams delimited with braces.

Resolves: rust-embedded#863

Author: rmsyn <[email protected]>
Co-author: Jan Niehusmann <[email protected]>
rmsyn added a commit to rmsyn/svd2rust that referenced this issue Oct 10, 2024
Uses `proc_macro2::Group` for token streams delimited with braces.

Resolves: rust-embedded#863

Authored-by: rmsyn <[email protected]>
Co-authored-by: Jan Niehusmann <[email protected]>
Rahix added a commit to Rahix/avr-device that referenced this issue Oct 12, 2024
Due to a regression caused by proc-macro2 [1], we have to use a locked
version of svd2rust to successfully build the code in this crate.
Document this in the installation instructions.

[1]: rust-embedded/svd2rust#863
Rahix added a commit to Rahix/avr-device that referenced this issue Oct 12, 2024
Due to a regression caused by proc-macro2 [1], we have to use a locked
version of svd2rust to successfully build the code in this crate.
Document this in the installation instructions.

[1]: rust-embedded/svd2rust#863
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 a pull request may close this issue.

3 participants