From 76a54d024d80f1fae93c94144a22819c2be79666 Mon Sep 17 00:00:00 2001 From: jtnunley Date: Fri, 16 Dec 2022 16:04:39 -0800 Subject: [PATCH 1/5] Remove libstd from objc-sys and block-sys --- crates/block-sys/src/lib.rs | 8 +------- crates/objc-sys/Cargo.toml | 1 - crates/objc-sys/src/class.rs | 2 +- crates/objc-sys/src/constants.rs | 2 +- crates/objc-sys/src/exception.rs | 6 +++--- crates/objc-sys/src/lib.rs | 8 -------- crates/objc-sys/src/method.rs | 4 ++-- crates/objc-sys/src/object.rs | 2 +- crates/objc-sys/src/property.rs | 4 ++-- crates/objc-sys/src/protocol.rs | 4 ++-- crates/objc-sys/src/selector.rs | 2 +- crates/objc-sys/src/types.rs | 2 +- crates/objc-sys/src/various.rs | 8 ++++---- 13 files changed, 19 insertions(+), 34 deletions(-) diff --git a/crates/block-sys/src/lib.rs b/crates/block-sys/src/lib.rs index ff2aefa46..067e06d90 100644 --- a/crates/block-sys/src/lib.rs +++ b/crates/block-sys/src/lib.rs @@ -24,11 +24,6 @@ #![cfg_attr(feature = "unstable-docsrs", feature(doc_auto_cfg, doc_cfg_hide))] #![cfg_attr(feature = "unstable-docsrs", doc(cfg_hide(doc)))] -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 _; @@ -38,9 +33,8 @@ extern crate objc_sys as _; extern "C" {} use core::cell::UnsafeCell; -use core::ffi::c_void; +use core::ffi::{c_char, c_ulong, c_void}; use core::marker::{PhantomData, PhantomPinned}; -use std::os::raw::{c_char, c_ulong}; #[repr(C)] pub struct Class { diff --git a/crates/objc-sys/Cargo.toml b/crates/objc-sys/Cargo.toml index 16031dc64..0098fe9d6 100644 --- a/crates/objc-sys/Cargo.toml +++ b/crates/objc-sys/Cargo.toml @@ -29,7 +29,6 @@ build = "build.rs" # correct feature flag is not specified. default = ["std", "apple"] -# Currently not possible to turn off, put here for forwards compatibility. std = ["alloc"] alloc = [] diff --git a/crates/objc-sys/src/class.rs b/crates/objc-sys/src/class.rs index 0a1027ad5..f30c7490c 100644 --- a/crates/objc-sys/src/class.rs +++ b/crates/objc-sys/src/class.rs @@ -1,4 +1,4 @@ -use std::os::raw::{c_char, c_int, c_uint}; +use core::ffi::{c_char, c_int, c_uint}; #[cfg(any(doc, not(objfw)))] use crate::{objc_ivar, objc_method, objc_object, objc_property, objc_property_attribute_t}; diff --git a/crates/objc-sys/src/constants.rs b/crates/objc-sys/src/constants.rs index 9d2fb02f8..99a4986aa 100644 --- a/crates/objc-sys/src/constants.rs +++ b/crates/objc-sys/src/constants.rs @@ -1,7 +1,7 @@ //! Various common #defines and enum constants. #[cfg(any(doc, apple))] -use std::os::raw::c_int; +use core::ffi::c_int; use crate::{id, objc_class, BOOL}; diff --git a/crates/objc-sys/src/exception.rs b/crates/objc-sys/src/exception.rs index a78b4378e..82aba313d 100644 --- a/crates/objc-sys/src/exception.rs +++ b/crates/objc-sys/src/exception.rs @@ -2,11 +2,11 @@ //! Apple: `objc-exception.h` //! GNUStep: `eh_personality.c`, which is a bit brittle to rely on, but I //! think it's fine... -use core::ffi::c_void; #[cfg(any(doc, apple_new))] -use std::os::raw::c_int; +use core::ffi::c_int; #[cfg(feature = "unstable-exception")] -use std::os::raw::c_uchar; +use core::ffi::c_uchar; +use core::ffi::c_void; #[cfg(any(doc, apple_new))] use crate::objc_class; diff --git a/crates/objc-sys/src/lib.rs b/crates/objc-sys/src/lib.rs index a018e1ff8..167d4e10b 100644 --- a/crates/objc-sys/src/lib.rs +++ b/crates/objc-sys/src/lib.rs @@ -29,14 +29,6 @@ #![cfg_attr(feature = "unstable-docsrs", feature(doc_auto_cfg, doc_cfg_hide))] #![cfg_attr(feature = "unstable-docsrs", doc(cfg_hide(doc)))] -// TODO: Remove this and add "no-std" category to Cargo.toml -// Requires a better solution for C-types in `no_std` crates. -// 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/crates/objc-sys/src/method.rs b/crates/objc-sys/src/method.rs index 87770aeb0..54d9488cb 100644 --- a/crates/objc-sys/src/method.rs +++ b/crates/objc-sys/src/method.rs @@ -1,6 +1,6 @@ -use std::os::raw::c_char; +use core::ffi::c_char; #[cfg(any(doc, not(objfw)))] -use std::os::raw::c_uint; +use core::ffi::c_uint; #[cfg(any(doc, not(objfw)))] use crate::IMP; diff --git a/crates/objc-sys/src/object.rs b/crates/objc-sys/src/object.rs index 5c774bb5d..4227033ef 100644 --- a/crates/objc-sys/src/object.rs +++ b/crates/objc-sys/src/object.rs @@ -1,6 +1,6 @@ +use core::ffi::c_char; #[cfg(any(doc, not(objfw)))] use core::ffi::c_void; -use std::os::raw::c_char; #[cfg(any(doc, not(objfw)))] use crate::objc_ivar; diff --git a/crates/objc-sys/src/property.rs b/crates/objc-sys/src/property.rs index 9de45a3df..30ec91b17 100644 --- a/crates/objc-sys/src/property.rs +++ b/crates/objc-sys/src/property.rs @@ -1,6 +1,6 @@ -use std::os::raw::c_char; +use core::ffi::c_char; #[cfg(any(doc, not(objfw)))] -use std::os::raw::c_uint; +use core::ffi::c_uint; use crate::OpaqueData; diff --git a/crates/objc-sys/src/protocol.rs b/crates/objc-sys/src/protocol.rs index cef8088e8..bf6851d7e 100644 --- a/crates/objc-sys/src/protocol.rs +++ b/crates/objc-sys/src/protocol.rs @@ -1,6 +1,6 @@ -use std::os::raw::c_char; +use core::ffi::c_char; #[cfg(any(doc, not(objfw)))] -use std::os::raw::c_uint; +use core::ffi::c_uint; #[cfg(any(doc, not(objfw)))] use crate::{objc_method_description, objc_property, objc_property_attribute_t, objc_selector}; diff --git a/crates/objc-sys/src/selector.rs b/crates/objc-sys/src/selector.rs index c1c471969..0145ef0cf 100644 --- a/crates/objc-sys/src/selector.rs +++ b/crates/objc-sys/src/selector.rs @@ -1,4 +1,4 @@ -use std::os::raw::c_char; +use core::ffi::c_char; use crate::{OpaqueData, BOOL}; diff --git a/crates/objc-sys/src/types.rs b/crates/objc-sys/src/types.rs index 1b1175472..315e37b7a 100644 --- a/crates/objc-sys/src/types.rs +++ b/crates/objc-sys/src/types.rs @@ -45,7 +45,7 @@ mod inner { mod inner { // windows && !32bit-MinGW #[cfg(all(windows, not(all(target_pointer_width = "64", target_env = "gnu"))))] - pub(crate) type BOOL = std::os::raw::c_int; + pub(crate) type BOOL = core::ffi::c_int; // The inverse #[cfg(not(all(windows, not(all(target_pointer_width = "64", target_env = "gnu")))))] diff --git a/crates/objc-sys/src/various.rs b/crates/objc-sys/src/various.rs index fd9fdce5c..af4511b13 100644 --- a/crates/objc-sys/src/various.rs +++ b/crates/objc-sys/src/various.rs @@ -1,9 +1,9 @@ -use core::ffi::c_void; #[cfg(any(doc, not(objfw)))] -use std::os::raw::c_char; -use std::os::raw::c_int; +use core::ffi::c_char; +use core::ffi::c_int; #[cfg(any(doc, apple))] -use std::os::raw::c_uint; +use core::ffi::c_uint; +use core::ffi::c_void; #[cfg(any(doc, not(objfw)))] use crate::{objc_AssociationPolicy, BOOL}; From bc685e29b8e2ff479df24f30b62a6242fdbe79f6 Mon Sep 17 00:00:00 2001 From: jtnunley Date: Fri, 16 Dec 2022 16:11:59 -0800 Subject: [PATCH 2/5] Fix block-sys tests --- crates/block-sys/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/block-sys/src/lib.rs b/crates/block-sys/src/lib.rs index 067e06d90..df14e2f47 100644 --- a/crates/block-sys/src/lib.rs +++ b/crates/block-sys/src/lib.rs @@ -409,7 +409,7 @@ pub struct Block_byref_extended { pub layout: *const c_char, } -#[cfg(test)] +#[cfg(all(test, feature = "std"))] mod tests { use super::*; use core::ptr; From 2ae898df528defd753f34dc788ed92fed994dafb Mon Sep 17 00:00:00 2001 From: jtnunley Date: Fri, 16 Dec 2022 16:38:09 -0800 Subject: [PATCH 3/5] Add no_std to CI --- .github/workflows/ci.yml | 5 +++++ crates/block-sys/src/lib.rs | 3 +++ 2 files changed, 8 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6cb9a3605..a0ee00339 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -369,6 +369,11 @@ jobs: - name: Build run: $CMD build ${{ env.ARGS }} + - name: Build objc-sys/block-sys with no_std + run: | + $CMD build ${{ env.ARGS }} --no-default-features -p objc-sys + $CMD build ${{ env.ARGS }} --no-default-features -p block-sys + - name: Check documentation run: $CMD doc ${{ env.ARGS }} --no-deps --document-private-items diff --git a/crates/block-sys/src/lib.rs b/crates/block-sys/src/lib.rs index df14e2f47..2eab8931f 100644 --- a/crates/block-sys/src/lib.rs +++ b/crates/block-sys/src/lib.rs @@ -24,6 +24,9 @@ #![cfg_attr(feature = "unstable-docsrs", feature(doc_auto_cfg, doc_cfg_hide))] #![cfg_attr(feature = "unstable-docsrs", doc(cfg_hide(doc)))] +#[cfg(feature = "std")] +extern crate std; + // Ensure linkage actually happens #[cfg(feature = "gnustep-1-7")] extern crate objc_sys as _; From 739726a2c43c5278fc264ef4287e715d73a58105 Mon Sep 17 00:00:00 2001 From: jtnunley Date: Fri, 16 Dec 2022 16:44:27 -0800 Subject: [PATCH 4/5] Forgot to add std extern conditional for objc-sys --- crates/objc-sys/src/lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/objc-sys/src/lib.rs b/crates/objc-sys/src/lib.rs index 167d4e10b..9c9e54dc0 100644 --- a/crates/objc-sys/src/lib.rs +++ b/crates/objc-sys/src/lib.rs @@ -29,6 +29,9 @@ #![cfg_attr(feature = "unstable-docsrs", feature(doc_auto_cfg, doc_cfg_hide))] #![cfg_attr(feature = "unstable-docsrs", doc(cfg_hide(doc)))] +#[cfg(feature = "std")] +extern crate std; + #[cfg(doctest)] #[doc = include_str!("../README.md")] extern "C" {} From f9a1957527778f13480d551ec850c52e6c56ef30 Mon Sep 17 00:00:00 2001 From: jtnunley Date: Fri, 16 Dec 2022 16:53:28 -0800 Subject: [PATCH 5/5] Fix CI error --- .github/workflows/ci.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a0ee00339..ecc5e4e38 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -156,6 +156,7 @@ jobs: CXXFLAGS: ${{ matrix.cflags }} ASMFLAGS: ${{ matrix.cflags }} LDFLAGS: ${{ matrix.cflags }} + NDF_ARGS: --no-default-features --features=${{ matrix.runtime || 'apple' }} ${{ matrix.args }} ARGS: --no-default-features --features=std,${{ matrix.runtime || 'apple' }} ${{ matrix.args }} # Use --no-fail-fast, except with dinghy TESTARGS: ${{ matrix.dinghy && ' ' || '--no-fail-fast' }} ${{ matrix.test-args }} @@ -371,8 +372,8 @@ jobs: - name: Build objc-sys/block-sys with no_std run: | - $CMD build ${{ env.ARGS }} --no-default-features -p objc-sys - $CMD build ${{ env.ARGS }} --no-default-features -p block-sys + $CMD build ${{ env.NDF_ARGS }} -p objc-sys + $CMD build ${{ env.NDF_ARGS }} -p block-sys - name: Check documentation run: $CMD doc ${{ env.ARGS }} --no-deps --document-private-items