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

In-tree crate built-in.rlib support? #1091

Open
ToolmanP opened this issue Jul 19, 2024 · 3 comments
Open

In-tree crate built-in.rlib support? #1091

ToolmanP opened this issue Jul 19, 2024 · 3 comments
Labels
• kbuild Related to building the kernel, `make`, `Kbuild`, `Kconfig` options...

Comments

@ToolmanP
Copy link

Hello, everyone. So recently i've been working on a possible rewrite of a filesystem module in rust. I'm already implemented a small and thin core-only crate (which is also used for userspace progs) and i want to embed it into kernel tree . Given the current status of vfs, the code only provides some ffi hooks to the original C implementations before the virtual filesystem abstraction is ready to be merged. But i have some problems here.

  1. Apart from the default kernel/core/alloc cfg provided in rust/Makefile, can i specify my own extra cfgs for rustc so that my in-kernel rust driver source can find the crate i introduce?
  2. Are there any built-in rlib recipes so that i can designate a lib.rs and produce a rlib file and then make it to the linking stage?
  3. It seems that in the current implementation of generate_rust_analyzer.py, the code only provides only minimal deps configs for kernel/core/alloc crate and does not respect the KBuild/Makefile if i want to introduce some module-local crates that also depends on kernel crate there. I've looked through Third-party crates support: proc-macro2, quote, syn, serde and serde_derive #1007 which seems to introduce those crates kernel-wide, however i want to keep it module-local. So maybe we need some enhancements on this part too?
for folder in extra_dirs:
        for path in folder.rglob("*.rs"):
            logging.info("Checking %s", path)
            name = path.name.replace(".rs", "")

            # Skip those that are not crate roots.
            if not is_root_crate(path.parent / "Makefile", name) and \
               not is_root_crate(path.parent / "Kbuild", name):
                continue

            logging.info("Adding %s", name)
            append_crate(
                name,
                path,
                ["core", "alloc", "kernel"],
                cfg=cfg,
            )

Any help or replies are much appreciated! Thanks!

@ToolmanP
Copy link
Author

Is this https://rust-for-linux.zulipchat.com/#narrow/stream/288089-General/topic/Custom.20crate.20import.3F/near/451833399?

Yeah, that's me. :) Thanks for Reply I will discuss this in zulip :)

@ToolmanP
Copy link
Author

ToolmanP commented Jul 19, 2024

https://rust-for-linux.zulipchat.com/#narrow/stream/288089-General/topic/Custom.20crate.20import.3F/near/451833399

I think maybe adding a %.rlib compilation rule in the Makefile.build and automatically generate externs is enough to do the job.
e.g by writing

CONFIG_FOO_USE_RUST_y += libfoo.rlib

Kbuild will just search the foo/lib.rs and use rustc to finish the compilation and also generate flags to append to the rust_cmd in the Makefile.build so that rustc will use flags when doing module-specific works. And in linking stage, the ld will also include the rlib files correspondingly. Fo in-tree module, it should be enough.

@ojeda ojeda added the • kbuild Related to building the kernel, `make`, `Kbuild`, `Kconfig` options... label Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
• kbuild Related to building the kernel, `make`, `Kbuild`, `Kconfig` options...
Development

No branches or pull requests

2 participants