From 9d01829a986bd9254934870633ad684330da48e6 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Tue, 2 Oct 2018 18:12:30 +0200 Subject: [PATCH] Rewrite bridge build system --- WireGuard.xcodeproj/project.pbxproj | 40 +++++--------- WireGuard/AppDelegate.swift | 4 +- .../TunnelsTableViewController.swift | 2 +- wireguard-go-bridge/Makefile | 52 +++++++++++-------- .../wireguard-go => }/api-ios.go | 0 .../wireguard-go => }/queueconstants.go | 0 .../wireguard-go => }/tun/tun_ios.go | 0 wireguard-go-bridge/xcode-build-helper.sh | 23 -------- 8 files changed, 45 insertions(+), 76 deletions(-) rename wireguard-go-bridge/src/{git.zx2c4.com/wireguard-go => }/api-ios.go (100%) rename wireguard-go-bridge/src/{git.zx2c4.com/wireguard-go => }/queueconstants.go (100%) rename wireguard-go-bridge/src/{git.zx2c4.com/wireguard-go => }/tun/tun_ios.go (100%) delete mode 100755 wireguard-go-bridge/xcode-build-helper.sh diff --git a/WireGuard.xcodeproj/project.pbxproj b/WireGuard.xcodeproj/project.pbxproj index 914128c..817fda2 100644 --- a/WireGuard.xcodeproj/project.pbxproj +++ b/WireGuard.xcodeproj/project.pbxproj @@ -103,7 +103,7 @@ /* Begin PBXFileReference section */ 0CE52E030FAA93F3BF5747B2 /* Pods-WireGuard.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WireGuard.release.xcconfig"; path = "Pods/Target Support Files/Pods-WireGuard/Pods-WireGuard.release.xcconfig"; sourceTree = ""; }; 25E2BE31A33C8CCE6E79B6EF /* Pods-WireGuard.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WireGuard.debug.xcconfig"; path = "Pods/Target Support Files/Pods-WireGuard/Pods-WireGuard.debug.xcconfig"; sourceTree = ""; }; - 4A0F8694215C0726002AEE4B /* libwg-go.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = "libwg-go.a"; sourceTree = ""; }; + 4A0F8694215C0726002AEE4B /* libwg-go.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = "libwg-go.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 4A430E7F2139DC8F0078172C /* icon_20pt@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "icon_20pt@3x.png"; sourceTree = ""; }; 4A430E812139DCCB0078172C /* icon_20pt.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = icon_20pt.png; sourceTree = ""; }; 4A430E832139DCFB0078172C /* icon_60pt@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "icon_60pt@3x.png"; path = "WireGuard/Assets.xcassets/AppIcon.appiconset/icon_60pt@3x.png"; sourceTree = SOURCE_ROOT; }; @@ -144,7 +144,6 @@ 4A8A229D215B793C00736141 /* AppCoordinator+TunnelInfoTableViewControllerDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AppCoordinator+TunnelInfoTableViewControllerDelegate.swift"; sourceTree = ""; }; 4A8A229F215B821A00736141 /* ExtensionMessage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExtensionMessage.swift; sourceTree = ""; }; 4A8A22A7215BC6A800736141 /* Makefile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.make; path = Makefile; sourceTree = ""; }; - 4A8A22AC215BCFB000736141 /* xcode-build-helper.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = "xcode-build-helper.sh"; sourceTree = ""; }; 4A8AABD720B6A79100B6D8C1 /* UITableView+WireGuard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UITableView+WireGuard.swift"; sourceTree = ""; }; 4ABF718D214D8B0300A1E0BF /* TunnelInfoTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TunnelInfoTableViewController.swift; sourceTree = ""; }; 4ABFFE9D212D399F00107136 /* WireGuard-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "WireGuard-Bridging-Header.h"; sourceTree = ""; }; @@ -343,7 +342,6 @@ 4AD08FFE20DC4171000E9CF5 /* wireguard-go-bridge */ = { isa = PBXGroup; children = ( - 4A8A22AC215BCFB000736141 /* xcode-build-helper.sh */, 4A8A22A7215BC6A800736141 /* Makefile */, 4A0F8694215C0726002AEE4B /* libwg-go.a */, 4AD0900720DC4171000E9CF5 /* wireguard.h */, @@ -388,7 +386,7 @@ buildConfigurationList = 4A8A22A9215BC9B200736141 /* Build configuration list for PBXLegacyTarget "WireGuardGoBridge" */; buildPhases = ( ); - buildToolPath = "$(PROJECT_DIR)/wireguard-go-bridge/xcode-build-helper.sh"; + buildToolPath = make; buildWorkingDirectory = "$(PROJECT_DIR)/wireguard-go-bridge"; dependencies = ( ); @@ -470,6 +468,7 @@ TargetAttributes = { 4A4BACE120B5F1BF00F12B28 = { CreatedOnToolsVersion = 9.3.1; + LastSwiftMigration = 1000; SystemCapabilities = { com.apple.ApplicationGroups.iOS = { enabled = 1; @@ -484,6 +483,7 @@ }; 4A4BACF520B5F1C100F12B28 = { CreatedOnToolsVersion = 9.3.1; + LastSwiftMigration = 1000; TestTargetID = 4A4BACE120B5F1BF00F12B28; }; 4A61D82520D98CE1006C7A76 = { @@ -790,6 +790,7 @@ SDKROOT = iphoneos; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; }; @@ -843,6 +844,7 @@ SDKROOT = iphoneos; SWIFT_COMPILATION_MODE = wholemodule; SWIFT_OPTIMIZATION_LEVEL = "-O"; + TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; }; name = Release; @@ -859,7 +861,6 @@ CODE_SIGN_STYLE = Manual; DEVELOPMENT_TEAM = L82V4Y2P3C; INFOPLIST_FILE = WireGuard/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 10.3; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -873,8 +874,7 @@ PROVISIONING_PROFILE_SPECIFIER = "WireGuard Development"; SWIFT_OBJC_BRIDGING_HEADER = "WireGuard/WireGuard-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.0; - TARGETED_DEVICE_FAMILY = "1,2"; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -890,7 +890,6 @@ CODE_SIGN_STYLE = Manual; DEVELOPMENT_TEAM = L82V4Y2P3C; INFOPLIST_FILE = WireGuard/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 10.3; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -903,8 +902,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = "WireGuard Development"; SWIFT_OBJC_BRIDGING_HEADER = "WireGuard/WireGuard-Bridging-Header.h"; - SWIFT_VERSION = 4.0; - TARGETED_DEVICE_FAMILY = "1,2"; + SWIFT_VERSION = 4.2; }; name = Release; }; @@ -923,8 +921,7 @@ ); PRODUCT_BUNDLE_IDENTIFIER = com.wireguard.ios.WireGuardTests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.0; - TARGETED_DEVICE_FAMILY = "1,2"; + SWIFT_VERSION = 4.2; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/WireGuard.app/WireGuard"; }; name = Debug; @@ -944,8 +941,7 @@ ); PRODUCT_BUNDLE_IDENTIFIER = com.wireguard.ios.WireGuardTests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.0; - TARGETED_DEVICE_FAMILY = "1,2"; + SWIFT_VERSION = 4.2; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/WireGuard.app/WireGuard"; }; name = Release; @@ -960,24 +956,18 @@ DEVELOPMENT_TEAM = L82V4Y2P3C; ENABLE_BITCODE = NO; INFOPLIST_FILE = WireGuardNetworkExtension/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 11.4; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", "@executable_path/../../Frameworks", ); - LIBRARY_SEARCH_PATHS = ( - "$(inherited)", - "$(PROJECT_DIR)/wireguard-go-bridge", - ); PRODUCT_BUNDLE_IDENTIFIER = "com.wireguard.ios.network-extension"; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = "WireGuard Network Extension Development"; SKIP_INSTALL = YES; SWIFT_OBJC_BRIDGING_HEADER = "WireGuardNetworkExtension/WireGuardNetworkExtension-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.0; - TARGETED_DEVICE_FAMILY = "1,2"; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -991,23 +981,17 @@ DEVELOPMENT_TEAM = L82V4Y2P3C; ENABLE_BITCODE = NO; INFOPLIST_FILE = WireGuardNetworkExtension/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 11.4; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", "@executable_path/../../Frameworks", ); - LIBRARY_SEARCH_PATHS = ( - "$(inherited)", - "$(PROJECT_DIR)/wireguard-go-bridge", - ); PRODUCT_BUNDLE_IDENTIFIER = "com.wireguard.ios.network-extension"; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = "WireGuard Network Extension Development"; SKIP_INSTALL = YES; SWIFT_OBJC_BRIDGING_HEADER = "WireGuardNetworkExtension/WireGuardNetworkExtension-Bridging-Header.h"; - SWIFT_VERSION = 4.0; - TARGETED_DEVICE_FAMILY = "1,2"; + SWIFT_VERSION = 4.2; }; name = Release; }; diff --git a/WireGuard/AppDelegate.swift b/WireGuard/AppDelegate.swift index 44464f8..6380636 100644 --- a/WireGuard/AppDelegate.swift +++ b/WireGuard/AppDelegate.swift @@ -11,7 +11,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? var appCoordinator: AppCoordinator! - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { self.window = UIWindow(frame: UIScreen.main.bounds) appCoordinator = AppCoordinator(window: self.window!) @@ -22,7 +22,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { return true } - func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey: Any] = [:]) -> Bool { + func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool { defer { do { try FileManager.default.removeItem(at: url) diff --git a/WireGuard/ViewControllers/TunnelsTableViewController.swift b/WireGuard/ViewControllers/TunnelsTableViewController.swift index 830cb75..37354b0 100644 --- a/WireGuard/ViewControllers/TunnelsTableViewController.swift +++ b/WireGuard/ViewControllers/TunnelsTableViewController.swift @@ -151,7 +151,7 @@ class TunnelsTableViewController: UITableViewController { return true } - override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { + override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) { if editingStyle == .delete { guard let sections = fetchedResultsController.sections else { diff --git a/wireguard-go-bridge/Makefile b/wireguard-go-bridge/Makefile index 9cc98c7..7b98c92 100644 --- a/wireguard-go-bridge/Makefile +++ b/wireguard-go-bridge/Makefile @@ -2,50 +2,58 @@ # # Copyright (C) 2018 Jason A. Donenfeld . All Rights Reserved. -FILES := $(filter-out %/main.go %/queueconstants.go,$(wildcard ../wireguard-go/*/*.go) $(wildcard ../wireguard-go/*.go)) +UPSTREAM_FILES := $(filter-out %/main.go %/queueconstants.go,$(wildcard ../wireguard-go/*/*.go) $(wildcard ../wireguard-go/*.go)) +DOWNSTREAM_FILES := $(wildcard src/*.go) $(wildcard src/*/*.go) -ARCHES := arm64 armv7 x86_64 +ARCHS ?= arm64 armv7 x86_64 GOARCH_arm64 := arm64 GOARCH_armv7 := arm GOARCH_x86_64 := amd64 -CGO_FLAGS_x86_64 := -arch x86_64 -isysroot $(shell xcrun --sdk iphonesimulator --show-sdk-path) -CGO_FLAGS_arm64 := -arch arm64 -isysroot $(shell xcrun --sdk iphoneos --show-sdk-path) -CGO_FLAGS_armv7 := -arch armv7 -isysroot $(shell xcrun --sdk iphoneos --show-sdk-path) +DEPLOYMENT_CFLAGS := $(DEPLOYMENT_TARGET_CLANG_FLAG_PREFIX)$($(DEPLOYMENT_TARGET_CLANG_ENV_NAME)) +CGO_FLAGS_x86_64 := -arch x86_64 -isysroot $(shell xcrun --sdk iphonesimulator --show-sdk-path) $(DEPLOYMENT_CFLAGS) +CGO_FLAGS_arm64 := -arch arm64 -isysroot $(shell xcrun --sdk iphoneos --show-sdk-path) $(DEPLOYMENT_CFLAGS) +CGO_FLAGS_armv7 := -arch armv7 -isysroot $(shell xcrun --sdk iphoneos --show-sdk-path) $(DEPLOYMENT_CFLAGS) CC_x86_64 := $(shell xcrun --sdk iphonesimulator --find clang) CC_arm64 := $(shell xcrun --sdk iphoneos --find clang) CC_armv7 := $(shell xcrun --sdk iphoneos --find clang) +CONFIGURATION_BUILD_DIR ?= $(CURDIR)/out +CONFIGURATION_TEMP_DIR ?= $(CURDIR)/.tmp +DESTDIR ?= $(CONFIGURATION_BUILD_DIR) +GOBUILDDIR ?= $(CONFIGURATION_TEMP_DIR)/wireguard-go-bridge export GOOS := darwin export CGO_ENABLED := 1 -default: libwg-go.a +build: $(DESTDIR)/libwg-go.a -src/.prepared: $(FILES) src/git.zx2c4.com/wireguard-go/api-ios.go src/git.zx2c4.com/wireguard-go/tun/tun_ios.go - find . -name '*.go' -type l -delete - find . -type d -empty -delete - mkdir -p $(subst ../wireguard-go/,./src/git.zx2c4.com/wireguard-go/,$(dir $(FILES))) - $(foreach FILE,$(FILES),ln -sf $(abspath $(FILE)) $(subst ../wireguard-go/,./src/git.zx2c4.com/wireguard-go/,$(dir $(FILE)))$(notdir $(FILE));) - GOPATH=$(CURDIR) go get -v -d git.zx2c4.com/wireguard-go +$(GOBUILDDIR)/src/.prepared: $(UPSTREAM_FILES) $(DOWNSTREAM_FILES) + rm -rf $(GOBUILDDIR)/src + mkdir -p $(subst ../wireguard-go/,$(GOBUILDDIR)/src/git.zx2c4.com/wireguard-go/,$(dir $(UPSTREAM_FILES))) + mkdir -p $(subst src/,$(GOBUILDDIR)/src/git.zx2c4.com/wireguard-go/,$(dir $(DOWNSTREAM_FILES))) + $(foreach FILE,$(UPSTREAM_FILES),ln -sf $(abspath $(FILE)) $(subst ../wireguard-go/,$(GOBUILDDIR)/src/git.zx2c4.com/wireguard-go/,$(dir $(FILE)))$(notdir $(FILE));) + $(foreach FILE,$(DOWNSTREAM_FILES),ln -sf $(abspath $(FILE)) $(subst src/,$(GOBUILDDIR)/src/git.zx2c4.com/wireguard-go/,$(dir $(FILE)))$(notdir $(FILE));) + GOPATH=$(GOBUILDDIR) go get -v -d git.zx2c4.com/wireguard-go touch $@ define libwg-go-a -libwg-go-$(1).a: $(FILES) src/git.zx2c4.com/wireguard-go/api-ios.go src/git.zx2c4.com/wireguard-go/tun/tun_ios.go src/.prepared +$(GOBUILDDIR)/libwg-go-$(1).a: $(UPSTREAM_FILES) $(DOWNSTREAM_FILES) $(GOBUILDDIR)/src/.prepared CC="$(CC_$(1))" \ CGO_CFLAGS="$(CGO_FLAGS_$(1))" \ CGO_LDFLAGS="$(CGO_FLAGS_$(1))" \ GOARCH=$(GOARCH_$(1)) \ - GOPATH=$(CURDIR) \ - go build -tags ios -v -o libwg-go-$(1).a -buildmode c-archive git.zx2c4.com/wireguard-go - @rm -f libwg-go-$(1).h + GOPATH=$(GOBUILDDIR) \ + go build -tags ios -v -o $(GOBUILDDIR)/libwg-go-$(1).a -buildmode c-archive git.zx2c4.com/wireguard-go + @rm -f $(GOBUILDDIR)/libwg-go-$(1).h endef -$(foreach ARCH,$(ARCHES),$(eval $(call libwg-go-a,$(ARCH)))) +$(foreach ARCH,$(ARCHS),$(eval $(call libwg-go-a,$(ARCH)))) -libwg-go.a: $(foreach ARCH,$(ARCHES),libwg-go-$(ARCH).a) +$(DESTDIR)/libwg-go.a: $(foreach ARCH,$(ARCHS),$(GOBUILDDIR)/libwg-go-$(ARCH).a) + mkdir -p $(DESTDIR) xcrun --sdk iphoneos lipo -create -output $@ $^ -example: example.c libwg-go.a - xcrun --sdk iphoneos clang -framework CoreFoundation -isysroot $(shell xcrun --sdk iphoneos --show-sdk-path) -arch arm64 -arch armv7 -L. -lwg-go -o example example.c +$(DESTDIR)/example: example.c $(DESTDIR)/libwg-go.a + xcrun --sdk iphoneos clang -framework CoreFoundation -isysroot $(shell xcrun --sdk iphoneos --show-sdk-path) -arch arm64 -arch armv7 -L$(DESTDIR) -lwg-go -o $@ $< clean: - rm -f libwg-go.a $(foreach ARCH,$(ARCHES),libwg-go-$(ARCH).a) example + rm -rf $(GOBUILDDIR) $(DESTDIR)/libwg-go.a $(DESTDIR)/example -.PHONY: clean default +.PHONY: clean build diff --git a/wireguard-go-bridge/src/git.zx2c4.com/wireguard-go/api-ios.go b/wireguard-go-bridge/src/api-ios.go similarity index 100% rename from wireguard-go-bridge/src/git.zx2c4.com/wireguard-go/api-ios.go rename to wireguard-go-bridge/src/api-ios.go diff --git a/wireguard-go-bridge/src/git.zx2c4.com/wireguard-go/queueconstants.go b/wireguard-go-bridge/src/queueconstants.go similarity index 100% rename from wireguard-go-bridge/src/git.zx2c4.com/wireguard-go/queueconstants.go rename to wireguard-go-bridge/src/queueconstants.go diff --git a/wireguard-go-bridge/src/git.zx2c4.com/wireguard-go/tun/tun_ios.go b/wireguard-go-bridge/src/tun/tun_ios.go similarity index 100% rename from wireguard-go-bridge/src/git.zx2c4.com/wireguard-go/tun/tun_ios.go rename to wireguard-go-bridge/src/tun/tun_ios.go diff --git a/wireguard-go-bridge/xcode-build-helper.sh b/wireguard-go-bridge/xcode-build-helper.sh deleted file mode 100755 index b5b467d..0000000 --- a/wireguard-go-bridge/xcode-build-helper.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/sh -cd "$PROJECT_DIR"/wireguard-go-bridge -case $1 in - clean) - make clean - ;; - *) - if [ -e "$DERIVED_FILE_DIR/libwg-go.a" ] - then - echo "Clean before building" - else - make - fi - - ;; -esac - -if [ -f "libwg-go.a" ] -then - mkdir -p "$DERIVED_FILE_DIR" - mv *.a "$DERIVED_FILE_DIR" - ln -sf "$DERIVED_FILE_DIR/libwg-go.a" libwg-go.a -fi