mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 22:37:49 +00:00
The collections crate was merged into the alloc crate (#333)
This commit is contained in:
committed by
GitHub
parent
7d584818ff
commit
ff8e8e0f8b
@@ -1,2 +1,2 @@
|
||||
[target.x86_64-blog_os.dependencies]
|
||||
collections = {}
|
||||
alloc = {}
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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` […]
|
||||
|
||||
@@ -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
|
||||
|
||||
<!-- more --><aside id="toc"></aside>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user