diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 27cbb6b17..a1feb880b 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -116,47 +116,6 @@ jobs: path: | ./rust/connlib-${{ needs.draft-release.outputs.tag_name }}.aar - rust_build-apple: - needs: - - rust_draft-release - runs-on: macos-latest - permissions: - contents: read - steps: - - uses: actions/checkout@v3 - - uses: Swatinem/rust-cache@v2 - with: - workspaces: ./rust - - name: Update toolchain - run: rustup show - - name: Setup lipo - run: cargo install cargo-lipo - - uses: actions/cache@v3 - with: - path: apple/.build - key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }} - restore-keys: | - ${{ runner.os }}-spm- - - name: Build Connlib.xcframework.zip - env: - CONFIGURATION: Release - PROJECT_DIR: . - working-directory: ./rust/connlib/clients/apple - run: | - # build-xcframework.sh calls build-rust.sh indirectly via `xcodebuild`, but it pollutes the environment - # to the point that it causes the `ring` build to fail for the aarch64-apple-darwin target. So, explicitly - # build first. See https://github.com/briansmith/ring/issues/1332 - ./build-rust.sh - ./build-xcframework.sh - mv Connlib.xcframework.zip ../../../../Connlib-${{ needs.draft-release.outputs.tag_name }}.xcframework.zip - mv Connlib.xcframework.zip.checksum.txt ../../../../Connlib-${{ needs.draft-release.outputs.tag_name }}.xcframework.zip.checksum.txt - - uses: actions/upload-artifact@v3 - with: - name: connlib-apple - path: | - ./Connlib-${{ needs.draft-release.outputs.tag_name }}.xcframework.zip - ./Connlib-${{ needs.draft-release.outputs.tag_name }}.xcframework.zip.checksum.txt - rust_cross-compile-relay: # cross is separate from test because cross-compiling yields different artifacts and we cannot reuse the cache. runs-on: ubuntu-latest steps: diff --git a/.github/workflows/swift-pass-checks.yml b/.github/workflows/swift-pass-checks.yml index 34e90d41d..02873a0d9 100644 --- a/.github/workflows/swift-pass-checks.yml +++ b/.github/workflows/swift-pass-checks.yml @@ -3,7 +3,7 @@ name: Swift on: pull_request: - paths-ginore: + paths-ignore: - "swift/**" - "rust/connlib/**" - ".github/workflows/swift.yml" diff --git a/.github/workflows/swift.yml b/.github/workflows/swift.yml index 9fd25c138..387948cde 100644 --- a/.github/workflows/swift.yml +++ b/.github/workflows/swift.yml @@ -47,26 +47,12 @@ jobs: save-if: ${{ github.ref == 'refs/heads/cloud' }} - name: Update toolchain run: rustup show - - name: Setup lipo - run: cargo install cargo-lipo - uses: actions/cache@v3 with: path: apple/.build key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }} restore-keys: | ${{ runner.os }}-spm- - - name: Build Connlib.xcframework - env: - CONFIGURATION: Release - PROJECT_DIR: . - working-directory: ./rust/connlib/clients/apple - run: | - # build-xcframework.sh calls build-rust.sh indirectly via `xcodebuild`, but it pollutes the environment - # to the point that it causes the `ring` build to fail for the aarch64-apple-darwin target. So, explicitly - # build first. See https://github.com/briansmith/ring/issues/1332 - PLATFORM_NAME=macosx ./build-rust.sh - PLATFORM_NAME=iphoneos ./build-rust.sh - ./build-xcframework-dev.sh - name: Select Xcode uses: maxim-lobanov/setup-xcode@v1 with: @@ -74,10 +60,10 @@ jobs: - name: Build app for macOS working-directory: ./swift/apple run: | - cp Firezone/Developer.xcconfig.ci-macOS Firezone/Developer.xcconfig - xcodebuild build -scheme Firezone -sdk macosx -destination 'platform=macOS' CODE_SIGNING_ALLOWED=NO + cp Firezone/xcconfig/Developer.xcconfig.ci-macOS Firezone/xcconfig/Developer.xcconfig + xcodebuild archive -scheme Firezone -sdk macosx -destination 'platform=macOS' CODE_SIGNING_ALLOWED=NO - name: Build app for iOS working-directory: ./swift/apple run: | - cp Firezone/Developer.xcconfig.ci-iOS Firezone/Developer.xcconfig - xcodebuild build -scheme Firezone -sdk iphoneos -destination 'generic/platform=iOS' CODE_SIGNING_ALLOWED=NO + cp Firezone/xcconfig/Developer.xcconfig.ci-iOS Firezone/xcconfig/Developer.xcconfig + xcodebuild archive -scheme Firezone -sdk iphoneos -destination 'generic/platform=iOS' CODE_SIGNING_ALLOWED=NO diff --git a/rust/connlib/clients/apple/README.md b/rust/connlib/clients/apple/README.md index cc0a8d357..58be4bda5 100644 --- a/rust/connlib/clients/apple/README.md +++ b/rust/connlib/clients/apple/README.md @@ -1,19 +1,6 @@ # Connlib Apple Wrapper -Apple Package wrapper for Connlib distributed as a binary XCFramework for -inclusion in the Firezone Apple client. +Apple Package wrapper for Connlib for inclusion in the Firezone Apple +client. -## Prerequisites - -1. Install [ stable rust ](https://www.rust-lang.org/tools/install) for your - platform -1. Install `llvm` from Homebrew: - -``` - -brew install llvm - -``` - -This fixes build issues with Apple's command line tools. See -https://github.com/briansmith/ring/issues/1374 +This is built as part of the Apple client build. diff --git a/rust/connlib/clients/apple/Sources/Connlib/BridgingHeader-SwiftPM.h b/rust/connlib/clients/apple/Sources/Connlib/BridgingHeader-SwiftPM.h deleted file mode 100644 index 137094540..000000000 --- a/rust/connlib/clients/apple/Sources/Connlib/BridgingHeader-SwiftPM.h +++ /dev/null @@ -1,17 +0,0 @@ -// This header is used in `build.rs`, and is exactly the same as -// `BridgingHeader.h` *except* the `include` paths are relative. -// -// Attempting to build an `xcframework` with a quoted `include` violates rules -// around non-modular imports, as only headers specified as part of the module -// can be included. -// -// However, SwiftPM has no equivalent to "modular headers", so we can only rely -// on normal, simple `include` paths. - -#ifndef BridgingHeader_h -#define BridgingHeader_h - -#include "Generated/SwiftBridgeCore.h" -#include "Generated/connlib-apple/connlib-apple.h" - -#endif diff --git a/rust/connlib/clients/apple/Sources/Connlib/BridgingHeader.h b/rust/connlib/clients/apple/Sources/Connlib/BridgingHeader.h deleted file mode 100644 index 1a7814212..000000000 --- a/rust/connlib/clients/apple/Sources/Connlib/BridgingHeader.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef BridgingHeader_h -#define BridgingHeader_h - -#include -#include - -#endif diff --git a/rust/connlib/clients/apple/Sources/Connlib/CallbackHandler.swift b/rust/connlib/clients/apple/Sources/Connlib/CallbackHandler.swift index 42b3360fd..a9c7edcd1 100644 --- a/rust/connlib/clients/apple/Sources/Connlib/CallbackHandler.swift +++ b/rust/connlib/clients/apple/Sources/Connlib/CallbackHandler.swift @@ -8,100 +8,42 @@ import NetworkExtension import os.log +// When the FFI changes from the Rust side, change the CallbackHandler +// functions along with that, but not the delegate protocol. +// When the app gets updated to use the FFI, the delegate protocol +// shall get updated. +// This is so that the app stays buildable even when the FFI changes. + // TODO: https://github.com/chinedufn/swift-bridge/issues/150 extension SwiftConnlibError: @unchecked Sendable {} extension SwiftConnlibError: Error {} public protocol CallbackHandlerDelegate: AnyObject { - func didUpdateResources(_ resourceList: ResourceList) + func onConnect(tunnelAddressIPv4: String, tunnelAddressIPv6: String) + func onUpdateResources(resourceList: String) + func onDisconnect() + func onError(error: Error, isRecoverable: Bool) } public class CallbackHandler { - // TODO: Add a table view property here to update? - var adapter: Adapter? public weak var delegate: CallbackHandlerDelegate? - init(adapter: Adapter) { - self.adapter = adapter + func onUpdateResources(resourceList: ResourceList) { + delegate?.onUpdateResources(resourceList: resourceList.resources.toString()) } - func onUpdateResources(resourceList: ResourceList) -> Bool { - - // If there's any entity that assigned itself as this callbackHandler's delegate, it will be called every time this `onUpdateResources` method is, allowing that entity to react to resource updates and do whatever they want. - - delegate?.didUpdateResources(resourceList) - - let addresses4 = - self.adapter?.lastNetworkSettings?.ipv4Settings?.addresses ?? ["100.100.111.2"] - let addresses6 = - self.adapter?.lastNetworkSettings?.ipv6Settings?.addresses ?? [ - "fd00:0222:2021:1111::2" - ] - - // TODO: Use actual passed in resources to achieve split tunnel - let ipv4Routes = [NEIPv4Route(destinationAddress: "100.64.0.0", subnetMask: "255.192.0.0")] - let ipv6Routes = [ - NEIPv6Route(destinationAddress: "fd00:0222:2021:1111::0", networkPrefixLength: 64) - ] - - return setTunnelSettingsKeepingSomeExisting( - addresses4: addresses4, addresses6: addresses6, ipv4Routes: ipv4Routes, ipv6Routes: ipv6Routes - ) - } - - func onConnect(tunnelAddresses: TunnelAddresses) -> Bool { - let addresses4 = [tunnelAddresses.address4.toString()] - let addresses6 = [tunnelAddresses.address6.toString()] - let ipv4Routes = - Adapter.currentAdapter?.lastNetworkSettings?.ipv4Settings?.includedRoutes ?? [] - let ipv6Routes = - Adapter.currentAdapter?.lastNetworkSettings?.ipv6Settings?.includedRoutes ?? [] - - return setTunnelSettingsKeepingSomeExisting( - addresses4: addresses4, addresses6: addresses6, ipv4Routes: ipv4Routes, ipv6Routes: ipv6Routes + func onConnect(tunnelAddresses: TunnelAddresses) { + delegate?.onConnect( + tunnelAddressIPv4: tunnelAddresses.address4.toString(), + tunnelAddressIPv6: tunnelAddresses.address6.toString() ) } func onDisconnect() { - // TODO: handle disconnect - } - - private func setTunnelSettingsKeepingSomeExisting( - addresses4: [String], addresses6: [String], ipv4Routes: [NEIPv4Route], ipv6Routes: [NEIPv6Route] - ) -> Bool { - let logger = Logger(subsystem: "dev.firezone.firezone", category: "packet-tunnel") - - if self.adapter != nil { - do { - /* If the tunnel interface addresses are being updated, it's impossible for the tunnel to - stay up due to the way WireGuard works. Still, we try not to change the tunnel's routes - here Just In Case™. - */ - try self.adapter!.setNetworkSettings( - self.adapter!.generateNetworkSettings( - addresses4: addresses4, - addresses6: addresses6, - ipv4Routes: ipv4Routes, - ipv6Routes: ipv6Routes - ) - ) - - return true - } catch let error { - logger.log(level: .debug, "Error setting adapter settings: \(String(describing: error))") - - return false - } - } else { - logger.log(level: .debug, "Adapter not initialized!") - - return false - } + delegate?.onDisconnect() } func onError(error: SwiftConnlibError, error_type: SwiftErrorType) { - // TODO: handle/report errors - let logger = Logger(subsystem: "dev.firezone.firezone", category: "packet-tunnel") - logger.log(level: .error, "Internal connlib error: \(String(describing: error), privacy: .public)") + delegate?.onError(error: error, isRecoverable: error_type == .Recoverable) } } diff --git a/rust/connlib/clients/apple/Sources/Connlib/connlib.h b/rust/connlib/clients/apple/Sources/Connlib/connlib.h index cc7c7b14a..b8be1fa70 100644 --- a/rust/connlib/clients/apple/Sources/Connlib/connlib.h +++ b/rust/connlib/clients/apple/Sources/Connlib/connlib.h @@ -1,18 +1,9 @@ -// -// connlib.h -// connlib -// -// Created by Jamil Bou Kheir on 4/3/23. -// +// Umbrella header for connlib -#import +#ifndef connlib_h +#define connlib_h -//! Project version number for connlib. -FOUNDATION_EXPORT double connlibVersionNumber; +#include "Generated/SwiftBridgeCore.h" +#include "Generated/connlib-apple/connlib-apple.h" -//! Project version string for connlib. -FOUNDATION_EXPORT const unsigned char connlibVersionString[]; - -// In this header, you should import all the public headers of your framework using statements like #import - -#import +#endif diff --git a/rust/connlib/clients/apple/Tests/connlibTests/.gitkeep b/rust/connlib/clients/apple/Tests/connlibTests/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/rust/connlib/clients/apple/build-rust.sh b/rust/connlib/clients/apple/build-rust.sh index 9487e514e..ad2681264 100755 --- a/rust/connlib/clients/apple/build-rust.sh +++ b/rust/connlib/clients/apple/build-rust.sh @@ -4,12 +4,16 @@ # We call this from an Xcode run script. ################################################## -set -ex +set -e + +if [[ $1 == "clean" ]]; then + echo "Skipping build during 'clean'" + exit 0 +fi # Default PLATFORM_NAME to macosx if not set. : "${PLATFORM_NAME:=macosx}" - export PATH="$HOME/.cargo/bin:$PATH" base_dir=$(xcrun --sdk $PLATFORM_NAME --show-sdk-path) @@ -22,12 +26,36 @@ export INCLUDE_PATH="${base_dir}/usr/include" export CFLAGS="-L ${LIBRARY_PATH} -I ${INCLUDE_PATH} -Qunused-arguments" export RUSTFLAGS="-C link-arg=-F$base_dir/System/Library/Frameworks" -TARGETS="" +TARGETS=() if [[ "$PLATFORM_NAME" = "macosx" ]]; then - TARGETS="aarch64-apple-darwin,x86_64-apple-darwin" + if [[ $CONFIGURATION == "Release" ]] || [[ -z "$NATIVE_ARCH" ]]; then + TARGETS=("aarch64-apple-darwin" "x86_64-apple-darwin") + else + if [[ $NATIVE_ARCH == "arm64" ]]; then + TARGETS=("aarch64-apple-darwin") + else + if [[ $NATIVE_ARCH == "x86_64" ]]; then + TARGETS=("x86_64-apple-darwin") + else + echo "Unsupported native arch for $PLATFORM_NAME: $NATIVE_ARCH" + fi + fi + fi else if [[ "$PLATFORM_NAME" = "iphonesimulator" ]]; then - TARGETS="aarch64-apple-ios-sim,x86_64-apple-ios" + if [[ $CONFIGURATION == "Release" ]] || [[ -z "$NATIVE_ARCH" ]]; then + TARGETS=("aarch64-apple-ios-sim" "x86_64-apple-ios") + else + if [[ $NATIVE_ARCH == "arm64" ]]; then + TARGETS=("aarch64-apple-ios-sim") + else + if [[ $NATIVE_ARCH == "x86_64" ]]; then + TARGETS=("x86_64-apple-ios") + else + echo "Unsupported native arch for $PLATFORM_NAME: $NATIVE_ARCH" + fi + fi + fi else if [[ "$PLATFORM_NAME" = "iphoneos" ]]; then TARGETS="aarch64-apple-ios" @@ -38,22 +66,29 @@ else fi fi +MESSAGE="Building Connlib" + if [[ -n "$CONNLIB_MOCK" ]]; then - LIPO_ARGS="--features mock" + MESSAGE="${MESSAGE} (mock)" + FEATURE_ARGS="--features mock" fi -# if [ $ENABLE_PREVIEWS == "NO" ]; then +if [[ $CONFIGURATION == "Release" ]]; then + echo "${MESSAGE} for Release" + CONFIGURATION_ARGS="--release" +else + echo "${MESSAGE} for Debug" +fi - if [[ $CONFIGURATION == "Release" ]]; then - echo "BUILDING FOR RELEASE ($TARGETS)" +if [[ -n "$CONNLIB_TARGET_DIR" ]]; then + set -x + CARGO_TARGET_DIR=$CONNLIB_TARGET_DIR + set +x +fi - cargo lipo --release --manifest-path ./Cargo.toml --targets $TARGETS $LIPO_ARGS - else - echo "BUILDING FOR DEBUG ($TARGETS)" - - cargo lipo --manifest-path ./Cargo.toml --targets $TARGETS $LIPO_ARGS - fi - -# else -# echo "Skipping the script because of preview mode" -# fi +for target in "${TARGETS[@]}" +do + set -x + cargo build --target $target $FEATURE_ARGS $CONFIGURATION_ARGS + set +x +done diff --git a/rust/connlib/clients/apple/build-xcframework-dev.sh b/rust/connlib/clients/apple/build-xcframework-dev.sh deleted file mode 100755 index 324b12322..000000000 --- a/rust/connlib/clients/apple/build-xcframework-dev.sh +++ /dev/null @@ -1,29 +0,0 @@ -# For more info: -# https://github.com/firezone/firezone-apple/blob/main/USING_UNRELEASED_CONNLIB.md - -#!/bin/bash -set -ex - -echo $SRC_ROOT - -for sdk in macosx iphoneos; do - echo "Building for $sdk" - - xcodebuild archive \ - -scheme Connlib \ - -destination "generic/platform=$sdk" \ - -sdk $sdk \ - -archivePath ./connlib-$sdk \ - SKIP_INSTALL=NO \ - BUILD_LIBRARY_FOR_DISTRIBUTION=YES -done - -rm -rf ./Connlib.xcframework -xcodebuild -create-xcframework \ - -framework ./connlib-iphoneos.xcarchive/Products/Library/Frameworks/connlib.framework \ - -framework ./connlib-macosx.xcarchive/Products/Library/Frameworks/connlib.framework \ - -output ./Connlib.xcframework - -echo "Build successful. Removing temporary archives" -rm -rf ./connlib-iphoneos.xcarchive -rm -rf ./connlib-macosx.xcarchive diff --git a/rust/connlib/clients/apple/build-xcframework.sh b/rust/connlib/clients/apple/build-xcframework.sh deleted file mode 100755 index 1ac275209..000000000 --- a/rust/connlib/clients/apple/build-xcframework.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash -set -ex - -for sdk in macosx iphoneos iphonesimulator; do - echo "Building for $sdk" - - xcodebuild archive \ - -scheme Connlib \ - -destination "generic/platform=$sdk" \ - -sdk $sdk \ - -archivePath ./connlib-$sdk \ - SKIP_INSTALL=NO \ - BUILD_LIBRARY_FOR_DISTRIBUTION=YES -done - -xcodebuild -create-xcframework \ - -framework ./connlib-iphoneos.xcarchive/Products/Library/Frameworks/connlib.framework \ - -framework ./connlib-iphonesimulator.xcarchive/Products/Library/Frameworks/connlib.framework \ - -framework ./connlib-macosx.xcarchive/Products/Library/Frameworks/connlib.framework \ - -output ./Connlib.xcframework - -echo "Build successful. Removing temporary archives" -rm -rf ./connlib-iphoneos.xcarchive -rm -rf ./connlib-iphonesimulator.xcarchive -rm -rf ./connlib-macosx.xcarchive - -echo "Computing checksum" -touch Package.swift -zip -r -y Connlib.xcframework.zip Connlib.xcframework -swift package compute-checksum Connlib.xcframework.zip > Connlib.xcframework.zip.checksum.txt - -rm Package.swift -rm -rf Connlib.xcframework diff --git a/rust/connlib/clients/apple/build.rs b/rust/connlib/clients/apple/build.rs index 5c9c53b22..ddc9a9ccb 100644 --- a/rust/connlib/clients/apple/build.rs +++ b/rust/connlib/clients/apple/build.rs @@ -1,145 +1,14 @@ -// Referenced from https://github.com/chinedufn/swift-bridge/blob/master/examples/rust-binary-calls-swift-package/build.rs +const XCODE_CONFIGURATION_ENV: &str = "CONFIGURATION"; -use std::path::PathBuf; -use walkdir::WalkDir; +fn main() { + let out_dir = "Sources/Connlib/Generated"; -static XCODE_CONFIGURATION_ENV: &str = "CONFIGURATION"; -static SWIFT_PKG_NAME: &str = "Connlib"; -static SWIFT_LIB_NAME: &str = "libConnlib.a"; -static BRIDGE_SRCS: &[&str] = &["src/lib.rs"]; -static BRIDGING_HEADER: &str = "BridgingHeader-SwiftPM.h"; -static MACOSX_DEPLOYMENT_TARGET: &str = "12.4"; -static IPHONEOS_DEPLOYMENT_TARGET: &str = "15.6"; - -mod sdk { - pub static MACOS: &str = "macosx"; - pub static IOS: &str = "iphoneos"; - pub static IOS_SIM: &str = "iphonesimulator"; -} - -struct Env { - swift_pkg_dir: PathBuf, - swift_src_dir: PathBuf, - bridge_dst_dir: PathBuf, - swift_built_lib_dir: PathBuf, - release: bool, - triple: String, - sdk: &'static str, -} - -impl Env { - fn gather() -> Self { - let manifest_dir = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap()); - let swift_pkg_dir = manifest_dir; - let swift_src_dir = swift_pkg_dir.join("Sources").join(SWIFT_PKG_NAME); - let bridge_dst_dir = swift_src_dir.join("Generated"); - let release = std::env::var("PROFILE").unwrap() == "release"; - let target = std::env::var("TARGET").unwrap(); - let (triple, sdk) = match target.as_str() { - "aarch64-apple-darwin" => ( - format!("arm64-apple-macosx{MACOSX_DEPLOYMENT_TARGET}"), - sdk::MACOS, - ), - "x86_64-apple-darwin" => ( - format!("x86_64-apple-macosx{MACOSX_DEPLOYMENT_TARGET}"), - sdk::MACOS, - ), - "aarch64-apple-ios" => ( - format!("arm64-apple-ios{IPHONEOS_DEPLOYMENT_TARGET}"), - sdk::IOS, - ), - "aarch64-apple-ios-sim" => ( - format!("arm64-apple-ios{IPHONEOS_DEPLOYMENT_TARGET}-simulator"), - sdk::IOS_SIM, - ), - "x86_64-apple-ios" | "x86_64-apple-ios-sim" => ( - format!("x86_64-apple-ios{IPHONEOS_DEPLOYMENT_TARGET}-simulator"), - sdk::IOS_SIM, - ), - _ => todo!("unsupported target triple: {target:?}"), - }; - let swift_built_lib_dir = swift_pkg_dir.join(".build").join(&triple).join(if release { - "release" - } else { - "debug" - }); - Self { - swift_pkg_dir, - swift_src_dir, - bridge_dst_dir, - swift_built_lib_dir, - release, - triple, - sdk, - } + let bridges = vec!["src/lib.rs"]; + for path in &bridges { + println!("cargo:rerun-if-changed={}", path); } -} + println!("cargo:rerun-if-env-changed={}", XCODE_CONFIGURATION_ENV); -fn gen_bridges(env: &Env) { - for path in BRIDGE_SRCS { - println!("cargo:rerun-if-changed={path}"); - } - swift_bridge_build::parse_bridges(BRIDGE_SRCS) - .write_all_concatenated(&env.bridge_dst_dir, env!("CARGO_PKG_NAME")); -} - -// We use `swiftc` instead of SwiftPM/`swift build` because of this limitation: -// https://github.com/apple/swift-package-manager/pull/6572 -fn compile_swift(env: &Env) -> anyhow::Result<()> { - let swift_sdk = diva::Command::parse("xcrun --show-sdk-path --sdk") - .with_arg(env.sdk) - .run_and_wait_for_trimmed()?; - let swift_src_files = WalkDir::new(&env.swift_src_dir) - .into_iter() - .filter_map(Result::ok) - .filter_map(|entry| { - (entry.path().extension() == Some("swift".as_ref())).then(|| entry.path().to_owned()) - }); - std::fs::create_dir_all(&env.swift_built_lib_dir)?; - diva::Command::parse("swiftc -emit-library -static") - .with_args(["-module-name", SWIFT_PKG_NAME]) - .with_arg("-import-objc-header") - .with_arg(env.swift_src_dir.join(BRIDGING_HEADER)) - .with_arg("-sdk") - .with_arg(swift_sdk) - .with_args(["-target", &env.triple]) - // https://github.com/apple/swift-package-manager/blob/55006dce81ae70cd8f2b78479038423eeebde1e4/Documentation/Usage.md#setting-the-build-configuration - .with_parsed_args(if !env.release { - "-Onone -g -enable-testing" - } else { - "-O -whole-module-optimization" - }) - .with_arg("-o") - .with_arg(env.swift_built_lib_dir.join(SWIFT_LIB_NAME)) - .with_args(swift_src_files) - .with_cwd(&env.swift_pkg_dir) - .run_and_wait()?; - Ok(()) -} - -fn link_swift(env: &Env) { - println!("cargo:rustc-link-lib=static={SWIFT_PKG_NAME}"); - println!( - "cargo:rustc-link-search={}", - env.swift_built_lib_dir.display() - ); - let xcode_path = diva::Command::parse("xcode-select --print-path") - .run_and_wait_for_trimmed() - .unwrap_or_else(|_| "/Applications/Xcode.app/Contents/Developer".to_owned()); - println!("cargo:rustc-link-search={xcode_path}/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/"); - println!("cargo:rustc-link-search=/usr/lib/swift"); -} - -fn main() -> anyhow::Result<()> { - // Early exit build script to avoid errors on non-Apple platforms. - if std::env::var("CARGO_CFG_TARGET_VENDOR").as_deref() != Ok("apple") { - return Ok(()); - } - - println!("cargo:rerun-if-env-changed={XCODE_CONFIGURATION_ENV}"); - let env = Env::gather(); - gen_bridges(&env); - compile_swift(&env)?; - link_swift(&env); - Ok(()) + swift_bridge_build::parse_bridges(bridges) + .write_all_concatenated(out_dir, env!("CARGO_PKG_NAME")); } diff --git a/rust/connlib/clients/apple/connlib.xcodeproj/project.pbxproj b/rust/connlib/clients/apple/connlib.xcodeproj/project.pbxproj deleted file mode 100644 index 9af2e33ab..000000000 --- a/rust/connlib/clients/apple/connlib.xcodeproj/project.pbxproj +++ /dev/null @@ -1,466 +0,0 @@ -// !$*UTF8*$! -{ - archiveVersion = 1; - classes = { - }; - objectVersion = 56; - objects = { - -/* Begin PBXBuildFile section */ - 1DAA1D872A3142BC00D84E07 /* BridgingHeader.h in Headers */ = {isa = PBXBuildFile; fileRef = 1DAA1D862A3142BC00D84E07 /* BridgingHeader.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 8D46EDDF29DBC29800FF01CA /* Adapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8D46EDD729DBC29800FF01CA /* Adapter.swift */; }; - 8D46EDE029DBC29800FF01CA /* CallbackHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8D46EDD829DBC29800FF01CA /* CallbackHandler.swift */; }; - 8D967B2B29DBA064000B9D58 /* libconnlib.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 8D967B2A29DBA03F000B9D58 /* libconnlib.a */; }; - 8DA207F829DBD80C00703A4A /* connlib-apple.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8DA207F329DBD80C00703A4A /* connlib-apple.swift */; }; - 8DA207F929DBD80C00703A4A /* connlib-apple.h in Headers */ = {isa = PBXBuildFile; fileRef = 8DA207F429DBD80C00703A4A /* connlib-apple.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 8DA207FA29DBD80C00703A4A /* .gitignore in Resources */ = {isa = PBXBuildFile; fileRef = 8DA207F529DBD80C00703A4A /* .gitignore */; }; - 8DA207FC29DBD80C00703A4A /* SwiftBridgeCore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8DA207F729DBD80C00703A4A /* SwiftBridgeCore.swift */; }; - 8DA207FD29DBD86100703A4A /* SwiftBridgeCore.h in Headers */ = {isa = PBXBuildFile; fileRef = 8DA207F629DBD80C00703A4A /* SwiftBridgeCore.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 8DA207FE29DBD86100703A4A /* connlib.h in Headers */ = {isa = PBXBuildFile; fileRef = 8D4BADD129DBD6CC00940F0D /* connlib.h */; settings = {ATTRIBUTES = (Public, ); }; }; -/* End PBXBuildFile section */ - -/* Begin PBXFileReference section */ - 1DAA1D862A3142BC00D84E07 /* BridgingHeader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BridgingHeader.h; sourceTree = ""; }; - 8D209DCE29DBE96B00B68D27 /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS16.4.sdk/System/Library/Frameworks/Security.framework; sourceTree = DEVELOPER_DIR; }; - 8D46EDD729DBC29800FF01CA /* Adapter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Adapter.swift; sourceTree = ""; }; - 8D46EDD829DBC29800FF01CA /* CallbackHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CallbackHandler.swift; sourceTree = ""; }; - 8D4BADD129DBD6CC00940F0D /* connlib.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = connlib.h; sourceTree = ""; }; - 8D7D983129DB8437007B8198 /* connlib.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = connlib.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 8D967B2629DB9A3B000B9D58 /* build-rust.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = "build-rust.sh"; sourceTree = ""; }; - 8D967B2A29DBA03F000B9D58 /* libconnlib.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libconnlib.a; path = ../../target/universal/debug/libconnlib.a; sourceTree = ""; }; - 8DA207F329DBD80C00703A4A /* connlib-apple.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "connlib-apple.swift"; sourceTree = ""; }; - 8DA207F429DBD80C00703A4A /* connlib-apple.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "connlib-apple.h"; sourceTree = ""; }; - 8DA207F529DBD80C00703A4A /* .gitignore */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = .gitignore; sourceTree = ""; }; - 8DA207F629DBD80C00703A4A /* SwiftBridgeCore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SwiftBridgeCore.h; sourceTree = ""; }; - 8DA207F729DBD80C00703A4A /* SwiftBridgeCore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftBridgeCore.swift; sourceTree = ""; }; -/* End PBXFileReference section */ - -/* Begin PBXFrameworksBuildPhase section */ - 8D7D982E29DB8437007B8198 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - 8D967B2B29DBA064000B9D58 /* libconnlib.a in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXFrameworksBuildPhase section */ - -/* Begin PBXGroup section */ - 8D46EDCE29DBC29800FF01CA /* Connlib */ = { - isa = PBXGroup; - children = ( - 8DA207F129DBD80C00703A4A /* Generated */, - 8D4BADD129DBD6CC00940F0D /* connlib.h */, - 1DAA1D862A3142BC00D84E07 /* BridgingHeader.h */, - 8D46EDD729DBC29800FF01CA /* Adapter.swift */, - 8D46EDD829DBC29800FF01CA /* CallbackHandler.swift */, - ); - path = Connlib; - sourceTree = ""; - }; - 8D7D982729DB8437007B8198 = { - isa = PBXGroup; - children = ( - 8D967B3E29DBA34C000B9D58 /* Tests */, - 8D967B3D29DBA344000B9D58 /* Sources */, - 8D967B2629DB9A3B000B9D58 /* build-rust.sh */, - 8D7D983229DB8437007B8198 /* Products */, - 8D967B2929DBA03F000B9D58 /* Frameworks */, - ); - sourceTree = ""; - }; - 8D7D983229DB8437007B8198 /* Products */ = { - isa = PBXGroup; - children = ( - 8D7D983129DB8437007B8198 /* connlib.framework */, - ); - name = Products; - sourceTree = ""; - }; - 8D967B2929DBA03F000B9D58 /* Frameworks */ = { - isa = PBXGroup; - children = ( - 8D209DCE29DBE96B00B68D27 /* Security.framework */, - 8D967B2A29DBA03F000B9D58 /* libconnlib.a */, - ); - name = Frameworks; - sourceTree = ""; - }; - 8D967B3D29DBA344000B9D58 /* Sources */ = { - isa = PBXGroup; - children = ( - 8D46EDCE29DBC29800FF01CA /* Connlib */, - ); - path = Sources; - sourceTree = ""; - }; - 8D967B3E29DBA34C000B9D58 /* Tests */ = { - isa = PBXGroup; - children = ( - ); - path = Tests; - sourceTree = ""; - }; - 8DA207F129DBD80C00703A4A /* Generated */ = { - isa = PBXGroup; - children = ( - 8DA207F229DBD80C00703A4A /* connlib-apple */, - 8DA207F529DBD80C00703A4A /* .gitignore */, - 8DA207F629DBD80C00703A4A /* SwiftBridgeCore.h */, - 8DA207F729DBD80C00703A4A /* SwiftBridgeCore.swift */, - ); - path = Generated; - sourceTree = ""; - }; - 8DA207F229DBD80C00703A4A /* connlib-apple */ = { - isa = PBXGroup; - children = ( - 8DA207F329DBD80C00703A4A /* connlib-apple.swift */, - 8DA207F429DBD80C00703A4A /* connlib-apple.h */, - ); - path = "connlib-apple"; - sourceTree = ""; - }; -/* End PBXGroup section */ - -/* Begin PBXHeadersBuildPhase section */ - 8D7D982C29DB8437007B8198 /* Headers */ = { - isa = PBXHeadersBuildPhase; - buildActionMask = 2147483647; - files = ( - 8DA207F929DBD80C00703A4A /* connlib-apple.h in Headers */, - 1DAA1D872A3142BC00D84E07 /* BridgingHeader.h in Headers */, - 8DA207FD29DBD86100703A4A /* SwiftBridgeCore.h in Headers */, - 8DA207FE29DBD86100703A4A /* connlib.h in Headers */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXHeadersBuildPhase section */ - -/* Begin PBXNativeTarget section */ - 8D7D983029DB8437007B8198 /* connlib */ = { - isa = PBXNativeTarget; - buildConfigurationList = 8D7D984529DB8437007B8198 /* Build configuration list for PBXNativeTarget "connlib" */; - buildPhases = ( - 8D7D982C29DB8437007B8198 /* Headers */, - 8D967B2829DB9A91000B9D58 /* ShellScript */, - 8D7D982D29DB8437007B8198 /* Sources */, - 8D7D982E29DB8437007B8198 /* Frameworks */, - 8D7D982F29DB8437007B8198 /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = connlib; - productName = connlib; - productReference = 8D7D983129DB8437007B8198 /* connlib.framework */; - productType = "com.apple.product-type.framework"; - }; -/* End PBXNativeTarget section */ - -/* Begin PBXProject section */ - 8D7D982829DB8437007B8198 /* Project object */ = { - isa = PBXProject; - attributes = { - BuildIndependentTargetsInParallel = 1; - LastSwiftUpdateCheck = 1430; - LastUpgradeCheck = 1430; - TargetAttributes = { - 8D7D983029DB8437007B8198 = { - CreatedOnToolsVersion = 14.3; - }; - }; - }; - buildConfigurationList = 8D7D982B29DB8437007B8198 /* Build configuration list for PBXProject "connlib" */; - compatibilityVersion = "Xcode 14.0"; - developmentRegion = en; - hasScannedForEncodings = 0; - knownRegions = ( - en, - Base, - ); - mainGroup = 8D7D982729DB8437007B8198; - productRefGroup = 8D7D983229DB8437007B8198 /* Products */; - projectDirPath = ""; - projectRoot = ""; - targets = ( - 8D7D983029DB8437007B8198 /* connlib */, - ); - }; -/* End PBXProject section */ - -/* Begin PBXResourcesBuildPhase section */ - 8D7D982F29DB8437007B8198 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 8DA207FA29DBD80C00703A4A /* .gitignore in Resources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXResourcesBuildPhase section */ - -/* Begin PBXShellScriptBuildPhase section */ - 8D967B2829DB9A91000B9D58 /* ShellScript */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputFileListPaths = ( - ); - inputPaths = ( - ); - outputFileListPaths = ( - ); - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "./build-rust.sh\n"; - }; -/* End PBXShellScriptBuildPhase section */ - -/* Begin PBXSourcesBuildPhase section */ - 8D7D982D29DB8437007B8198 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 8DA207F829DBD80C00703A4A /* connlib-apple.swift in Sources */, - 8D46EDDF29DBC29800FF01CA /* Adapter.swift in Sources */, - 8D46EDE029DBC29800FF01CA /* CallbackHandler.swift in Sources */, - 8DA207FC29DBD80C00703A4A /* SwiftBridgeCore.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXSourcesBuildPhase section */ - -/* Begin XCBuildConfiguration section */ - 8D7D984329DB8437007B8198 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_ANALYZER_NONNULL = YES; - CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_ENABLE_OBJC_WEAK = YES; - CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_COMMA = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_DOCUMENTATION_COMMENTS = YES; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INFINITE_RECURSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; - CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; - CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; - CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; - CLANG_WARN_STRICT_PROTOTYPES = YES; - CLANG_WARN_SUSPICIOUS_MOVE = YES; - CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 1; - DEBUG_INFORMATION_FORMAT = dwarf; - ENABLE_STRICT_OBJC_MSGSEND = YES; - ENABLE_TESTABILITY = YES; - GCC_C_LANGUAGE_STANDARD = gnu11; - GCC_DYNAMIC_NO_PIC = NO; - GCC_NO_COMMON_BLOCKS = YES; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; - MTL_FAST_MATH = YES; - ONLY_ACTIVE_ARCH = YES; - SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; - SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - VERSIONING_SYSTEM = "apple-generic"; - VERSION_INFO_PREFIX = ""; - }; - name = Debug; - }; - 8D7D984429DB8437007B8198 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_ANALYZER_NONNULL = YES; - CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_ENABLE_OBJC_WEAK = YES; - CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_COMMA = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_DOCUMENTATION_COMMENTS = YES; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INFINITE_RECURSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; - CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; - CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; - CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; - CLANG_WARN_STRICT_PROTOTYPES = YES; - CLANG_WARN_SUSPICIOUS_MOVE = YES; - CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 1; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - ENABLE_NS_ASSERTIONS = NO; - ENABLE_STRICT_OBJC_MSGSEND = YES; - GCC_C_LANGUAGE_STANDARD = gnu11; - GCC_NO_COMMON_BLOCKS = YES; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - MTL_ENABLE_DEBUG_INFO = NO; - MTL_FAST_MATH = YES; - SWIFT_COMPILATION_MODE = wholemodule; - SWIFT_OPTIMIZATION_LEVEL = "-O"; - VERSIONING_SYSTEM = "apple-generic"; - VERSION_INFO_PREFIX = ""; - }; - name = Release; - }; - 8D7D984629DB8437007B8198 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - BUILD_LIBRARY_FOR_DISTRIBUTION = YES; - CODE_SIGN_IDENTITY = "Apple Development"; - CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 1; - DEFINES_MODULE = YES; - DEVELOPMENT_TEAM = ""; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - ENABLE_MODULE_VERIFIER = YES; - GENERATE_INFOPLIST_FILE = YES; - INFOPLIST_KEY_NSHumanReadableCopyright = ""; - INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 15.6; - LD_RUNPATH_SEARCH_PATHS = ( - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); - "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = ( - "@executable_path/../Frameworks", - "@loader_path/Frameworks", - ); - LIBRARY_SEARCH_PATHS = "$(PROJECT_DIR)/../../../target/universal/debug"; - MACOSX_DEPLOYMENT_TARGET = 12.4; - MARKETING_VERSION = 1.0; - MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++"; - MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++20"; - PRODUCT_BUNDLE_IDENTIFIER = dev.firezone.connlib; - PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; - PROVISIONING_PROFILE_SPECIFIER = ""; - SDKROOT = auto; - SKIP_INSTALL = YES; - SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx"; - SWIFT_EMIT_LOC_STRINGS = YES; - SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = "1,2"; - }; - name = Debug; - }; - 8D7D984729DB8437007B8198 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - BUILD_LIBRARY_FOR_DISTRIBUTION = YES; - CODE_SIGN_IDENTITY = "Apple Development"; - CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 1; - DEFINES_MODULE = YES; - DEVELOPMENT_TEAM = ""; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - ENABLE_MODULE_VERIFIER = YES; - GENERATE_INFOPLIST_FILE = YES; - INFOPLIST_KEY_NSHumanReadableCopyright = ""; - INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 15.6; - LD_RUNPATH_SEARCH_PATHS = ( - "@executable_path/Frameworks", - "@loader_path/Frameworks", - ); - "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = ( - "@executable_path/../Frameworks", - "@loader_path/Frameworks", - ); - LIBRARY_SEARCH_PATHS = ( - "$(PROJECT_DIR)/../../../target/universal/release", - "$(PROJECT_DIR)/../../../target/universal/debug", - ); - MACOSX_DEPLOYMENT_TARGET = 12.4; - MARKETING_VERSION = 1.0; - MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++"; - MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++20"; - PRODUCT_BUNDLE_IDENTIFIER = dev.firezone.connlib; - PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; - PROVISIONING_PROFILE_SPECIFIER = ""; - SDKROOT = auto; - SKIP_INSTALL = YES; - SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx"; - SWIFT_EMIT_LOC_STRINGS = YES; - SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = "1,2"; - }; - name = Release; - }; -/* End XCBuildConfiguration section */ - -/* Begin XCConfigurationList section */ - 8D7D982B29DB8437007B8198 /* Build configuration list for PBXProject "connlib" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 8D7D984329DB8437007B8198 /* Debug */, - 8D7D984429DB8437007B8198 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 8D7D984529DB8437007B8198 /* Build configuration list for PBXNativeTarget "connlib" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 8D7D984629DB8437007B8198 /* Debug */, - 8D7D984729DB8437007B8198 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; -/* End XCConfigurationList section */ - }; - rootObject = 8D7D982829DB8437007B8198 /* Project object */; -} diff --git a/rust/connlib/clients/apple/connlib.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/rust/connlib/clients/apple/connlib.xcodeproj/project.xcworkspace/contents.xcworkspacedata deleted file mode 100644 index 919434a62..000000000 --- a/rust/connlib/clients/apple/connlib.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/rust/connlib/clients/apple/connlib.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/rust/connlib/clients/apple/connlib.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist deleted file mode 100644 index 18d981003..000000000 --- a/rust/connlib/clients/apple/connlib.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +++ /dev/null @@ -1,8 +0,0 @@ - - - - - IDEDidComputeMac32BitWarning - - - diff --git a/rust/connlib/clients/apple/connlib.xcodeproj/xcshareddata/xcschemes/Connlib.xcscheme b/rust/connlib/clients/apple/connlib.xcodeproj/xcshareddata/xcschemes/Connlib.xcscheme deleted file mode 100644 index 6f69e4a37..000000000 --- a/rust/connlib/clients/apple/connlib.xcodeproj/xcshareddata/xcschemes/Connlib.xcscheme +++ /dev/null @@ -1,66 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/swift/apple/.gitignore b/swift/apple/.gitignore index ac8336430..09feda951 100644 --- a/swift/apple/.gitignore +++ b/swift/apple/.gitignore @@ -5,4 +5,5 @@ DerivedData/ xcuserdata/ **/*.xcuserstate -Firezone/Developer.xcconfig +Firezone/xcconfig/Developer.xcconfig +FirezoneNetworkExtension/Connlib diff --git a/swift/apple/Firezone.xcodeproj/project.pbxproj b/swift/apple/Firezone.xcodeproj/project.pbxproj index 18be8b2c8..ea4a50f21 100644 --- a/swift/apple/Firezone.xcodeproj/project.pbxproj +++ b/swift/apple/Firezone.xcodeproj/project.pbxproj @@ -14,6 +14,15 @@ 05CF1D16290B1FE700CF4755 /* PacketTunnelProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05833DFA28F73B070008FAB0 /* PacketTunnelProvider.swift */; }; 05CF1D17290B1FE700CF4755 /* PacketTunnelProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05833DFA28F73B070008FAB0 /* PacketTunnelProvider.swift */; }; 05D3BB2128FDE9C000BC3727 /* NetworkExtension.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 05D3BB1628FDBD8A00BC3727 /* NetworkExtension.framework */; }; + 6F68E44C2A588522003C7D08 /* AllConfigs.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 6F68E44B2A588522003C7D08 /* AllConfigs.xcconfig */; }; + 6FE454F62A5BFB93006549B1 /* Adapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FE454EA2A5BFABA006549B1 /* Adapter.swift */; }; + 6FE454F72A5BFB93006549B1 /* Adapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FE454EA2A5BFABA006549B1 /* Adapter.swift */; }; + 6FE455092A5D110D006549B1 /* CallbackHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FE455082A5D110D006549B1 /* CallbackHandler.swift */; }; + 6FE4550A2A5D110D006549B1 /* CallbackHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FE455082A5D110D006549B1 /* CallbackHandler.swift */; }; + 6FE4550C2A5D111E006549B1 /* SwiftBridgeCore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FE4550B2A5D111D006549B1 /* SwiftBridgeCore.swift */; }; + 6FE4550D2A5D111E006549B1 /* SwiftBridgeCore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FE4550B2A5D111D006549B1 /* SwiftBridgeCore.swift */; }; + 6FE4550F2A5D112C006549B1 /* connlib-apple.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FE4550E2A5D112C006549B1 /* connlib-apple.swift */; }; + 6FE455102A5D112C006549B1 /* connlib-apple.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FE4550E2A5D112C006549B1 /* connlib-apple.swift */; }; 794C38152970A2660029F38F /* FirezoneKit in Frameworks */ = {isa = PBXBuildFile; productRef = 794C38142970A2660029F38F /* FirezoneKit */; }; 794C38172970A26A0029F38F /* FirezoneKit in Frameworks */ = {isa = PBXBuildFile; productRef = 794C38162970A26A0029F38F /* FirezoneKit */; }; 79756C6629704A7A0018E2D5 /* FirezoneKit in Frameworks */ = {isa = PBXBuildFile; productRef = 79756C6529704A7A0018E2D5 /* FirezoneKit */; }; @@ -37,6 +46,20 @@ remoteGlobalIDString = 05CF1D02290B1DCD00CF4755; remoteInfo = FirezoneNetworkExtensionmacOS; }; + 6F3E231B2A5DC0DB00737CF1 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 8DCC021128D512AC007E12D2 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 6FE454BC2A5BC5F3006549B1; + remoteInfo = "Build Connlib"; + }; + 6F3E231D2A5DC0DF00737CF1 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 8DCC021128D512AC007E12D2 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 6FE454BC2A5BC5F3006549B1; + remoteInfo = "Build Connlib"; + }; /* End PBXContainerItemProxy section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -73,8 +96,12 @@ 05CF1CF6290B1CEE00CF4755 /* FirezoneNetworkExtension_iOS.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = FirezoneNetworkExtension_iOS.entitlements; sourceTree = ""; }; 05CF1D03290B1DCD00CF4755 /* FirezoneNetworkExtensionmacOS.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = FirezoneNetworkExtensionmacOS.appex; sourceTree = BUILT_PRODUCTS_DIR; }; 05D3BB1628FDBD8A00BC3727 /* NetworkExtension.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = NetworkExtension.framework; path = System/Library/Frameworks/NetworkExtension.framework; sourceTree = SDKROOT; }; - 79BA2AF229A00F8800A2E6DC /* Developer.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Developer.xcconfig; sourceTree = ""; }; - 79C88B24296F494500261800 /* Config.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Config.xcconfig; sourceTree = ""; }; + 6F68E44B2A588522003C7D08 /* AllConfigs.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = AllConfigs.xcconfig; path = xcconfig/AllConfigs.xcconfig; sourceTree = ""; }; + 6FE454EA2A5BFABA006549B1 /* Adapter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Adapter.swift; sourceTree = ""; }; + 6FE455082A5D110D006549B1 /* CallbackHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = CallbackHandler.swift; path = Connlib/CallbackHandler.swift; sourceTree = ""; }; + 6FE4550B2A5D111D006549B1 /* SwiftBridgeCore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SwiftBridgeCore.swift; path = Connlib/Generated/SwiftBridgeCore.swift; sourceTree = ""; }; + 6FE4550E2A5D112C006549B1 /* connlib-apple.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "connlib-apple.swift"; path = "Connlib/Generated/connlib-apple/connlib-apple.swift"; sourceTree = ""; }; + 6FE455112A5D13A2006549B1 /* FirezoneNetworkExtension-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "FirezoneNetworkExtension-Bridging-Header.h"; sourceTree = ""; }; 8DCC021928D512AC007E12D2 /* Firezone.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Firezone.app; sourceTree = BUILT_PRODUCTS_DIR; }; 8DCC021C28D512AC007E12D2 /* FirezoneApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirezoneApp.swift; sourceTree = ""; }; 8DCC022528D512AE007E12D2 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; @@ -128,6 +155,11 @@ 05CF1CF6290B1CEE00CF4755 /* FirezoneNetworkExtension_iOS.entitlements */, 05CF1CDE290B1A9000CF4755 /* FirezoneNetworkExtension_macOS.entitlements */, 05833DFA28F73B070008FAB0 /* PacketTunnelProvider.swift */, + 6FE454EA2A5BFABA006549B1 /* Adapter.swift */, + 6FE455082A5D110D006549B1 /* CallbackHandler.swift */, + 6FE4550B2A5D111D006549B1 /* SwiftBridgeCore.swift */, + 6FE4550E2A5D112C006549B1 /* connlib-apple.swift */, + 6FE455112A5D13A2006549B1 /* FirezoneNetworkExtension-Bridging-Header.h */, ); path = FirezoneNetworkExtension; sourceTree = ""; @@ -173,10 +205,9 @@ 8DCC021B28D512AC007E12D2 /* Firezone */ = { isa = PBXGroup; children = ( + 6F68E44B2A588522003C7D08 /* AllConfigs.xcconfig */, 05E1505F28FF398000170F82 /* Application */, 8DCC022528D512AE007E12D2 /* Assets.xcassets */, - 79C88B24296F494500261800 /* Config.xcconfig */, - 79BA2AF229A00F8800A2E6DC /* Developer.xcconfig */, 8DCC022728D512AE007E12D2 /* Firezone.entitlements */, 05CF1C39290995DA00CF4755 /* Info.plist */, 8DCC022828D512AE007E12D2 /* Preview Content */, @@ -202,11 +233,29 @@ }; /* End PBXGroup section */ +/* Begin PBXLegacyTarget section */ + 6FE454BC2A5BC5F3006549B1 /* Build Connlib */ = { + isa = PBXLegacyTarget; + buildArgumentsString = "$(ACTION)"; + buildConfigurationList = 6FE454BD2A5BC5F3006549B1 /* Build configuration list for PBXLegacyTarget "Build Connlib" */; + buildPhases = ( + ); + buildToolPath = "${CONNLIB_SOURCE_DIR}/build-rust.sh"; + buildWorkingDirectory = "${CONNLIB_SOURCE_DIR}"; + dependencies = ( + ); + name = "Build Connlib"; + passBuildSettingsInEnvironment = 1; + productName = "Build Connlib"; + }; +/* End PBXLegacyTarget section */ + /* Begin PBXNativeTarget section */ 05CF1CEF290B1CEE00CF4755 /* FirezoneNetworkExtensioniOS */ = { isa = PBXNativeTarget; buildConfigurationList = 05CF1CFA290B1CEE00CF4755 /* Build configuration list for PBXNativeTarget "FirezoneNetworkExtensioniOS" */; buildPhases = ( + 6F3E231A2A5D830D00737CF1 /* Copy Connlib Headers and Swift Files */, 05CF1CEC290B1CEE00CF4755 /* Sources */, 05CF1CED290B1CEE00CF4755 /* Frameworks */, 05CF1CEE290B1CEE00CF4755 /* Resources */, @@ -214,6 +263,7 @@ buildRules = ( ); dependencies = ( + 6F3E231C2A5DC0DB00737CF1 /* PBXTargetDependency */, ); name = FirezoneNetworkExtensioniOS; packageProductDependencies = ( @@ -227,6 +277,7 @@ isa = PBXNativeTarget; buildConfigurationList = 05CF1D0D290B1DCD00CF4755 /* Build configuration list for PBXNativeTarget "FirezoneNetworkExtensionmacOS" */; buildPhases = ( + 6F3E23192A5D823500737CF1 /* Copy Connlib Headers and Swift Files */, 05CF1CFF290B1DCD00CF4755 /* Sources */, 05CF1D00290B1DCD00CF4755 /* Frameworks */, 05CF1D01290B1DCD00CF4755 /* Resources */, @@ -234,6 +285,7 @@ buildRules = ( ); dependencies = ( + 6F3E231E2A5DC0DF00737CF1 /* PBXTargetDependency */, ); name = FirezoneNetworkExtensionmacOS; packageProductDependencies = ( @@ -279,9 +331,14 @@ TargetAttributes = { 05CF1CEF290B1CEE00CF4755 = { CreatedOnToolsVersion = 14.0.1; + LastSwiftMigration = 1430; }; 05CF1D02290B1DCD00CF4755 = { CreatedOnToolsVersion = 14.0.1; + LastSwiftMigration = 1430; + }; + 6FE454BC2A5BC5F3006549B1 = { + CreatedOnToolsVersion = 14.3; }; 8DCC021828D512AC007E12D2 = { CreatedOnToolsVersion = 14.0; @@ -307,6 +364,7 @@ 8DCC021828D512AC007E12D2 /* Firezone */, 05CF1CEF290B1CEE00CF4755 /* FirezoneNetworkExtensioniOS */, 05CF1D02290B1DCD00CF4755 /* FirezoneNetworkExtensionmacOS */, + 6FE454BC2A5BC5F3006549B1 /* Build Connlib */, ); }; /* End PBXProject section */ @@ -332,17 +390,67 @@ files = ( 8DCC022A28D512AE007E12D2 /* Preview Assets.xcassets in Resources */, 8DCC022628D512AE007E12D2 /* Assets.xcassets in Resources */, + 6F68E44C2A588522003C7D08 /* AllConfigs.xcconfig in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXResourcesBuildPhase section */ +/* Begin PBXShellScriptBuildPhase section */ + 6F3E23192A5D823500737CF1 /* Copy Connlib Headers and Swift Files */ = { + isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + name = "Copy Connlib Headers and Swift Files"; + outputFileListPaths = ( + "$(SRCROOT)/FirezoneNetworkExtension/Connlib.xcfilelist", + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "# Type a script or drag a script file from your workspace to insert its path.\n./copy_generated_connlib_files.sh\n"; + showEnvVarsInLog = 0; + }; + 6F3E231A2A5D830D00737CF1 /* Copy Connlib Headers and Swift Files */ = { + isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + name = "Copy Connlib Headers and Swift Files"; + outputFileListPaths = ( + "$(SRCROOT)/FirezoneNetworkExtension/Connlib.xcfilelist", + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "# Type a script or drag a script file from your workspace to insert its path.\n./copy_generated_connlib_files.sh\n"; + showEnvVarsInLog = 0; + }; +/* End PBXShellScriptBuildPhase section */ + /* Begin PBXSourcesBuildPhase section */ 05CF1CEC290B1CEE00CF4755 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 6FE455092A5D110D006549B1 /* CallbackHandler.swift in Sources */, + 6FE4550F2A5D112C006549B1 /* connlib-apple.swift in Sources */, 05CF1D17290B1FE700CF4755 /* PacketTunnelProvider.swift in Sources */, + 6FE454F62A5BFB93006549B1 /* Adapter.swift in Sources */, + 6FE4550C2A5D111E006549B1 /* SwiftBridgeCore.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -350,7 +458,11 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 6FE4550A2A5D110D006549B1 /* CallbackHandler.swift in Sources */, + 6FE455102A5D112C006549B1 /* connlib-apple.swift in Sources */, 05CF1D16290B1FE700CF4755 /* PacketTunnelProvider.swift in Sources */, + 6FE454F72A5BFB93006549B1 /* Adapter.swift in Sources */, + 6FE4550D2A5D111E006549B1 /* SwiftBridgeCore.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -379,12 +491,23 @@ target = 05CF1D02290B1DCD00CF4755 /* FirezoneNetworkExtensionmacOS */; targetProxy = 05CF1D0A290B1DCD00CF4755 /* PBXContainerItemProxy */; }; + 6F3E231C2A5DC0DB00737CF1 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 6FE454BC2A5BC5F3006549B1 /* Build Connlib */; + targetProxy = 6F3E231B2A5DC0DB00737CF1 /* PBXContainerItemProxy */; + }; + 6F3E231E2A5DC0DF00737CF1 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 6FE454BC2A5BC5F3006549B1 /* Build Connlib */; + targetProxy = 6F3E231D2A5DC0DF00737CF1 /* PBXContainerItemProxy */; + }; /* End PBXTargetDependency section */ /* Begin XCBuildConfiguration section */ 05CF1CFB290B1CEE00CF4755 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = FirezoneNetworkExtension/FirezoneNetworkExtension_iOS.entitlements; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; @@ -398,16 +521,24 @@ "@executable_path/Frameworks", "@executable_path/../../Frameworks", ); + "LIBRARY_SEARCH_PATHS[sdk=iphoneos*]" = "${CONNLIB_TARGET_DIR}/aarch64-apple-ios/debug"; + "LIBRARY_SEARCH_PATHS[sdk=iphonesimulator*]" = ( + "${CONNLIB_TARGET_DIR}/aarch64-apple-ios-sim/debug", + "${CONNLIB_TARGET_DIR}/x86_64-apple-ios/debug", + ); MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)"; MARKETING_VERSION = 1.0; ONLY_ACTIVE_ARCH = YES; + OTHER_LDFLAGS = "-lconnlib"; PRODUCT_BUNDLE_IDENTIFIER = "$(inherited).network-extension"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "iphonesimulator iphoneos"; SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_OBJC_BRIDGING_HEADER = "FirezoneNetworkExtension/FirezoneNetworkExtension-Bridging-Header.h"; SWIFT_OBJC_INTERFACE_HEADER_NAME = ""; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; TVOS_DEPLOYMENT_TARGET = ""; @@ -418,6 +549,7 @@ 05CF1CFC290B1CEE00CF4755 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = FirezoneNetworkExtension/FirezoneNetworkExtension_iOS.entitlements; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; @@ -431,14 +563,21 @@ "@executable_path/Frameworks", "@executable_path/../../Frameworks", ); + "LIBRARY_SEARCH_PATHS[sdk=iphoneos*]" = "${CONNLIB_TARGET_DIR}/aarch64-apple-ios/release"; + "LIBRARY_SEARCH_PATHS[sdk=iphonesimulator*]" = ( + "${CONNLIB_TARGET_DIR}/aarch64-apple-ios-sim/release", + "${CONNLIB_TARGET_DIR}/x86_64-apple-ios/release", + ); MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)"; MARKETING_VERSION = 1.0; + OTHER_LDFLAGS = "-lconnlib"; PRODUCT_BUNDLE_IDENTIFIER = "$(inherited).network-extension"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "iphonesimulator iphoneos"; SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_OBJC_BRIDGING_HEADER = "FirezoneNetworkExtension/FirezoneNetworkExtension-Bridging-Header.h"; SWIFT_OBJC_INTERFACE_HEADER_NAME = ""; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; @@ -451,6 +590,7 @@ 05CF1D0E290B1DCD00CF4755 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = FirezoneNetworkExtension/FirezoneNetworkExtension_macOS.entitlements; CODE_SIGN_IDENTITY = "-"; "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; @@ -468,14 +608,20 @@ "@executable_path/../Frameworks", "@executable_path/../../../../Frameworks", ); + "LIBRARY_SEARCH_PATHS[arch=arm64]" = "$(CONNLIB_TARGET_DIR)/aarch64-apple-darwin/debug"; + "LIBRARY_SEARCH_PATHS[arch=arm64e]" = "$(CONNLIB_TARGET_DIR)/aarch64-apple-darwin/debug"; + "LIBRARY_SEARCH_PATHS[arch=x86_64]" = "$(CONNLIB_TARGET_DIR)/x86_64-apple-darwin/debug"; MARKETING_VERSION = 1.0; + OTHER_LDFLAGS = "-lconnlib"; PRODUCT_BUNDLE_IDENTIFIER = "$(inherited).network-extension"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = macosx; SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_OBJC_BRIDGING_HEADER = "FirezoneNetworkExtension/FirezoneNetworkExtension-Bridging-Header.h"; SWIFT_OBJC_INTERFACE_HEADER_NAME = ""; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 5.0; TVOS_DEPLOYMENT_TARGET = ""; WATCHOS_DEPLOYMENT_TARGET = ""; @@ -485,6 +631,7 @@ 05CF1D0F290B1DCD00CF4755 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = FirezoneNetworkExtension/FirezoneNetworkExtension_macOS.entitlements; CODE_SIGN_IDENTITY = "-"; "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; @@ -502,13 +649,18 @@ "@executable_path/../Frameworks", "@executable_path/../../../../Frameworks", ); + "LIBRARY_SEARCH_PATHS[arch=arm64]" = "$(CONNLIB_TARGET_DIR)/aarch64-apple-darwin/release"; + "LIBRARY_SEARCH_PATHS[arch=arm64e]" = "$(CONNLIB_TARGET_DIR)/aarch64-apple-darwin/release"; + "LIBRARY_SEARCH_PATHS[arch=x86_64]" = "$(CONNLIB_TARGET_DIR)/x86_64-apple-darwin/release"; MARKETING_VERSION = 1.0; + OTHER_LDFLAGS = "-lconnlib"; PRODUCT_BUNDLE_IDENTIFIER = "$(inherited).network-extension"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = macosx; SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_OBJC_BRIDGING_HEADER = "FirezoneNetworkExtension/FirezoneNetworkExtension-Bridging-Header.h"; SWIFT_OBJC_INTERFACE_HEADER_NAME = ""; SWIFT_VERSION = 5.0; TVOS_DEPLOYMENT_TARGET = ""; @@ -516,9 +668,34 @@ }; name = Release; }; + 6FE454BE2A5BC5F3006549B1 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + DEBUGGING_SYMBOLS = YES; + DEBUG_INFORMATION_FORMAT = dwarf; + GCC_GENERATE_DEBUGGING_SYMBOLS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + OTHER_CFLAGS = ""; + OTHER_LDFLAGS = ""; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 6FE454BF2A5BC5F3006549B1 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + OTHER_CFLAGS = ""; + OTHER_LDFLAGS = ""; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; 8DCC024128D512AE007E12D2 /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 79C88B24296F494500261800 /* Config.xcconfig */; + baseConfigurationReference = 6F68E44B2A588522003C7D08 /* AllConfigs.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_NONNULL = YES; @@ -581,7 +758,7 @@ }; 8DCC024228D512AE007E12D2 /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 79C88B24296F494500261800 /* Config.xcconfig */; + baseConfigurationReference = 6F68E44B2A588522003C7D08 /* AllConfigs.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_NONNULL = YES; @@ -758,6 +935,15 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + 6FE454BD2A5BC5F3006549B1 /* Build configuration list for PBXLegacyTarget "Build Connlib" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 6FE454BE2A5BC5F3006549B1 /* Debug */, + 6FE454BF2A5BC5F3006549B1 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; 8DCC021428D512AC007E12D2 /* Build configuration list for PBXProject "Firezone" */ = { isa = XCConfigurationList; buildConfigurations = ( diff --git a/swift/apple/Firezone/Config.xcconfig b/swift/apple/Firezone/xcconfig/AllConfigs.xcconfig similarity index 53% rename from swift/apple/Firezone/Config.xcconfig rename to swift/apple/Firezone/xcconfig/AllConfigs.xcconfig index f2ad4da32..886409f00 100644 --- a/swift/apple/Firezone/Config.xcconfig +++ b/swift/apple/Firezone/xcconfig/AllConfigs.xcconfig @@ -1 +1,2 @@ #include "Developer.xcconfig" +#include "Build.xcconfig" diff --git a/swift/apple/Firezone/xcconfig/Build.xcconfig b/swift/apple/Firezone/xcconfig/Build.xcconfig new file mode 100644 index 000000000..f7ab44197 --- /dev/null +++ b/swift/apple/Firezone/xcconfig/Build.xcconfig @@ -0,0 +1,2 @@ +CONNLIB_SOURCE_DIR=${PROJECT_DIR}/../../rust/connlib/clients/apple +CONNLIB_TARGET_DIR=${PROJECT_DIR}/../../rust/target diff --git a/swift/apple/Firezone/Developer.xcconfig.ci-iOS b/swift/apple/Firezone/xcconfig/Developer.xcconfig.ci-iOS similarity index 100% rename from swift/apple/Firezone/Developer.xcconfig.ci-iOS rename to swift/apple/Firezone/xcconfig/Developer.xcconfig.ci-iOS diff --git a/swift/apple/Firezone/Developer.xcconfig.ci-macOS b/swift/apple/Firezone/xcconfig/Developer.xcconfig.ci-macOS similarity index 100% rename from swift/apple/Firezone/Developer.xcconfig.ci-macOS rename to swift/apple/Firezone/xcconfig/Developer.xcconfig.ci-macOS diff --git a/swift/apple/Firezone/Developer.xcconfig.template b/swift/apple/Firezone/xcconfig/Developer.xcconfig.template similarity index 74% rename from swift/apple/Firezone/Developer.xcconfig.template rename to swift/apple/Firezone/xcconfig/Developer.xcconfig.template index e1fd00e2c..f32287f21 100644 --- a/swift/apple/Firezone/Developer.xcconfig.template +++ b/swift/apple/Firezone/xcconfig/Developer.xcconfig.template @@ -5,3 +5,7 @@ DEVELOPMENT_TEAM = // Should be an app id created at developer.apple.com // with Network Extensions capability. PRODUCT_BUNDLE_IDENTIFIER = + +// If you want to build Connlib with mocks, +// enable it here. +// CONNLIB_MOCK=1 diff --git a/swift/apple/FirezoneKit/Package.swift b/swift/apple/FirezoneKit/Package.swift index 07120381d..f313ab0ad 100644 --- a/swift/apple/FirezoneKit/Package.swift +++ b/swift/apple/FirezoneKit/Package.swift @@ -9,7 +9,7 @@ let package = Package( products: [ // Products define the executables and libraries a package produces, and make them visible to // other packages. - .library(name: "FirezoneKit", targets: ["FirezoneKit", "Connlib"]), + .library(name: "FirezoneKit", targets: ["FirezoneKit"]), ], dependencies: [ // Dependencies declare other packages that this package depends on. @@ -18,10 +18,6 @@ let package = Package( .package(url: "https://github.com/auth0/JWTDecode.swift", from: "3.0.0"), ], targets: [ - .binaryTarget( - name: "Connlib", - path: "../../../rust/connlib/clients/apple/Connlib.xcframework" - ), .target( name: "FirezoneKit", dependencies: [ diff --git a/rust/connlib/clients/apple/Sources/Connlib/Adapter.swift b/swift/apple/FirezoneNetworkExtension/Adapter.swift similarity index 77% rename from rust/connlib/clients/apple/Sources/Connlib/Adapter.swift rename to swift/apple/FirezoneNetworkExtension/Adapter.swift index 1c94aba17..6adb88d6d 100644 --- a/rust/connlib/clients/apple/Sources/Connlib/Adapter.swift +++ b/swift/apple/FirezoneNetworkExtension/Adapter.swift @@ -57,7 +57,8 @@ public class Adapter { // There must be a better way than making this a static class var... Self.currentAdapter = self - Self.callbackHandler = CallbackHandler(adapter: self) + Self.callbackHandler = CallbackHandler() + Self.callbackHandler?.delegate = self } deinit { @@ -291,3 +292,74 @@ public class Adapter { #endif } } + +extension Adapter: CallbackHandlerDelegate { + public func onConnect(tunnelAddressIPv4: String, tunnelAddressIPv6: String) { + let addresses4 = [tunnelAddressIPv4] + let addresses6 = [tunnelAddressIPv6] + let ipv4Routes = + Adapter.currentAdapter?.lastNetworkSettings?.ipv4Settings?.includedRoutes ?? [] + let ipv6Routes = + Adapter.currentAdapter?.lastNetworkSettings?.ipv6Settings?.includedRoutes ?? [] + + _ = setTunnelSettingsKeepingSomeExisting( + addresses4: addresses4, addresses6: addresses6, ipv4Routes: ipv4Routes, ipv6Routes: ipv6Routes + ) + } + + public func onUpdateResources(resourceList: String) { + let addresses4 = + self.lastNetworkSettings?.ipv4Settings?.addresses ?? ["100.100.111.2"] + let addresses6 = + self.lastNetworkSettings?.ipv6Settings?.addresses ?? [ + "fd00:0222:2021:1111::2" + ] + + // TODO: Use actual passed in resources to achieve split tunnel + let ipv4Routes = [NEIPv4Route(destinationAddress: "100.64.0.0", subnetMask: "255.192.0.0")] + let ipv6Routes = [ + NEIPv6Route(destinationAddress: "fd00:0222:2021:1111::0", networkPrefixLength: 64) + ] + + _ = setTunnelSettingsKeepingSomeExisting( + addresses4: addresses4, addresses6: addresses6, ipv4Routes: ipv4Routes, ipv6Routes: ipv6Routes + ) + } + + public func onDisconnect() { + // Unimplemented + } + + public func onError(error: Error, isRecoverable: Bool) { + let logger = Logger(subsystem: "dev.firezone.firezone", category: "packet-tunnel") + logger.log(level: .error, "Internal connlib error: \(String(describing: error), privacy: .public)") + } + + private func setTunnelSettingsKeepingSomeExisting( + addresses4: [String], addresses6: [String], ipv4Routes: [NEIPv4Route], ipv6Routes: [NEIPv6Route] + ) -> Bool { + let logger = Logger(subsystem: "dev.firezone.firezone", category: "packet-tunnel") + + do { + /* If the tunnel interface addresses are being updated, it's impossible for the tunnel to + stay up due to the way WireGuard works. Still, we try not to change the tunnel's routes + here Just In Case™. + */ + try self.setNetworkSettings( + self.generateNetworkSettings( + addresses4: addresses4, + addresses6: addresses6, + ipv4Routes: ipv4Routes, + ipv6Routes: ipv6Routes + ) + ) + + return true + } catch let error { + logger.log(level: .debug, "Error setting adapter settings: \(String(describing: error))") + + return false + } + } + +} diff --git a/swift/apple/FirezoneNetworkExtension/Connlib.xcfilelist b/swift/apple/FirezoneNetworkExtension/Connlib.xcfilelist new file mode 100644 index 000000000..fcd813256 --- /dev/null +++ b/swift/apple/FirezoneNetworkExtension/Connlib.xcfilelist @@ -0,0 +1,6 @@ +$(PROJECT_DIR)/FirezoneNetworkExtension/Connlib/Generated/connlib-apple/connlib-apple.swift +$(PROJECT_DIR)/FirezoneNetworkExtension/Connlib/Generated/connlib-apple/connlib-apple.h +$(PROJECT_DIR)/FirezoneNetworkExtension/Connlib/Generated/SwiftBridgeCore.h +$(PROJECT_DIR)/FirezoneNetworkExtension/Connlib/Generated/SwiftBridgeCore.swift +$(PROJECT_DIR)/FirezoneNetworkExtension/Connlib/CallbackHandler.swift +$(PROJECT_DIR)/FirezoneNetworkExtension/Connlib/connlib.h diff --git a/swift/apple/FirezoneNetworkExtension/FirezoneNetworkExtension-Bridging-Header.h b/swift/apple/FirezoneNetworkExtension/FirezoneNetworkExtension-Bridging-Header.h new file mode 100644 index 000000000..c3a9be6ed --- /dev/null +++ b/swift/apple/FirezoneNetworkExtension/FirezoneNetworkExtension-Bridging-Header.h @@ -0,0 +1,5 @@ +// +// Use this file to import your target's public headers that you would like to expose to Swift. +// + +#include "Connlib/connlib.h" diff --git a/swift/apple/FirezoneNetworkExtension/PacketTunnelProvider.swift b/swift/apple/FirezoneNetworkExtension/PacketTunnelProvider.swift index 8cc47b168..8e7946315 100644 --- a/swift/apple/FirezoneNetworkExtension/PacketTunnelProvider.swift +++ b/swift/apple/FirezoneNetworkExtension/PacketTunnelProvider.swift @@ -4,7 +4,6 @@ // LICENSE: Apache-2.0 // -import connlib import Dependencies import NetworkExtension import os diff --git a/swift/apple/README.md b/swift/apple/README.md index 795a45af0..25ec792e3 100644 --- a/swift/apple/README.md +++ b/swift/apple/README.md @@ -2,33 +2,52 @@ Firezone app clients for macOS and iOS. -## Builidng +## Pre-requisites -Clone this repo: + - Rust + +## Building + + 1. Clone this repo: + + ```bash + git clone https://github.com/firezone/firezone + ``` + + 2. `cd` to the Apple clients code + + ```bash + cd swift/apple + ``` + + 3. Rename and populate developer team ID file: + + ```bash + cp Firezone/xcconfig/Developer.xcconfig.template Firezone/xcconfig/Developer.xcconfig + vim Firezone/xcconfig/Developer.xcconfig + ``` + + 4. Open project in Xcode: + + ```bash + open Firezone.xcodeproj + ``` + + Build the Firezone target + + +## Cleaning up + +To cleanup Swift build objects: ```bash -git clone https://github.com/firezone/firezone +cd swift/apple +./cleanup.sh ``` -Build Connlib: -```bash -cd rust/connlib/clients/apple -PLATFORM_NAME=macosx ./build-rust.sh # For macOS -PLATFORM_NAME=iphoneos ./build-rust.sh # For iOS -./build-xcframework-dev.sh -``` - -Rename and populate developer team ID file: +To cleanup both Swift and Rust build objects: ```bash -cp Firezone/Developer.xcconfig.template Firezone/Developer.xcconfig -vim Firezone/Developer.xcconfig +cd swift/apple +./cleanup.sh all ``` - -Open project in Xcode: - -```bash -open Firezone.xcodeproj -``` - -Build the Firezone target diff --git a/swift/apple/cleanup.sh b/swift/apple/cleanup.sh new file mode 100755 index 000000000..ddcdd43cf --- /dev/null +++ b/swift/apple/cleanup.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +set -e + +ARG=$1 + +if [[ -z "$ARG" ]]; then + ARG="swift" +fi + +if [[ $ARG == "all" ]] || [[ $ARG == "swift" ]] || [[ $ARG == "rust" ]]; then + echo "Cleaning up $ARG build artifacts"; +else + echo "Usage: $0 [ all | swift | rust ]" + echo " (Default: swift)" +fi + +if [[ $ARG == "swift" ]] || [[ $ARG == "all" ]]; then + set -x + xcodebuild clean + rm -rf ./FirezoneNetworkExtension/Connlib + set +x +fi + +if [[ $ARG == "rust" ]] || [[ $ARG == "all" ]]; then + set -x + cd ../../rust/connlib/clients/apple && cargo clean + cd Sources/Connlib/Generated && git clean -df + set +x +fi diff --git a/swift/apple/copy_generated_connlib_files.sh b/swift/apple/copy_generated_connlib_files.sh new file mode 100755 index 000000000..f863bc438 --- /dev/null +++ b/swift/apple/copy_generated_connlib_files.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +################################################## +# We call this from an Xcode run script. +################################################## + +set -e + +if [[ $1 == "clean" ]]; then + echo "Skipping copy during 'clean'" + exit 0 +fi + +DEST=./FirezoneNetworkExtension/Connlib +if [[ -n "$CONNLIB_SOURCE_DIR" ]]; then + set -x + rm -rf ${DEST} + find ${CONNLIB_SOURCE_DIR}/Sources/Connlib + cp -r ${CONNLIB_SOURCE_DIR}/Sources/Connlib ${DEST} + set +x +else + echo "CONNLIB_SOURCE_DIR is not set. Is this being invoked from Xcode?" +fi