Rust-for-Linux / linux

Adding support for the Rust language to the Linux kernel.
https://rust-for-linux.com
Other
3.97k stars 426 forks source link

issue building samples/rust/rust_minimal.rsi #870

Open nickdesaulniers opened 2 years ago

nickdesaulniers commented 2 years ago

I'm trying to review v9 of the kernel series. I'm having a hard time building a few of the make targets.

$ make LLVM=1 -j72 rust/kernel/print.ll
make[2]: *** No rule to make target 'rust/kernel/print.ll'.  Stop.
$ make LLVM=1 -j72 rust/kernel/print.s
make[2]: *** No rule to make target 'rust/kernel/print.s'.  Stop.
$ make LLVM=1 -j72 rust/kernel/print.o
make[2]: *** No rule to make target 'rust/kernel/print.o'.  Stop.

are there specific files that I can build the .ll, .s, .o, or .rsi files for, or did this regress?

ojeda commented 2 years ago

This only works for Rust translation units as a whole, i.e. crates (and currently for the ones outside rust/, i.e. not for the kernel crate).

We test it in the CI, so it shouldn't have regressed.

For instance, you can try:

make LLVM=1 -j72 samples/rust/rust_minimal.rsi
make LLVM=1 -j72 samples/rust/rust_minimal.s
make LLVM=1 -j72 samples/rust/rust_minimal.o
make LLVM=1 -j72 samples/rust/rust_minimal.ll

I will make that clearer in the help and add support for the rust/ crates.

nickdesaulniers commented 2 years ago
$ make LLVM=1 -j72 samples/rust/rust_minimal.rsi
error: macros that expand to items must be delimited with braces or followed by a semicolon
  --> /android0/kernel-all/samples/rust/rust_minimal.rsi:29:13
   |
29 | ...m! (".section \".initcall6.init\", \"a\"\n                __rust_minimal_initcall:\n                    .long   __rust_minimal_init - .\n                    .previous\n                ")
   |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
help: change the delimiters to curly braces
   |
29 | global_asm! {".section \".initcall6.init\", \"a\"\n                __rust_minimal_initcall:\n                    .long   __rust_minimal_init - .\n                    .previous\n                "}
   |             ~                                                                                                                                                                                     ~
help: add a semicolon
   |
29 | global_asm! (".section \".initcall6.init\", \"a\"\n                __rust_minimal_initcall:\n                    .long   __rust_minimal_init - .\n                    .previous\n                ");
   |                                                                                                                                                                                                    +

the rest seem to work, once I enable a few extra configs (SAMPLES, SAMPLES_RUST, SAMPLE_RUST_MINIMAL, SAMPLE_RUST_HOSTPROGS)

ojeda commented 2 years ago

Interesting, this looks like a bug in the compiler -- it removes the semicolon in its output, and then rustfmt detects the error.

Having said that, the output is not promised to be valid Rust, so I guess they may not fix it, but I will reduce it and open an issue.

You can workaround it with: make LLVM=1 -j72 samples/rust/rust_minimal.rsi RUSTFMT=n to avoid formatting. I could make it so that formatting is attempted only, though it would mean we don't detect this sort of thing (perhaps I could print a message, though).

ojeda commented 2 years ago

I forgot to mention: this reproduces only when building the module as built-in since that uses the global_asm!. The CI didn't detect it because it currently tries the single-file targets with an external module.

This should also fix itself when we move to the approach of using directly the MODULE_* C macros, though it is orthogonal to the issue.

ojeda commented 2 years ago

Filed https://github.com/rust-lang/rust/issues/101047 and https://github.com/rust-lang/rust/issues/101051.