Skip to content

Rename libmodule to libmacros #306

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

Merged
merged 1 commit into from
May 29, 2021
Merged

Rename libmodule to libmacros #306

merged 1 commit into from
May 29, 2021

Conversation

nbdd0121
Copy link
Member

Split from #278

Renaming to libmacros allows us to potentially have more procedural
macros in the future without introducing additional crates.

Having all our proc macros in a single crate allows potential code
sharing between macros, and it simplifies the build process compared
to multiple crates.

Multiple crate does allow parallel compilation, but given the limited
number of proc macros at this stage, the compilation time difference is
negligible. Even when we have a big `macros` crate we can still use
multiple codegen units while keep them in a single crate.

Signed-off-by: Gary Guo <gary@garyguo.net>
@ksquirrel
Copy link
Member

Review of 863bd2e4f203:

  • ✔️ Commit 863bd2e: Looks fine!

@ojeda
Copy link
Member

ojeda commented May 28, 2021

Looks fine to me. I let others comment in case someone thinks about any other pros/cons.

Off-topic: things would look better if the restriction on the entry points being in the root crate is lifted. Alas...

@wedsonaf
Copy link

I like that this is moving to its own directory.

Another thought I had some time back: can we move this to a directory outside rust/, perhaps some other subdirectory under tools/? My idea here is to avoid confusing reviewers that may think that this code is going to be part of the kernel; by moving this out we can claim that code in rust/ will likely end up in the kernel, but code in say tools/rust (or whatever place in find for it) is only used at compile time and will never be in the kernel.

WDYT?

@nbdd0121
Copy link
Member Author

I don't think anything in tools is currently required for building the kernel? Maybe sceipts?

But anyway I think it's the best to keep it within Rust directory, because even though itself is not compiled into the kernel, it does generate code that's compiled, and many of which is from templates.

@ojeda
Copy link
Member

ojeda commented May 29, 2021

I don't think anything in tools is currently required for building the kernel?

There is objtool for instance, but yeah, I am not sure what is the precise requirement between one and the other place. Perhaps the perceived complexity? :-)

From a quick look at history, there was not much fuss when creating the tools folder, it was simply done to move perf out of Documentation/.

Another thought I had some time back: can we move this to a directory outside rust/, perhaps some other subdirectory under tools/? My idea here is to avoid confusing reviewers that may think that this code is going to be part of the kernel; by moving this out we can claim that code in rust/ will likely end up in the kernel, but code in say tools/rust (or whatever place in find for it) is only used at compile time and will never be in the kernel.

WDYT?

I thought about this when I set the initial support, not just for procedural macros but also other bits like the bindings etc. My idea was that, at least initially, it would be best to "contain" Rust as much as possible within rust/ (obviously samples/, drivers/ and a few other bits in the infrastructure need to go outside).

For kernel code, it seems like that is still the right choice.

For procedural macros, I think it makes the most sense them close to the code too, since they are, after all, very tied to it. They not only generate Rust code in-place (in contrast with other host programs that generate e.g. a new C file or header); they also parse some kind of input (whether Rust code or not) that comes from Rust source files themselves too (rather than, e.g. from a non-C file).

Is this approach fine for the kernel? A few places also put their own host binaries that generate C code alongside the kernel C code, e.g. drivers/tty/vt/conmakehash.c or quite a few in arch/ etc. So keeping the procedural macros close to the code seems fine.

One could argue that e.g. objtool is not really independent either from the code either, and that it is as "kernel-wide" as our procedural macros such as module!. But I see objtool and similar tools/scripts as extra steps/phases in the build process, and they do not transform some input in-place in existing C files.

@ojeda
Copy link
Member

ojeda commented May 29, 2021

LGTM!

@ojeda ojeda merged commit 0164898 into Rust-for-Linux:rust May 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants