-
Notifications
You must be signed in to change notification settings - Fork 435
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
rust-analyzer for out-of-tree modules #914
base: rust
Are you sure you want to change the base?
Conversation
Thanks! Please read |
d812f19
to
c688922
Compare
rust/Makefile
Outdated
@@ -392,6 +392,10 @@ rust-analyzer: | |||
$(Q)$(srctree)/scripts/generate_rust_analyzer.py $(srctree) $(objtree) \ | |||
$(RUST_LIB_SRC) > $(objtree)/rust-project.json | |||
|
|||
rust-analyzer-extmod: | |||
$(Q)$(srctree)/scripts/generate_rust_analyzer.py $(abs_srctree) $(abs_objtree) \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are absolute paths required compared to the existing target? It would be good to mention the reason in a comment -- I did something similar in our other rustfmt
target for find
:
# We match using absolute paths since `find` does not resolve them
# when matching, which is a problem when e.g. `srctree` is `..`.
If it is due to some detail in the Python script, then it may make sense to resolve it / expand them / explain it in the Python script. Or, if the targets are merged (please see my other comment on that), then maybe we can use absolute paths for both here.
c688922
to
96f2342
Compare
Hi @ojeda ! Is there anything else that I need to do to get this PR merged? |
Now that the targets are merged, would the existing target work for both cases (in-tree and out-of-tree) with
Also, could you please submit this as a patch to the mailing list? Thanks! |
23d263e
to
2fca591
Compare
@bjorn3 @aliceinwire Since you reviewed this patch previously, you may want to send the |
scripts/generate_rust_analyzer.py
Outdated
for path in (srctree / folder).rglob("*.rs"): | ||
logging.info("Checking %s", path) | ||
name = path.name.replace(".rs", "") | ||
|
||
# Skip those that are not crate roots. | ||
if f"{name}.o" not in open(path.parent / "Makefile").read(): | ||
if os.path.exists(path.parent / "Makefile") and f"{name}.o" not in open(path.parent / "Makefile").read(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I was testing this with the rust-out-of-tree-module example, I found that the crate was getting skipped because of this logic. I believe this will also need to search a possible Kbuild
file (E.g. the example)
diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
index 1546b80db554..f5567825c94c 100755
--- a/scripts/generate_rust_analyzer.py
+++ b/scripts/generate_rust_analyzer.py
@@ -107,7 +107,15 @@ def generate_crates(srctree, objtree, sysroot_src, external_src):
name = path.name.replace(".rs", "")
# Skip those that are not crate roots.
- if os.path.exists(path.parent / "Makefile") and f"{name}.o" not in open(path.parent / "Makefile").read():
+ def is_crate_root(*filenames):+ for filename in filenames:
+ filepath = path.parent / filename
+ if os.path.exists(filepath) and f"{name}.o" in open(filepath).read():
+ return True
+ return False
+
+ if not is_crate_root("Makefile", "Kbuild"):
+ logging.warning(f"skipping")
continue
logging.info("Adding %s", name)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found an issue where .o
files referenced in Kbuild
files are causing the script to skip the crate addition in rust-project.json
Indeed, @bjorn3 also reported it in the mailing list today, and I agree it should be supported (and potentially a smarter way provided) -- please see the thread at https://lore.kernel.org/rust-for-linux/20230118160220.776302-1-varmavinaym@gmail.com/ |
Ah, sorry I missed it in the mailing list, will follow along there now (Y) |
No need to apologize! :) |
Adds support for out-of-tree rust modules to use the `rust-analyzer` make target to generate the rust-project.json file. The change involves adding an optional parameter `external_src` to the `generate_rust_analyzer.py` which expects the path to the out-of-tree module's source directory. When this parameter is passed, I have chosen not to add the non-core modules (samples and drivers) into the result since these are not expected to be used in third party modules. Related changes are also made to the Makefile and rust/Makefile allowing the `rust-analyzer` target to be used for out-of-tree modules as well. Link: Rust-for-Linux#914 Link: Rust-for-Linux/rust-out-of-tree-module#2 Signed-off-by: Vinay Varma <varmavinaym@gmail.com>
2fca591
to
33102ff
Compare
Adds support for out-of-tree rust modules to use the `rust-analyzer` make target to generate the rust-project.json file. The change involves adding an optional parameter `external_src` to the `generate_rust_analyzer.py` which expects the path to the out-of-tree module's source directory. When this parameter is passed, I have chosen not to add the non-core modules (samples and drivers) into the result since these are not expected to be used in third party modules. Related changes are also made to the Makefile and rust/Makefile allowing the `rust-analyzer` target to be used for out-of-tree modules as well. Link: Rust-for-Linux#914 Link: Rust-for-Linux/rust-out-of-tree-module#2 Signed-off-by: Vinay Varma <varmavinaym@gmail.com>
Adds support for out-of-tree rust modules to use the `rust-analyzer` make target to generate the rust-project.json file. The change involves adding an optional parameter `external_src` to the `generate_rust_analyzer.py` which expects the path to the out-of-tree module's source directory. When this parameter is passed, I have chosen not to add the non-core modules (samples and drivers) into the result since these are not expected to be used in third party modules. Related changes are also made to the Makefile and rust/Makefile allowing the `rust-analyzer` target to be used for out-of-tree modules as well. Link: Rust-for-Linux#914 Link: Rust-for-Linux/rust-out-of-tree-module#2 Signed-off-by: Vinay Varma <varmavinaym@gmail.com>
Adds support for out-of-tree rust modules to use the `rust-analyzer` make target to generate the rust-project.json file. The change involves adding an optional parameter `external_src` to the `generate_rust_analyzer.py` which expects the path to the out-of-tree module's source directory. When this parameter is passed, I have chosen not to add the non-core modules (samples and drivers) into the result since these are not expected to be used in third party modules. Related changes are also made to the Makefile and rust/Makefile allowing the `rust-analyzer` target to be used for out-of-tree modules as well. Link: Rust-for-Linux#914 Link: Rust-for-Linux/rust-out-of-tree-module#2 Signed-off-by: Vinay Varma <varmavinaym@gmail.com>
Adds support for out-of-tree rust modules to use the `rust-analyzer` make target to generate the rust-project.json file. The change involves adding an optional parameter `external_src` to the `generate_rust_analyzer.py` which expects the path to the out-of-tree module's source directory. When this parameter is passed, I have chosen not to add the non-core modules (samples and drivers) into the result since these are not expected to be used in third party modules. Related changes are also made to the Makefile and rust/Makefile allowing the `rust-analyzer` target to be used for out-of-tree modules as well. Link: Rust-for-Linux#914 Link: Rust-for-Linux/rust-out-of-tree-module#2 Signed-off-by: Vinay Varma <varmavinaym@gmail.com>
Adds support for out-of-tree rust modules to use the `rust-analyzer` make target to generate the rust-project.json file. The change involves adding an optional parameter `external_src` to the `generate_rust_analyzer.py` which expects the path to the out-of-tree module's source directory. When this parameter is passed, I have chosen not to add the non-core modules (samples and drivers) into the result since these are not expected to be used in third party modules. Related changes are also made to the Makefile and rust/Makefile allowing the `rust-analyzer` target to be used for out-of-tree modules as well. Link: #914 Link: Rust-for-Linux/rust-out-of-tree-module#2 Signed-off-by: Vinay Varma <varmavinaym@gmail.com> Link: https://lore.kernel.org/r/20230411091714.130525-1-varmavinaym@gmail.com Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Adds support for out-of-tree rust modules to use the `rust-analyzer` make target to generate the rust-project.json file. The change involves adding an optional parameter `external_src` to the `generate_rust_analyzer.py` which expects the path to the out-of-tree module's source directory. When this parameter is passed, I have chosen not to add the non-core modules (samples and drivers) into the result since these are not expected to be used in third party modules. Related changes are also made to the Makefile and rust/Makefile allowing the `rust-analyzer` target to be used for out-of-tree modules as well. Link: #914 Link: Rust-for-Linux/rust-out-of-tree-module#2 Signed-off-by: Vinay Varma <varmavinaym@gmail.com> Link: https://lore.kernel.org/r/20230411091714.130525-1-varmavinaym@gmail.com Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Adds support for out-of-tree rust modules to use the `rust-analyzer` make target to generate the rust-project.json file. The change involves adding an optional parameter `external_src` to the `generate_rust_analyzer.py` which expects the path to the out-of-tree module's source directory. When this parameter is passed, I have chosen not to add the non-core modules (samples and drivers) into the result since these are not expected to be used in third party modules. Related changes are also made to the Makefile and rust/Makefile allowing the `rust-analyzer` target to be used for out-of-tree modules as well. Link: Rust-for-Linux#914 Link: Rust-for-Linux/rust-out-of-tree-module#2 Signed-off-by: Vinay Varma <varmavinaym@gmail.com> Link: https://lore.kernel.org/r/20230411091714.130525-1-varmavinaym@gmail.com Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Adds support for out-of-tree rust modules to use the `rust-analyzer` make target to generate the rust-project.json file. The change involves adding an optional parameter `external_src` to the `generate_rust_analyzer.py` which expects the path to the out-of-tree module's source directory. When this parameter is passed, I have chosen not to add the non-core modules (samples and drivers) into the result since these are not expected to be used in third party modules. Related changes are also made to the Makefile and rust/Makefile allowing the `rust-analyzer` target to be used for out-of-tree modules as well. Link: Rust-for-Linux#914 Link: Rust-for-Linux/rust-out-of-tree-module#2
adding support for running
make rust-analyzer
from an out-of-tree module.