From 0b5e89fbb740ac4f84e4f54fc8f848fb91a664bd Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Sun, 18 Nov 2018 15:30:19 +0100 Subject: [PATCH] Remove all the `extern crate` definitions --- .../posts/02-minimal-rust-kernel/index.md | 6 ---- .../posts/03-vga-text-buffer/index.md | 19 ------------- .../posts/04-unit-testing/index.md | 10 +------ .../posts/05-integration-tests/index.md | 28 +------------------ .../posts/08-hardware-interrupts/index.md | 12 -------- 5 files changed, 2 insertions(+), 73 deletions(-) diff --git a/blog/content/second-edition/posts/02-minimal-rust-kernel/index.md b/blog/content/second-edition/posts/02-minimal-rust-kernel/index.md index 5f7b5f62..f816f306 100644 --- a/blog/content/second-edition/posts/02-minimal-rust-kernel/index.md +++ b/blog/content/second-edition/posts/02-minimal-rust-kernel/index.md @@ -332,12 +332,6 @@ Instead of writing our own bootloader, which is a project on its own, we use the bootloader = "0.3.4" ``` -```rust -// in main.rs - -extern crate bootloader; -``` - Adding the bootloader as dependency is not enough to actually create a bootable disk image. The problem is that we need to combine the bootloader with the kernel after it has been compiled, but cargo has no support for additional build steps after successful compilation (see [this issue][post-build script] for more information). [post-build script]: https://github.com/rust-lang/cargo/issues/545 diff --git a/blog/content/second-edition/posts/03-vga-text-buffer/index.md b/blog/content/second-edition/posts/03-vga-text-buffer/index.md index f7df65c6..0ecb211a 100644 --- a/blog/content/second-edition/posts/03-vga-text-buffer/index.md +++ b/blog/content/second-edition/posts/03-vga-text-buffer/index.md @@ -285,14 +285,6 @@ The `0.2.3` is the [semantic] version number. For more information, see the [Spe [semantic]: http://semver.org/ [Specifying Dependencies]: http://doc.crates.io/specifying-dependencies.html -Now we've declared that our project depends on the `volatile` crate and are able to import it in `src/main.rs`: - -```rust -// in src/main.rs - -extern crate volatile; -``` - Let's use it to make writes to the VGA buffer volatile. We update our `Buffer` type as follows: ```rust @@ -475,12 +467,6 @@ The one-time initialization of statics with non-const functions is a common prob Let's add the `lazy_static` crate to our project: -```rust -// in src/main.rs - -extern crate lazy_static; -``` - ```toml # in Cargo.toml @@ -532,11 +518,6 @@ To use a spinning mutex, we can add the [spin crate] as a dependency: spin = "0.4.9" ``` -```rust -// in src/main.rs -extern crate spin; -``` - Then we can use the spinning Mutex to add safe [interior mutability] to our static `WRITER`: ```rust diff --git a/blog/content/second-edition/posts/04-unit-testing/index.md b/blog/content/second-edition/posts/04-unit-testing/index.md index a98a2848..ae8962e2 100644 --- a/blog/content/second-edition/posts/04-unit-testing/index.md +++ b/blog/content/second-edition/posts/04-unit-testing/index.md @@ -244,18 +244,10 @@ To use that crate, we add the following to our `Cargo.toml`: array-init = "0.0.3" ``` -Note that we're using the [`dev-dependencies`] table instead of the `dependencies` table, because we only need the crate for `cargo test` and not for a normal build. Consequently, we also add a `#[cfg(test)]` attribute to the `extern crate` declaration in `main.rs`: +Note that we're using the [`dev-dependencies`] table instead of the `dependencies` table, because we only need the crate for `cargo test` and not for a normal build. [`dev-dependencies`]: https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#development-dependencies - -```rust -// in main.rs - -#[cfg(test)] -extern crate array_init; -``` - Now we can fix our `construct_buffer` function: ```rust diff --git a/blog/content/second-edition/posts/05-integration-tests/index.md b/blog/content/second-edition/posts/05-integration-tests/index.md index 2e38b415..56351524 100644 --- a/blog/content/second-edition/posts/05-integration-tests/index.md +++ b/blog/content/second-edition/posts/05-integration-tests/index.md @@ -66,12 +66,6 @@ We will use the [`uart_16550`] crate to initialize the UART and send data over t uart_16550 = "0.1.0" ``` -```rust -// in src/main.rs - -extern crate uart_16550; -``` - The `uart_16550` crate contains a `SerialPort` struct that represents the UART registers, but we still need to construct an instance of it ourselves. For that we create a new `serial` module with the following content: ```rust @@ -210,8 +204,6 @@ x86_64 = "0.2.8" ```rust // in src/main.rs -extern crate x86_64; - pub unsafe fn exit_qemu() { use x86_64::instructions::port::Port; @@ -376,16 +368,6 @@ Cargo supports hybrid projects that are both a library and a binary. We only nee #![cfg_attr(not(test), no_std)] // don't link the Rust standard library -extern crate bootloader; -extern crate spin; -extern crate volatile; -extern crate lazy_static; -extern crate uart_16550; -extern crate x86_64; - -#[cfg(test)] -extern crate array_init; - // NEW: We need to add `pub` here to make them accessible from the outside pub mod vga_buffer; pub mod serial; @@ -405,9 +387,6 @@ pub unsafe fn exit_qemu() { #![cfg_attr(not(test), no_main)] // disable all Rust-level entry points #![cfg_attr(test, allow(dead_code, unused_macros, unused_imports))] -// NEW: Add the library as dependency (same crate name as executable) -extern crate blog_os; - use core::panic::PanicInfo; use blog_os::println; @@ -430,7 +409,7 @@ fn panic(info: &PanicInfo) -> ! { } ``` -So we move everything except `_start` and `panic` to `lib.rs`, make the `vga_buffer` and `serial` modules public, and add an `extern crate` definition to our `main.rs`. Everything should work exactly as before, including `bootimage run` and `cargo test`. +So we move everything except `_start` and `panic` to `lib.rs` and make the `vga_buffer` and `serial` modules public. Everything should work exactly as before, including `bootimage run` and `cargo test`. ### Test Basic Boot @@ -443,9 +422,6 @@ We are finally able to create our first integration test executable. We start si #![cfg_attr(not(test), no_main)] // disable all Rust-level entry points #![cfg_attr(test, allow(dead_code, unused_macros, unused_imports))] -// add the library as dependency (same crate name as executable) -extern crate blog_os; - use core::panic::PanicInfo; use blog_os::{exit_qemu, serial_println}; @@ -507,8 +483,6 @@ To test that our panic handler is really invoked on a panic, we create a `test-p #![cfg_attr(not(test), no_main)] #![cfg_attr(test, allow(dead_code, unused_macros, unused_imports))] -extern crate blog_os; - use core::panic::PanicInfo; use blog_os::{exit_qemu, serial_println}; diff --git a/blog/content/second-edition/posts/08-hardware-interrupts/index.md b/blog/content/second-edition/posts/08-hardware-interrupts/index.md index 58175f31..5d4a71e8 100644 --- a/blog/content/second-edition/posts/08-hardware-interrupts/index.md +++ b/blog/content/second-edition/posts/08-hardware-interrupts/index.md @@ -85,12 +85,6 @@ To add the crate as dependency, we add the following to our project: pic8259_simple = "0.1.1" ``` -```rust -// in src/lib.rs - -extern crate pic8259_simple; -``` - The main abstraction provided by the crate is the [`ChainedPics`] struct that represents the primary/secondary PIC layout we saw above. It is designed to be used in the following way: [`ChainedPics`]: https://docs.rs/pic8259_simple/0.1.1/pic8259_simple/struct.ChainedPics.html @@ -543,12 +537,6 @@ Translating the other keys works in the same way. Fortunately there is a crate n pc-keyboard = "0.3.1" ``` -```rust -// in src/lib.rs - -extern crate pc_keyboard; -``` - Now we can use this crate to rewrite our `keyboard_interrupt_handler`: ```rust