[PATCH v4 10/11] scripts: generate_rust_analyzer.py: define scripts

Tamir Duberstein posted 11 patches 9 months ago
There is a newer version of this series
[PATCH v4 10/11] scripts: generate_rust_analyzer.py: define scripts
Posted by Tamir Duberstein 9 months ago
Generate rust-project.json entries for scripts written in Rust. This is
possible now that we have a definition for `std` built for the host.

Signed-off-by: Tamir Duberstein <tamird@gmail.com>
---
 scripts/generate_rust_analyzer.py | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
index ccb15aa66929..957b413fe0b6 100755
--- a/scripts/generate_rust_analyzer.py
+++ b/scripts/generate_rust_analyzer.py
@@ -209,6 +209,19 @@ def generate_crates(
     uapi = append_crate_with_generated("uapi", [core])
     kernel = append_crate_with_generated("kernel", [core, macros, build_error, bindings, pin_init, uapi])
 
+    scripts = srctree / "scripts"
+    with open(scripts / "Makefile") as f:
+        makefile = f.read()
+    for path in scripts.glob("*.rs"):
+        name = path.name.replace(".rs", "")
+        if f"{name}-rust" not in makefile:
+            continue
+        _script = append_crate(
+            name,
+            path,
+            [host_std],
+        )
+
     def is_root_crate(build_file: pathlib.Path, target: str) -> bool:
         try:
             with open(build_file) as f:

-- 
2.48.1
Re: [PATCH v4 10/11] scripts: generate_rust_analyzer.py: define scripts
Posted by Fiona Behrens 8 months, 4 weeks ago
Tamir Duberstein <tamird@gmail.com> writes:

> Generate rust-project.json entries for scripts written in Rust. This is
> possible now that we have a definition for `std` built for the host.
>
> Signed-off-by: Tamir Duberstein <tamird@gmail.com>

Reviewed-by: Fiona Behrens <me@kloenk.dev>

> ---
>  scripts/generate_rust_analyzer.py | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
>
> diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
> index ccb15aa66929..957b413fe0b6 100755
> --- a/scripts/generate_rust_analyzer.py
> +++ b/scripts/generate_rust_analyzer.py
> @@ -209,6 +209,19 @@ def generate_crates(
>      uapi = append_crate_with_generated("uapi", [core])
>      kernel = append_crate_with_generated("kernel", [core, macros, build_error, bindings, pin_init, uapi])
>  
> +    scripts = srctree / "scripts"
> +    with open(scripts / "Makefile") as f:
> +        makefile = f.read()
> +    for path in scripts.glob("*.rs"):
> +        name = path.name.replace(".rs", "")
> +        if f"{name}-rust" not in makefile:
> +            continue
> +        _script = append_crate(
> +            name,
> +            path,
> +            [host_std],
> +        )
> +
>      def is_root_crate(build_file: pathlib.Path, target: str) -> bool:
>          try:
>              with open(build_file) as f:
Re: [PATCH v4 10/11] scripts: generate_rust_analyzer.py: define scripts
Posted by Daniel Almeida 8 months, 4 weeks ago

> On 22 Mar 2025, at 10:23, Tamir Duberstein <tamird@gmail.com> wrote:
> 
> Generate rust-project.json entries for scripts written in Rust. This is
> possible now that we have a definition for `std` built for the host.
> 
> Signed-off-by: Tamir Duberstein <tamird@gmail.com>
> ---
> scripts/generate_rust_analyzer.py | 13 +++++++++++++
> 1 file changed, 13 insertions(+)
> 
> diff --git a/scripts/generate_rust_analyzer.py b/scripts/generate_rust_analyzer.py
> index ccb15aa66929..957b413fe0b6 100755
> --- a/scripts/generate_rust_analyzer.py
> +++ b/scripts/generate_rust_analyzer.py
> @@ -209,6 +209,19 @@ def generate_crates(
>     uapi = append_crate_with_generated("uapi", [core])
>     kernel = append_crate_with_generated("kernel", [core, macros, build_error, bindings, pin_init, uapi])
> 
> +    scripts = srctree / "scripts"
> +    with open(scripts / "Makefile") as f:
> +        makefile = f.read()
> +    for path in scripts.glob("*.rs"):
> +        name = path.name.replace(".rs", "")
> +        if f"{name}-rust" not in makefile:
> +            continue
> +        _script = append_crate(
> +            name,
> +            path,
> +            [host_std],
> +        )
> +
>     def is_root_crate(build_file: pathlib.Path, target: str) -> bool:
>         try:
>             with open(build_file) as f:
> 
> -- 
> 2.48.1
> 
> 

Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>