@@ -29,8 +29,9 @@ This document describes the Linux kernel Makefiles.
29
29
--- 4.1 Simple Host Program
30
30
--- 4.2 Composite Host Programs
31
31
--- 4.3 Using C++ for host programs
32
- --- 4.4 Controlling compiler options for host programs
33
- --- 4.5 When host programs are actually built
32
+ --- 4.4 Using Rust for host programs
33
+ --- 4.5 Controlling compiler options for host programs
34
+ --- 4.6 When host programs are actually built
34
35
35
36
=== 5 Userspace Program support
36
37
--- 5.1 Simple Userspace Program
@@ -835,7 +836,24 @@ Both possibilities are described in the following.
835
836
qconf-cxxobjs := qconf.o
836
837
qconf-objs := check.o
837
838
838
- 4.4 Controlling compiler options for host programs
839
+ 4.4 Using Rust for host programs
840
+ --------------------------------
841
+
842
+ Kbuild offers support for host programs written in Rust. However,
843
+ since a Rust toolchain is not mandatory for kernel compilation,
844
+ it may only be used in scenarios where Rust is required to be
845
+ available (e.g. when ``CONFIG_RUST `` is enabled).
846
+
847
+ Example::
848
+
849
+ hostprogs := target
850
+ target-rust := y
851
+
852
+ Kbuild will compile ``target `` using ``target.rs `` as the crate root,
853
+ located in the same directory as the ``Makefile ``. The crate may
854
+ consist of several source files (see ``samples/rust/hostprogs ``).
855
+
856
+ 4.5 Controlling compiler options for host programs
839
857
--------------------------------------------------
840
858
841
859
When compiling host programs, it is possible to set specific flags.
@@ -867,7 +885,7 @@ Both possibilities are described in the following.
867
885
When linking qconf, it will be passed the extra option
868
886
"-L$(QTDIR)/lib".
869
887
870
- 4.5 When host programs are actually built
888
+ 4.6 When host programs are actually built
871
889
-----------------------------------------
872
890
873
891
Kbuild will only build host-programs when they are referenced
@@ -1181,6 +1199,17 @@ When kbuild executes, the following steps are followed (roughly):
1181
1199
The first example utilises the trick that a config option expands
1182
1200
to 'y' when selected.
1183
1201
1202
+ KBUILD_RUSTFLAGS
1203
+ $(RUSTC) compiler flags
1204
+
1205
+ Default value - see top level Makefile
1206
+ Append or modify as required per architecture.
1207
+
1208
+ Often, the KBUILD_RUSTFLAGS variable depends on the configuration.
1209
+
1210
+ Note that target specification file generation (for ``--target ``)
1211
+ is handled in ``scripts/generate_rust_target.rs ``.
1212
+
1184
1213
KBUILD_AFLAGS_KERNEL
1185
1214
Assembler options specific for built-in
1186
1215
@@ -1208,6 +1237,19 @@ When kbuild executes, the following steps are followed (roughly):
1208
1237
are used for $(CC).
1209
1238
From commandline CFLAGS_MODULE shall be used (see kbuild.rst).
1210
1239
1240
+ KBUILD_RUSTFLAGS_KERNEL
1241
+ $(RUSTC) options specific for built-in
1242
+
1243
+ $(KBUILD_RUSTFLAGS_KERNEL) contains extra Rust compiler flags used to
1244
+ compile resident kernel code.
1245
+
1246
+ KBUILD_RUSTFLAGS_MODULE
1247
+ Options for $(RUSTC) when building modules
1248
+
1249
+ $(KBUILD_RUSTFLAGS_MODULE) is used to add arch-specific options that
1250
+ are used for $(RUSTC).
1251
+ From commandline RUSTFLAGS_MODULE shall be used (see kbuild.rst).
1252
+
1211
1253
KBUILD_LDFLAGS_MODULE
1212
1254
Options for $(LD) when linking modules
1213
1255
0 commit comments