Skip to contentSkip to conversation

rust: crates in other kernel directories

RFC PATCH Superseded Martin Rodriguez Reboredo 4 participants 11 messages Oct 6, 2023 – Oct 23, 2023

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover rust: crates in other kernel directories

This RFC provides makes possible to have bindings for kernel subsystems that are compiled as modules.

Previously, if you wanted to have Rust bindings for a subsystem, like AMBA for example, you had to put it under rust/kernel/ so it came part of the kernel crate, but this came with many downsides. Namely if you compiled said subsystem as a module you've a dependency on it from kernel, which is linked directly on vmlinux.

So instead of overpopulating kernel with a gazillion modules that throws you into dire straits you should rather have the bindings in the same directory as the subsystem you want to bind with and link it to it.

For now I don't have a completely working example but I have an MWE as following...

    # Add this line to drivers/usb/core/Kconfig
    config USB_RUST
    	bool "Rust USB bindings"
    	depends on USB && RUST
    	default n
    	help
    	  Enables Rust bindings for USB.

    # Add this line to drivers/usb/core/Makefile
    usbcore-$(CONFIG_USB_RUST)		+= usb.rlib

    # Create this file drivers/usb/core/usb.rs
    // SPDX-License-Identifier: GPL-2.0
    
    //! USB devices and drivers.
    //!
    //! C header: [`include/linux/usb.h`](../../../../include/linux/usb.h)
    
    use kernel::bindings;
    
    /// Check if USB is disabled.
    pub fn disabled() -> bool {
        // SAFETY: FFI call.
        unsafe { bindings::usb_disabled() != 0 }
    }

    # Compile the .rlib with
    make drivers/usb/core/usb.rlib LLVM=1

If everything went well then you should have
drivers/usb/core/usb.rlib ready to be linked.

As of now this PR won't compile the kernel fully as it serves as an starting point and it's going to change in the future.

Martin Rodriguez Reboredo (1):
scripts: Build per module Rust crates

 Makefile               |  4 ++--
 scripts/Makefile.build | 10 +++++++++-
 scripts/Makefile.lib   | 19 +++++++++++++------
 3 files changed, 24 insertions(+), 9 deletions(-)
Signature · 1 line
2.42.0
#1 lore raw

RFC PATCH 1/1 scripts: Build per module Rust crates

Enables compiling Rust crates as dependencies of kernel modules.

When a composite object depends on an .rlib file, which by the way is a current ar archive, Kbuild will compile it from its base Rust source and link it.

This makes possible to have Rust bindings for a subsystem that is compiled as a module.

---
 Makefile               |  4 ++--
 scripts/Makefile.build | 10 +++++++++-
 scripts/Makefile.lib   | 19 +++++++++++++------
 3 files changed, 24 insertions(+), 9 deletions(-)
Makefile +2 -2
index 7d6be12e4c3e..7774c97e8aa0 100644
@@ -283,7 +283,7 @@ no-compiler-targets := $(no-dot-config-targets) install dtbs_install \
 			headers_install modules_install modules_sign kernelrelease image_name
 no-sync-config-targets := $(no-dot-config-targets) %install modules_sign kernelrelease \
 			  image_name
-single-targets := %.a %.i %.ko %.lds %.ll %.lst %.mod %.o %.rsi %.s %.symtypes %/
+single-targets := %.a %.i %.ko %.lds %.ll %.lst %.mod %.o %.rlib %.rsi %.s %.symtypes %/
 
 config-build	:=
 mixed-build	:=
@@ -1919,7 +1919,7 @@ $(clean-dirs):
 clean: $(clean-dirs)
 	$(call cmd,rmfiles)
 	@find $(or $(KBUILD_EXTMOD), .) $(RCS_FIND_IGNORE) \
-		\( -name '*.[aios]' -o -name '*.rsi' -o -name '*.ko' -o -name '.*.cmd' \
+		\( -name '*.[aios]' -o -name '*.rlib' -o -name '*.rsi' -o -name '*.ko' -o -name '.*.cmd' \
 		-o -name '*.ko.*' \
 		-o -name '*.dtb' -o -name '*.dtbo' \
 		-o -name '*.dtb.S' -o -name '*.dtbo.S' \
scripts/Makefile.build +9 -1
index da37bfa97211..627010518b27 100644
@@ -246,7 +246,9 @@ $(obj)/%.o: $(src)/%.c $(recordmcount_source) FORCE
 # To make this rule robust against "Argument list too long" error,
 # ensure to add $(obj)/ prefix by a shell command.
 cmd_mod = printf '%s\n' $(call real-search, $*.o, .o, -objs -y -m) | \
-	$(AWK) '!x[$$0]++ { print("$(obj)/"$$0) }' > $@
+	$(AWK) '!x[$$0]++ { print("$(obj)/"$$0) }' > $@ && \
+	printf '%s\n' $(call real-search, $*.rlib, .rlib, -objs -y -m) | \
+	$(AWK) '!x[$$0]++ { print("--library=$(obj)/"$$0) }' >> $@
 
 $(obj)/%.mod: FORCE
 	$(call if_changed,mod)
@@ -291,6 +293,12 @@ quiet_cmd_rustc_o_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@
 $(obj)/%.o: $(src)/%.rs FORCE
 	$(call if_changed_dep,rustc_o_rs)
 
+quiet_cmd_rustc_rlib_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@
+      cmd_rustc_rlib_rs = $(rust_common_cmd) -Ccodegen-units=1 --emit=link=$@ $<
+
+$(obj)/%.rlib: $(src)/%.rs FORCE
+	$(call if_changed_dep,rustc_rlib_rs)
+
 quiet_cmd_rustc_rsi_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@
       cmd_rustc_rsi_rs = \
 	$(rust_common_cmd) -Zunpretty=expanded $< >$@; \
scripts/Makefile.lib +13 -6
index 68d0134bdbf9..6e8cfbad015d 100644
@@ -53,14 +53,18 @@ multi-search = $(sort $(foreach m, $1, $(if $(call suffix-search, $m, $2, $3 -),
 real-search = $(foreach m, $1, $(if $(call suffix-search, $m, $2, $3 -), $(call suffix-search, $m, $2, $3), $m))
 
 # If $(foo-objs), $(foo-y), $(foo-m), or $(foo-) exists, foo.o is a composite object
-multi-obj-y := $(call multi-search, $(obj-y), .o, -objs -y)
-multi-obj-m := $(call multi-search, $(obj-m), .o, -objs -y -m)
+multi-obj-y := $(call multi-search, $(obj-y), .o, -objs -y) \
+	$(call multi-search, $(obj-y), .rlib, -objs -y)
+multi-obj-m := $(call multi-search, $(obj-m), .o, -objs -y -m) \
+	$(call multi-search, $(obj-m), .rlib, -objs -y -m)
 multi-obj-ym := $(multi-obj-y) $(multi-obj-m)
 
 # Replace multi-part objects by their individual parts,
 # including built-in.a from subdirectories
-real-obj-y := $(call real-search, $(obj-y), .o, -objs -y)
-real-obj-m := $(call real-search, $(obj-m), .o, -objs -y -m)
+real-obj-y := $(call real-search, $(obj-y), .o, -objs -y) \
+	$(call real-search, $(obj-y), .rlib, -objs -y)
+real-obj-m := $(call real-search, $(obj-m), .o, -objs -y -m) \
+	$(call real-search, $(obj-m), .rlib, -objs -y -m)
 
 always-y += $(always-m)
 
@@ -107,7 +111,8 @@ endif
 # Finds the multi-part object the current object will be linked into.
 # If the object belongs to two or more multi-part objects, list them all.
 modname-multi = $(sort $(foreach m,$(multi-obj-ym),\
-		$(if $(filter $*.o, $(call suffix-search, $m, .o, -objs -y -m)),$(m:.o=))))
+		$(if $(filter $*.o, $(call suffix-search, $m, .o, -objs -y -m)),$(m:.o=)) \
+		$(if $(filter $*.rlib, $(call suffix-search, $m, .rlib, -objs -y -m)),$(m:.rlib=))))
 
 __modname = $(or $(modname-multi),$(basetarget))
 
@@ -210,7 +215,9 @@ _cpp_flags += -I $(srctree)/$(src) -I $(objtree)/$(obj)
 endif
 endif
 
-part-of-module = $(if $(filter $(basename $@).o, $(real-obj-m)),y)
+part-of-module =                                             \
+	$(if $(or $(filter $(basename $@).o, $(real-obj-m)), \
+		$(filter $(basename $@).rlib, $(real-obj-m))),y)
 quiet_modtag = $(if $(part-of-module),[M],   )
 
 modkern_cflags =                                          \
Signature · 1 line
2.42.0
#2 lore raw

Re: [RFC PATCH 1/1] scripts: Build per module Rust crates

kernel test robot noticed the following build errors:

Hi Martin,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:

[auto build test ERROR on masahiroy-kbuild/for-next]
[also build test ERROR on masahiroy-kbuild/fixes linus/master v6.6-rc4 next-20231006] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Martin-Rodriguez-Reboredo/scripts-Build-per-module-Rust-crates/20231006-235823
base:   https://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild.git for-next
patch link:    https://lore.kernel.org/r/20231006155739.246381-2-yakoyoku%40gmail.com
patch subject: [RFC PATCH 1/1] scripts: Build per module Rust crates
config: arc-defconfig (https://download.01.org/0day-ci/archive/20231007/[email protected]/config)
compiler: arc-elf-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231007/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> make[4]: *** No rule to make target 'crypto/crypto.o', needed by 'crypto/built-in.a'.
>> make[4]: *** No rule to make target 'crypto/crypto_algapi.o', needed by 'crypto/built-in.a'.
>> make[4]: *** No rule to make target 'crypto/crypto_hash.o', needed by 'crypto/built-in.a'.
   make[4]: Target 'crypto/' not remade because of errors.
--
>> make[5]: *** No rule to make target 'fs/ext2/ext2.o', needed by 'fs/ext2/built-in.a'.
   make[5]: Target 'fs/ext2/' not remade because of errors.
--
>> make[5]: *** No rule to make target 'fs/nfs/nfs.o', needed by 'fs/nfs/built-in.a'.
>> make[5]: *** No rule to make target 'fs/nfs/nfsv2.o', needed by 'fs/nfs/built-in.a'.
>> make[5]: *** No rule to make target 'fs/nfs/nfsv3.o', needed by 'fs/nfs/built-in.a'.
   make[5]: Target 'fs/nfs/' not remade because of errors.
--
>> make[5]: *** No rule to make target 'fs/lockd/lockd.o', needed by 'fs/lockd/built-in.a'.
   make[5]: Target 'fs/lockd/' not remade because of errors.
--
>> make[5]: *** No rule to make target 'fs/tracefs/tracefs.o', needed by 'fs/tracefs/built-in.a'.
   make[5]: Target 'fs/tracefs/' not remade because of errors.
--
>> make[5]: *** No rule to make target 'lib/crypto/libcryptoutils.o', needed by 'lib/crypto/built-in.a'.
   make[5]: *** No rule to make target 'lib/crypto/libblake2s.o', needed by 'lib/crypto/built-in.a'.
>> make[5]: *** No rule to make target 'lib/crypto/libsha1.o', needed by 'lib/crypto/built-in.a'.
   make[5]: Target 'lib/crypto/' not remade because of errors.
--
>> make[5]: *** No rule to make target 'lib/zlib_inflate/zlib_inflate.o', needed by 'lib/zlib_inflate/built-in.a'.
   make[5]: Target 'lib/zlib_inflate/' not remade because of errors.
--
>> make[5]: *** No rule to make target 'lib/lzo/lzo_decompress.o', needed by 'lib/lzo/built-in.a'.
   make[5]: Target 'lib/lzo/' not remade because of errors.
--
>> make[5]: *** No rule to make target 'lib/zstd/zstd_decompress.o', needed by 'lib/zstd/built-in.a'.
>> make[5]: *** No rule to make target 'lib/zstd/zstd_common.o', needed by 'lib/zstd/built-in.a'.
   make[5]: Target 'lib/zstd/' not remade because of errors.
--
>> make[5]: *** No rule to make target 'lib/xz/xz_dec.o', needed by 'lib/xz/built-in.a'.
   make[5]: Target 'lib/xz/' not remade because of errors.
--
>> make[5]: *** No rule to make target 'net/ethtool/ethtool_nl.o', needed by 'net/ethtool/built-in.a'.

make[5]: Target 'net/ethtool/' not remade because of errors.
..

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#3 lore raw

Re: [RFC PATCH 1/1] scripts: Build per module Rust crates

In reply to Martin Rodriguez Reboredo
kernel test robot noticed the following build errors:

Hi Martin,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:

[auto build test ERROR on masahiroy-kbuild/for-next]
[also build test ERROR on masahiroy-kbuild/fixes linus/master v6.6-rc4 next-20231006] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Martin-Rodriguez-Reboredo/scripts-Build-per-module-Rust-crates/20231006-235823
base:   https://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild.git for-next
patch link:    https://lore.kernel.org/r/20231006155739.246381-2-yakoyoku%40gmail.com
patch subject: [RFC PATCH 1/1] scripts: Build per module Rust crates
config: arc-allnoconfig (https://download.01.org/0day-ci/archive/20231007/[email protected]/config)
compiler: arc-elf-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231007/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> make[5]: *** No rule to make target 'drivers/input/input-core.o', needed by 'drivers/input/built-in.a'.
   make[5]: Target 'drivers/input/' not remade because of errors.
--
>> make[5]: *** No rule to make target 'fs/iomap/iomap.o', needed by 'fs/iomap/built-in.a'.
   make[5]: Target 'fs/iomap/' not remade because of errors.
--
>> make[5]: *** No rule to make target 'fs/proc/proc.o', needed by 'fs/proc/built-in.a'.
   make[5]: Target 'fs/proc/' not remade because of errors.
--
>> make[5]: *** No rule to make target 'fs/devpts/devpts.o', needed by 'fs/devpts/built-in.a'.
   make[5]: Target 'fs/devpts/' not remade because of errors.
--
>> make[5]: *** No rule to make target 'fs/ramfs/ramfs.o', needed by 'fs/ramfs/built-in.a'.
   make[5]: Target 'fs/ramfs/' not remade because of errors.
--
>> make[5]: *** No rule to make target 'fs/exportfs/exportfs.o', needed by 'fs/exportfs/built-in.a'.
   make[5]: Target 'fs/exportfs/' not remade because of errors.
--
>> make[5]: *** No rule to make target 'kernel/printk/printk_support.o', needed by 'kernel/printk/built-in.a'.
   make[5]: Target 'kernel/printk/' not remade because of errors.
--
>> make[5]: *** No rule to make target 'lib/crypto/libblake2s.o', needed by 'lib/crypto/built-in.a'.
   make[5]: Target 'lib/crypto/' not remade because of errors.
--
>> make[6]: *** No rule to make target 'drivers/base/firmware_loader/firmware_class.o', needed by 'drivers/base/firmware_loader/built-in.a'.

make[6]: Target 'drivers/base/firmware_loader/' not remade because of errors.

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#4 lore raw

Re: [RFC PATCH 1/1] scripts: Build per module Rust crates

In reply to Martin Rodriguez Reboredo
Quoted 11 lines · Martin Rodriguez Reboredo

Enables compiling Rust crates as dependencies of kernel modules.

When a composite object depends on an .rlib file, which by the way is a current ar archive, Kbuild will compile it from its base Rust source and link it.

This makes possible to have Rust bindings for a subsystem that is compiled as a module.

I could not understand how this will work because there is no explanation how to use *.rlib in the later build steps.

If I understand correctly, does this intend to link *.rlib as a part of modules?

In C, there was a discussion about
"that would be nice to be able to link static libraries", but we do not do it any more. [1]

Following that discussion, linking libraries does not seem what we want to do.

[1]: https://lore.kernel.org/lkml/[email protected]/

Quoted 105 lines
---
 Makefile               |  4 ++--
 scripts/Makefile.build | 10 +++++++++-
 scripts/Makefile.lib   | 19 +++++++++++++------
 3 files changed, 24 insertions(+), 9 deletions(-)
Makefile +2 -2
index 7d6be12e4c3e..7774c97e8aa0 100644
@@ -283,7 +283,7 @@ no-compiler-targets := $(no-dot-config-targets) install dtbs_install \
                        headers_install modules_install modules_sign kernelrelease image_name
 no-sync-config-targets := $(no-dot-config-targets) %install modules_sign kernelrelease \
                          image_name
-single-targets := %.a %.i %.ko %.lds %.ll %.lst %.mod %.o %.rsi %.s %.symtypes %/
+single-targets := %.a %.i %.ko %.lds %.ll %.lst %.mod %.o %.rlib %.rsi %.s %.symtypes %/
 
 config-build   :=
 mixed-build    :=
@@ -1919,7 +1919,7 @@ $(clean-dirs):
 clean: $(clean-dirs)
        $(call cmd,rmfiles)
        @find $(or $(KBUILD_EXTMOD), .) $(RCS_FIND_IGNORE) \
-               \( -name '*.[aios]' -o -name '*.rsi' -o -name '*.ko' -o -name '.*.cmd' \
+               \( -name '*.[aios]' -o -name '*.rlib' -o -name '*.rsi' -o -name '*.ko' -o -name '.*.cmd' \
                -o -name '*.ko.*' \
                -o -name '*.dtb' -o -name '*.dtbo' \
                -o -name '*.dtb.S' -o -name '*.dtbo.S' \
scripts/Makefile.build +9 -1
index da37bfa97211..627010518b27 100644
@@ -246,7 +246,9 @@ $(obj)/%.o: $(src)/%.c $(recordmcount_source) FORCE
 # To make this rule robust against "Argument list too long" error,
 # ensure to add $(obj)/ prefix by a shell command.
 cmd_mod = printf '%s\n' $(call real-search, $*.o, .o, -objs -y -m) | \
-       $(AWK) '!x[$$0]++ { print("$(obj)/"$$0) }' > $@
+       $(AWK) '!x[$$0]++ { print("$(obj)/"$$0) }' > $@ && \
+       printf '%s\n' $(call real-search, $*.rlib, .rlib, -objs -y -m) | \
+       $(AWK) '!x[$$0]++ { print("--library=$(obj)/"$$0) }' >> $@
 
 $(obj)/%.mod: FORCE
        $(call if_changed,mod)
@@ -291,6 +293,12 @@ quiet_cmd_rustc_o_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@
 $(obj)/%.o: $(src)/%.rs FORCE
        $(call if_changed_dep,rustc_o_rs)
 
+quiet_cmd_rustc_rlib_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@
+      cmd_rustc_rlib_rs = $(rust_common_cmd) -Ccodegen-units=1 --emit=link=$@ $<
+
+$(obj)/%.rlib: $(src)/%.rs FORCE
+       $(call if_changed_dep,rustc_rlib_rs)
+
 quiet_cmd_rustc_rsi_rs = $(RUSTC_OR_CLIPPY_QUIET) $(quiet_modtag) $@
       cmd_rustc_rsi_rs = \
        $(rust_common_cmd) -Zunpretty=expanded $< >$@; \
scripts/Makefile.lib +13 -7
index 68d0134bdbf9..6e8cfbad015d 100644
@@ -53,14 +53,18 @@ multi-search = $(sort $(foreach m, $1, $(if $(call suffix-search, $m, $2, $3 -),
 real-search = $(foreach m, $1, $(if $(call suffix-search, $m, $2, $3 -), $(call suffix-search, $m, $2, $3), $m))
 
 # If $(foo-objs), $(foo-y), $(foo-m), or $(foo-) exists, foo.o is a composite object
-multi-obj-y := $(call multi-search, $(obj-y), .o, -objs -y)
-multi-obj-m := $(call multi-search, $(obj-m), .o, -objs -y -m)
+multi-obj-y := $(call multi-search, $(obj-y), .o, -objs -y) \
+       $(call multi-search, $(obj-y), .rlib, -objs -y)
+multi-obj-m := $(call multi-search, $(obj-m), .o, -objs -y -m) \
+       $(call multi-search, $(obj-m), .rlib, -objs -y -m)
 multi-obj-ym := $(multi-obj-y) $(multi-obj-m)
 
 # Replace multi-part objects by their individual parts,
 # including built-in.a from subdirectories
-real-obj-y := $(call real-search, $(obj-y), .o, -objs -y)
-real-obj-m := $(call real-search, $(obj-m), .o, -objs -y -m)
+real-obj-y := $(call real-search, $(obj-y), .o, -objs -y) \
+       $(call real-search, $(obj-y), .rlib, -objs -y)
+real-obj-m := $(call real-search, $(obj-m), .o, -objs -y -m) \
+       $(call real-search, $(obj-m), .rlib, -objs -y -m)
 
 always-y += $(always-m)
 
@@ -107,7 +111,8 @@ endif
 # Finds the multi-part object the current object will be linked into.
 # If the object belongs to two or more multi-part objects, list them all.
 modname-multi = $(sort $(foreach m,$(multi-obj-ym),\
-               $(if $(filter $*.o, $(call suffix-search, $m, .o, -objs -y -m)),$(m:.o=))))
+               $(if $(filter $*.o, $(call suffix-search, $m, .o, -objs -y -m)),$(m:.o=)) \
+               $(if $(filter $*.rlib, $(call suffix-search, $m, .rlib, -objs -y -m)),$(m:.rlib=))))
 
 __modname = $(or $(modname-multi),$(basetarget))
 
@@ -210,7 +215,9 @@ _cpp_flags += -I $(srctree)/$(src) -I $(objtree)/$(obj)
 endif
 endif
 
-part-of-module = $(if $(filter $(basename $@).o, $(real-obj-m)),y)
+part-of-module =                                             \
+       $(if $(or $(filter $(basename $@).o, $(real-obj-m)), \
+               $(filter $(basename $@).rlib, $(real-obj-m))),y)
 quiet_modtag = $(if $(part-of-module),[M],   )
 
 modkern_cflags =                                          \
--
Quoted 2 lines

2.42.0

--
Best Regards
Masahiro Yamada

#5 lore raw

Re: [RFC PATCH 1/1] scripts: Build per module Rust crates

Quoted 4 lines · Masahiro Yamada

I could not understand how this will work because there is no explanation how to use *.rlib in the later build steps.

It seems linux-kbuild was not Cc'd in the cover letter -- I replied to
Martin there: https://lore.kernel.org/rust-for-linux/[email protected]/

Cheers,
Miguel

#6 lore raw

Re: [RFC PATCH 1/1] scripts: Build per module Rust crates

In reply to Masahiro Yamada
Quoted 15 lines · Masahiro Yamada
Quoted 11 lines · Martin Rodriguez Reboredo

Enables compiling Rust crates as dependencies of kernel modules.

When a composite object depends on an .rlib file, which by the way is a current ar archive, Kbuild will compile it from its base Rust source and link it.

This makes possible to have Rust bindings for a subsystem that is compiled as a module.

Quoted 6 lines

I could not understand how this will work because there is no explanation how to use *.rlib in the later build steps.

If I understand correctly, does this intend to link *.rlib as a part of modules?

Yes, the purpose of this RFC is to link the *.rlib, its members specifically, as part of modules to avoid the scenario of having Rust bindings linked statically and their C counterparts dynamically.

I'll write a v2 that'll clarify its usage. I've made more progress locally and had run tests with success.

#7 lore raw
In reply to Martin Rodriguez Reboredo
Quoted 3 lines · Martin Rodriguez Reboredo

For now I don't have a completely working example but I have an MWE as following...

Thanks Martin, I appreciate it, but I don't think this would work in the general case we want to solve.

I have been intending to work on this for a long time now, and I still mean to. Hopefully I will have some news at LPC.

Cheers,
Miguel

#8 lore raw
Quoted 8 lines · Miguel Ojeda
Quoted 3 lines · Martin Rodriguez Reboredo

For now I don't have a completely working example but I have an MWE as following...

Thanks Martin, I appreciate it, but I don't think this would work in the general case we want to solve.

Well, there's the network PHY driver series that is stuck on this topic, I (and probably others) have local work that have the same issue and said general case might not arrive that soon. So it'd better to start on a feature that will benefit API users right away and can be updated to fit needs. That's what I think.

Quoted 5 lines

I have been intending to work on this for a long time now, and I still mean to. Hopefully I will have some news at LPC.

Cheers,
Miguel

#9 lore raw
Quoted 3 lines · Martin Rodriguez Reboredo

Well, there's the network PHY driver series that is stuck on this topic, I (and probably others) have local work that have the same issue

No, that series is not stuck on this.

Quoted 3 lines

and said general case might not arrive that soon. So it'd better to start on a feature that will benefit API users right away and can be updated to fit needs. That's what I think.

If there is an in-tree use case that will really require a solution to this very soon, then please focus on explaining that (e.g. what "local work" do you have and what are your plans for landing it upstream?) and we will do our best to reschedule priorities or we can provide a workaround for the time being.

In any case, please note that this RFC breaks the kernel build and does not really solve the overall issue.

Cheers,
Miguel

#10 lore raw
Quoted 19 lines · Miguel Ojeda
Quoted 3 lines · Martin Rodriguez Reboredo

Well, there's the network PHY driver series that is stuck on this topic, I (and probably others) have local work that have the same issue

No, that series is not stuck on this.

Quoted 3 lines

and said general case might not arrive that soon. So it'd better to start on a feature that will benefit API users right away and can be updated to fit needs. That's what I think.

If there is an in-tree use case that will really require a solution to this very soon, then please focus on explaining that (e.g. what "local work" do you have and what are your plans for landing it upstream?) and we will do our best to reschedule priorities or we can provide a workaround for the time being.

Quoted 6 lines

In any case, please note that this RFC breaks the kernel build and does not really solve the overall issue.

Cheers,
Miguel

Does this rely on the assumption that usb.rlib is small enough because usb.rlib will be linked to every usb driver.

So, usb.rlib is just a binding, not able to write the subsystem code in Rust, correct?

Signature · 2 lines
Best Regards
Masahiro Yamada