diff --git a/.github/workflows/build-bsp.yml b/.github/workflows/build-bsp.yml index 792d157591b7..a8ba87e6f176 100644 --- a/.github/workflows/build-bsp.yml +++ b/.github/workflows/build-bsp.yml @@ -69,4 +69,4 @@ jobs: run: | set -ex cd hal - cargo build \ No newline at end of file + cargo build --features="library" \ No newline at end of file diff --git a/hal/Cargo.toml b/hal/Cargo.toml index 3b178f5a4231..660da465a4d0 100644 --- a/hal/Cargo.toml +++ b/hal/Cargo.toml @@ -146,14 +146,24 @@ optional = true [features] default = ["unproven"] -# This section lists our feature name to dependency mapping. This are separated + +# This section lists our feature name to dependency mapping. This is separated # out so that the board support crates can reference a single feature name to # select the appropriate chip, and to keep that separate from the dependency name # for the `rt` feature below, which has to list out all possible optional deps. # If we simply used feature names that matched the dependency names, enabling the # rt feature would link all possible parts in and cause a linker error due to # the high degree of similar symbols present in the various parts. -device = [] # Should be included if we are building for a specific target device. + +# The `device` feature is a dependency of each specific target device. It +# should not be enabled directly, as that could lead to cryptic build errors. +# The `library` feature can be enabled to use atsamd-hal without selecting a +# specific target device. +device = [] + +# Bypasses compile-time checks that a specific device is enabled. +library = [] + samd11 = ["device"] # Convenience feature for shared configuration of samd11 chips. samd11c = ["atsamd11c", "samd11"] samd11c-rt = ["samd11c", "atsamd11c/rt"] diff --git a/hal/src/lib.rs b/hal/src/lib.rs index e712920f0c2e..f853c35ddb4c 100644 --- a/hal/src/lib.rs +++ b/hal/src/lib.rs @@ -6,6 +6,13 @@ pub use paste; pub mod typelevel; +#[cfg(not(any(feature = "library", feature = "device")))] +compile_error!( + "The HAL is usually built for a specific target device, selected using a \ + feature. If atsamd-hal is being built as a library, bypass this check by \ + specifying the `library` feature" +); + #[cfg(feature = "samd11c")] pub use atsamd11c as target_device; @@ -98,6 +105,15 @@ pub mod timer_traits; #[cfg(all(feature = "unproven", feature = "dma"))] pub mod dmac; +#[cfg(all(feature = "usb", feature = "samd11"))] +compile_error!("'usb' is enabled, but USB isn't supported on SAMD11"); + +#[cfg(all( + feature = "usb", + not(any(feature = "samd21", feature = "min-samd51g", feature = "library")) +))] +compile_error!("The 'usb' feature is enabled, but not a chip with USB support"); + #[cfg(any(feature = "samd11", feature = "samd21"))] pub mod thumbv6m; #[cfg(any(feature = "samd11", feature = "samd21"))]