Skip to content

Commit e185bd1

Browse files
committed
Add skeleton and test for Encode/RefEncode macros
1 parent 0e7162f commit e185bd1

File tree

6 files changed

+52
-1
lines changed

6 files changed

+52
-1
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ jobs:
153153
ARGS: --no-default-features --features ${{ matrix.runtime || 'apple' }} ${{ matrix.args }}
154154
# Use --no-fail-fast, except with dinghy
155155
TESTARGS: ${{ matrix.dinghy && ' ' || '--no-fail-fast' }} ${{ matrix.test-args }}
156-
FEATURES: ${{ matrix.features || 'malloc,block,exception,catch_all,verify_message' }}
156+
FEATURES: ${{ matrix.features || 'malloc,block,exception,catch_all,verify_message,derive' }}
157157
UNSTABLE_FEATURES: ${{ matrix.unstable-features || 'unstable-autoreleasesafe' }}
158158

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

objc2-encode/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ repository = "https://github.com/madsmtm/objc2"
1818
documentation = "https://docs.rs/objc2-encode/"
1919
license = "MIT"
2020

21+
[features]
22+
derive = ["objc2-proc-macros"]
23+
24+
[dependencies]
25+
objc2-proc-macros = { path = "../objc2-proc-macros", optional = true }
26+
2127
[package.metadata.docs.rs]
2228
default-target = "x86_64-apple-darwin"
2329

objc2-encode/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,5 @@ mod static_str;
115115

116116
pub use self::encode::{Encode, EncodeArguments, RefEncode};
117117
pub use self::encoding::Encoding;
118+
#[cfg(feature = "derive")]
119+
pub use objc2_proc_macros::{Encode, RefEncode};

objc2-encode/tests/test_derive.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#![cfg(feature = "derive")]
2+
use objc2_encode::{Encode, Encoding, RefEncode};
3+
4+
#[cfg(target_pointer_width = "32")]
5+
type CGFloat = f32;
6+
7+
#[cfg(target_pointer_width = "64")]
8+
type CGFloat = f64;
9+
10+
#[derive(Encode, RefEncode)]
11+
#[repr(C)]
12+
struct CGPoint {
13+
x: CGFloat,
14+
y: CGFloat,
15+
}
16+
17+
#[test]
18+
fn cgpoint() {
19+
let enc = Encoding::Struct("CGPoint", &[CGFloat::ENCODING, CGFloat::ENCODING]);
20+
assert_eq!(CGPoint::ENCODING, enc);
21+
assert_eq!(CGPoint::ENCODING_REF, Encoding::Pointer(&enc));
22+
}

objc2-proc-macros/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,10 @@ gnustep-1-9 = ["gnustep-1-8"]
3030
gnustep-2-0 = ["gnustep-1-9"]
3131
gnustep-2-1 = ["gnustep-2-0"]
3232

33+
[dependencies]
34+
syn = "1.0"
35+
quote = "1.0"
36+
# TODO: Use `proc-macro-crate` or similar for better usage downstream?
37+
3338
[package.metadata.docs.rs]
3439
default-target = "x86_64-apple-darwin"

objc2-proc-macros/src/lib.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,19 @@
1616
#[cfg(doctest)]
1717
#[doc = include_str!("../README.md")]
1818
extern "C" {}
19+
20+
use proc_macro::TokenStream;
21+
22+
/// TODO
23+
#[proc_macro_derive(Encode)]
24+
pub fn encode_derive(input: TokenStream) -> TokenStream {
25+
dbg!(input);
26+
todo!()
27+
}
28+
29+
/// TODO
30+
#[proc_macro_derive(RefEncode)]
31+
pub fn ref_encode_derive(input: TokenStream) -> TokenStream {
32+
dbg!(input);
33+
todo!()
34+
}

0 commit comments

Comments
 (0)