Cool! I went through a similar process. Eventually decided that adding complexity of an extra build step was not worth it so I started converting the performance sensitive statements to binary logs.
Conversation
I do wonder though. Is this an actual parser, or a regexp hack?
1
No idea how the TRACE library works. defmt works by placing the interned strings into an unused linker section, and decodes it automatically when you give it an ELF file and a stream of logs.
1
Oh nice. I tried something like that for C but couldn't figure it out how to do it for const strings.
1
At least in Rust, with the benefit of macros, defmt is pretty well documented, even in impl details:
defmt.ferrous-systems.com/interning.html
1
1
Thanks.
The issue I had is how to annotate a const string without first binding it to a variable like answer here:
1
But it might be possible to wrap it with a C expression statement in a macro, do a variable binding in that expression statement and add the annotation.
3
Yeah, something like that might work. I think defmt relies on the linker to gc all the strings out, after creating it as a static string in the specific section.
I think the defmt section is expressly excluded from the final binary.
1
(Rust procedural macros are also much more powerful, basically compiler plugins, so doing shenanigans like generating random identifiers for each string and encoding as JSON is much easier)
1
Yeah man don't rub salt on the wound :-)
But TBH I actually enjoy this kind of C hackery.
1
1
One day I will be hired by a Rust company. It is inevitable. Or I'll turn my current client into a Rust shop.

