Skip to content

Commit

Permalink
Prepare for a time when we can make the crates no_std
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed May 25, 2022
1 parent d3dc9e5 commit 9b643fc
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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' }}
Expand Down
6 changes: 5 additions & 1 deletion block-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
3 changes: 3 additions & 0 deletions block-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 _;
Expand Down
6 changes: 5 additions & 1 deletion block2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
6 changes: 5 additions & 1 deletion objc-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
3 changes: 3 additions & 0 deletions objc-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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" {}
Expand Down
8 changes: 8 additions & 0 deletions objc2-encode/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 2 additions & 2 deletions objc2-encode/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion objc2-foundation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
6 changes: 5 additions & 1 deletion objc2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
6 changes: 6 additions & 0 deletions objc2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 9b643fc

Please sign in to comment.