Commit dbd5058b authored by Benno Lossin's avatar Benno Lossin Committed by Miguel Ojeda
Browse files

rust: make pin-init its own crate

Rename relative paths inside of the crate to still refer to the same
items, also rename paths inside of the kernel crate and adjust the build
system to build the crate.

[ Remove the `expect` (and thus the `lint_reasons` feature) since
  the tree now uses `quote!` from `rust/macros/export.rs`. Remove the
  `TokenStream` import removal, since it is now used as well.

  In addition, temporarily (i.e. just for this commit) use an `--extern
  force:alloc` to prevent an unknown `new_uninit` error in the `rustdoc`
  target. For context, please see a similar case in:

      https://lore.kernel.org/lkml/20240422090644.525520-1-ojeda@kernel.org/



  And adjusted the message above. - Miguel ]

Signed-off-by: default avatarBenno Lossin <benno.lossin@proton.me>
Reviewed-by: default avatarFiona Behrens <me@kloenk.dev>
Tested-by: default avatarAndreas Hindborg <a.hindborg@kernel.org>
Link: https://lore.kernel.org/r/20250308110339.2997091-16-benno.lossin@proton.me


Signed-off-by: default avatarMiguel Ojeda <ojeda@kernel.org>
parent d7659acc
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -116,13 +116,13 @@ rustdoc-ffi: $(src)/ffi.rs rustdoc-core FORCE
rustdoc-pin_init_internal: private rustdoc_host = yes
rustdoc-pin_init_internal: private rustc_target_flags = --cfg kernel \
    --extern proc_macro --crate-type proc-macro
rustdoc-pin_init_internal: $(src)/pin-init/internal/src/_lib.rs FORCE
rustdoc-pin_init_internal: $(src)/pin-init/internal/src/lib.rs FORCE
	+$(call if_changed,rustdoc)

rustdoc-pin_init: private rustdoc_host = yes
rustdoc-pin_init: private rustc_target_flags = --extern pin_init_internal \
    --extern macros --extern alloc --cfg kernel --cfg feature=\"alloc\"
rustdoc-pin_init: $(src)/pin-init/src/_lib.rs rustdoc-pin_init_internal \
    --extern macros --extern force:alloc --cfg kernel --cfg feature=\"alloc\"
rustdoc-pin_init: $(src)/pin-init/src/lib.rs rustdoc-pin_init_internal \
    rustdoc-macros FORCE
	+$(call if_changed,rustdoc)

@@ -158,12 +158,12 @@ rusttestlib-macros: $(src)/macros/lib.rs FORCE
rusttestlib-pin_init_internal: private rustc_target_flags = --cfg kernel \
    --extern proc_macro
rusttestlib-pin_init_internal: private rustc_test_library_proc = yes
rusttestlib-pin_init_internal: $(src)/pin-init/internal/src/_lib.rs FORCE
rusttestlib-pin_init_internal: $(src)/pin-init/internal/src/lib.rs FORCE
	+$(call if_changed,rustc_test_library)

rusttestlib-pin_init: private rustc_target_flags = --extern pin_init_internal \
    --extern macros --cfg kernel
rusttestlib-pin_init: $(src)/pin-init/src/_lib.rs rusttestlib-macros \
rusttestlib-pin_init: $(src)/pin-init/src/lib.rs rusttestlib-macros \
    rusttestlib-pin_init_internal $(obj)/$(libpin_init_internal_name) FORCE
	+$(call if_changed,rustc_test_library)

@@ -401,7 +401,7 @@ $(obj)/$(libmacros_name): $(src)/macros/lib.rs FORCE
	+$(call if_changed_dep,rustc_procmacro)

$(obj)/$(libpin_init_internal_name): private rustc_target_flags = --cfg kernel
$(obj)/$(libpin_init_internal_name): $(src)/pin-init/internal/src/_lib.rs FORCE
$(obj)/$(libpin_init_internal_name): $(src)/pin-init/internal/src/lib.rs FORCE
	+$(call if_changed_dep,rustc_procmacro)

quiet_cmd_rustc_library = $(if $(skip_clippy),RUSTC,$(RUSTC_OR_CLIPPY_QUIET)) L $@
@@ -486,7 +486,7 @@ $(obj)/compiler_builtins.o: $(src)/compiler_builtins.rs $(obj)/core.o FORCE
$(obj)/pin_init.o: private skip_gendwarfksyms = 1
$(obj)/pin_init.o: private rustc_target_flags = --extern pin_init_internal \
    --extern macros --cfg kernel
$(obj)/pin_init.o: $(src)/pin-init/src/_lib.rs $(obj)/compiler_builtins.o \
$(obj)/pin_init.o: $(src)/pin-init/src/lib.rs $(obj)/compiler_builtins.o \
    $(obj)/$(libpin_init_internal_name) $(obj)/$(libmacros_name) FORCE
	+$(call if_changed_rule,rustc_library)

+2 −2
Original line number Diff line number Diff line
@@ -15,9 +15,9 @@
use core::ptr::NonNull;
use core::result::Result;

use crate::init::{InPlaceWrite, Init, PinInit, ZeroableOption};
use crate::init_ext::InPlaceInit;
use crate::init::InPlaceInit;
use crate::types::ForeignOwnable;
use pin_init::{InPlaceWrite, Init, PinInit, ZeroableOption};

/// The kernel's [`Box`] type -- a heap allocation for a single value of type `T`.
///
+2 −3
Original line number Diff line number Diff line
@@ -10,12 +10,11 @@
    bindings,
    block::mq::{operations::OperationsVTable, request::RequestDataWrapper, Operations},
    error,
    prelude::PinInit,
    try_pin_init,
    prelude::try_pin_init,
    types::Opaque,
};
use core::{convert::TryInto, marker::PhantomData};
use macros::{pin_data, pinned_drop};
use pin_init::{pin_data, pinned_drop, PinInit};

/// A wrapper for the C `struct blk_mq_tag_set`.
///
+3 −3
Original line number Diff line number Diff line
@@ -6,9 +6,9 @@
//! register using the [`Registration`] class.

use crate::error::{Error, Result};
use crate::{device, init::PinInit, of, str::CStr, try_pin_init, types::Opaque, ThisModule};
use crate::{device, of, str::CStr, try_pin_init, types::Opaque, ThisModule};
use core::pin::Pin;
use macros::{pin_data, pinned_drop};
use pin_init::{pin_data, pinned_drop, PinInit};

/// The [`RegistrationOps`] trait serves as generic interface for subsystems (e.g., PCI, Platform,
/// Amba, etc.) to provide the corresponding subsystem specific implementation to register /
@@ -114,7 +114,7 @@ struct DriverModule {
        impl $crate::InPlaceModule for DriverModule {
            fn init(
                module: &'static $crate::ThisModule
            ) -> impl $crate::init::PinInit<Self, $crate::error::Error> {
            ) -> impl ::pin_init::PinInit<Self, $crate::error::Error> {
                $crate::try_pin_init!(Self {
                    _driver <- $crate::driver::Registration::new(
                        <Self as $crate::ModuleMetadata>::NAME,
+12 −10
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@
//!
//! [`Opaque<T>`]: crate::types::Opaque
//! [`Opaque::ffi_init`]: crate::types::Opaque::ffi_init
//! [`pin_init!`]: crate::pin_init
//! [`pin_init!`]: pin_init::pin_init
//!
//! # Examples
//!
@@ -137,8 +137,8 @@
use crate::{
    alloc::{AllocError, Flags},
    error::{self, Error},
    init::{init_from_closure, pin_init_from_closure, Init, PinInit},
};
use pin_init::{init_from_closure, pin_init_from_closure, Init, PinInit};

/// Smart pointer that can initialize memory in-place.
pub trait InPlaceInit<T>: Sized {
@@ -205,7 +205,8 @@ fn init<E>(init: impl Init<T, E>, flags: Flags) -> error::Result<Self>
/// # Examples
///
/// ```rust
/// use kernel::{init::zeroed, error::Error};
/// use kernel::error::Error;
/// use pin_init::zeroed;
/// struct BigBuf {
///     big: KBox<[u8; 1024 * 1024 * 1024]>,
///     small: [u8; 1024 * 1024],
@@ -222,7 +223,7 @@ fn init<E>(init: impl Init<T, E>, flags: Flags) -> error::Result<Self>
/// ```
///
/// [`Infallible`]: core::convert::Infallible
/// [`init!`]: crate::init!
/// [`init!`]: pin_init::init
/// [`try_pin_init!`]: crate::try_pin_init!
/// [`Error`]: crate::error::Error
#[macro_export]
@@ -230,14 +231,14 @@ macro_rules! try_init {
    ($(&$this:ident in)? $t:ident $(::<$($generics:ty),* $(,)?>)? {
        $($fields:tt)*
    }) => {
        $crate::_try_init!($(&$this in)? $t $(::<$($generics),* $(,)?>)? {
        ::pin_init::try_init!($(&$this in)? $t $(::<$($generics),* $(,)?>)? {
            $($fields)*
        }? $crate::error::Error)
    };
    ($(&$this:ident in)? $t:ident $(::<$($generics:ty),* $(,)?>)? {
        $($fields:tt)*
    }? $err:ty) => {
        $crate::_try_init!($(&$this in)? $t $(::<$($generics),* $(,)?>)? {
        ::pin_init::try_init!($(&$this in)? $t $(::<$($generics),* $(,)?>)? {
            $($fields)*
        }? $err)
    };
@@ -262,7 +263,8 @@ macro_rules! try_init {
///
/// ```rust
/// # #![feature(new_uninit)]
/// use kernel::{init::zeroed, error::Error};
/// use kernel::error::Error;
/// use pin_init::zeroed;
/// #[pin_data]
/// struct BigBuf {
///     big: KBox<[u8; 1024 * 1024 * 1024]>,
@@ -282,21 +284,21 @@ macro_rules! try_init {
/// ```
///
/// [`Infallible`]: core::convert::Infallible
/// [`pin_init!`]: crate::pin_init
/// [`pin_init!`]: pin_init::pin_init
/// [`Error`]: crate::error::Error
#[macro_export]
macro_rules! try_pin_init {
    ($(&$this:ident in)? $t:ident $(::<$($generics:ty),* $(,)?>)? {
        $($fields:tt)*
    }) => {
        $crate::_try_pin_init!($(&$this in)? $t $(::<$($generics),* $(,)?>)? {
        ::pin_init::try_pin_init!($(&$this in)? $t $(::<$($generics),* $(,)?>)? {
            $($fields)*
        }? $crate::error::Error)
    };
    ($(&$this:ident in)? $t:ident $(::<$($generics:ty),* $(,)?>)? {
        $($fields:tt)*
    }? $err:ty) => {
        $crate::_try_pin_init!($(&$this in)? $t $(::<$($generics),* $(,)?>)? {
        ::pin_init::try_pin_init!($(&$this in)? $t $(::<$($generics),* $(,)?>)? {
            $($fields)*
        }? $err)
    };
Loading