|
| 1 | +# Third-party crates |
| 2 | + |
| 3 | +## Introduction |
| 4 | + |
| 5 | +Rust provides a package manager and build system called [Cargo](https://doc.rust-lang.org/cargo/). Rust also provides [crates.io](https://crates.io), its default package registry. In userspace, all these form a solution that a lot of open-source Rust projects use. |
| 6 | + |
| 7 | +Some of those open-source libraries are potentially usable in the kernel because they only depend on `core` and `alloc` (rather than `std`), or because they only provide macro facilities. |
| 8 | + |
| 9 | +Thus it is natural to consider whether some of these libraries could be reused for the kernel. |
| 10 | + |
| 11 | +## Suitability of a crate |
| 12 | + |
| 13 | +Even if a library only depends on `core` and `alloc`, it may still not be usable within the kernel for other reasons. |
| 14 | + |
| 15 | +For instance, its license may be incompatible, it may not support fallible allocations, the kernel may only need a very small subset of what it supports (even if it supports configuring out some of its features), the kernel may already provide the same functionality on the C side (which could be abstracted), etc. |
| 16 | + |
| 17 | +On top of that, the code of a crate may require some changes to be adapted for the kernel anyway. For instance, adding SPDX license identifiers, removing a dependency, tweaking some code, enabling an unstable feature, etc. |
| 18 | + |
| 19 | +Moreover, new code arriving to the kernel should be maintained; and thus somebody needs to step up for that role. |
| 20 | + |
| 21 | +Therefore, in general, whether a third-party crate is suitable for the kernel needs to be decided on a case-by-case basis. |
| 22 | + |
| 23 | +## Importing crates |
| 24 | + |
| 25 | +The kernel currently integrates some dependencies (e.g. some of the compression algorithms or our Rust `alloc` fork) by importing the files into its source tree, adapted as needed. In other words, they are not fetched/patched on demand. |
| 26 | + |
| 27 | +There have been discussions about potentially incorporating a system where crates/libraries are fetched dynamically given a list of crates, versions, hashes, etc.; however, it remains to be seen whether such a system would be preferred and accepted. |
| 28 | + |
| 29 | +## Supporting out-of-tree modules |
| 30 | + |
| 31 | +The project is focused on getting features upstreamed, i.e. available for everybody. Therefore, if mainline does not support third-party crates and/or a system to fetch them dynamically, then it is unlikely it will be supported for out-of-tree modules. |
| 32 | + |
| 33 | +## Experiment |
| 34 | + |
| 35 | +Experimental integration for a few popular crates has been provided for interested users, e.g. [PR #1007](https://github.com/Rust-for-Linux/linux/pull/1007) adds support for `proc-macro2`, `quote`, `syn`, `serde` and `serde_derive`. |
| 36 | + |
| 37 | +## Feedback |
| 38 | + |
| 39 | +We are looking for [feedback](Contact.md) from other kernel developers, maintainers and companies on which third-party crates would be most useful to have in the kernel. |
0 commit comments