Skip to content

Commit a7ff4c4

Browse files
committed
build: Add apple xcframework support.
1 parent 7bc4798 commit a7ff4c4

File tree

5 files changed

+117
-3
lines changed

5 files changed

+117
-3
lines changed

.github/workflows/build.yaml

+5-1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ jobs:
8686
with:
8787
fetch-depth: 1
8888
submodules: true
89-
- name: Build
89+
- name: Build native
9090
run: |
9191
make
92+
make clean
93+
- name: Build cross
94+
run: |
95+
./build-apple.sh

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
bin
22
build
3+
HevTaskSystem.xcframework

README.md

+16-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ and perform I/O operations in synchronized mode.
2727

2828
## How to Build
2929

30-
**Unix**:
30+
### Unix
31+
3132
```bash
3233
git clone https://gitlab.com/hev/hev-task-system
3334
cd hev-task-system
@@ -55,15 +56,26 @@ make apps
5556
make tests
5657
```
5758

58-
**Android**:
59+
### Android
60+
5961
```bash
6062
mkdir hev-task-system
6163
cd hev-task-system
6264
git clone https://gitlab.com/hev/hev-task-system jni
6365
ndk-build
6466
```
6567

68+
### iOS and MacOS
69+
70+
```bash
71+
git clone https://gitlab.com/hev/hev-task-system
72+
cd hev-task-system
73+
# will generate HevTaskSystem.xcframework
74+
./build-apple.sh
75+
```
76+
6677
## Demos
78+
6779
1. [simple](https://gitlab.com/hev/hev-task-system/blob/master/apps/simple.c)
6880
1. [channel](https://gitlab.com/hev/hev-task-system/blob/master/apps/channel.c)
6981
1. [timeout](https://gitlab.com/hev/hev-task-system/blob/master/apps/timeout.c)
@@ -74,8 +86,10 @@ ndk-build
7486
1. [curl](https://gitlab.com/hev/hev-task-system/blob/master/apps/curl.c)
7587

7688
## Contributors
89+
7790
* **hev** - https://hev.cc
7891

7992
## License
93+
8094
MIT
8195

build-apple.sh

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
XCFRAMEWORK_DIR="./apple_xcframework"
6+
7+
# buildStatic iphoneos -mios-version-min=15.0 arm64
8+
buildStatic()
9+
{
10+
echo "build for $1, $2, min version $3"
11+
12+
local MIN_VERSION="-m$1-version-min=$3"
13+
make PP="xcrun --sdk $1 --toolchain $1 clang" \
14+
CC="xcrun --sdk $1 --toolchain $1 clang" \
15+
CFLAGS="-arch $2 $MIN_VERSION" \
16+
LFLAGS="-arch $2 $MIN_VERSION -Wl,-Bsymbolic-functions" static
17+
18+
local OUTPUT_DIR="$XCFRAMEWORK_DIR/$1-$2"
19+
mkdir -p $OUTPUT_DIR
20+
local OUTPUT_ARCH_FILE="$OUTPUT_DIR/libhev-task-system.a"
21+
22+
libtool -static -o $OUTPUT_ARCH_FILE bin/libhev-task-system.a
23+
make clean
24+
}
25+
26+
mergeStatic()
27+
{
28+
echo "merge for $1, $2, $3"
29+
local FIRST_LIB_FILE="$XCFRAMEWORK_DIR/$1-$2/libhev-task-system.a"
30+
local SECOND_LIB_FILE="$XCFRAMEWORK_DIR/$1-$3/libhev-task-system.a"
31+
local OUTPUT_DIR="$XCFRAMEWORK_DIR/$1-$2-$3"
32+
mkdir -p $OUTPUT_DIR
33+
local OUTPUT_ARCH_FILE="$OUTPUT_DIR/libhev-task-system.a"
34+
lipo -create \
35+
-arch $2 $FIRST_LIB_FILE \
36+
-arch $3 $SECOND_LIB_FILE \
37+
-output $OUTPUT_ARCH_FILE
38+
}
39+
40+
rm -rf $XCFRAMEWORK_DIR
41+
rm -rf HevTaskSystem.xcframework
42+
mkdir $XCFRAMEWORK_DIR
43+
44+
buildStatic iphoneos arm64 15.0
45+
buildStatic iphonesimulator x86_64 15.0
46+
buildStatic iphonesimulator arm64 15.0
47+
mergeStatic iphonesimulator x86_64 arm64
48+
49+
# keep same with flutter
50+
buildStatic macosx x86_64 10.14
51+
buildStatic macosx arm64 10.14
52+
mergeStatic macosx x86_64 arm64
53+
54+
buildStatic appletvos arm64 17.0
55+
buildStatic appletvsimulator x86_64 17.0
56+
buildStatic appletvsimulator arm64 17.0
57+
mergeStatic appletvsimulator x86_64 arm64
58+
59+
INCLUDE_DIR="$XCFRAMEWORK_DIR/include"
60+
mkdir -p $INCLUDE_DIR
61+
cp ./include/*.h $INCLUDE_DIR
62+
cp ./module.modulemap $INCLUDE_DIR
63+
xcodebuild -create-xcframework \
64+
-library ./apple_xcframework/iphoneos-arm64/libhev-task-system.a -headers $INCLUDE_DIR \
65+
-library ./apple_xcframework/iphonesimulator-x86_64-arm64/libhev-task-system.a -headers $INCLUDE_DIR \
66+
-library ./apple_xcframework/macosx-x86_64-arm64/libhev-task-system.a -headers $INCLUDE_DIR \
67+
-library ./apple_xcframework/appletvos-arm64/libhev-task-system.a -headers $INCLUDE_DIR \
68+
-library ./apple_xcframework/appletvsimulator-x86_64-arm64/libhev-task-system.a -headers $INCLUDE_DIR \
69+
-output ./HevTaskSystem.xcframework
70+
71+
rm -rf ./apple_xcframework

module.modulemap

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module HevTaskSystem {
2+
umbrella header "hev-circular-buffer.h"
3+
umbrella header "hev-memory-allocator.h"
4+
umbrella header "hev-object-atomic.h"
5+
umbrella header "hev-object.h"
6+
umbrella header "hev-task-call.h"
7+
umbrella header "hev-task-channel.h"
8+
umbrella header "hev-task-channel-select.h"
9+
umbrella header "hev-task-cio-buffer.h"
10+
umbrella header "hev-task-cio-fd.h"
11+
umbrella header "hev-task-cio.h"
12+
umbrella header "hev-task-cio-null.h"
13+
umbrella header "hev-task-cio-socket.h"
14+
umbrella header "hev-task-cond.h"
15+
umbrella header "hev-task-dns.h"
16+
umbrella header "hev-task.h"
17+
umbrella header "hev-task-io.h"
18+
umbrella header "hev-task-io-pipe.h"
19+
umbrella header "hev-task-io-poll.h"
20+
umbrella header "hev-task-io-socket.h"
21+
umbrella header "hev-task-mutex.h"
22+
umbrella header "hev-task-system.h"
23+
export *
24+
}

0 commit comments

Comments
 (0)