Skip to content

Commit

Permalink
Specify the "links" key in objc_sys
Browse files Browse the repository at this point in the history
Makes it possible for downstream users to customize the linking to libobjc, see https://doc.rust-lang.org/cargo/reference/build-scripts.html#overriding-build-scripts
  • Loading branch information
madsmtm committed Sep 5, 2021
1 parent 9028470 commit b8a54e5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
13 changes: 12 additions & 1 deletion objc_sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "objc_sys"
version = "0.0.0"
version = "0.0.0" # Remember to update html_root_url in lib.rs
authors = ["Mads Marquart <mads@marquart.dk>"]
edition = "2018"

Expand All @@ -13,3 +13,14 @@ categories = [
repository = "https://github.com/madsmtm/objc"
documentation = "https://docs.rs/objc_sys/"
license = "MIT"

exclude = [
# Used to help developers track changes by running bindgen against
# different revisions of Apple's open source `objc4`.
"helper-scripts/*",
]

# Downstream users can customize the linking to libobjc!
# See https://doc.rust-lang.org/cargo/reference/build-scripts.html#overriding-build-scripts
links = "objc"
build = "build.rs"
10 changes: 10 additions & 0 deletions objc_sys/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fn main() {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rustc-link-lib=dylib=objc");

// TODO: Should we vendor GNUStep's libobjc2 on non-apple targets?
// Check std::env::env::var("CARGO_CFG_TARGET_VENDOR").unwrap()
// Cargo.toml:
// [target.'cfg(not(target_vendor = "apple"))'.build-dependencies]
// cc = "1.0"
}
10 changes: 5 additions & 5 deletions objc_sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@
//! Protocol / objc_protocol is no longer a type alias of objc_object, for
//! better type safety. Their internal representation is the same, so the
//! functionality is just a cast away.
//!
//! Deprecated functions are not included since they could be removed at any
//! macOS release, and then our code would break.
// TODO: Replace `extern "C"` with `extern "C-unwind"`.

#![no_std]
#![allow(non_camel_case_types)]
#![allow(non_upper_case_globals)]
// Update in Cargo.toml as well.
#![doc(html_root_url = "https://docs.rs/objc_sys/1.1.0")]
#![doc(html_root_url = "https://docs.rs/objc_sys/0.0.0")]

// TODO: Remove this and add "no-std" category to Cargo.toml
extern crate std;

use core::cell::UnsafeCell;
Expand Down Expand Up @@ -52,6 +55,3 @@ pub use various::*;
///
/// TODO: Replace this with `extern type` to also mark it as unsized.
type OpaqueData = PhantomData<(UnsafeCell<*const ()>, PhantomPinned)>;

#[link(name = "objc", kind = "dylib")]
extern "C" {}

0 comments on commit b8a54e5

Please sign in to comment.