Skip to content

Commit bf2cc78

Browse files
committed
Updated to build for apple silicon catalyst
1 parent 0958d85 commit bf2cc78

File tree

7 files changed

+56
-37
lines changed

7 files changed

+56
-37
lines changed

Cargo.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,12 @@ edition = "2018"
88

99
[lib]
1010
name = "test1"
11-
crate-type = ["staticlib", "lib"]
11+
crate-type = ["staticlib"]
1212

1313
[build-dependencies]
1414
cbindgen = "*"
1515

1616
[dependencies]
17-
lazy_static = "1.4.0"
18-
twox-hash = "1.5.0"
19-
foreign-types = "*"
20-
libc = "*"
2117

2218
[profile.dev]
2319
panic = 'unwind'
Binary file not shown.
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <stdarg.h>
2+
#include <stdbool.h>
3+
#include <stdint.h>
4+
#include <stdlib.h>
5+
6+
void example(const void *swift_string, uintptr_t len);

build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::env;
44

55
fn main() {
66
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
7-
let filename = "test1_rust.h";
7+
let filename = "XcodeIntegration/XcodeIntegration/Rust/test1_rust.h";
88

99
let _build = cbindgen::Builder::new()
1010
.with_crate(crate_dir)

make_fat.sh

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,42 @@
33
# We need the SDK Root
44
export SDKROOT=`xcrun --sdk macosx --show-sdk-path`
55

6-
# lipo together the different architectures into a universal 'fat' file
6+
# We will build two different frameworks:
7+
# The first one contains X86_64 iOS (Simulator) and ARM iOS
8+
# The other contains Catalyst ARM and Catalyst X86_64
9+
# Then we tell Xcode to only use the first one for iOS builds,
10+
# and the second one for macOS builds.
11+
# The reason is that fat binaries can't contain the same architecture
12+
# slice twice (i.e. ARM64 iOS and ARM64 Catalyst)
13+
14+
# Simulator:
15+
echo "Building for iOS X86_64 (Simulator)..."
16+
cargo build -Z build-std --target x86_64-apple-ios --release > /dev/null 2>&1
17+
18+
# X86 Catalyst
719
# use `cargo build-std` to automatically build the std for non-tier1 platforms
8-
# such as catalyst
9-
cargo +nightly build -Z build-std --target x86_64-apple-ios-macabi --release
10-
cargo build --target aarch64-apple-ios --release
11-
lipo -create -output target/libtest1.a target/{aarch64-apple-ios,x86_64-apple-ios-macabi}/release/libtest1.a
20+
echo "Building for Mac Catalyst X86_64..."
21+
cargo +nightly build -Z build-std --target x86_64-apple-ios-macabi --release > /dev/null 2>&1
22+
23+
# ARM64 Catalyst
24+
echo "Building for Mac Catalyst ARM64..."
25+
cargo +myrust build -Z build-std --target aarch64-apple-ios-macabi --release > /dev/null 2>&1
26+
27+
# iOS
28+
echo "Building for ARM iOS..."
29+
cargo build -Z build-std --target aarch64-apple-ios --release > /dev/null 2>&1
30+
31+
32+
# Build Fat Libraries:
33+
# lipo together the different architectures into a universal 'fat' file
34+
35+
# macOS
36+
echo "Building Fat Libaries"
37+
lipo -create -output XcodeIntegration/XcodeIntegration/Rust/libtest1_mac.a target/{aarch64-apple-ios-macabi,x86_64-apple-ios-macabi}/release/libtest1.a
38+
39+
echo "Wrote XcodeIntegration/XcodeIntegration/Rust/libtest1_ios.a"
40+
41+
# iOS
42+
lipo -create -output XcodeIntegration/XcodeIntegration/Rust/libtest1_ios.a target/{aarch64-apple-ios,x86_64-apple-ios}/release/libtest1.a
43+
44+
echo "Wrote XcodeIntegration/XcodeIntegration/Rust/libtest1_mac.a"

src/lib.rs

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,14 @@
1-
use std::collections::HashMap;
2-
use libc::c_char;
1+
use std::os::raw::c_void;
2+
use std::slice;
3+
use std::str;
34

4-
/// Free a markdown slide buffer.
55
#[no_mangle]
6-
pub unsafe extern "C" fn example(buffer: *mut c_char) {
7-
println!("Yeah");
6+
pub unsafe extern "C" fn example(
7+
swift_string: *const c_void,
8+
len: usize
9+
) {
10+
let bytes: &[u8] = slice::from_raw_parts(swift_string as *mut u8 as _, len);
11+
let string = str::from_utf8_unchecked(&bytes);
12+
println!("String: {}", &string);
813
}
914

10-
pub fn makeit() {
11-
// Type inference lets us omit an explicit type signature (which
12-
// would be `HashMap<String, String>` in this example).
13-
let mut book_reviews = HashMap::new();
14-
15-
// Review some books.
16-
book_reviews.insert(
17-
"Adventures of Huckleberry Finn".to_string(),
18-
"My favorite book.".to_string(),
19-
);
20-
21-
println!("{:?}", &book_reviews);
22-
}
23-
24-
#[cfg(test)]
25-
mod tests {
26-
#[test]
27-
fn it_works() {
28-
assert_eq!(2 + 2, 4);
29-
}
30-
}

0 commit comments

Comments
 (0)