mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 22:37:49 +00:00
Merge pull request #201 from phil-opp/lazy_static
Use upstream lazy_static and upgrade `once` to latest version
This commit is contained in:
@@ -6,7 +6,7 @@ version = "0.1.0"
|
||||
[dependencies]
|
||||
bit_field = "0.1.0"
|
||||
bitflags = "0.7.0"
|
||||
once = "0.2.1"
|
||||
once = "0.3.2"
|
||||
rlibc = "0.1.4"
|
||||
spin = "0.3.4"
|
||||
|
||||
@@ -20,6 +20,10 @@ git = "https://github.com/phil-opp/multiboot2-elf64"
|
||||
default-features = false
|
||||
version = "0.7.1"
|
||||
|
||||
[dependencies.lazy_static]
|
||||
version = "0.2.1"
|
||||
features = ["spin_no_std"]
|
||||
|
||||
[lib]
|
||||
crate-type = ["staticlib"]
|
||||
|
||||
|
||||
@@ -435,6 +435,24 @@ The reason is that the Rust compiler is not able to evaluate the value of the `s
|
||||
#### Lazy Statics to the Rescue
|
||||
Fortunately the `lazy_static` macro exists. Instead of evaluating a `static` at compile time, the macro performs the initialization when the `static` is referenced the first time. Thus, we can do almost everything in the initialization block and are even able to read runtime values.
|
||||
|
||||
Let's add the `lazy_static` crate to our project:
|
||||
|
||||
```rust
|
||||
// in src/lib.rs
|
||||
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
```
|
||||
|
||||
```toml
|
||||
# in Cargo.toml
|
||||
|
||||
[dependencies.lazy_static]
|
||||
version = "0.2.1"
|
||||
features = ["spin_no_std"]
|
||||
```
|
||||
We need the `spin_no_std` feature, since we don't link the standard library.
|
||||
|
||||
With `lazy_static`, we can define our IDT without problems:
|
||||
|
||||
```rust
|
||||
|
||||
@@ -24,6 +24,8 @@ extern crate x86;
|
||||
#[macro_use]
|
||||
extern crate once;
|
||||
extern crate bit_field;
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
|
||||
extern crate hole_list_allocator;
|
||||
extern crate alloc;
|
||||
|
||||
Reference in New Issue
Block a user