Conversation

Jarkko Sakkinen

Procedural macros: how to get started? How they play with compiler? How can I, or can I use them with rustc w/o cargo?

I'm specifically not interested on "how to program proc macros tutorial". At this point more about "geometry" and how they link and in essence all bin related info.

#rust #cargo #macros
3
1
2

@jarkko handles them itself, as long as the crate has proper settings. It has to be *separate* crate, as it's build as compiler plug-in to use at building stage.

Using them w/o cargo is going to be tricky - I haven't seen guidelines how. You need a build script to build the procmacro crate first - it's a loadable library. Then pass an option to load it... I can't find what it is, so probably looking into Cargo code may be required.

0
0
1

@jarkko In essence proc macros do not depend on cargo. The only really required thing is the proc_macro library which is the interface to the compiler. *BUT* doing this all manually (or even create a Makefile calling rustc for that) would be quite some work.

2
0
0

@jarkko
Then there is of-course even more when you want to use such a bare proc macro. In simple terms proc macros are compiler plugins. So when you have some source code that wants to use your proc macro you have to tell the compiler there to use it as well.

0
0
1
@cehteh yeah i know :-) i might try GNU make proc macro compilation for the sake of experiment at least. in tpm2-protocol i have everything building with make including all test programs: https://git.kernel.org/pub/scm/linux/kernel/git/jarkko/tpm2-protocol.git/tree/Makefile.

For this crate per se I think procedural macros would be a bad idea, it is good as it is but I might give them a shot in a crate called "tpm2-policy", which uses tpm2-protocol to create expression language for policies.
1
0
0

@jarkko <ad> When you don't want to parse rust, then you may take a look at my library. Preferably look at the devel version because 0.2 is around the corner and has a lot improvements. </ad>

unsynn-rust for parsing rust is still in the incubator.

1
0
0
or actually i might use some dependencies for tpm2-policy but have not decided on that so i keep it in mind :-) generally i don't prefer external dependencies as they don't translate to bootloaders, firmware and kernel.
1
0
0

@jarkko Understandable ... anyway when you like it you could could copy over/vendor some parts of unsynn. I can add GPL2 to the lists of licenses.

1
0
1
@cehteh The protocol crate is in the process of scraping parsing completely as it parsing has a memory cost (it produces an object to stack) :-) But yeah, I'll check it out for expression parser once I get into doing tpm2-policy. I'm not really sure how I'm going to scope that yet.
1
0
1
@cehteh sorry if I was a bit rude in my first response, i'll definitely checkout usynn once i have a chance :-) (not just saying that for plain politeness/ignorance).
1
0
0

@jarkko Nah I am ok with direct answers. I only glanced what you are doing. Of course kernel work has pretty specific demands.

0
0
1