From d7659acca7a390b5830f0b67f3aa4a5f9929ab79 Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Sat, 8 Mar 2025 11:05:01 +0000 Subject: rust: add pin-init crate build infrastructure Add infrastructure for moving the initialization API to its own crate. Covers all make targets such as `rust-analyzer` and `rustdoc`. The tests of pin-init are not added to `rusttest`, as they are already tested in the user-space repository [1]. Link: https://github.com/Rust-for-Linux/pin-init [1] Co-developed-by: Benno Lossin Signed-off-by: Benno Lossin Tested-by: Andreas Hindborg Link: https://lore.kernel.org/r/20250308110339.2997091-15-benno.lossin@proton.me Signed-off-by: Miguel Ojeda --- scripts/generate_rust_analyzer.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'scripts/generate_rust_analyzer.py') diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py index aa8ea1a4dbe5..a44a4475d11f 100755 --- a/scripts/generate_rust_analyzer.py +++ b/scripts/generate_rust_analyzer.py @@ -93,10 +93,25 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs): ) crates[-1]["env"]["OBJTREE"] = str(objtree.resolve(True)) + append_crate( + "pin_init_internal", + srctree / "rust" / "pin-init" / "internal" / "src" / "_lib.rs", + [], + cfg=["kernel"], + is_proc_macro=True, + ) + + append_crate( + "pin_init", + srctree / "rust" / "pin-init" / "src" / "_lib.rs", + ["core", "pin_init_internal", "macros"], + cfg=["kernel"], + ) + append_crate( "kernel", srctree / "rust" / "kernel" / "lib.rs", - ["core", "macros", "build_error", "bindings"], + ["core", "macros", "build_error", "bindings", "pin_init"], cfg=cfg, ) crates[-1]["source"] = { -- cgit From dbd5058ba60c3499b24a7133a4e2e24dba6ea77b Mon Sep 17 00:00:00 2001 From: Benno Lossin Date: Sat, 8 Mar 2025 11:05:09 +0000 Subject: rust: make pin-init its own crate Rename relative paths inside of the crate to still refer to the same items, also rename paths inside of the kernel crate and adjust the build system to build the crate. [ Remove the `expect` (and thus the `lint_reasons` feature) since the tree now uses `quote!` from `rust/macros/export.rs`. Remove the `TokenStream` import removal, since it is now used as well. In addition, temporarily (i.e. just for this commit) use an `--extern force:alloc` to prevent an unknown `new_uninit` error in the `rustdoc` target. For context, please see a similar case in: https://lore.kernel.org/lkml/20240422090644.525520-1-ojeda@kernel.org/ And adjusted the message above. - Miguel ] Signed-off-by: Benno Lossin Reviewed-by: Fiona Behrens Tested-by: Andreas Hindborg Link: https://lore.kernel.org/r/20250308110339.2997091-16-benno.lossin@proton.me Signed-off-by: Miguel Ojeda --- scripts/generate_rust_analyzer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'scripts/generate_rust_analyzer.py') diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py index a44a4475d11f..54228e87e577 100755 --- a/scripts/generate_rust_analyzer.py +++ b/scripts/generate_rust_analyzer.py @@ -95,7 +95,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs): append_crate( "pin_init_internal", - srctree / "rust" / "pin-init" / "internal" / "src" / "_lib.rs", + srctree / "rust" / "pin-init" / "internal" / "src" / "lib.rs", [], cfg=["kernel"], is_proc_macro=True, @@ -103,7 +103,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs): append_crate( "pin_init", - srctree / "rust" / "pin-init" / "src" / "_lib.rs", + srctree / "rust" / "pin-init" / "src" / "lib.rs", ["core", "pin_init_internal", "macros"], cfg=["kernel"], ) -- cgit From c1f4534b213d7be41b5d8b815a42d201a8f2978f Mon Sep 17 00:00:00 2001 From: Andrei Lalaev Date: Mon, 31 Mar 2025 06:17:52 +0000 Subject: scripts: generate_rust_analyzer: fix pin-init name in kernel deps Because of different crate names ("pin-init" and "pin_init") passed to "append_crate" and "append_crate_with_generated", the script fails with "KeyError: 'pin-init'". To overcome the issue, pass the same name to both functions. Signed-off-by: Andrei Lalaev Link: https://lore.kernel.org/r/AM9PR03MB7074692E5D24C288D2BBC801C8AD2@AM9PR03MB7074.eurprd03.prod.outlook.com Fixes: 4e82c87058f4 ("Merge tag 'rust-6.15' of git://git.kernel.org/pub/scm/linux/kernel/git/ojeda/linux") [ Made author match the Signed-off-by one. Added newline. - Miguel ] Signed-off-by: Miguel Ojeda --- scripts/generate_rust_analyzer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'scripts/generate_rust_analyzer.py') diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py index b0d7dc1e9267..cd41bc906fbd 100755 --- a/scripts/generate_rust_analyzer.py +++ b/scripts/generate_rust_analyzer.py @@ -133,7 +133,7 @@ def generate_crates(srctree, objtree, sysroot_src, external_src, cfgs): append_crate_with_generated("bindings", ["core"]) append_crate_with_generated("uapi", ["core"]) - append_crate_with_generated("kernel", ["core", "macros", "build_error", "pin-init", "bindings", "uapi"]) + append_crate_with_generated("kernel", ["core", "macros", "build_error", "pin_init", "bindings", "uapi"]) def is_root_crate(build_file, target): try: -- cgit