From ff8e8e0f8b7122e112d4c43b6f005073dfb8be6a Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Tue, 20 Jun 2017 17:41:28 +0200 Subject: [PATCH] The collections crate was merged into the alloc crate (#333) --- Xargo.toml | 2 +- blog/content/extra/cross-compile-libcore.md | 2 +- .../03-returning-from-exceptions/index.md | 7 +++---- blog/content/posts/08-kernel-heap/index.md | 20 +++++++++---------- src/lib.rs | 5 ++--- 5 files changed, 16 insertions(+), 20 deletions(-) diff --git a/Xargo.toml b/Xargo.toml index e1d040b3..73f2a1d2 100644 --- a/Xargo.toml +++ b/Xargo.toml @@ -1,2 +1,2 @@ [target.x86_64-blog_os.dependencies] -collections = {} +alloc = {} diff --git a/blog/content/extra/cross-compile-libcore.md b/blog/content/extra/cross-compile-libcore.md index a67b78c4..c27301fe 100644 --- a/blog/content/extra/cross-compile-libcore.md +++ b/blog/content/extra/cross-compile-libcore.md @@ -29,7 +29,7 @@ If the installation fails, make sure that you have `cmake` and the OpenSSL heade [xargo]: https://github.com/japaric/xargo [dependency section]: https://github.com/japaric/xargo#dependencies -Xargo is “a drop-in replacement for cargo”, so every cargo command also works with `xargo`. You can do e.g. `xargo --help`, `xargo clean`, or `xargo doc`. However, the `build` command gains additional functionality: `xargo build` will automatically cross compile the `core` library (and a few other libraries such as `alloc` and `collections`) when compiling for custom targets. +Xargo is “a drop-in replacement for cargo”, so every cargo command also works with `xargo`. You can do e.g. `xargo --help`, `xargo clean`, or `xargo doc`. However, the `build` command gains additional functionality: `xargo build` will automatically cross compile the `core` library (and a few other libraries such as `alloc`) when compiling for custom targets. [xargo]: https://github.com/japaric/xargo diff --git a/blog/content/extra/naked-exceptions/03-returning-from-exceptions/index.md b/blog/content/extra/naked-exceptions/03-returning-from-exceptions/index.md index e9223f1b..79d9eee7 100644 --- a/blog/content/extra/naked-exceptions/03-returning-from-exceptions/index.md +++ b/blog/content/extra/naked-exceptions/03-returning-from-exceptions/index.md @@ -655,23 +655,22 @@ error: aborting due to previous error ``` We see that `xargo` now compiles the `core` crate in release mode. Then it starts the normal cargo build. Cargo then recompiles all dependencies, since it needs to generate different code for the new target. -However, the build still fails. The reason is that xargo only installs `core` by default, but we also need the `alloc` and `collections` crates. We can enable them by creating a file named `Xargo.toml` with the following contents: +However, the build still fails. The reason is that xargo only installs `core` by default, but we also need the `alloc` crate. We can enable it by creating a file named `Xargo.toml` with the following contents: ```toml # Xargo.toml [target.x86_64-blog_os.dependencies] -collections = {} +alloc = {} ``` -Now xargo compiles `alloc` and `collections`, too: +Now xargo compiles `alloc`, too: ``` > make run Compiling core v0.0.0 (file:///…/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore) Compiling std_unicode v0.0.0 (file:///…/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd_unicode) Compiling alloc v0.0.0 (file:///…/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/liballoc) - Compiling collections v0.0.0 (file:///…/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcollections) Finished release [optimized] target(s) in 28.84 secs Compiling blog_os v0.1.0 (file:///…/Documents/blog_os/master) warning: unused variable: `allocator` […] diff --git a/blog/content/posts/08-kernel-heap/index.md b/blog/content/posts/08-kernel-heap/index.md index c9e0855e..fdd97994 100644 --- a/blog/content/posts/08-kernel-heap/index.md +++ b/blog/content/posts/08-kernel-heap/index.md @@ -5,12 +5,11 @@ url = "kernel-heap" date = "2016-04-11" +++ -In the previous posts we have created a [frame allocator] and a [page table module]. Now we are ready to create a kernel heap and a memory allocator. Thus, we will unlock `Box`, `Vec`, `BTreeMap`, and the rest of the [alloc] and [collections] crates. +In the previous posts we have created a [frame allocator] and a [page table module]. Now we are ready to create a kernel heap and a memory allocator. Thus, we will unlock `Box`, `Vec`, `BTreeMap`, and the rest of the [alloc] crate. [frame allocator]: ./posts/05-allocating-frames/index.md [page table module]: ./posts/06-page-tables/index.md [alloc]: https://doc.rust-lang.org/nightly/alloc/index.html -[collections]: https://doc.rust-lang.org/nightly/collections/index.html @@ -292,19 +291,18 @@ Additionally, we need to tell cargo where our `bump_allocator` crate lives: path = "libs/bump_allocator" ``` -Now we're able to import the `alloc` and `collections` crates in order to unlock `Box`, `Vec`, `BTreeMap`, and friends: +Now we're able to import the `alloc` crate in order to unlock `Box`, `Vec`, `BTreeMap`, and friends: ```rust // in src/lib.rs of our main project -#![feature(alloc, collections)] +#![feature(alloc)] extern crate bump_allocator; -extern crate alloc; #[macro_use] -extern crate collections; +extern crate alloc; ``` -The `collections` crate provides the [format!] and [vec!] macros, so we use `#[macro_use]` to import them. +The `alloc` crate provides the [format!] and [vec!] macros, so we use `#[macro_use]` to import them. [format!]: //doc.rust-lang.org/nightly/collections/macro.format!.html [vec!]: https://doc.rust-lang.org/nightly/collections/macro.vec!.html @@ -319,16 +317,16 @@ error[E0463]: can't find crate for `alloc` | ^^^^^^^^^^^^^^^^^^^ can't find crate ``` -The problem is that [`xargo`] only cross compiles `libcore` by default. To also cross compile the `alloc` and `collections` crates, we need to create a file named `Xargo.toml` in our project root (right next to the `Cargo.toml`) with the following content: +The problem is that [`xargo`] only cross compiles `libcore` by default. To also cross compile the `alloc` crate, we need to create a file named `Xargo.toml` in our project root (right next to the `Cargo.toml`) with the following content: [`xargo`]: https://github.com/japaric/xargo ```toml [target.x86_64-blog_os.dependencies] -collections = {} +alloc = {} ``` -This instructs `xargo` that we also need `collections` and `alloc` (a dependency of `collections`). Now it should compile again. +This instructs `xargo` that we also need `alloc`. Now it should compile again. ### Testing @@ -573,7 +571,7 @@ for i in &vec_test { } ``` -We can also use all other types of the `alloc` and `collections` crates, including: +We can also use all other types of the `alloc` crate, including: - the reference counted pointers [Rc] and [Arc] - the owned string type [String] and the [format!] macro diff --git a/src/lib.rs b/src/lib.rs index 2afc3004..7260108a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,7 +9,7 @@ #![feature(lang_items)] #![feature(const_fn, unique)] -#![feature(alloc, collections)] +#![feature(alloc)] #![feature(asm)] #![feature(naked_functions)] #![feature(abi_x86_interrupt)] @@ -29,9 +29,8 @@ extern crate bit_field; extern crate lazy_static; extern crate hole_list_allocator; -extern crate alloc; #[macro_use] -extern crate collections; +extern crate alloc; #[macro_use] mod vga_buffer;