From 9b2f885daf6c1a4ac8e8cb7916bb89e9121e5220 Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Thu, 10 Nov 2022 10:59:24 -0800 Subject: [PATCH] feat(hal-x86_64): make `alloc` a feature flag (#372) Currently, some code in `hal-x86_64` depends on `liballoc`, while other code does not. This makes it difficult to use parts of the HAL crate in early boot environments without an allocator. This commit adds an "alloc" feature flag to `hal-x86_64`, which enables code that depends on `liballoc`. This commit was factored out of #371. --- hal-x86_64/Cargo.toml | 2 ++ hal-x86_64/src/cpu.rs | 1 + hal-x86_64/src/lib.rs | 7 +++---- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/hal-x86_64/Cargo.toml b/hal-x86_64/Cargo.toml index a5489ef9..ea66edc2 100644 --- a/hal-x86_64/Cargo.toml +++ b/hal-x86_64/Cargo.toml @@ -6,7 +6,9 @@ edition = "2018" license = "MIT" [features] +default = ["alloc"] log = ["tracing/log"] +alloc = [] [dependencies] acpi = "4.1.1" diff --git a/hal-x86_64/src/cpu.rs b/hal-x86_64/src/cpu.rs index b18b5eb8..6100c880 100644 --- a/hal-x86_64/src/cpu.rs +++ b/hal-x86_64/src/cpu.rs @@ -3,6 +3,7 @@ use mycelium_util::bits; pub mod entropy; pub mod intrinsics; +#[cfg(feature = "alloc")] pub mod local; mod msr; pub use self::msr::Msr; diff --git a/hal-x86_64/src/lib.rs b/hal-x86_64/src/lib.rs index 773fc012..011f4f9d 100644 --- a/hal-x86_64/src/lib.rs +++ b/hal-x86_64/src/lib.rs @@ -3,18 +3,17 @@ // Allow const operands in asm. #![feature(asm_const)] #![feature(abi_x86_interrupt)] -#![feature(doc_cfg)] +#![feature(doc_cfg, doc_auto_cfg)] +#![feature(extern_types)] // A bunch of const fn features. #![feature(const_mut_refs)] // Oftentimes it's necessary to write to a value at a particular location in // memory, and these types don't implement Copy to ensure they aren't // inadvertantly copied. #![allow(clippy::trivially_copy_pass_by_ref)] -// Macros generated by `tracing` often generate large amounts of code, which -// causes this lint to complain about relatively simple methods. -#![allow(clippy::cognitive_complexity)] pub(crate) use hal_core::{PAddr, VAddr}; +#[cfg(feature = "alloc")] extern crate alloc; pub mod control_regs;