Skip to content

Commit 42c54f6

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 42c54f6

File tree

19 files changed

+716
-37
lines changed

19 files changed

+716
-37
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-archiverm
7+
8+
libtailscale_ios.a:
9+
GOOS=ios GOARCH=arm64 CGO_ENABLED=1 CC=$(PWD)/swift/script/clangwrap.sh 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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ With the latest version of Go, run:
1313
go build -buildmode=c-archive
1414
```
1515

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

@@ -22,6 +27,12 @@ It is also possible to build a shared library using
2227
go build -buildmode=c-shared
2328
```
2429

30+
or
31+
32+
```
33+
make shared
34+
```
35+
2536
## Bugs
2637

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

swift/Makefile

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,35 @@ 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+
mkdir -p build && \
16+
xcodebuild build -scheme "TailscaleKit (macOS)" -derivedDataPath build -configuration Release -destination 'platform=macOS,arch=arm64' | $(XCPRETTIFIER)
1517

16-
test:
17-
xcodebuild test -scheme TailscaleKitXCTests -derivedDataPath $(OUTPUT_DIR) -configuration Debug | $(XCPRETTIFIER)
18+
.PHONY: ios
19+
ios: ## Builds TailscaleKit for iOS to swift/build/Build/Products/Release
20+
mkdir -p build && \
21+
xcodebuild build -scheme "TailscaleKit (iOS)" -derivedDataPath build -configuration Release -destination 'generic/platform=iOS' | $(XCPRETTIFIER)
1822

19-
clean:
20-
rm -rf $(OUTPUT_DIR)
23+
.PHONY: test
24+
test: ## Run tests (macOS)
25+
xcodebuild test -scheme TailscaleKitXCTests -derivedDataPath build -configuration Debug -destination 'platform=macOS,arch=arm64' | $(XCPRETTIFIER)
26+
27+
.PHONY: clean
28+
clean: ## Clean up build artifacts (including the libtailscale dependencies)
29+
rm -f ../libtailscale.a
30+
rm -f ../libtailscale_ios.a
31+
rm -f ../libtailscale.h
32+
rm -f ../libtailscale_ios.h
33+
rm -rf build
34+
35+
.PHONY: help
36+
help: ## Show this help
37+
@echo "\nSpecify a command. The choices are:\n"
38+
@grep -hE '^[0-9a-zA-Z_-]+:.*?## .*$$' ${MAKEFILE_LIST} | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[0;36m%-12s\033[m %s\n", $$1, $$2}'
39+
@echo ""
40+
41+
.DEFAULT_GOAL := help

0 commit comments

Comments
 (0)