Skip to content

Commit 13b2c8a

Browse files
authored
Merge pull request #141 from madsmtm/more-stable-sys-crates
Improve stability of `objc-sys` and `block-sys` crates
2 parents 06e538a + 5dbf3e7 commit 13b2c8a

File tree

30 files changed

+295
-124
lines changed

30 files changed

+295
-124
lines changed

block-sys/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66

77
## Unreleased - YYYY-MM-DD
88

9+
### Changed
10+
* **BREAKING**: Changed `links` key from `block` to `block_0_0` for better
11+
future compatibility, until we reach 1.0 (so `DEP_BLOCK_X` in build scripts
12+
becomes `DEP_BLOCK_0_0_X`).
13+
914

1015
## 0.0.3 - 2022-01-03
1116

block-sys/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ readme = "README.md"
1919

2020
# Downstream users can customize the linking!
2121
# See https://doc.rust-lang.org/cargo/reference/build-scripts.html#overriding-build-scripts
22-
links = "block"
22+
links = "block_0_0"
2323
build = "build.rs"
2424

2525
[features]

block-sys/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ TODO.
9494

9595
To our knowledge, currently only `clang` supports the [Language Specification
9696
for Blocks][block-lang]. To assist in compiling C (or Objective-C) sources
97-
using these features, this crate's build script expose the `DEP_BLOCK_CC_ARGS`
98-
environment variable to downstream build scripts.
97+
using these features, this crate's build script expose the
98+
`DEP_BLOCK_0_0_CC_ARGS` environment variable to downstream build scripts.
9999

100100
Example usage in your `build.rs` (using the `cc` crate) would be as follows:
101101

@@ -105,7 +105,7 @@ fn main() {
105105
builder.compiler("clang");
106106
builder.file("my_script_using_blocks.c");
107107

108-
for flag in std::env::var("DEP_BLOCK_CC_ARGS").unwrap().split(' ') {
108+
for flag in std::env::var("DEP_BLOCK_0_0_CC_ARGS").unwrap().split(' ') {
109109
builder.flag(flag);
110110
}
111111

block-sys/build.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,24 @@ fn main() {
4747
// work (on newer GNUStep versions these headers are present)
4848
if env::var_os("CARGO_FEATURE_GNUSTEP_2_0").is_none() {
4949
let compat_headers =
50-
Path::new(env!("CARGO_MANIFEST_DIR")).join("gnustep-compat-headers");
50+
Path::new(env!("CARGO_MANIFEST_DIR")).join("compat-headers/gnustep");
5151
cc_args.push_str(" -I");
5252
cc_args.push_str(compat_headers.to_str().unwrap());
5353
}
5454
}
55-
(false, false, false, true) => unimplemented!(),
55+
(false, false, false, true) => {
56+
// Add compability headers to make `#include <Block.h>` work.
57+
let compat_headers = Path::new(env!("CARGO_MANIFEST_DIR")).join("compat-headers/objfw");
58+
cc_args.push_str(" -I");
59+
cc_args.push_str(compat_headers.to_str().unwrap());
60+
println!("cargo:rustc-link-lib=dylib=objfw");
61+
unimplemented!("ObjFW is not yet supported")
62+
}
5663
// Checked in if-let above
5764
(false, false, false, false) => unreachable!(),
5865
(_, _, _, _) => panic!("Invalid feature combination; only one runtime may be selected!"),
5966
}
6067

61-
// Add DEP_BLOCK_CC_ARGS
68+
// Add DEP_BLOCK_[version]_CC_ARGS
6269
println!("cargo:cc_args={}", cc_args);
6370
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include <ObjFW/block.h>

block-sys/src/lib.rs

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99
//!
1010
//! [ABI]: https://clang.llvm.org/docs/Block-ABI-Apple.html
1111
12+
#![no_std]
1213
// Update in Cargo.toml as well.
1314
#![doc(html_root_url = "https://docs.rs/block-sys/0.0.3")]
1415

16+
extern crate std;
17+
1518
// Ensure linkage actually happens
1619
#[cfg(feature = "gnustep-1-7")]
1720
extern crate objc_sys as _;
@@ -298,7 +301,6 @@ pub struct Block_descriptor {
298301
///
299302
/// Requires BLOCK_HAS_SIGNATURE
300303
#[repr(C)]
301-
#[cfg(not(feature = "objfw"))]
302304
pub struct Block_descriptor_basic {
303305
pub header: Block_descriptor_header,
304306

@@ -388,3 +390,50 @@ pub struct Block_byref_extended {
388390
pub inner: Block_byref,
389391
pub layout: *const c_char,
390392
}
393+
394+
#[cfg(test)]
395+
mod tests {
396+
use super::*;
397+
use core::ptr;
398+
use std::println;
399+
400+
#[test]
401+
fn smoke() {
402+
assert_eq!(unsafe { _Block_copy(ptr::null()) }, ptr::null_mut());
403+
}
404+
405+
#[test]
406+
fn test_linkable() {
407+
println!("{:p}", unsafe { &_NSConcreteGlobalBlock });
408+
println!("{:p}", unsafe { &_NSConcreteStackBlock });
409+
println!("{:p}", unsafe { &_NSConcreteMallocBlock });
410+
println!(
411+
"{:p}",
412+
_Block_copy as unsafe extern "C" fn(*const c_void) -> *mut c_void
413+
);
414+
println!(
415+
"{:p}",
416+
_Block_object_assign
417+
as unsafe extern "C" fn(*mut c_void, *const c_void, block_assign_dispose_flags)
418+
);
419+
println!(
420+
"{:p}",
421+
_Block_object_dispose
422+
as unsafe extern "C" fn(*const c_void, block_assign_dispose_flags)
423+
);
424+
println!(
425+
"{:p}",
426+
_Block_release as unsafe extern "C" fn(*const c_void)
427+
);
428+
#[cfg(any(feature = "apple", feature = "compiler-rt"))]
429+
{
430+
println!("{:p}", unsafe { &_NSConcreteAutoBlock });
431+
println!("{:p}", unsafe { &_NSConcreteFinalizingBlock });
432+
println!("{:p}", unsafe { &_NSConcreteWeakBlockVariable });
433+
println!(
434+
"{:p}",
435+
Block_size as unsafe extern "C" fn(*mut c_void) -> c_ulong
436+
);
437+
}
438+
}
439+
}

objc-sys/CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66

77
## Unreleased - YYYY-MM-DD
88

9+
### Changed
10+
* **BREAKING**: Changed `links` key from `objc` to `objc_0_2` for better
11+
future compatibility, until we reach 1.0 (so `DEP_OBJC_X` in build scripts
12+
becomes `DEP_OBJC_0_2_X`).
13+
14+
### Removed
15+
* **BREAKING**: Removed type aliases `Class`, `Ivar`, `Method` and `Protocol`
16+
since they could easily be mistaken for the `objc2::runtime` structs with
17+
the same name.
18+
* **BREAKING**: Removed `objc_property_t`.
19+
* **BREAKING**: Removed `objc_hook_getClass` and `objc_hook_lazyClassNamer`
20+
type aliases (for now).
21+
922

1023
## 0.2.0-alpha.1 - 2022-01-03
1124

objc-sys/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ readme = "README.md"
1919

2020
# Downstream users can customize the linking to libobjc!
2121
# See https://doc.rust-lang.org/cargo/reference/build-scripts.html#overriding-build-scripts
22-
links = "objc"
22+
links = "objc_0_2"
2323
build = "build.rs"
2424

2525
# The default is `apple` on Apple platforms; all other platforms will error

0 commit comments

Comments
 (0)