Quick notes
Quick notes
Posted Mar 28, 2025 12:24 UTC (Fri) by jgg (subscriber, #55211)In reply to: Quick notes by ojeda
Parent article: A process for handling Rust code in the core kernel
You can build it, but not following the instructions in Documentation/rust/quick-start.rst:
$ sudo apt install rustc-1.80 rust-1.80-src bindgen-0.65 rustfmt-1.80 rust-1.80-clippy
$ export RUST_LIB_SRC=/usr/src/rustc-$(rustc-1.80 --version | cut -d' ' -f2)/library
$ make LLVM=1 rustavailable
***
*** Rust bindings generator 'bindgen' could not be found.
***
***
*** Please see Documentation/rust/quick-start.rst for details
*** on how to set up the Rust support.
***
make[1]: *** [/tmp/x/Makefile:1798: rustavailable] Error 1
make: *** [Makefile:251: __sub-make] Error 2
So what is the make command?
$ make LLVM=1 BINDGEN=bindgen-0.65 rustavailable
***
*** Rust compiler 'rustc' is too old.
*** Your version: 1.75.0
*** Minimum version: 1.78.0
Ugh.
$ make LLVM=1 BINDGEN=bindgen-0.65 RUSTC=rustc-1.80 rustavailable
Failed to run rustfmt: No such file or directory (os error 2) (non-fatal, continuing)
***
*** Rust bindings generator 'bindgen-0.65' < 0.69.5 together with libclang >= 19.1
*** may not work due to a bug (https://github.com/rust-lang/rust-bindgen/pull/2824),
*** unless patched (like Debian's).
*** Your bindgen version: 0.65.1
*** Your libclang version: 19.1.7
***
clang: unknown C compiler
Uh.. OK..
$ make LLVM=1 LLVM_SUFFIX=-17 BINDGEN=bindgen-0.65 RUSTC=rustc-1.80 rustavailable
Failed to run rustfmt: No such file or directory (os error 2) (non-fatal, continuing)
***
*** Rust bindings generator 'bindgen-0.65' < 0.69.5 together with libclang >= 19.1
*** may not work due to a bug (https://github.com/rust-lang/rust-bindgen/pull/2824),
*** unless patched (like Debian's).
*** Your bindgen version: 0.65.1
*** Your libclang version: 19.1.7
***
***
*** libclang (used by the Rust bindings generator 'bindgen-0.65')
*** version does not match Clang's. This may be a problem.
*** libclang version: 19.1.7
*** Clang version: 17.0.6
***
***
*** Please see Documentation/rust/quick-start.rst for details
*** on how to set up the Rust support.
***
Rust is available!
Progress?
I have lots of libclang's:
$ ls /lib/x86_64-linux-gnu/libclang*
/lib/x86_64-linux-gnu/libclang-17.so.1@ /lib/x86_64-linux-gnu/libclang-19.so.19
/lib/x86_64-linux-gnu/libclang-17.so.17 /lib/x86_64-linux-gnu/libclang-cpp.so.17@
/lib/x86_64-linux-gnu/libclang-18.so.1@ /lib/x86_64-linux-gnu/libclang-cpp.so.18@
/lib/x86_64-linux-gnu/libclang-18.so.18 /lib/x86_64-linux-gnu/libclang-cpp.so.18.1@
/lib/x86_64-linux-gnu/libclang-19.so.1@ /lib/x86_64-linux-gnu/libclang-cpp.so.19.1
Maybe don't automatically pick the wrong one :\
$ make LLVM=1 LLVM_SUFFIX=-17 BINDGEN=bindgen-0.65 RUSTC=rustc-1.80 LIBCLANG_PATH=/lib/x86_64-linux-gnu/libclang-17.so.1 rustavailable
Rust is available!
Yay, finally..
The instructions in quick-start really should say the special make command required as well.
Posted Mar 28, 2025 15:13 UTC (Fri)
by ojeda (subscriber, #143370)
[Link] (1 responses)
You can definitely argue the instructions could be more detailed, but the existing instructions are currently meant as examples on installing the toolchain, not as a full guide on building the kernel for each particular distribution/LTS/set of packages/setup.
> Maybe don't automatically pick the wrong one :\
Hmm... I don't think we should automatically override whatever the user's tool (or its distribution) does.
> The instructions in quick-start really should say the special make command required as well.
I wouldn't say it is really special. In a fresh 24.04 LTS, using the install command provided, this works:
make LLVM=1 RUSTC=rustc-1.80 BINDGEN=bindgen-0.65 rustavailable
`LLVM=1` is common and `RUSTC`/`BINDGEN` are needed just like in the C side when using different binaries.
The biggest pitfalls are the `RUST_LIB_SRC` one and the `bindgen` bugs -- they are mentioned and they were reported to upstream Ubuntu.
Now, yes, an example `make` for cases that we know that work could help, or perhaps a list of related variables, but we cannot try to cover every setup either, so it is a balance.
Over time, this will get easier, e.g. Ubuntu 25.04 will be better -- no versioned packages needed.
And others like Fedora just work already.
Posted Mar 28, 2025 18:25 UTC (Fri)
by jgg (subscriber, #55211)
[Link]
Quick notes
Quick notes