Skip to content

Commit

Permalink
merge(swiftui): Merge pull request #14 from genshen/feature-client-ma…
Browse files Browse the repository at this point in the history
…cos-arm-support

Feature: add macOS arm architecture support for swiftui client app
  • Loading branch information
genshen authored Aug 14, 2023
2 parents 6153c63 + ee6482a commit 2e18fca
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 21 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ jobs:
mv client-ui-macOS-amd64.app.zip ../
cd ../
echo "building swiftui-client"
cd extra/go-api && ./build_archive.sh && cd ../../
cd swiftui-client && xcodebuild -arch "x86_64"
cd build/Release/ && zip -r wssocks-ustb-client-macOS-amd64.app.zip wssocks-ustb-client.app && cd ../../../
mv swiftui-client/build/Release/wssocks-ustb-client-macOS-amd64.app.zip ./
cd extra/go-api && make && cd ../../
cd swiftui-client && xcodebuild -arch x86_64 -arch arm64
cd build/Release/ && zip -r wssocks-ustb-client-macOS-universal.app.zip wssocks-ustb-client.app && cd ../../../
mv swiftui-client/build/Release/wssocks-ustb-client-macOS-universal.app.zip ./
- name: Build Windows
if: matrix.os == 'windows-latest'
Expand Down Expand Up @@ -88,7 +88,7 @@ jobs:
files: |
client-ui-windows-amd64.exe
client-ui-macOS-amd64.app.zip
wssocks-ustb-client-macOS-amd64.app.zip
wssocks-ustb-client-macOS-universal.app.zip
wssocks-ustb-darwin-amd64
wssocks-ustb-linux-arm64
wssocks-ustb-linux-amd64
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
extra/go-api/libwssocks_go_api.a
extra/go-api/libwssocks_go_api_arm64.a
extra/go-api/libwssocks_go_api_amd64.a
extra/go-api/libwssocks_go_api.h

.DS_Store
Expand Down
23 changes: 23 additions & 0 deletions extra/go-api/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# this makefile builds go api into an archive file (static library)

BUILD_FLAGS=--trimpath -gcflags "-N"

BUILD_ENVS=CGO_ENABLED=1 CGO_CFLAGS="-mmacosx-version-min=12.1" CGO_CXXFLAGS="-mmacosx-version-min=12.1" CC=clang

.PHONY: all clean

all: libwssocks_go_api.a

libwssocks_go_api_amd64.a: wssocks_client_wrapper.go
$(BUILD_ENVS) GOOS=darwin GOARCH=amd64 go build $(BUILD_FLAGS) --buildmode=c-archive -o libwssocks_go_api_amd64.a
mv libwssocks_go_api_amd64.h libwssocks_go_api.h

libwssocks_go_api_arm64.a: wssocks_client_wrapper.go
$(BUILD_ENVS) GOOS=darwin GOARCH=arm64 go build $(BUILD_FLAGS) --buildmode=c-archive -o libwssocks_go_api_arm64.a
mv libwssocks_go_api_arm64.h libwssocks_go_api.h

libwssocks_go_api.a: libwssocks_go_api_amd64.a libwssocks_go_api_arm64.a
lipo libwssocks_go_api_amd64.a libwssocks_go_api_arm64.a -create -output libwssocks_go_api.a

clean:
rm libwssocks_go_api.a libwssocks_go_api_arm64.a libwssocks_go_api_amd64.a libwssocks_go_api.h
7 changes: 0 additions & 7 deletions extra/go-api/build_archive.sh

This file was deleted.

12 changes: 5 additions & 7 deletions swiftui-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
1. build C header file and archive file from go API.
```bash
cd extra/go-api
./build_archive.sh
make
```

2. Update target’s build settings
In Xcode, set `SWIFT_INCLUDE_PATHS` (Header Search Paths) to `$(SRCROOT)`,
where `$(SRCROOT)` is the same directory as .xcodeproj.
Then `LIBRARY_SEARCH_PATHS` (Library Search Paths) to `$(SRCROOT)/../extra/go-api`.

3. Build application in Xcode.
2. Build App
```bash
xcodebuild -arch=x86_64 -arch=arm64
```
6 changes: 4 additions & 2 deletions swiftui-client/wssocks-ustb-client.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@
8021423027BA823700643775 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALLOW_TARGET_PLATFORM_SPECIALIZATION = NO;
ARCHS = "$(ARCHS_STANDARD)";
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
Expand All @@ -453,7 +454,7 @@
DEVELOPMENT_TEAM = "";
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
EXCLUDED_ARCHS = arm64;
EXCLUDED_ARCHS = "";
GENERATE_INFOPLIST_FILE = YES;
HEADER_SEARCH_PATHS = "${SRCROOT}/";
INFOPLIST_FILE = "wssocks-ustb-client/Info.plist";
Expand All @@ -476,6 +477,7 @@
8021423127BA823700643775 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALLOW_TARGET_PLATFORM_SPECIALIZATION = NO;
ARCHS = "$(ARCHS_STANDARD)";
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
Expand All @@ -488,7 +490,7 @@
DEVELOPMENT_TEAM = "";
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES;
EXCLUDED_ARCHS = arm64;
EXCLUDED_ARCHS = "";
GENERATE_INFOPLIST_FILE = YES;
HEADER_SEARCH_PATHS = "${SRCROOT}/";
INFOPLIST_FILE = "wssocks-ustb-client/Info.plist";
Expand Down

0 comments on commit 2e18fca

Please sign in to comment.