Rust for Linux List
 help / color / mirror / Atom feed
* [PATCH RESEND] rust: doctest: trim function name for reproducbility
@ 2026-09-24  0:50 Gary Guo
  2026-09-30 11:35 ` Miguel Ojeda
  2026-09-30 17:40 ` Miguel Ojeda
  0 siblings, 2 replies; 3+ messages in thread
From: Gary Guo @ 2026-09-24  0:50 UTC (permalink / raw)
  To: Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
	Alexandre Courbot, Onur Özkan, Brendan Higgins, David Gow,
	Rae Moar
  Cc: linux-kselftest, kunit-dev, rust-for-linux, linux-kernel

From: Gary Guo <gary@garyguo.net>

Currently rustdoc will generate function names like
"_doctest_main__home_gary_Projects_linux_rust_kernel_io_rs_824_0" for a
doctest located at rust/kernel/io.rs:824, when building with separate
outdir using `O=`. This creates overlong symbol names and is also not
reproducible.

Fix it by doing a custom remapping to trim it to something like
`_doctest_main_rust_kernel_io_rs_824_0`.

Signed-off-by: Gary Guo <gary@garyguo.net>
---
 scripts/rustdoc_test_builder.rs | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/scripts/rustdoc_test_builder.rs b/scripts/rustdoc_test_builder.rs
index df864437cef7..561f912c2000 100644
--- a/scripts/rustdoc_test_builder.rs
+++ b/scripts/rustdoc_test_builder.rs
@@ -72,6 +72,11 @@ fn main() {
     // Figure out a smaller test name based on the generated function name.
     let name = rustdoc_function_name.split_once("_rust_kernel_").unwrap().1;
 
+    // The rustdoc function name can include the absolute path when building with `O=` which is
+    // undesireable and create overlong symbol names. Remap it to use relative path.
+    let trimmed_function_name = format!("_doctest_main_rust_kernel_{name}");
+    let body = body.replace(&rustdoc_function_name, &trimmed_function_name);
+
     let path = format!("rust/test/doctests/kernel/{name}");
 
     std::fs::write(path, body.as_bytes()).unwrap();

base-commit: 93f51579e7df248780214094418f205253383cc5
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH RESEND] rust: doctest: trim function name for reproducbility
  2026-09-24  0:50 [PATCH RESEND] rust: doctest: trim function name for reproducbility Gary Guo
@ 2026-09-30 11:35 ` Miguel Ojeda
  2026-09-30 17:40 ` Miguel Ojeda
  1 sibling, 0 replies; 3+ messages in thread
From: Miguel Ojeda @ 2026-09-30 11:35 UTC (permalink / raw)
  To: Gary Guo
  Cc: Miguel Ojeda, Boqun Feng, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
	Daniel Almeida, Tamir Duberstein, Alexandre Courbot,
	Onur Özkan, Brendan Higgins, David Gow, Rae Moar,
	linux-kselftest, kunit-dev, rust-for-linux, linux-kernel

On Thu, Sep 24, 2026 at 2:51 AM Gary Guo <gary@kernel.org> wrote:
>
> Currently rustdoc will generate function names like

Just to clarify, this happens only for Rust < 1.95 since we use
`--remap` which already  it in newer versions -- I will add a note to
the comment, since we can remove this on the next version bump.

But please shout if I am missing something.

Cheers,
Miguel

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH RESEND] rust: doctest: trim function name for reproducbility
  2026-09-24  0:50 [PATCH RESEND] rust: doctest: trim function name for reproducbility Gary Guo
  2026-09-30 11:35 ` Miguel Ojeda
@ 2026-09-30 17:40 ` Miguel Ojeda
  1 sibling, 0 replies; 3+ messages in thread
From: Miguel Ojeda @ 2026-09-30 17:40 UTC (permalink / raw)
  To: Gary Guo
  Cc: Miguel Ojeda, Boqun Feng, Björn Roy Baron, Benno Lossin,
	Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich,
	Daniel Almeida, Tamir Duberstein, Alexandre Courbot,
	Onur Özkan, Brendan Higgins, David Gow, Rae Moar,
	linux-kselftest, kunit-dev, rust-for-linux, linux-kernel

On Thu, Sep 24, 2026 at 2:51 AM Gary Guo <gary@kernel.org> wrote:
>
> From: Gary Guo <gary@garyguo.net>
>
> Currently rustdoc will generate function names like
> "_doctest_main__home_gary_Projects_linux_rust_kernel_io_rs_824_0" for a
> doctest located at rust/kernel/io.rs:824, when building with separate
> outdir using `O=`. This creates overlong symbol names and is also not
> reproducible.
>
> Fix it by doing a custom remapping to trim it to something like
> `_doctest_main_rust_kernel_io_rs_824_0`.
>
> Signed-off-by: Gary Guo <gary@garyguo.net>

Applied to `rust-next` -- thanks!

    [ `rustdoc` already remaps these paths when we use Rust >= 1.95, thus
      this fix is needed for older toolchains. - Miguel ]

    [ Added `TODO` comment about the minimum version bump. Reworded title
      and comment for typos. - Miguel ]

Cheers,
Miguel

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-09-30 17:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-24  0:50 [PATCH RESEND] rust: doctest: trim function name for reproducbility Gary Guo
2026-09-30 11:35 ` Miguel Ojeda
2026-09-30 17:40 ` Miguel Ojeda

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox