Skip to content

Commit bf500bb

Browse files
committed
Remove objc2 build script
1 parent b6b9f9c commit bf500bb

File tree

7 files changed

+61
-60
lines changed

7 files changed

+61
-60
lines changed

objc-sys/Cargo.toml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
[package]
22
name = "objc-sys"
3-
version = "0.2.0-alpha.1" # Remember to update html_root_url in lib.rs
3+
# Remember to update `html_root_url` in lib.rs, the `links` key, and the
4+
# exception function name.
5+
version = "0.2.0-alpha.1"
46
authors = ["Mads Marquart <[email protected]>"]
57
edition = "2021"
68

@@ -43,6 +45,12 @@ winobjc = ["gnustep-1-8"]
4345
# TODO
4446
objfw = []
4547

48+
# Private/unstable features - must not be relied on!
49+
unstable-exception = ["cc"]
50+
51+
[build-dependencies]
52+
cc = { version = "1", optional = true }
53+
4654
[package.metadata.docs.rs]
4755
default-target = "x86_64-apple-darwin"
4856
no-default-features = true

objc-sys/build.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,25 @@ fn main() {
211211
// Link to libobjc
212212
println!("cargo:rustc-link-lib=dylib=objc");
213213
}
214+
215+
// We do this compilation step here instead of in `objc2` to cut down on
216+
// the total number of build scripts required.
217+
#[cfg(feature = "unstable-exception")]
218+
{
219+
if std::env::var("DOCS_RS").is_ok() {
220+
// docs.rs doesn't have clang, so skip building this. The
221+
// documentation will still work since it doesn't need to link.
222+
return;
223+
}
224+
println!("cargo:rerun-if-changed=extern/exception.m");
225+
226+
let mut builder = cc::Build::new();
227+
builder.file("extern/exception.m");
228+
229+
for flag in cc_args.split(' ') {
230+
builder.flag(flag);
231+
}
232+
233+
builder.compile("librust_objc_sys_0_2_try_catch_exception.a");
234+
}
214235
}

objc2/extern/exception.m renamed to objc-sys/extern/exception.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
/// See <https://clang.llvm.org/docs/AutomaticReferenceCounting.html#arc-runtime-objc-retain>.
77
id objc_retain(id value);
88

9-
// We return `unsigned char`, since it is guaranteed to be an `u8` on all platforms
10-
unsigned char rust_objc_try_catch_exception(void (*f)(void *), void *context, id *error) {
9+
/// Unsure how C name resolution works, so we make sure to version this symbol.
10+
///
11+
/// Return `unsigned char` since it is guaranteed to be `u8` on all platforms.
12+
unsigned char rust_objc_sys_0_2_try_catch_exception(void (*f)(void *), void *context, id *error) {
1113
@try {
1214
f(context);
1315
if (error) {

objc-sys/src/exception.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
//! Apple: `objc-exception.h`
33
//! GNUStep: `eh_personality.c`, which is a bit brittle to rely on, but I
44
//! think it's fine...
5-
#[cfg(not(objfw))]
5+
#[cfg(any(not(objfw), feature = "unstable-exception"))]
66
use core::ffi::c_void;
77
#[cfg(apple)]
88
use std::os::raw::c_int;
9+
#[cfg(feature = "unstable-exception")]
10+
use std::os::raw::c_uchar;
911

1012
#[cfg(apple)]
1113
use crate::objc_class;
@@ -73,4 +75,26 @@ extern_c! {
7375
//
7476
// #[cfg(gnustep)]
7577
// pub fn objc_set_apple_compatible_objcxx_exceptions(newValue: c_int) -> c_int;
78+
79+
/// Call the given function inside an Objective-C `@try/@catch` block.
80+
///
81+
/// Defined in `extern/exception.m` and compiled in `build.rs`.
82+
///
83+
/// Alternatively, we could manually write assembly for this function like
84+
/// [`objrs` does][manual-asm] does, that would cut down on a build stage
85+
/// (and would probably give us a bit better performance), but it gets
86+
/// unwieldy _very_ quickly, so I chose the much more stable option.
87+
///
88+
/// Another thing to remember: While Rust's and Objective-C's unwinding
89+
/// mechanisms are similar now, Rust's is explicitly unspecified, and they
90+
/// may diverge significantly in the future; so handling this in pure Rust
91+
/// (using mechanisms like core::intrinsics::r#try) is not an option!
92+
///
93+
/// [manual-asm]: https://gitlab.com/objrs/objrs/-/blob/b4f6598696b3fa622e6fddce7aff281770b0a8c2/src/exception.rs
94+
#[cfg(feature = "unstable-exception")]
95+
pub fn rust_objc_sys_0_2_try_catch_exception(
96+
f: extern "C" fn(*mut c_void),
97+
context: *mut c_void,
98+
error: *mut *mut objc_object,
99+
) -> c_uchar;
76100
}

objc2/Cargo.toml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,13 @@ repository = "https://github.com/madsmtm/objc2"
1616
documentation = "https://docs.rs/objc2/"
1717
license = "MIT"
1818

19-
build = "build.rs"
20-
2119
# NOTE: 'unstable' features are _not_ considered part of the SemVer contract,
2220
# and may be removed in a minor release.
2321
[features]
2422
default = ["apple"]
2523

2624
# Enables `objc2::exception::throw` and `objc2::exception::catch`
27-
exception = ["cc"]
25+
exception = ["objc-sys/unstable-exception"]
2826

2927
# Wrap every `objc2::msg_send` call in a `@try/@catch` block
3028
catch_all = ["exception"]
@@ -56,9 +54,6 @@ malloc_buf = { version = "1.0", optional = true }
5654
objc-sys = { path = "../objc-sys", version = "=0.2.0-alpha.1", default-features = false }
5755
objc2-encode = { path = "../objc2-encode", version = "=2.0.0-beta.2", default-features = false }
5856

59-
[build-dependencies]
60-
cc = { version = "1", optional = true }
61-
6257
[dev-dependencies]
6358
iai = { version = "0.1", git = "https://github.com/madsmtm/iai", branch = "callgrind" }
6459

objc2/build.rs

Lines changed: 0 additions & 25 deletions
This file was deleted.

objc2/src/exception.rs

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,11 @@
2020
use core::ffi::c_void;
2121
use core::mem;
2222
use core::ptr;
23-
use std::os::raw::c_uchar;
2423

2524
use crate::ffi;
2625
use crate::rc::{Id, Shared};
2726
use crate::runtime::Object;
2827

29-
extern "C" {
30-
/// Call the given function inside an Objective-C `@try/@catch` block.
31-
///
32-
/// Defined in `extern/exception.m` and compiled in `build.rs`.
33-
///
34-
/// Alternatively, we could manually write assembly for this function like
35-
/// [`objrs` does][manual-asm] does, that would cut down on a build stage
36-
/// (and would probably give us a bit better performance), but it gets
37-
/// unwieldy _very_ quickly, so I chose the much more stable option.
38-
///
39-
/// Another thing to remember: While Rust's and Objective-C's unwinding
40-
/// mechanisms are similar now, Rust's is explicitly unspecified, and they
41-
/// may diverge significantly in the future; so handling this in pure Rust
42-
/// (using mechanisms like core::intrinsics::r#try) is not an option!
43-
///
44-
/// [manual-asm]: https://gitlab.com/objrs/objrs/-/blob/b4f6598696b3fa622e6fddce7aff281770b0a8c2/src/exception.rs
45-
fn rust_objc_try_catch_exception(
46-
f: extern "C" fn(*mut c_void),
47-
context: *mut c_void,
48-
error: *mut *mut ffi::objc_object,
49-
) -> c_uchar;
50-
}
51-
5228
/// Throws an Objective-C exception.
5329
///
5430
/// The argument must be a pointer to an Objective-C object.
@@ -87,7 +63,7 @@ unsafe fn try_no_ret<F: FnOnce()>(closure: F) -> Result<(), Option<Id<Object, Sh
8763
let context = &mut closure as *mut _ as *mut c_void;
8864

8965
let mut exception = ptr::null_mut();
90-
let success = unsafe { rust_objc_try_catch_exception(f, context, &mut exception) };
66+
let success = unsafe { ffi::rust_objc_sys_0_2_try_catch_exception(f, context, &mut exception) };
9167

9268
if success == 0 {
9369
Ok(())

0 commit comments

Comments
 (0)