Skip to content

Commit 5568db2

Browse files
committed
serial: Use lazy_static crate
The recent version of Rust does not allow runtime calls in statics. This commit adds lazy_static crate to mitigate this limitation. Signed-off-by: Akira Moroo <[email protected]>
1 parent a689ee0 commit 5568db2

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ log-serial = []
2424
log-panic = ["log-serial"]
2525
integration_tests = []
2626

27+
[dependencies.lazy_static]
28+
version = "1.4.0"
29+
features = ["spin_no_std"]
30+
2731
[dependencies]
2832
bitflags = "1.2"
2933
x86_64 = "0.12"

src/serial.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@
1818
use core::fmt;
1919

2020
use atomic_refcell::AtomicRefCell;
21+
use lazy_static::lazy_static;
2122
use uart_16550::SerialPort;
2223

2324
// We use COM1 as it is the standard first serial port.
24-
pub static PORT: AtomicRefCell<SerialPort> = AtomicRefCell::new(unsafe { SerialPort::new(0x3f8) });
25+
lazy_static! {
26+
pub static ref PORT: AtomicRefCell<SerialPort> =
27+
AtomicRefCell::new(unsafe { SerialPort::new(0x3f8) });
28+
}
2529

2630
pub struct Serial;
2731
impl fmt::Write for Serial {

0 commit comments

Comments
 (0)