Skip to content

Commit c85dd9a

Browse files
authored
Merge pull request #402 from ojeda/alloc
Custom `alloc`, using stable Rust compilers, and more
2 parents dfaa42f + 3bb8661 commit c85dd9a

39 files changed

+18616
-73
lines changed

.github/workflows/ci.yaml

+11-9
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
arch: [arm, arm64, ppc64le, riscv64, x86_64]
1414
toolchain: [gcc, clang, llvm]
1515
config: [debug, release]
16-
rustc: [2021-05-29]
16+
rustc: [2021-06-23]
1717
output: [src] # [src, build]
1818
install: [rustup] # [rustup, standalone]
1919
sysroot: [common] # [common, custom]
@@ -30,30 +30,30 @@ jobs:
3030

3131
# A few independent combinations to avoid exploding the matrix:
3232
# - The other option for `output`.
33-
# - Different nightlies for `rustc`.
33+
# - Different releases for `rustc`.
3434
# - The other three (`install`, `sysroot`) combinations
3535
# (they are interrelated, so the cross-product needs to be tested)
3636
include:
3737
- arch: arm64
3838
toolchain: gcc
3939
config: debug
40-
rustc: 2021-05-29
40+
rustc: 2021-06-23
4141
output: build
4242
install: rustup
4343
sysroot: custom
4444

4545
- arch: ppc64le
4646
toolchain: clang
4747
config: release
48-
rustc: 2021-05-29
48+
rustc: 2021-06-23
4949
output: build
5050
install: standalone
5151
sysroot: common
5252

5353
- arch: x86_64
5454
toolchain: llvm
5555
config: debug
56-
rustc: 2021-05-29
56+
rustc: 2021-06-23
5757
output: build
5858
install: standalone
5959
sysroot: custom
@@ -178,12 +178,14 @@ jobs:
178178
# Setup: rustc
179179
- if: matrix.install == 'rustup'
180180
run: |
181-
rustup default nightly-${{ matrix.rustc }}
181+
rustup default beta-${{ matrix.rustc }}
182182
rustup component add rustfmt
183183
- if: matrix.install == 'standalone'
184184
run: |
185-
curl https://static.rust-lang.org/dist/${{ matrix.rustc }}/rust-nightly-x86_64-unknown-linux-gnu.tar.gz | tar xz
186-
rust-nightly-x86_64-unknown-linux-gnu/install.sh --without=rust-docs --prefix=$HOME/rustc
185+
# FIXME: there is no beta equivalent for https://static.rust-lang.org/dist/channel-rust-x.yy.z.toml,
186+
# so just hardcode the URL/date for the moment, since we will moving to a stable release soon anyway.
187+
curl https://static.rust-lang.org/dist/${{ matrix.rustc }}/rust-beta-x86_64-unknown-linux-gnu.tar.gz | tar xz
188+
rust-beta-x86_64-unknown-linux-gnu/install.sh --without=rust-docs --prefix=$HOME/rustc
187189
echo $HOME/rustc/bin >> $GITHUB_PATH
188190
189191
# Setup: rustc native libs
@@ -402,7 +404,7 @@ jobs:
402404
- run: make ${{ env.MAKE_ARCH }} ${{ env.MAKE_CROSS_COMPILE }} ${{ env.MAKE_TOOLCHAIN }} ${{ env.MAKE_OUTPUT }} ${{ env.MAKE_SYSROOT }} -j3 rusttest
403405

404406
# Formatting
405-
- run: make rustfmtcheck
407+
- run: make ${{ env.MAKE_ARCH }} ${{ env.MAKE_CROSS_COMPILE }} ${{ env.MAKE_TOOLCHAIN }} ${{ env.MAKE_OUTPUT }} ${{ env.MAKE_SYSROOT }} -j3 rustfmtcheck
406408

407409
# View changes to ccache
408410
- run: ccache -s

.rustfmt.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
edition = "2018"
2-
format_code_in_doc_comments = true
32
newline_style = "Unix"
43

54
# Unstable options that help catching some mistakes in formatting and that we may want to enable
65
# when they become stable.
76
#
87
# They are kept here since they are useful to run from time to time.
8+
#format_code_in_doc_comments = true
99
#reorder_impl_items = true
1010
#comment_width = 100
1111
#wrap_comments = true

Documentation/process/changes.rst

+6-2
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,17 @@ running a Linux kernel. Also, not all tools are necessary on all
2626
systems; obviously, if you don't have any PC Card hardware, for example,
2727
you probably needn't concern yourself with pcmciautils.
2828

29+
Furthermore, note that newer versions of the Rust toolchain may or may not work
30+
because, for the moment, we depend on some unstable features. Thus, unless you
31+
know what you are doing, use the exact version listed here. Please see
32+
:ref:`Documentation/rust/quick-start.rst <rust_quick_start>` for details.
33+
2934
====================== =============== ========================================
3035
Program Minimal version Command to check the version
3136
====================== =============== ========================================
3237
GNU C 4.9 gcc --version
3338
Clang/LLVM (optional) 10.0.1 clang --version
34-
rustc (optional) nightly rustc --version
39+
rustc (optional) 1.54.0-beta.1 rustc --version
3540
bindgen (optional) 0.56.0 bindgen --version
3641
GNU make 3.81 make --version
3742
binutils 2.23 ld -v
@@ -57,7 +62,6 @@ iptables 1.4.2 iptables -V
5762
openssl & libcrypto 1.0.0 openssl version
5863
bc 1.06.95 bc --version
5964
Sphinx\ [#f1]_ 1.3 sphinx-build --version
60-
rustdoc (optional) nightly rustdoc --version
6165
====================== =============== ========================================
6266

6367
.. [#f1] Sphinx is needed only to build the Kernel documentation

Documentation/rust/quick-start.rst

+23-9
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ at the time of writing, they are likely to not be recent enough.
2323
rustc
2424
*****
2525

26-
A recent *nightly* Rust toolchain (with, at least, ``rustc``) is required,
27-
e.g. ``nightly-2021-05-29``. Our goal is to use a stable toolchain as soon
28-
as possible, but for the moment we depend on a handful of nightly features.
26+
A particular version (`1.54.0-beta.1`) of the Rust compiler is required.
27+
Newer versions may or may not work because, for the moment, we depend on
28+
some unstable Rust features.
2929

3030
If you are using ``rustup``, run::
3131

32-
rustup default nightly-2021-05-29
32+
rustup default beta-2021-06-23
3333

3434
Otherwise, fetch a standalone installer or install ``rustup`` from:
3535

@@ -125,16 +125,30 @@ the component manually::
125125
The standalone installers also come with ``clippy``.
126126

127127

128+
cargo
129+
*****
130+
131+
``cargo`` is the Rust native build system. It is currently required to run
132+
the tests (``rusttest`` target) since we use it to build a custom standard
133+
library that contains the facilities provided by our custom ``alloc``.
134+
135+
If you are using ``rustup``, all the profiles already install the tool,
136+
so you should be good to go. The standalone installers also include ``cargo``.
137+
138+
128139
rustdoc
129140
*******
130141

131-
If you install the ``rustdoc`` tool, then you will be able to generate pretty
132-
HTML documentation for Rust code, including for the libraries (crates) inside
133-
``rust/`` that are used by the rest of the kernel (for details, please see
134-
:ref:`Documentation/rust/docs.rst <rust_docs>`).
142+
``rustdoc`` is the documentation tool for Rust. It generates pretty HTML
143+
documentation for Rust code (for details, please see
144+
:ref:`Documentation/rust/docs.rst <rust_docs>`.
145+
146+
``rustdoc`` is also able to test the examples provided in documented Rust code
147+
(called doctests or documentation tests). We use this feature, thus ``rustdoc``
148+
is required to run the tests (``rusttest`` target).
135149

136150
If you are using ``rustup``, all the profiles already install the tool,
137-
so you should be good to go. The standalone installers also come with ``rustdoc``.
151+
so you should be good to go. The standalone installers also include ``rustdoc``.
138152

139153

140154
rust-analyzer

Makefile

+22-9
Original file line numberDiff line numberDiff line change
@@ -460,9 +460,12 @@ READELF = $(CROSS_COMPILE)readelf
460460
STRIP = $(CROSS_COMPILE)strip
461461
endif
462462
RUSTC = rustc
463+
RUSTC_BOOTSTRAP = 1
464+
RUSTDOC = rustdoc
463465
RUSTFMT = rustfmt
464466
CLIPPY_DRIVER = clippy-driver
465467
BINDGEN = bindgen
468+
CARGO = cargo
466469
PAHOLE = pahole
467470
RESOLVE_BTFIDS = $(objtree)/tools/bpf/resolve_btfids/resolve_btfids
468471
LEX = flex
@@ -524,7 +527,7 @@ KBUILD_RUSTCFLAGS := --emit=dep-info,obj,metadata --edition=2018 \
524527
-Cpanic=abort -Cembed-bitcode=n -Clto=n -Crpath=n \
525528
-Cforce-unwind-tables=n -Ccodegen-units=1 \
526529
-Zbinary_dep_depinfo=y -Zsymbol-mangling-version=v0 \
527-
-D unsafe_op_in_unsafe_fn
530+
-Dunsafe_op_in_unsafe_fn -Wmissing_docs
528531
KBUILD_AFLAGS_KERNEL :=
529532
KBUILD_CFLAGS_KERNEL :=
530533
KBUILD_RUSTCFLAGS_KERNEL :=
@@ -542,13 +545,13 @@ else
542545
RUSTC_OR_CLIPPY_QUIET := RUSTC
543546
RUSTC_OR_CLIPPY = $(RUSTC)
544547
endif
545-
export RUSTC_OR_CLIPPY_QUIET RUSTC_OR_CLIPPY
546548

547549
ifdef RUST_LIB_SRC
548550
export RUST_LIB_SRC
549551
endif
550552

551-
export ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE LD CC RUSTC BINDGEN
553+
export ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE LD CC
554+
export RUSTC RUSTC_BOOTSTRAP RUSTDOC RUSTFMT RUSTC_OR_CLIPPY_QUIET RUSTC_OR_CLIPPY BINDGEN CARGO
552555
export CPP AR NM STRIP OBJCOPY OBJDUMP READELF PAHOLE RESOLVE_BTFIDS LEX YACC AWK INSTALLKERNEL
553556
export PERL PYTHON3 CHECK CHECKFLAGS MAKE UTS_MACHINE HOSTCXX
554557
export KGZIP KBZIP2 KLZOP LZMA LZ4 XZ ZSTD
@@ -1596,7 +1599,7 @@ endif # CONFIG_MODULES
15961599
# Directories & files removed with 'make clean'
15971600
CLEAN_FILES += include/ksym vmlinux.symvers modules-only.symvers \
15981601
modules.builtin modules.builtin.modinfo modules.nsdeps \
1599-
compile_commands.json .thinlto-cache
1602+
compile_commands.json .thinlto-cache rust/test rust/doc
16001603

16011604
# Directories & files removed with 'make mrproper'
16021605
MRPROPER_FILES += include/config include/generated \
@@ -1726,7 +1729,7 @@ help:
17261729
@echo ' rustdoc - Generate Rust documentation'
17271730
@echo ' (requires kernel .config)'
17281731
@echo ' rusttest - Runs the Rust tests'
1729-
@echo ' (requires kernel .config)'
1732+
@echo ' (requires kernel .config; downloads external repos)'
17301733
@echo ' rust-analyzer - Generate rust-project.json rust-analyzer support file'
17311734
@echo ' (requires kernel .config)'
17321735
@echo ''
@@ -1820,11 +1823,21 @@ rusttest: prepare0
18201823
# Formatting targets
18211824
PHONY += rustfmt rustfmtcheck
18221825

1826+
# We skip `rust/alloc` since we want to minimize the diff w.r.t. upstream.
1827+
#
1828+
# We match using absolute paths since `find` does not resolve them
1829+
# when matching, which is a problem when e.g. `srctree` is `..`.
1830+
# We `grep` afterwards in order to remove the directory entry itself.
18231831
rustfmt:
1824-
find $(srctree) -type f -name '*.rs' | xargs $(RUSTFMT)
1825-
1826-
rustfmtcheck:
1827-
find $(srctree) -type f -name '*.rs' | xargs $(RUSTFMT) --check
1832+
$(Q)find $(abs_srctree) -type f -name '*.rs' \
1833+
-o -path $(abs_srctree)/rust/alloc -prune \
1834+
-o -path $(abs_objtree)/rust/test -prune \
1835+
| grep -Fv $(abs_srctree)/rust/alloc \
1836+
| grep -Fv $(abs_objtree)/rust/test \
1837+
| xargs $(RUSTFMT) $(rustfmt_flags)
1838+
1839+
rustfmtcheck: rustfmt_flags = --check
1840+
rustfmtcheck: rustfmt
18281841

18291842
# IDE support targets
18301843
PHONY += rust-analyzer

drivers/android/process.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -614,12 +614,11 @@ impl Process {
614614
for _ in 0..page_count {
615615
let page = Pages::<0>::new()?;
616616
page.insert_page(vma, address)?;
617-
pages.push(page);
617+
pages.try_push(page)?;
618618
address += 1 << bindings::PAGE_SHIFT;
619619
}
620620

621-
// TODO: This allocates memory.
622-
let arc = Arc::from(pages);
621+
let arc = Arc::try_from_vec(pages)?;
623622

624623
// Save pages for later.
625624
let mut inner = self.inner.lock();

0 commit comments

Comments
 (0)