Skip to content

Commit fd83dda

Browse files
committed
Makefile/swift: update Makefile and add support for iOS
updates tailscale/tailscale#13937 Adds a Makefile for building various targets. Adds support for building iOS compatible libtailscale_ios.a. Removes SOCKS5 support for iOS where it looks like the CFNetwork support is lacking.
1 parent 9d45e58 commit fd83dda

File tree

20 files changed

+659
-106
lines changed

20 files changed

+659
-106
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ libtailscale.so
22
libtailscale.a
33
libtailscale.h
44
libtailscale.tar*
5+
libtailscale_ios.a
6+
libtailscale_ios.h
57

68
/tstestcontrol/libtstestcontrol.a
79
/tstestcontrol/libtstestcontrol.h

Makefile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright (c) Tailscale Inc & AUTHORS
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
4+
5+
libtailscale.a:
6+
go build -buildmode=c-archive
7+
8+
libtailscale_ios.a:
9+
GOOS=ios GOARCH=arm64 CGO_ENABLED=1 CC=$(PWD)/swift/script/clangwrap.sh /usr/local/go/bin/go build -v -ldflags -w -tags ios -o libtailscale_ios.a -buildmode=c-archive
10+
11+
.PHONY: c-archive-ios
12+
c-archive-ios: libtailscale_ios.a ## Builds libtailscale_ios.a for iOS (iOS SDK required)
13+
14+
.PHONY: c-archive
15+
c-archive: libtailscale.a ## Builds libtailscale.a for the target platform
16+
17+
.PHONY: shared
18+
shared: ## Builds libtailscale.so for the target platform
19+
go build -v -buildmode=c-shared
20+
21+
.PHONY: clean
22+
clean: ## Clean up build artifacts
23+
rm -f libtailscale.a
24+
rm -f libtailscale_ios.a
25+
rm -f libtailscale.h
26+
rm -f libtailscale_ios.h
27+
28+
.PHONY: help
29+
help: ## Show this help
30+
@echo "\nSpecify a command. The choices are:\n"
31+
@grep -hE '^[0-9a-zA-Z_-]+:.*?## .*$$' ${MAKEFILE_LIST} | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[0;36m%-12s\033[m %s\n", $$1, $$2}'
32+
@echo ""
33+
34+
.DEFAULT_GOAL := help

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ With the latest version of Go, run:
1313
go build -buildmode=c-archive
1414
```
1515

16+
or
17+
18+
```
19+
make archive
20+
```
21+
1622
This will produce a `libtailscale.a` file. Link it into your binary,
1723
and use the `tailscale.h` header to reference it.
1824

@@ -22,6 +28,12 @@ It is also possible to build a shared library using
2228
go build -buildmode=c-shared
2329
```
2430

31+
or
32+
33+
```
34+
make shared
35+
```
36+
2537
## Bugs
2638

2739
Please file any issues about this code or the hosted service on

swift/Makefile

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,44 @@ ifeq (, $(shell which $(XCPRETTIFIER)))
77
XCPRETTIFIER := cat
88
endif
99

10-
OUTPUT_DIR=build
10+
# The xcodebuild schemes will run the Makefile in the root directory to build
11+
# the libtailscale.a and libtailscale_ios.a dependencies.
1112

12-
build:
13-
mkdir -p $(OUTPUT_DIR)
14-
xcodebuild build -scheme TailscaleKit -derivedDataPath $(OUTPUT_DIR) -configuration Release -destination 'generic/platform=macOS,arch=arm64' -destination 'generic/platform=iOS' | $(XCPRETTIFIER)
13+
.PHONY: macos
14+
macos: ## Builds TailscaleKit for macos to swift/build/Build/Products/Release
15+
cd .. && make c-archive
16+
mkdir -p build && \
17+
xcodebuild build -scheme "TailscaleKit (macOS)" \
18+
-derivedDataPath build \
19+
-configuration Release \
20+
-destination 'platform=macOS,arch=arm64' | $(XCPRETTIFIER)
1521

16-
test:
17-
xcodebuild test -scheme TailscaleKitXCTests -derivedDataPath $(OUTPUT_DIR) -configuration Debug | $(XCPRETTIFIER)
22+
.PHONY: ios
23+
ios: ## Builds TailscaleKit for iOS to swift/build/Build/Products/Release
24+
cd .. && make c-archive-ios
25+
mkdir -p build && \
26+
xcodebuild build -scheme "TailscaleKit (iOS)" \
27+
-derivedDataPath build \
28+
-configuration Release \
29+
-destination 'generic/platform=iOS' | $(XCPRETTIFIER)
1830

19-
clean:
20-
rm -rf $(OUTPUT_DIR)
31+
.PHONY: test
32+
test: ## Run tests (macOS)
33+
cd .. && make c-archive
34+
xcodebuild test -scheme TailscaleKitXCTests \
35+
-derivedDataPath build \
36+
-configuration Debug \
37+
-destination 'platform=macOS,arch=arm64' | $(XCPRETTIFIER)
38+
39+
.PHONY: clean
40+
clean: ## Clean up build artifacts (including the libtailscale dependencies)
41+
cd .. && make clean
42+
rm -rf build
43+
44+
.PHONY: help
45+
help: ## Show this help
46+
@echo "\nSpecify a command. The choices are:\n"
47+
@grep -hE '^[0-9a-zA-Z_-]+:.*?## .*$$' ${MAKEFILE_LIST} | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[0;36m%-12s\033[m %s\n", $$1, $$2}'
48+
@echo ""
49+
50+
.DEFAULT_GOAL := help

swift/README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,30 @@ Build Requirements:
1414

1515
Building Tailscale.framework:
1616

17+
First build the libtailscale dependecies:
18+
19+
20+
1721
From /swift
1822
```
19-
$ make build
23+
$ make macos
24+
# make ios
2025
```
2126

2227
Will build TailscaleKit.framework into /swift/build/Build/Products.
2328

2429
Separate frameworks will be built for macOS and iOS. All dependencies (libtailscale.a)
2530
are built automatically. Swift 6 is supported.
2631

27-
Alternatively, you may build from xCode using the Tailscale scheme.
32+
Alternatively, you may build from xCode using the Tailscale scheme but the
33+
libraries must be built first (since xCode will complain about paths and
34+
permissions)
35+
36+
From /
37+
```
38+
$ make c-archive
39+
$ make c-archive-ios
40+
```
2841

2942
Non-apple builds are not supported (yet). We do use URLSession and Combine though
3043
it is possible to purge both.

0 commit comments

Comments
 (0)