Skip to content

Commit 4e82c87

Browse files
committed
Merge tag 'rust-6.15' of git://git.kernel.org/pub/scm/linux/kernel/git/ojeda/linux
Pull Rust updates from Miguel Ojeda: "Toolchain and infrastructure: - Extract the 'pin-init' API from the 'kernel' crate and make it into a standalone crate. In order to do this, the contents are rearranged so that they can easily be kept in sync with the version maintained out-of-tree that other projects have started to use too (or plan to, like QEMU). This will reduce the maintenance burden for Benno, who will now have his own sub-tree, and will simplify future expected changes like the move to use 'syn' to simplify the implementation. - Add '#[test]'-like support based on KUnit. We already had doctests support based on KUnit, which takes the examples in our Rust documentation and runs them under KUnit. Now, we are adding the beginning of the support for "normal" tests, similar to those the '#[test]' tests in userspace Rust. For instance: #[kunit_tests(my_suite)] mod tests { #[test] fn my_test() { assert_eq!(1 + 1, 2); } } Unlike with doctests, the 'assert*!'s do not map to the KUnit assertion APIs yet. - Check Rust signatures at compile time for functions called from C by name. In particular, introduce a new '#[export]' macro that can be placed in the Rust function definition. It will ensure that the function declaration on the C side matches the signature on the Rust function: #[export] pub unsafe extern "C" fn my_function(a: u8, b: i32) -> usize { // ... } The macro essentially forces the compiler to compare the types of the actual Rust function and the 'bindgen'-processed C signature. These cases are rare so far. In the future, we may consider introducing another tool, 'cbindgen', to generate C headers automatically. Even then, having these functions explicitly marked may be a good idea anyway. - Enable the 'raw_ref_op' Rust feature: it is already stable, and allows us to use the new '&raw' syntax, avoiding a couple macros. After everyone has migrated, we will disallow the macros. - Pass the correct target to 'bindgen' on Usermode Linux. - Fix 'rusttest' build in macOS. 'kernel' crate: - New 'hrtimer' module: add support for setting up intrusive timers without allocating when starting the timer. Add support for 'Pin<Box<_>>', 'Arc<_>', 'Pin<&_>' and 'Pin<&mut _>' as pointer types for use with timer callbacks. Add support for setting clock source and timer mode. - New 'dma' module: add a simple DMA coherent allocator abstraction and a test sample driver. - 'list' module: make the linked list 'Cursor' point between elements, rather than at an element, which is more convenient to us and allows for cursors to empty lists; and document it with examples of how to perform common operations with the provided methods. - 'str' module: implement a few traits for 'BStr' as well as the 'strip_prefix()' method. - 'sync' module: add 'Arc::as_ptr'. - 'alloc' module: add 'Box::into_pin'. - 'error' module: extend the 'Result' documentation, including a few examples on different ways of handling errors, a warning about using methods that may panic, and links to external documentation. 'macros' crate: - 'module' macro: add the 'authors' key to support multiple authors. The original key will be kept until everyone has migrated. Documentation: - Add error handling sections. MAINTAINERS: - Add Danilo Krummrich as reviewer of the Rust "subsystem". - Add 'RUST [PIN-INIT]' entry with Benno Lossin as maintainer. It has its own sub-tree. - Add sub-tree for 'RUST [ALLOC]'. - Add 'DMA MAPPING HELPERS DEVICE DRIVER API [RUST]' entry with Abdiel Janulgue as primary maintainer. It will go through the sub-tree of the 'RUST [ALLOC]' entry. - Add 'HIGH-RESOLUTION TIMERS [RUST]' entry with Andreas Hindborg as maintainer. It has its own sub-tree. And a few other cleanups and improvements" * tag 'rust-6.15' of git://git.kernel.org/pub/scm/linux/kernel/git/ojeda/linux: (71 commits) rust: dma: add `Send` implementation for `CoherentAllocation` rust: macros: fix `make rusttest` build on macOS rust: block: refactor to use `&raw mut` rust: enable `raw_ref_op` feature rust: uaccess: name the correct function rust: rbtree: fix comments referring to Box instead of KBox rust: hrtimer: add maintainer entry rust: hrtimer: add clocksource selection through `ClockId` rust: hrtimer: add `HrTimerMode` rust: hrtimer: implement `HrTimerPointer` for `Pin<Box<T>>` rust: alloc: add `Box::into_pin` rust: hrtimer: implement `UnsafeHrTimerPointer` for `Pin<&mut T>` rust: hrtimer: implement `UnsafeHrTimerPointer` for `Pin<&T>` rust: hrtimer: add `hrtimer::ScopedHrTimerPointer` rust: hrtimer: add `UnsafeHrTimerPointer` rust: hrtimer: allow timer restart from timer handler rust: str: implement `strip_prefix` for `BStr` rust: str: implement `AsRef<BStr>` for `[u8]` and `BStr` rust: str: implement `Index` for `BStr` rust: str: implement `PartialEq` for `BStr` ...
2 parents 01d5b16 + e6ea10d commit 4e82c87

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+5999
-1845
lines changed

Documentation/rust/coding-guidelines.rst

+8
Original file line numberDiff line numberDiff line change
@@ -373,3 +373,11 @@ triggered due to non-local changes (such as ``dead_code``).
373373
For more information about diagnostics in Rust, please see:
374374

375375
https://doc.rust-lang.org/stable/reference/attributes/diagnostics.html
376+
377+
Error handling
378+
--------------
379+
380+
For some background and guidelines about Rust for Linux specific error handling,
381+
please see:
382+
383+
https://rust.docs.kernel.org/kernel/error/type.Result.html#error-codes-in-c-and-rust

Documentation/rust/testing.rst

+7
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ A current limitation is that KUnit does not support assertions in other tasks.
123123
Thus, we presently simply print an error to the kernel log if an assertion
124124
actually failed. Additionally, doctests are not run for nonpublic functions.
125125

126+
Since these tests are examples, i.e. they are part of the documentation, they
127+
should generally be written like "real code". Thus, for example, instead of
128+
using ``unwrap()`` or ``expect()``, use the ``?`` operator. For more background,
129+
please see:
130+
131+
https://rust.docs.kernel.org/kernel/error/type.Result.html#error-codes-in-c-and-rust
132+
126133
The ``#[test]`` tests
127134
---------------------
128135

MAINTAINERS

+44
Original file line numberDiff line numberDiff line change
@@ -6981,6 +6981,19 @@ F: include/linux/dma-mapping.h
69816981
F: include/linux/swiotlb.h
69826982
F: kernel/dma/
69836983

6984+
DMA MAPPING HELPERS DEVICE DRIVER API [RUST]
6985+
M: Abdiel Janulgue <[email protected]>
6986+
M: Danilo Krummrich <[email protected]>
6987+
R: Daniel Almeida <[email protected]>
6988+
R: Robin Murphy <[email protected]>
6989+
R: Andreas Hindborg <[email protected]>
6990+
6991+
S: Supported
6992+
W: https://rust-for-linux.com
6993+
T: git https://github.com/Rust-for-Linux/linux.git alloc-next
6994+
F: rust/kernel/dma.rs
6995+
F: samples/rust/rust_dma.rs
6996+
69846997
DMA-BUF HEAPS FRAMEWORK
69856998
M: Sumit Semwal <[email protected]>
69866999
R: Benjamin Gaignard <[email protected]>
@@ -10539,6 +10552,21 @@ F: kernel/time/timer_list.c
1053910552
F: kernel/time/timer_migration.*
1054010553
F: tools/testing/selftests/timers/
1054110554

10555+
HIGH-RESOLUTION TIMERS [RUST]
10556+
M: Andreas Hindborg <[email protected]>
10557+
R: Boqun Feng <[email protected]>
10558+
R: Frederic Weisbecker <[email protected]>
10559+
R: Lyude Paul <[email protected]>
10560+
R: Thomas Gleixner <[email protected]>
10561+
R: Anna-Maria Behnsen <[email protected]>
10562+
10563+
S: Supported
10564+
W: https://rust-for-linux.com
10565+
B: https://github.com/Rust-for-Linux/linux/issues
10566+
T: git https://github.com/Rust-for-Linux/linux.git hrtimer-next
10567+
F: rust/kernel/time/hrtimer.rs
10568+
F: rust/kernel/time/hrtimer/
10569+
1054210570
HIGH-SPEED SCC DRIVER FOR AX.25
1054310571
1054410572
S: Orphan
@@ -12902,6 +12930,7 @@ F: Documentation/dev-tools/kunit/
1290212930
F: include/kunit/
1290312931
F: lib/kunit/
1290412932
F: rust/kernel/kunit.rs
12933+
F: rust/macros/kunit.rs
1290512934
F: scripts/rustdoc_test_*
1290612935
F: tools/testing/kunit/
1290712936

@@ -20993,6 +21022,7 @@ R: Benno Lossin <[email protected]>
2099321022
R: Andreas Hindborg <[email protected]>
2099421023
R: Alice Ryhl <[email protected]>
2099521024
R: Trevor Gross <[email protected]>
21025+
R: Danilo Krummrich <[email protected]>
2099621026
2099721027
S: Supported
2099821028
W: https://rust-for-linux.com
@@ -21013,9 +21043,23 @@ RUST [ALLOC]
2101321043
M: Danilo Krummrich <[email protected]>
2101421044
2101521045
S: Maintained
21046+
T: git https://github.com/Rust-for-Linux/linux.git alloc-next
2101621047
F: rust/kernel/alloc.rs
2101721048
F: rust/kernel/alloc/
2101821049

21050+
RUST [PIN-INIT]
21051+
M: Benno Lossin <[email protected]>
21052+
21053+
S: Maintained
21054+
W: https://rust-for-linux.com/pin-init
21055+
B: https://github.com/Rust-for-Linux/pin-init/issues
21056+
C: zulip://rust-for-linux.zulipchat.com
21057+
P: rust/pin-init/CONTRIBUTING.md
21058+
T: git https://github.com/Rust-for-Linux/linux.git pin-init-next
21059+
F: rust/kernel/init.rs
21060+
F: rust/pin-init/
21061+
K: \bpin-init\b|pin_init\b|PinInit
21062+
2101921063
RXRPC SOCKETS (AF_RXRPC)
2102021064
M: David Howells <[email protected]>
2102121065
M: Marc Dionne <[email protected]>

drivers/block/rnull.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use kernel::{
2727
module! {
2828
type: NullBlkModule,
2929
name: "rnull_mod",
30-
author: "Andreas Hindborg",
30+
authors: ["Andreas Hindborg"],
3131
description: "Rust implementation of the C null block driver",
3232
license: "GPL v2",
3333
}

drivers/gpu/drm/drm_panic.c

-5
Original file line numberDiff line numberDiff line change
@@ -486,11 +486,6 @@ static void drm_panic_qr_exit(void)
486486
stream.workspace = NULL;
487487
}
488488

489-
extern size_t drm_panic_qr_max_data_size(u8 version, size_t url_len);
490-
491-
extern u8 drm_panic_qr_generate(const char *url, u8 *data, size_t data_len, size_t data_size,
492-
u8 *tmp, size_t tmp_size);
493-
494489
static int drm_panic_get_qr_code_url(u8 **qr_image)
495490
{
496491
struct kmsg_dump_iter iter;

drivers/gpu/drm/drm_panic_qr.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
//! * <https://github.com/erwanvivien/fast_qr>
2828
//! * <https://github.com/bjguillot/qr>
2929
30-
use kernel::str::CStr;
30+
use kernel::{prelude::*, str::CStr};
3131

3232
#[derive(Debug, Clone, Copy, PartialEq, Eq, Ord, PartialOrd)]
3333
struct Version(usize);
@@ -891,7 +891,7 @@ impl QrImage<'_> {
891891
/// * `tmp` must be valid for reading and writing for `tmp_size` bytes.
892892
///
893893
/// They must remain valid for the duration of the function call.
894-
#[no_mangle]
894+
#[export]
895895
pub unsafe extern "C" fn drm_panic_qr_generate(
896896
url: *const kernel::ffi::c_char,
897897
data: *mut u8,
@@ -942,8 +942,13 @@ pub unsafe extern "C" fn drm_panic_qr_generate(
942942
/// * If `url_len` > 0, remove the 2 segments header/length and also count the
943943
/// conversion to numeric segments.
944944
/// * If `url_len` = 0, only removes 3 bytes for 1 binary segment.
945-
#[no_mangle]
946-
pub extern "C" fn drm_panic_qr_max_data_size(version: u8, url_len: usize) -> usize {
945+
///
946+
/// # Safety
947+
///
948+
/// Always safe to call.
949+
// Required to be unsafe due to the `#[export]` annotation.
950+
#[export]
951+
pub unsafe extern "C" fn drm_panic_qr_max_data_size(version: u8, url_len: usize) -> usize {
947952
#[expect(clippy::manual_range_contains)]
948953
if version < 1 || version > 40 {
949954
return 0;

drivers/net/phy/ax88796b_rust.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ kernel::module_phy_driver! {
1919
DeviceId::new_with_driver::<PhyAX88796B>()
2020
],
2121
name: "rust_asix_phy",
22-
author: "FUJITA Tomonori <[email protected]>",
22+
authors: ["FUJITA Tomonori <[email protected]>"],
2323
description: "Rust Asix PHYs driver",
2424
license: "GPL",
2525
}

drivers/net/phy/qt2025.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ kernel::module_phy_driver! {
2626
phy::DeviceId::new_with_driver::<PhyQT2025>(),
2727
],
2828
name: "qt2025_phy",
29-
author: "FUJITA Tomonori <[email protected]>",
29+
authors: ["FUJITA Tomonori <[email protected]>"],
3030
description: "AMCC QT2025 PHY driver",
3131
license: "GPL",
3232
firmware: ["qt2025-2.0.3.3.fw"],

include/drm/drm_panic.h

+7
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,11 @@ static inline void drm_panic_unlock(struct drm_device *dev, unsigned long flags)
163163

164164
#endif
165165

166+
#if defined(CONFIG_DRM_PANIC_SCREEN_QR_CODE)
167+
size_t drm_panic_qr_max_data_size(u8 version, size_t url_len);
168+
169+
u8 drm_panic_qr_generate(const char *url, u8 *data, size_t data_len, size_t data_size,
170+
u8 *tmp, size_t tmp_size);
171+
#endif
172+
166173
#endif /* __DRM_PANIC_H__ */

include/linux/sprintf.h

+3
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,7 @@ __scanf(2, 0) int vsscanf(const char *, const char *, va_list);
2424
extern bool no_hash_pointers;
2525
int no_hash_pointers_enable(char *str);
2626

27+
/* Used for Rust formatting ('%pA') */
28+
char *rust_fmt_argument(char *buf, char *end, const void *ptr);
29+
2730
#endif /* _LINUX_KERNEL_SPRINTF_H */

lib/vsprintf.c

-3
Original file line numberDiff line numberDiff line change
@@ -2291,9 +2291,6 @@ int __init no_hash_pointers_enable(char *str)
22912291
}
22922292
early_param("no_hash_pointers", no_hash_pointers_enable);
22932293

2294-
/* Used for Rust formatting ('%pA'). */
2295-
char *rust_fmt_argument(char *buf, char *end, void *ptr);
2296-
22972294
/*
22982295
* Show a '%p' thing. A kernel extension is that the '%p' is followed
22992296
* by an extra set of alphanumeric characters that are extended format

rust/.kunitconfig

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CONFIG_KUNIT=y
2+
CONFIG_RUST=y
3+
CONFIG_RUST_KERNEL_DOCTESTS=y

rust/Makefile

+58-18
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ obj-$(CONFIG_RUST) += helpers/helpers.o
1212
CFLAGS_REMOVE_helpers/helpers.o = -Wmissing-prototypes -Wmissing-declarations
1313

1414
always-$(CONFIG_RUST) += bindings/bindings_generated.rs bindings/bindings_helpers_generated.rs
15-
obj-$(CONFIG_RUST) += bindings.o kernel.o
15+
obj-$(CONFIG_RUST) += bindings.o pin_init.o kernel.o
1616
always-$(CONFIG_RUST) += exports_helpers_generated.h \
1717
exports_bindings_generated.h exports_kernel_generated.h
1818

@@ -41,7 +41,10 @@ ifdef CONFIG_RUST
4141
libmacros_name := $(shell MAKEFLAGS= $(RUSTC) --print file-names --crate-name macros --crate-type proc-macro - </dev/null)
4242
libmacros_extension := $(patsubst libmacros.%,%,$(libmacros_name))
4343

44-
always-$(CONFIG_RUST) += $(libmacros_name)
44+
libpin_init_internal_name := $(shell MAKEFLAGS= $(RUSTC) --print file-names --crate-name pin_init_internal --crate-type proc-macro - </dev/null)
45+
libpin_init_internal_extension := $(patsubst libpin_init_internal.%,%,$(libpin_init_internal_name))
46+
47+
always-$(CONFIG_RUST) += $(libmacros_name) $(libpin_init_internal_name)
4548

4649
# `$(rust_flags)` is passed in case the user added `--sysroot`.
4750
rustc_sysroot := $(shell MAKEFLAGS= $(RUSTC) $(rust_flags) --print sysroot)
@@ -80,7 +83,7 @@ quiet_cmd_rustdoc = RUSTDOC $(if $(rustdoc_host),H, ) $<
8083
# command-like flags to solve the issue. Meanwhile, we use the non-custom case
8184
# and then retouch the generated files.
8285
rustdoc: rustdoc-core rustdoc-macros rustdoc-compiler_builtins \
83-
rustdoc-kernel
86+
rustdoc-kernel rustdoc-pin_init
8487
$(Q)cp $(srctree)/Documentation/images/logo.svg $(rustdoc_output)/static.files/
8588
$(Q)cp $(srctree)/Documentation/images/COPYING-logo $(rustdoc_output)/static.files/
8689
$(Q)find $(rustdoc_output) -name '*.html' -type f -print0 | xargs -0 sed -Ei \
@@ -110,11 +113,24 @@ rustdoc-compiler_builtins: $(src)/compiler_builtins.rs rustdoc-core FORCE
110113
rustdoc-ffi: $(src)/ffi.rs rustdoc-core FORCE
111114
+$(call if_changed,rustdoc)
112115

113-
rustdoc-kernel: private rustc_target_flags = --extern ffi \
116+
rustdoc-pin_init_internal: private rustdoc_host = yes
117+
rustdoc-pin_init_internal: private rustc_target_flags = --cfg kernel \
118+
--extern proc_macro --crate-type proc-macro
119+
rustdoc-pin_init_internal: $(src)/pin-init/internal/src/lib.rs FORCE
120+
+$(call if_changed,rustdoc)
121+
122+
rustdoc-pin_init: private rustdoc_host = yes
123+
rustdoc-pin_init: private rustc_target_flags = --extern pin_init_internal \
124+
--extern macros --extern alloc --cfg kernel --cfg feature=\"alloc\"
125+
rustdoc-pin_init: $(src)/pin-init/src/lib.rs rustdoc-pin_init_internal \
126+
rustdoc-macros FORCE
127+
+$(call if_changed,rustdoc)
128+
129+
rustdoc-kernel: private rustc_target_flags = --extern ffi --extern pin_init \
114130
--extern build_error --extern macros \
115131
--extern bindings --extern uapi
116132
rustdoc-kernel: $(src)/kernel/lib.rs rustdoc-core rustdoc-ffi rustdoc-macros \
117-
rustdoc-compiler_builtins $(obj)/$(libmacros_name) \
133+
rustdoc-pin_init rustdoc-compiler_builtins $(obj)/$(libmacros_name) \
118134
$(obj)/bindings.o FORCE
119135
+$(call if_changed,rustdoc)
120136

@@ -139,12 +155,24 @@ rusttestlib-macros: private rustc_test_library_proc = yes
139155
rusttestlib-macros: $(src)/macros/lib.rs FORCE
140156
+$(call if_changed,rustc_test_library)
141157

158+
rusttestlib-pin_init_internal: private rustc_target_flags = --cfg kernel \
159+
--extern proc_macro
160+
rusttestlib-pin_init_internal: private rustc_test_library_proc = yes
161+
rusttestlib-pin_init_internal: $(src)/pin-init/internal/src/lib.rs FORCE
162+
+$(call if_changed,rustc_test_library)
163+
164+
rusttestlib-pin_init: private rustc_target_flags = --extern pin_init_internal \
165+
--extern macros --cfg kernel
166+
rusttestlib-pin_init: $(src)/pin-init/src/lib.rs rusttestlib-macros \
167+
rusttestlib-pin_init_internal $(obj)/$(libpin_init_internal_name) FORCE
168+
+$(call if_changed,rustc_test_library)
169+
142170
rusttestlib-kernel: private rustc_target_flags = --extern ffi \
143-
--extern build_error --extern macros \
171+
--extern build_error --extern macros --extern pin_init \
144172
--extern bindings --extern uapi
145-
rusttestlib-kernel: $(src)/kernel/lib.rs \
146-
rusttestlib-bindings rusttestlib-uapi rusttestlib-build_error \
147-
$(obj)/$(libmacros_name) $(obj)/bindings.o FORCE
173+
rusttestlib-kernel: $(src)/kernel/lib.rs rusttestlib-bindings rusttestlib-uapi \
174+
rusttestlib-build_error rusttestlib-pin_init $(obj)/$(libmacros_name) \
175+
$(obj)/bindings.o FORCE
148176
+$(call if_changed,rustc_test_library)
149177

150178
rusttestlib-bindings: private rustc_target_flags = --extern ffi
@@ -172,8 +200,8 @@ quiet_cmd_rustdoc_test_kernel = RUSTDOC TK $<
172200
mkdir -p $(objtree)/$(obj)/test/doctests/kernel; \
173201
OBJTREE=$(abspath $(objtree)) \
174202
$(RUSTDOC) --test $(rust_flags) \
175-
-L$(objtree)/$(obj) --extern ffi --extern kernel \
176-
--extern build_error --extern macros \
203+
-L$(objtree)/$(obj) --extern ffi --extern pin_init \
204+
--extern kernel --extern build_error --extern macros \
177205
--extern bindings --extern uapi \
178206
--no-run --crate-name kernel -Zunstable-options \
179207
--sysroot=/dev/null \
@@ -203,18 +231,18 @@ quiet_cmd_rustc_test = $(RUSTC_OR_CLIPPY_QUIET) T $<
203231
rusttest: rusttest-macros rusttest-kernel
204232

205233
rusttest-macros: private rustc_target_flags = --extern proc_macro \
206-
--extern macros --extern kernel
234+
--extern macros --extern kernel --extern pin_init
207235
rusttest-macros: private rustdoc_test_target_flags = --crate-type proc-macro
208236
rusttest-macros: $(src)/macros/lib.rs \
209-
rusttestlib-macros rusttestlib-kernel FORCE
237+
rusttestlib-macros rusttestlib-kernel rusttestlib-pin_init FORCE
210238
+$(call if_changed,rustc_test)
211239
+$(call if_changed,rustdoc_test)
212240

213-
rusttest-kernel: private rustc_target_flags = --extern ffi \
241+
rusttest-kernel: private rustc_target_flags = --extern ffi --extern pin_init \
214242
--extern build_error --extern macros --extern bindings --extern uapi
215243
rusttest-kernel: $(src)/kernel/lib.rs rusttestlib-ffi rusttestlib-kernel \
216244
rusttestlib-build_error rusttestlib-macros rusttestlib-bindings \
217-
rusttestlib-uapi FORCE
245+
rusttestlib-uapi rusttestlib-pin_init FORCE
218246
+$(call if_changed,rustc_test)
219247

220248
ifdef CONFIG_CC_IS_CLANG
@@ -246,6 +274,7 @@ bindgen_skip_c_flags := -mno-fp-ret-in-387 -mpreferred-stack-boundary=% \
246274
# Derived from `scripts/Makefile.clang`.
247275
BINDGEN_TARGET_x86 := x86_64-linux-gnu
248276
BINDGEN_TARGET_arm64 := aarch64-linux-gnu
277+
BINDGEN_TARGET_um := $(BINDGEN_TARGET_$(SUBARCH))
249278
BINDGEN_TARGET := $(BINDGEN_TARGET_$(SRCARCH))
250279

251280
# All warnings are inhibited since GCC builds are very experimental,
@@ -361,7 +390,7 @@ $(obj)/exports_kernel_generated.h: $(obj)/kernel.o FORCE
361390

362391
quiet_cmd_rustc_procmacro = $(RUSTC_OR_CLIPPY_QUIET) P $@
363392
cmd_rustc_procmacro = \
364-
$(RUSTC_OR_CLIPPY) $(rust_common_flags) \
393+
$(RUSTC_OR_CLIPPY) $(rust_common_flags) $(rustc_target_flags) \
365394
-Clinker-flavor=gcc -Clinker=$(HOSTCC) \
366395
-Clink-args='$(call escsq,$(KBUILD_PROCMACROLDFLAGS))' \
367396
--emit=dep-info=$(depfile) --emit=link=$@ --extern proc_macro \
@@ -372,6 +401,10 @@ quiet_cmd_rustc_procmacro = $(RUSTC_OR_CLIPPY_QUIET) P $@
372401
$(obj)/$(libmacros_name): $(src)/macros/lib.rs FORCE
373402
+$(call if_changed_dep,rustc_procmacro)
374403

404+
$(obj)/$(libpin_init_internal_name): private rustc_target_flags = --cfg kernel
405+
$(obj)/$(libpin_init_internal_name): $(src)/pin-init/internal/src/lib.rs FORCE
406+
+$(call if_changed_dep,rustc_procmacro)
407+
375408
quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L $@
376409
cmd_rustc_library = \
377410
OBJTREE=$(abspath $(objtree)) \
@@ -451,6 +484,13 @@ $(obj)/compiler_builtins.o: private rustc_objcopy = -w -W '__*'
451484
$(obj)/compiler_builtins.o: $(src)/compiler_builtins.rs $(obj)/core.o FORCE
452485
+$(call if_changed_rule,rustc_library)
453486

487+
$(obj)/pin_init.o: private skip_gendwarfksyms = 1
488+
$(obj)/pin_init.o: private rustc_target_flags = --extern pin_init_internal \
489+
--extern macros --cfg kernel
490+
$(obj)/pin_init.o: $(src)/pin-init/src/lib.rs $(obj)/compiler_builtins.o \
491+
$(obj)/$(libpin_init_internal_name) $(obj)/$(libmacros_name) FORCE
492+
+$(call if_changed_rule,rustc_library)
493+
454494
$(obj)/build_error.o: private skip_gendwarfksyms = 1
455495
$(obj)/build_error.o: $(src)/build_error.rs $(obj)/compiler_builtins.o FORCE
456496
+$(call if_changed_rule,rustc_library)
@@ -473,9 +513,9 @@ $(obj)/uapi.o: $(src)/uapi/lib.rs \
473513
$(obj)/uapi/uapi_generated.rs FORCE
474514
+$(call if_changed_rule,rustc_library)
475515

476-
$(obj)/kernel.o: private rustc_target_flags = --extern ffi \
516+
$(obj)/kernel.o: private rustc_target_flags = --extern ffi --extern pin_init \
477517
--extern build_error --extern macros --extern bindings --extern uapi
478-
$(obj)/kernel.o: $(src)/kernel/lib.rs $(obj)/build_error.o \
518+
$(obj)/kernel.o: $(src)/kernel/lib.rs $(obj)/build_error.o $(obj)/pin_init.o \
479519
$(obj)/$(libmacros_name) $(obj)/bindings.o $(obj)/uapi.o FORCE
480520
+$(call if_changed_rule,rustc_library)
481521

0 commit comments

Comments
 (0)