<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux/scripts/generate_rust_analyzer.py, branch v6.14</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/
</subtitle>
<id>https://git.shady.money/linux/atom?h=v6.14</id>
<link rel='self' href='https://git.shady.money/linux/atom?h=v6.14'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/'/>
<updated>2025-03-11T23:13:07Z</updated>
<entry>
<title>scripts: generate_rust_analyzer: add uapi crate</title>
<updated>2025-03-11T23:13:07Z</updated>
<author>
<name>Tamir Duberstein</name>
<email>tamird@gmail.com</email>
</author>
<published>2025-02-10T18:04:17Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=a1eb95d6b5f4cf5cc7b081e85e374d1dd98a213b'/>
<id>urn:sha1:a1eb95d6b5f4cf5cc7b081e85e374d1dd98a213b</id>
<content type='text'>
Commit 4e1746656839 ("rust: uapi: Add UAPI crate") did not update
rust-analyzer to include the new crate.

Add the missing definition to improve the developer experience.

Fixes: 4e1746656839 ("rust: uapi: Add UAPI crate")
Signed-off-by: Tamir Duberstein &lt;tamird@gmail.com&gt;
Tested-by: Andreas Hindborg &lt;a.hindborg@kernel.org&gt;
Link: https://lore.kernel.org/r/20250210-rust-analyzer-bindings-include-v2-2-23dff845edc3@gmail.com
[ Slightly reworded title. - Miguel ]
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>scripts: generate_rust_analyzer: add missing include_dirs</title>
<updated>2025-03-11T23:12:58Z</updated>
<author>
<name>Tamir Duberstein</name>
<email>tamird@gmail.com</email>
</author>
<published>2025-02-10T18:04:16Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=d1f928052439cad028438a8b8b34c1f01bc06068'/>
<id>urn:sha1:d1f928052439cad028438a8b8b34c1f01bc06068</id>
<content type='text'>
Commit 8c4555ccc55c ("scripts: add `generate_rust_analyzer.py`")
specified OBJTREE for the bindings crate, and `source.include_dirs` for
the kernel crate, likely in an attempt to support out-of-source builds
for those crates where the generated files reside in `objtree` rather
than `srctree`. This was insufficient because both bits of configuration
are required for each crate; the result is that rust-analyzer is unable
to resolve generated files for either crate in an out-of-source build.

  [ Originally we were not using `OBJTREE` in the `kernel` crate, but
    we did pass the variable anyway, so conceptually it could have been
    there since then.

    Regarding `include_dirs`, it started in `kernel` before being in
    mainline because we included the bindings directly there (i.e.
    there was no `bindings` crate). However, when that crate got
    created, we moved the `OBJTREE` there but not the `include_dirs`.
    Nowadays, though, we happen to need the `include_dirs` also in
    the `kernel` crate for `generated_arch_static_branch_asm.rs` which
    was not there back then -- Tamir confirms it is indeed required
    for that reason. - Miguel ]

Add the missing bits to improve the developer experience.

Fixes: 8c4555ccc55c ("scripts: add `generate_rust_analyzer.py`")
Signed-off-by: Tamir Duberstein &lt;tamird@gmail.com&gt;
Tested-by: Andreas Hindborg &lt;a.hindborg@kernel.org&gt;
Link: https://lore.kernel.org/r/20250210-rust-analyzer-bindings-include-v2-1-23dff845edc3@gmail.com
[ Slightly reworded title. - Miguel ]
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>scripts: generate_rust_analyzer: add missing macros deps</title>
<updated>2025-03-11T22:37:45Z</updated>
<author>
<name>Tamir Duberstein</name>
<email>tamird@gmail.com</email>
</author>
<published>2025-02-10T17:03:24Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=2e0f91aba507a3cb59f7a12fc3ea2b7d4d6675b7'/>
<id>urn:sha1:2e0f91aba507a3cb59f7a12fc3ea2b7d4d6675b7</id>
<content type='text'>
The macros crate has depended on std and proc_macro since its
introduction in commit 1fbde52bde73 ("rust: add `macros` crate"). These
dependencies were omitted from commit 8c4555ccc55c ("scripts: add
`generate_rust_analyzer.py`") resulting in missing go-to-definition and
autocomplete, and false-positive warnings emitted from rust-analyzer
such as:

  [{
  	"resource": "/Users/tamird/src/linux/rust/macros/module.rs",
  	"owner": "_generated_diagnostic_collection_name_#1",
  	"code": {
  		"value": "non_snake_case",
  		"target": {
  			"$mid": 1,
  			"path": "/rustc/",
  			"scheme": "https",
  			"authority": "doc.rust-lang.org",
  			"query": "search=non_snake_case"
  		}
  	},
  	"severity": 4,
  	"message": "Variable `None` should have snake_case name, e.g. `none`",
  	"source": "rust-analyzer",
  	"startLineNumber": 123,
  	"startColumn": 17,
  	"endLineNumber": 123,
  	"endColumn": 21
  }]

Add the missing dependencies to improve the developer experience.

  [ Fiona had a different approach (thanks!) at:

        https://lore.kernel.org/rust-for-linux/20241205115438.234221-1-me@kloenk.dev/

    But Tamir and Fiona agreed to this one. - Miguel ]

Fixes: 8c4555ccc55c ("scripts: add `generate_rust_analyzer.py`")
Reviewed-by: Fiona Behrens &lt;me@kloenk.dev&gt;
Diagnosed-by: Chayim Refael Friedman &lt;chayimfr@gmail.com&gt;
Link: https://github.com/rust-lang/rust-analyzer/issues/17759#issuecomment-2646328275
Signed-off-by: Tamir Duberstein &lt;tamird@gmail.com&gt;
Tested-by: Andreas Hindborg &lt;a.hindborg@kernel.org&gt;
Link: https://lore.kernel.org/r/20250210-rust-analyzer-macros-core-dep-v3-1-45eb4836f218@gmail.com
[ Removed `return`. Changed tag name. Added Link. Slightly
  reworded. - Miguel ]
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: use host dylib naming convention to support macOS</title>
<updated>2025-01-10T00:01:24Z</updated>
<author>
<name>Tamir Duberstein</name>
<email>tamird@gmail.com</email>
</author>
<published>2024-12-16T15:54:22Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=0730422bced5e8325fb6806d9a80bb10673588e6'/>
<id>urn:sha1:0730422bced5e8325fb6806d9a80bb10673588e6</id>
<content type='text'>
Because the `macros` crate exposes procedural macros, it must be
compiled as a dynamic library (so it can be loaded by the compiler at
compile-time).

Before this change the resulting artifact was always named
`libmacros.so`, which works on hosts where this matches the naming
convention for dynamic libraries. However the proper name on macOS would
be `libmacros.dylib`.

This turns out to matter even when the dependency is passed with a path
(`--extern macros=path/to/libmacros.so` rather than `--extern macros`)
because rustc uses the file name to infer the type of the library (see
link). This is because there's no way to specify both the path to and
the type of the external library via CLI flags. The compiler could
speculatively parse the file to determine its type, but it does not do
so today.

This means that libraries that match neither rustc's naming convention
for static libraries nor the platform's naming convention for dynamic
libraries are *rejected*.

The only solution I've found is to follow the host platform's naming
convention. This patch does that by querying the compiler to determine
the appropriate name for the artifact. This allows the kernel to build
with CONFIG_RUST=y on macOS.

Link: https://github.com/rust-lang/rust/blob/d829780/compiler/rustc_metadata/src/locator.rs#L728-L752
Tested-by: Daniel Gomez &lt;da.gomez@samsung.com&gt;
Co-developed-by: Fiona Behrens &lt;me@kloenk.dev&gt;
Signed-off-by: Fiona Behrens &lt;me@kloenk.dev&gt;
Signed-off-by: Tamir Duberstein &lt;tamird@gmail.com&gt;
Tested-by: Andreas Hindborg &lt;a.hindborg@kernel.org&gt;
Link: https://lore.kernel.org/r/20241216-b4-dylib-host-macos-v7-1-cfc507681447@gmail.com
[ Added `MAKEFLAGS=`s to avoid jobserver warnings. Removed space.
  Reworded title. - Miguel ]
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>kbuild: rust: remove the `alloc` crate and `GlobalAlloc`</title>
<updated>2024-10-15T21:10:32Z</updated>
<author>
<name>Danilo Krummrich</name>
<email>dakr@kernel.org</email>
</author>
<published>2024-10-04T15:41:32Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=392e34b6bc22077ef63abf62387ea3e9f39418c1'/>
<id>urn:sha1:392e34b6bc22077ef63abf62387ea3e9f39418c1</id>
<content type='text'>
Now that we have our own `Allocator`, `Box` and `Vec` types we can remove
Rust's `alloc` crate and the `new_uninit` unstable feature.

Also remove `Kmalloc`'s `GlobalAlloc` implementation -- we can't remove
this in a separate patch, since the `alloc` crate requires a
`#[global_allocator]` to set, that implements `GlobalAlloc`.

Signed-off-by: Danilo Krummrich &lt;dakr@kernel.org&gt;
Link: https://lore.kernel.org/r/20241004154149.93856-29-dakr@kernel.org
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: Support latest version of `rust-analyzer`</title>
<updated>2024-08-06T23:16:52Z</updated>
<author>
<name>Sarthak Singh</name>
<email>sarthak.singh99@gmail.com</email>
</author>
<published>2024-07-24T17:27:06Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=fe992163575b187405899c5abaad8ef6fb828ff6'/>
<id>urn:sha1:fe992163575b187405899c5abaad8ef6fb828ff6</id>
<content type='text'>
Sets the `sysroot` field in rust-project.json which is now needed in
newer versions of rust-analyzer instead of the `sysroot_src` field.

Till [1] `rust-analyzer` used to guess the `sysroot` based on the
`sysroot_src` at [2]. Now `sysroot` is a required parameter for a
`rust-project.json` file. It is required because `rust-analyzer`
need it to find the proc-macro server [3].

In the current version of `rust-analyzer` the `sysroot_src` is only used
to include the inbuilt library crates (std, core, alloc, etc) [4]. Since
we already specify the core library to be included in the
`rust-project.json` we don't need to define the `sysroot_src`.

Code editors like VS Code try to use the latest version of rust-analyzer
(which is updated every week) instead of the version of rust-analyzer
that comes with the rustup toolchain (which is updated every six weeks
along with the rust version).

Without this change `rust-analyzer` is breaking for anyone using VS Code.
As they are getting the latest version of `rust-analyzer` with the
changes made in [1].

`rust-analyzer` will also start breaking for other developers as they
update their rust version (assuming that also updates the rust-analyzer
version on their system).

This patch should work with every setup as there is no more guess work
being done by `rust-analyzer`.

[ Lukas, who leads the rust-analyzer team, says:

    `sysroot_src` is required now if you want to have the sysroot
    source libraries be loaded. I think we used to infer it as
    `{sysroot}/lib/rustlib/src/rust/library` before when only the
    `sysroot` field was given but that was since changed to make it
    possible in having a sysroot without the standard library sources
    (that is only have the binaries available). So if you want the
    library sources to be loaded by rust-analyzer you will have to set
    that field as well now.

  - Miguel ]

Link: https://github.com/rust-lang/rust-analyzer/pull/17287 [1]
Link: https://github.com/rust-lang/rust-analyzer/blob/f372a8a1176ff8dd5f45ab2ddd45f3530db0374f/crates/project-model/src/workspace.rs#L367-L374 [2]
Link: https://github.com/rust-lang/rust-analyzer/blob/eeb192b79aeac47b40add66347022af17a74fbaf/crates/project-model/src/sysroot.rs#L180-L192 [3]
Link: https://github.com/search?q=repo%3AVeykril%2Frust-analyzer%20src_root()&amp;type=code [4]
Tested-by: Dirk Behme &lt;dirk.behme@de.bosch.com&gt;
Signed-off-by: Sarthak Singh &lt;sarthak.singh99@gmail.com&gt;
Link: https://rust-for-linux.zulipchat.com/#narrow/stream/291565-Help/topic/How.20to.20rust-analyzer.20correctly.20working
Link: https://lore.kernel.org/r/20240724172713.899399-1-sarthak.singh99@gmail.com
[ Formatted comment, fixed typo and removed spurious empty line. - Miguel ]
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>kbuild: use the upstream `alloc` crate</title>
<updated>2024-04-16T20:03:14Z</updated>
<author>
<name>Wedson Almeida Filho</name>
<email>walmeida@microsoft.com</email>
</author>
<published>2024-03-28T01:35:56Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=11795ae4cc430192fb9aee2c1142e313cbce3ec5'/>
<id>urn:sha1:11795ae4cc430192fb9aee2c1142e313cbce3ec5</id>
<content type='text'>
Switch away from our fork of the `alloc` crate. We remove it altogether
in the next commit.

Signed-off-by: Wedson Almeida Filho &lt;walmeida@microsoft.com&gt;
Link: https://lore.kernel.org/r/20240328013603.206764-4-wedsonaf@gmail.com
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>scripts: generate_rust_analyzer: provide `cfg`s for `core` and `alloc`</title>
<updated>2023-08-20T20:54:32Z</updated>
<author>
<name>Martin Rodriguez Reboredo</name>
<email>yakoyoku@gmail.com</email>
</author>
<published>2023-08-04T17:14:39Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=4f353e0d1282dfe6b8082290fe8e606c5739a954'/>
<id>urn:sha1:4f353e0d1282dfe6b8082290fe8e606c5739a954</id>
<content type='text'>
Both `core` and `alloc` have their `cfgs` (such as `no_rc`) missing
in `rust-project.json`.

To remedy this, pass the flags to `generate_rust_analyzer.py` for
them to be added to a dictionary where each key corresponds to
a crate and each value to a list of `cfg`s. The dictionary is then
used to pass the `cfg`s to each crate in the generated file (for
`core` and `alloc` only).

Signed-off-by: Martin Rodriguez Reboredo &lt;yakoyoku@gmail.com&gt;
Link: https://lore.kernel.org/r/20230804171448.54976-1-yakoyoku@gmail.com
[ Removed `Suggested-by` as discussed in mailing list. ]
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>scripts: `make rust-analyzer` for out-of-tree modules</title>
<updated>2023-08-07T09:33:34Z</updated>
<author>
<name>Vinay Varma</name>
<email>varmavinaym@gmail.com</email>
</author>
<published>2023-04-11T09:17:15Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=49a9ef76740206d52e7393f6fe25fc764de8df32'/>
<id>urn:sha1:49a9ef76740206d52e7393f6fe25fc764de8df32</id>
<content type='text'>
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: https://github.com/Rust-for-Linux/linux/pull/914
Link: https://github.com/Rust-for-Linux/rust-out-of-tree-module/pull/2
Signed-off-by: Vinay Varma &lt;varmavinaym@gmail.com&gt;
Link: https://lore.kernel.org/r/20230411091714.130525-1-varmavinaym@gmail.com
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>scripts: generate_rust_analyzer: Handle sub-modules with no Makefile</title>
<updated>2023-04-06T22:53:34Z</updated>
<author>
<name>Asahi Lina</name>
<email>lina@asahilina.net</email>
</author>
<published>2023-04-06T22:25:22Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=5c7548d5a25306dcdb97689479be81cacc8ce596'/>
<id>urn:sha1:5c7548d5a25306dcdb97689479be81cacc8ce596</id>
<content type='text'>
More complex drivers might want to use modules to organize their Rust
code, but those module folders do not need a Makefile.
generate_rust_analyzer.py currently crashes on those. Fix it so that a
missing Makefile is silently ignored.

Link: https://github.com/Rust-for-Linux/linux/pull/883
Signed-off-by: Asahi Lina &lt;lina@asahilina.net&gt;
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
</feed>
