diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a4fb16d49..6a7ff855d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -137,8 +137,8 @@ jobs: CXXFLAGS: ${{ matrix.cflags }} ASMFLAGS: ${{ matrix.cflags }} LDFLAGS: ${{ matrix.cflags }} - HOSTARGS: --no-default-features --features ${{ matrix.runtime || 'apple' }} - ARGS: --no-default-features --features ${{ matrix.runtime || 'apple' }} ${{ matrix.args }} + HOSTARGS: --no-default-features --features std --features ${{ matrix.runtime || 'apple' }} + ARGS: --no-default-features --features std --features ${{ matrix.runtime || 'apple' }} ${{ matrix.args }} # Use --no-fail-fast, except with dinghy TESTARGS: ${{ matrix.dinghy && ' ' || '--no-fail-fast' }} ${{ matrix.test-args }} FEATURES: ${{ matrix.features || 'malloc,block,exception,catch_all,verify_message' }} diff --git a/block-sys/Cargo.toml b/block-sys/Cargo.toml index 8cd558314..d1f8a255c 100644 --- a/block-sys/Cargo.toml +++ b/block-sys/Cargo.toml @@ -25,7 +25,11 @@ build = "build.rs" [features] # The default runtime is Apple's. Other platforms will probably error if the # correct feature flag is not specified. -default = ["apple"] +default = ["std", "apple"] + +# Currently not possible to turn off, put here for forwards compatibility. +std = ["alloc", "objc-sys?/std"] +alloc = ["objc-sys?/alloc"] # Link to Apple's libclosure (exists in libSystem) apple = [] diff --git a/block-sys/src/lib.rs b/block-sys/src/lib.rs index f71aab144..8afedfcac 100644 --- a/block-sys/src/lib.rs +++ b/block-sys/src/lib.rs @@ -15,6 +15,9 @@ extern crate std; +#[cfg(not(feature = "std"))] +compile_error!("The `std` feature currently must be enabled."); + // Ensure linkage actually happens #[cfg(feature = "gnustep-1-7")] extern crate objc_sys as _; diff --git a/block2/Cargo.toml b/block2/Cargo.toml index c893cb0ca..f1067c78d 100644 --- a/block2/Cargo.toml +++ b/block2/Cargo.toml @@ -18,7 +18,11 @@ documentation = "https://docs.rs/block2/" license = "MIT" [features] -default = ["apple"] +default = ["std", "apple"] + +# Currently not possible to turn off, put here for forwards compatibility. +std = ["alloc", "objc2-encode/std", "block-sys/std"] +alloc = ["objc2-encode/alloc", "block-sys/alloc"] # Runtime selection. Default is `apple`. See `block-sys` for details. apple = ["block-sys/apple"] diff --git a/objc-sys/Cargo.toml b/objc-sys/Cargo.toml index 93ce3f483..3c403e12e 100644 --- a/objc-sys/Cargo.toml +++ b/objc-sys/Cargo.toml @@ -27,7 +27,11 @@ build = "build.rs" [features] # The default runtime is Apple's. Other platforms will probably error if the # correct feature flag is not specified. -default = ["apple"] +default = ["std", "apple"] + +# Currently not possible to turn off, put here for forwards compatibility. +std = ["alloc"] +alloc = [] # Link to Apple's objc4 apple = [] diff --git a/objc-sys/src/lib.rs b/objc-sys/src/lib.rs index 28e12060d..10ab5f6b0 100644 --- a/objc-sys/src/lib.rs +++ b/objc-sys/src/lib.rs @@ -28,6 +28,9 @@ // See https://github.com/japaric/cty/issues/14. extern crate std; +#[cfg(not(feature = "std"))] +compile_error!("The `std` feature currently must be enabled."); + #[cfg(doctest)] #[doc = include_str!("../README.md")] extern "C" {} diff --git a/objc2-encode/Cargo.toml b/objc2-encode/Cargo.toml index 4f7d542bb..6e2fc9c32 100644 --- a/objc2-encode/Cargo.toml +++ b/objc2-encode/Cargo.toml @@ -18,5 +18,13 @@ repository = "https://github.com/madsmtm/objc2" documentation = "https://docs.rs/objc2-encode/" license = "MIT" +[features] +default = ["std"] + +# Doesn't do anything (this crate works on no_std), put here for forwards +# compatibility. +std = ["alloc"] +alloc = [] + [package.metadata.docs.rs] default-target = "x86_64-apple-darwin" diff --git a/objc2-encode/src/lib.rs b/objc2-encode/src/lib.rs index e6367b655..dce1b1f74 100644 --- a/objc2-encode/src/lib.rs +++ b/objc2-encode/src/lib.rs @@ -97,10 +97,10 @@ #[doc = include_str!("../README.md")] extern "C" {} -#[cfg(doc)] +#[cfg(any(feature = "std", doc))] extern crate std; -#[cfg(any(test, doc))] +#[cfg(any(feature = "alloc", test, doc))] extern crate alloc; mod encode; diff --git a/objc2-foundation/Cargo.toml b/objc2-foundation/Cargo.toml index bd2c11a2b..305ead5b2 100644 --- a/objc2-foundation/Cargo.toml +++ b/objc2-foundation/Cargo.toml @@ -17,10 +17,14 @@ documentation = "https://docs.rs/objc2-foundation/" license = "MIT" [features] -default = ["apple", "block"] +default = ["std", "apple", "block"] # Provided as a way to cut down on dependencies block = ["block2"] +# Currently not possible to turn off, put here for forwards compatibility. +std = ["alloc", "objc2/std", "block2?/std"] +alloc = ["objc2/alloc", "block2?/alloc"] + # Runtime selection. See `objc-sys` and `block-sys` for details. apple = ["objc2/apple", "block2?/apple"] gnustep-1-7 = ["objc2/gnustep-1-7", "block2?/gnustep-1-7"] diff --git a/objc2/Cargo.toml b/objc2/Cargo.toml index 2bc8217c1..b5f0e506d 100644 --- a/objc2/Cargo.toml +++ b/objc2/Cargo.toml @@ -19,7 +19,11 @@ license = "MIT" # NOTE: 'unstable' features are _not_ considered part of the SemVer contract, # and may be removed in a minor release. [features] -default = ["apple"] +default = ["std", "apple"] + +# Currently not possible to turn off, put here for forwards compatibility. +std = ["alloc"] +alloc = [] # Enables `objc2::exception::throw` and `objc2::exception::catch` exception = ["objc-sys/unstable-exception"] diff --git a/objc2/src/lib.rs b/objc2/src/lib.rs index 577524d13..45d8076b0 100644 --- a/objc2/src/lib.rs +++ b/objc2/src/lib.rs @@ -133,6 +133,12 @@ // Update in Cargo.toml as well. #![doc(html_root_url = "https://docs.rs/objc2/0.3.0-alpha.6")] +#[cfg(not(feature = "alloc"))] +compile_error!("The `alloc` feature currently must be enabled."); + +#[cfg(not(feature = "std"))] +compile_error!("The `std` feature currently must be enabled."); + extern crate alloc; extern crate std;