Skip to content

Commit

Permalink
Merge pull request #149 from madsmtm/feature-cleanup
Browse files Browse the repository at this point in the history
Cargo features cleanup
  • Loading branch information
madsmtm authored May 25, 2022
2 parents c75691e + 08a13d3 commit d3dc9e5
Show file tree
Hide file tree
Showing 16 changed files with 62 additions and 50 deletions.
25 changes: 18 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ env:
RUSTFLAGS: "-C debuginfo=0 -D warnings"
RUSTDOCFLAGS: "-D warnings"
CARGO_TERM_VERBOSE: true
FEATURES: malloc,block,exception,catch_all,verify_message
UNSTABLE_FEATURES: unstable_autoreleasesafe
MACOSX_DEPLOYMENT_TARGET: 10.7
IPHONEOS_DEPLOYMENT_TARGET: 7.0
# We only support compiling Objective-C code with clang
Expand Down Expand Up @@ -125,6 +123,13 @@ jobs:
components: rust-src
args: -Zbuild-std -Zdoctest-xcompile
test-args: --no-run
- name: Test Compiler-RT
os: ubuntu-latest
target: x86_64-unknown-linux-gnu
runtime: compiler-rt
args: -p block-sys -p block2
features: ' '
unstable-features: ' '

env:
CARGO_BUILD_TARGET: ${{ matrix.target }}
Expand All @@ -136,6 +141,8 @@ jobs:
ARGS: --no-default-features --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' }}
UNSTABLE_FEATURES: ${{ matrix.unstable-features || 'unstable-autoreleasesafe' }}

runs-on: ${{ matrix.os }}

Expand Down Expand Up @@ -195,6 +202,10 @@ jobs:
sudo apt-get update
sudo apt-get -y install clang valgrind
- name: Install libBlocksRuntime
if: contains(matrix.runtime, 'compiler-rt')
run: sudo apt-get -y install libblocksruntime-dev

- name: Install cross compilation tools
if: matrix.target == 'i686-unknown-linux-gnu'
run: |
Expand All @@ -220,11 +231,11 @@ jobs:
mv MacOSX${{ matrix.sdk }}.sdk $HOME/extern/sdk
- name: Install Make and Cmake
if: contains(matrix.os, 'ubuntu') && steps.extern-cache.outputs.cache-hit != 'true'
if: contains(matrix.runtime, 'gnustep') && steps.extern-cache.outputs.cache-hit != 'true'
run: sudo apt-get -y install make cmake

- name: Install GNUStep libobjc2 v1.9
if: contains(matrix.os, 'ubuntu') && steps.extern-cache.outputs.cache-hit != 'true'
if: contains(matrix.runtime, 'gnustep') && steps.extern-cache.outputs.cache-hit != 'true'
run: |
wget https://github.com/gnustep/libobjc2/archive/refs/tags/v1.9.tar.gz
tar -xzf v1.9.tar.gz
Expand All @@ -234,7 +245,7 @@ jobs:
make install
- name: Install GNUStep make
if: contains(matrix.os, 'ubuntu') && steps.extern-cache.outputs.cache-hit != 'true'
if: contains(matrix.runtime, 'gnustep') && steps.extern-cache.outputs.cache-hit != 'true'
run: |
wget https://github.com/gnustep/tools-make/archive/refs/tags/make-2_9_0.tar.gz
tar -xzf make-2_9_0.tar.gz
Expand All @@ -244,7 +255,7 @@ jobs:
make install
- name: Install GNUStep-Base
if: contains(matrix.os, 'ubuntu') && steps.extern-cache.outputs.cache-hit != 'true'
if: contains(matrix.runtime, 'gnustep') && steps.extern-cache.outputs.cache-hit != 'true'
run: |
wget https://github.com/gnustep/libs-base/archive/refs/tags/base-1_28_0.tar.gz
tar -xzf base-1_28_0.tar.gz
Expand Down Expand Up @@ -326,7 +337,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: bench
args: ${{ env.ARGS }} ${{ env.TESTARGS }} --bench autorelease
args: ${{ env.ARGS }} ${{ env.TESTARGS }}

- name: Test with unstable features
if: ${{ !matrix.dinghy && matrix.rust.toolchain == 'nightly' }}
Expand Down
6 changes: 3 additions & 3 deletions block-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ gnustep-2-0 = ["objc-sys/gnustep-2-0", "gnustep-1-9"]
gnustep-2-1 = ["objc-sys/gnustep-2-1", "gnustep-2-0"]

# Link to Microsoft's libobjc2
winobjc = ["objc-sys/winobjc", "gnustep-1-8"]
unstable-winobjc = ["objc-sys/unstable-winobjc", "gnustep-1-8"]

# TODO
objfw = []
# Link to ObjFW
unstable-objfw = []

[dependencies]
objc-sys = { path = "../objc-sys", version = "=0.2.0-alpha.1", default-features = false, optional = true }
Expand Down
10 changes: 7 additions & 3 deletions block-sys/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,19 @@ Sources:

### Microsoft's [`WinObjC`](https://github.com/microsoft/WinObjC)

- Feature flag: `winobjc`.
- Feature flag: `unstable-winobjc`.

**Unstable: Hasn't been tested on Windows yet!**

Essentially just [a fork](https://github.com/microsoft/libobjc2) based on
GNUStep's `libobjc2` version 1.8.


### [`ObjFW`](https://github.com/ObjFW/ObjFW) (WIP)
### [`ObjFW`](https://github.com/ObjFW/ObjFW)

- Feature flag: `unstable-objfw`.

- Feature flag: `objfw`.
**Unstable: Doesn't work yet!**

TODO.

Expand Down
2 changes: 1 addition & 1 deletion block-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn main() {
let mut apple = env::var_os("CARGO_FEATURE_APPLE").is_some();
let compiler_rt = env::var_os("CARGO_FEATURE_COMPILER_RT").is_some();
let mut gnustep = env::var_os("CARGO_FEATURE_GNUSTEP_1_7").is_some();
let objfw = env::var_os("CARGO_FEATURE_OBJFW").is_some();
let objfw = env::var_os("CARGO_FEATURE_UNSTABLE_OBJFW").is_some();

if std::env::var("DOCS_RS").is_ok() {
if let "macos" | "ios" | "tvos" | "watchos" = &*target_os {
Expand Down
1 change: 0 additions & 1 deletion block2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ gnustep-1-8 = ["gnustep-1-7", "block-sys/gnustep-1-8"]
gnustep-1-9 = ["gnustep-1-8", "block-sys/gnustep-1-9"]
gnustep-2-0 = ["gnustep-1-9", "block-sys/gnustep-2-0"]
gnustep-2-1 = ["gnustep-2-0", "block-sys/gnustep-2-1"]
winobjc = ["gnustep-1-8", "block-sys/winobjc"]

[dependencies]
objc2-encode = { path = "../objc2-encode", version = "=2.0.0-beta.2", default-features = false }
Expand Down
8 changes: 4 additions & 4 deletions objc-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ gnustep-2-0 = ["gnustep-1-9"]
gnustep-2-1 = ["gnustep-2-0"]

# Link to Microsoft's libobjc2
winobjc = ["gnustep-1-8"]
unstable-winobjc = ["gnustep-1-8"]

# TODO
objfw = []
# Link to ObjFW
unstable-objfw = []

# Private/unstable features - must not be relied on!
# Private
unstable-exception = ["cc"]

[build-dependencies]
Expand Down
15 changes: 9 additions & 6 deletions objc-sys/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,21 @@ chosen using the standard `X_DEPLOYMENT_TARGET` environment variables:
`gnustep-1-8`.


### Window's [`WinObjC`](https://github.com/microsoft/WinObjC)
### Microsoft's [`WinObjC`](https://github.com/microsoft/WinObjC)

- Feature flag: `winobjc`.
- Feature flag: `unstable-winobjc`.

**Unstable: Hasn't been tested on Windows yet!**

This is essentially just [a fork](https://github.com/microsoft/libobjc2) based
on GNUStep's `libobjc2` version 1.8, with very few user-facing changes.


### [`ObjFW`](https://github.com/ObjFW/ObjFW) (WIP)
### [`ObjFW`](https://github.com/ObjFW/ObjFW)

- Feature flag: `unstable-objfw`.

- Feature flag: `objfw`.
**Unstable: Doesn't work yet!**

TODO.

Expand All @@ -79,7 +83,7 @@ and `objc_autoreleasePoolPop` is a vital requirement for most applications.

Just so we're being clear, this rules out the GCC [`libobjc`][gcc-libobjc]
runtime (see [this][gcc-objc-support]), the [`mulle-objc`] runtime and
[cocotron]. (But support for [`ObjFW`] and [`darling`] may be added).
[cocotron]. (But support for [`darling`] may be added).
More information on different runtimes can be found in GNUStep's
[Objective-C Compiler and Runtime FAQ][gnustep-faq].

Expand All @@ -88,7 +92,6 @@ More information on different runtimes can be found in GNUStep's
[gcc-objc-support]: https://gcc.gnu.org/onlinedocs/gcc/Standards.html#Objective-C-and-Objective-C_002b_002b-Languages
[`mulle-objc`]: https://github.com/mulle-objc/mulle-objc-runtime
[cocotron]: https://cocotron.org/
[`ObjFW`]: https://github.com/ObjFW/ObjFW
[`darling`]: https://github.com/darlinghq/darling-objc4
[gnustep-faq]: http://wiki.gnustep.org/index.php/Objective-C_Compiler_and_Runtime_FAQ

Expand Down
4 changes: 2 additions & 2 deletions objc-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fn main() {

let mut apple = env::var_os("CARGO_FEATURE_APPLE").is_some();
let mut gnustep = env::var_os("CARGO_FEATURE_GNUSTEP_1_7").is_some();
let objfw = env::var_os("CARGO_FEATURE_OBJFW").is_some();
let objfw = env::var_os("CARGO_FEATURE_UNSTABLE_OBJFW").is_some();

// Choose defaults when generating docs
if std::env::var("DOCS_RS").is_ok() {
Expand Down Expand Up @@ -106,7 +106,7 @@ fn main() {
} else {
GNUStep(1, 7)
}
} else if env::var_os("CARGO_FEATURE_WINOBJC").is_some() {
} else if env::var_os("CARGO_FEATURE_UNSTABLE_WINOBJC").is_some() {
WinObjC
} else if env::var_os("CARGO_FEATURE_GNUSTEP_2_1").is_some() {
GNUStep(2, 1)
Expand Down
2 changes: 1 addition & 1 deletion objc-sys/src/exception.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ extern_c! {
// objc_exception_get_functions
// objc_exception_set_functions

#[cfg(any(gnustep, winobjc))]
#[cfg(gnustep)]
pub fn objc_exception_rethrow(exc_buf: *mut c_void) -> !;

#[cfg(apple_new)]
Expand Down
1 change: 0 additions & 1 deletion objc2-foundation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ gnustep-1-8 = ["gnustep-1-7", "objc2/gnustep-1-8", "block2?/gnustep-1-8"]
gnustep-1-9 = ["gnustep-1-8", "objc2/gnustep-1-9", "block2?/gnustep-1-9"]
gnustep-2-0 = ["gnustep-1-9", "objc2/gnustep-2-0", "block2?/gnustep-2-0"]
gnustep-2-1 = ["gnustep-2-0", "objc2/gnustep-2-1", "block2?/gnustep-2-1"]
winobjc = ["gnustep-1-8", "objc2/winobjc", "block2?/winobjc"]

[dependencies]
block2 = { path = "../block2", version = "=0.2.0-alpha.3", default-features = false, optional = true }
Expand Down
3 changes: 1 addition & 2 deletions objc2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ verify_message = ["malloc"] # TODO: Remove malloc feature here
malloc = ["malloc_buf"]

# Uses nightly features to make AutoreleasePool zero-cost even in debug mode
unstable_autoreleasesafe = []
unstable-autoreleasesafe = []

# Runtime selection. See `objc-sys` for details.
apple = ["objc-sys/apple"]
Expand All @@ -47,7 +47,6 @@ gnustep-1-8 = ["gnustep-1-7", "objc-sys/gnustep-1-8"]
gnustep-1-9 = ["gnustep-1-8", "objc-sys/gnustep-1-9"]
gnustep-2-0 = ["gnustep-1-9", "objc-sys/gnustep-2-0"]
gnustep-2-1 = ["gnustep-2-0", "objc-sys/gnustep-2-1"]
winobjc = ["gnustep-1-8", "objc-sys/winobjc"]

[dependencies]
malloc_buf = { version = "1.0", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion objc2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
#![no_std]
#![cfg_attr(
feature = "unstable_autoreleasesafe",
feature = "unstable-autoreleasesafe",
feature(negative_impls, auto_traits)
)]
#![warn(elided_lifetimes_in_paths)]
Expand Down
30 changes: 15 additions & 15 deletions objc2/src/rc/autorelease.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use core::cell::UnsafeCell;
use core::ffi::c_void;
use core::fmt;
use core::marker::PhantomData;
#[cfg(all(debug_assertions, not(feature = "unstable_autoreleasesafe")))]
#[cfg(all(debug_assertions, not(feature = "unstable-autoreleasesafe")))]
use std::{cell::RefCell, thread_local, vec::Vec};

use crate::ffi;
Expand All @@ -25,7 +25,7 @@ pub struct AutoreleasePool {
p: PhantomData<*mut UnsafeCell<c_void>>,
}

#[cfg(all(debug_assertions, not(feature = "unstable_autoreleasesafe")))]
#[cfg(all(debug_assertions, not(feature = "unstable-autoreleasesafe")))]
thread_local! {
/// We track the thread's pools to verify that object lifetimes are only
/// taken from the innermost pool.
Expand All @@ -49,7 +49,7 @@ impl AutoreleasePool {
unsafe fn new() -> Self {
// TODO: Make this function pub when we're more certain of the API
let context = unsafe { ffi::objc_autoreleasePoolPush() };
#[cfg(all(debug_assertions, not(feature = "unstable_autoreleasesafe")))]
#[cfg(all(debug_assertions, not(feature = "unstable-autoreleasesafe")))]
POOLS.with(|c| c.borrow_mut().push(context));
Self {
context,
Expand All @@ -61,7 +61,7 @@ impl AutoreleasePool {
#[inline]
#[doc(hidden)]
pub fn __verify_is_inner(&self) {
#[cfg(all(debug_assertions, not(feature = "unstable_autoreleasesafe")))]
#[cfg(all(debug_assertions, not(feature = "unstable-autoreleasesafe")))]
POOLS.with(|c| {
assert_eq!(
c.borrow().last(),
Expand Down Expand Up @@ -140,7 +140,7 @@ impl Drop for AutoreleasePool {
#[inline]
fn drop(&mut self) {
unsafe { ffi::objc_autoreleasePoolPop(self.context) }
#[cfg(all(debug_assertions, not(feature = "unstable_autoreleasesafe")))]
#[cfg(all(debug_assertions, not(feature = "unstable-autoreleasesafe")))]
POOLS.with(|c| {
assert_eq!(
c.borrow_mut().pop(),
Expand All @@ -159,15 +159,15 @@ impl fmt::Pointer for AutoreleasePool {

/// We use a macro here so that the documentation is included whether the
/// feature is enabled or not.
#[cfg(not(feature = "unstable_autoreleasesafe"))]
#[cfg(not(feature = "unstable-autoreleasesafe"))]
macro_rules! auto_trait {
{$(#[$fn_meta:meta])* $v:vis unsafe trait AutoreleaseSafe {}} => {
$(#[$fn_meta])*
$v unsafe trait AutoreleaseSafe {}
}
}

#[cfg(feature = "unstable_autoreleasesafe")]
#[cfg(feature = "unstable-autoreleasesafe")]
macro_rules! auto_trait {
{$(#[$fn_meta:meta])* $v:vis unsafe trait AutoreleaseSafe {}} => {
$(#[$fn_meta])*
Expand All @@ -179,7 +179,7 @@ auto_trait! {
/// Marks types that are safe to pass across the closure in an
/// [`autoreleasepool`].
///
/// With the `unstable_autoreleasesafe` feature enabled, this is an auto
/// With the `unstable-autoreleasesafe` feature enabled, this is an auto
/// trait that is implemented for all types except [`AutoreleasePool`].
///
/// Otherwise it is just a dummy trait that is implemented for all types;
Expand All @@ -194,14 +194,14 @@ auto_trait! {
/// likewise, this should be negatively implemented for that.
///
/// This can easily be accomplished with an `PhantomData<AutoreleasePool>`
/// if the `unstable_autoreleasesafe` feature is enabled.
/// if the `unstable-autoreleasesafe` feature is enabled.
pub unsafe trait AutoreleaseSafe {}
}

#[cfg(not(feature = "unstable_autoreleasesafe"))]
#[cfg(not(feature = "unstable-autoreleasesafe"))]
unsafe impl<T: ?Sized> AutoreleaseSafe for T {}

#[cfg(feature = "unstable_autoreleasesafe")]
#[cfg(feature = "unstable-autoreleasesafe")]
impl !AutoreleaseSafe for AutoreleasePool {}

/// Execute `f` in the context of a new autorelease pool. The pool is
Expand All @@ -216,7 +216,7 @@ impl !AutoreleaseSafe for AutoreleasePool {}
/// The given reference must not be used in an inner `autoreleasepool`,
/// doing so will panic with debug assertions enabled, and be a compile
/// error in a future release. You can test the compile error with the
/// `unstable_autoreleasesafe` crate feature on nightly Rust.
/// `unstable-autoreleasesafe` crate feature on nightly Rust.
///
/// # Examples
///
Expand Down Expand Up @@ -266,8 +266,8 @@ impl !AutoreleaseSafe for AutoreleasePool {}
/// Incorrect usage which panics (with debug assertions enabled) because we
/// tried to pass an outer pool to an inner pool:
///
#[cfg_attr(feature = "unstable_autoreleasesafe", doc = "```compile_fail")]
#[cfg_attr(not(feature = "unstable_autoreleasesafe"), doc = "```should_panic")]
#[cfg_attr(feature = "unstable-autoreleasesafe", doc = "```compile_fail")]
#[cfg_attr(not(feature = "unstable-autoreleasesafe"), doc = "```should_panic")]
/// # use objc2::{class, msg_send};
/// # use objc2::rc::{autoreleasepool, AutoreleasePool};
/// # use objc2::runtime::Object;
Expand Down Expand Up @@ -300,7 +300,7 @@ where
f(&pool)
}

#[cfg(all(test, feature = "unstable_autoreleasesafe"))]
#[cfg(all(test, feature = "unstable-autoreleasesafe"))]
mod tests {
use super::AutoreleaseSafe;
use crate::runtime::Object;
Expand Down
1 change: 0 additions & 1 deletion tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ gnustep-1-8 = ["gnustep-1-7", "block2/gnustep-1-8", "objc2-foundation/gnustep-1-
gnustep-1-9 = ["gnustep-1-8", "block2/gnustep-1-9", "objc2-foundation/gnustep-1-9"]
gnustep-2-0 = ["gnustep-1-9", "block2/gnustep-2-0", "objc2-foundation/gnustep-2-0"]
gnustep-2-1 = ["gnustep-2-0", "block2/gnustep-2-1", "objc2-foundation/gnustep-2-1"]
winobjc = ["gnustep-1-8", "block2/winobjc", "objc2-foundation/winobjc"]

malloc = ["objc2/malloc"]

Expand Down
1 change: 0 additions & 1 deletion tests/assembly/test_msg_send_zero_cost/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ gnustep-1-8 = ["gnustep-1-7", "objc2/gnustep-1-8"]
gnustep-1-9 = ["gnustep-1-8", "objc2/gnustep-1-9"]
gnustep-2-0 = ["gnustep-1-9", "objc2/gnustep-2-0"]
gnustep-2-1 = ["gnustep-2-0", "objc2/gnustep-2-1"]
winobjc = ["gnustep-1-8", "objc2/winobjc"]
1 change: 0 additions & 1 deletion tests/assembly/test_retain_autoreleased/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ gnustep-1-8 = ["gnustep-1-7", "objc2/gnustep-1-8"]
gnustep-1-9 = ["gnustep-1-8", "objc2/gnustep-1-9"]
gnustep-2-0 = ["gnustep-1-9", "objc2/gnustep-2-0"]
gnustep-2-1 = ["gnustep-2-0", "objc2/gnustep-2-1"]
winobjc = ["gnustep-1-8", "objc2/winobjc"]

0 comments on commit d3dc9e5

Please sign in to comment.