diff --git a/.github/pre-commit-config.yaml b/.github/pre-commit-config.yaml index 15c00bf01..9b06bb6b2 100644 --- a/.github/pre-commit-config.yaml +++ b/.github/pre-commit-config.yaml @@ -24,9 +24,9 @@ repos: - id: check-yaml - id: check-merge-conflict - id: end-of-file-fixer - exclude: (^website/public/images/|^elixir/apps/web/priv/static/) + exclude: (^website/public/images/|^elixir/apps/web/priv/static/|^swift/apple/FirezoneNetworkExtension/Connlib/Generated/) - id: trailing-whitespace - exclude: ^website/public/images/ + exclude: (^website/public/images/|^swift/apple/FirezoneNetworkExtension/Connlib/Generated/) - id: check-merge-conflict - id: no-commit-to-branch args: diff --git a/rust/connlib/clients/apple/Sources/Connlib/Generated/.gitignore b/rust/connlib/clients/apple/Sources/Connlib/Generated/.gitignore deleted file mode 100644 index d6b7ef32c..000000000 --- a/rust/connlib/clients/apple/Sources/Connlib/Generated/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore diff --git a/rust/connlib/clients/apple/build-rust.sh b/rust/connlib/clients/apple/build-rust.sh index 17f33080c..ad6dfae8d 100755 --- a/rust/connlib/clients/apple/build-rust.sh +++ b/rust/connlib/clients/apple/build-rust.sh @@ -115,14 +115,3 @@ target_list="${target_list% }" # Build the library cargo build --verbose $target_list $CONFIGURATION_ARGS - -# Strip unused symbols from the libraries -for target in "${TARGETS[@]}"; do - profile="debug" - if [ "$CONFIGURATION" == "Release" ]; then - profile="release" - fi - - lib="$CONNLIB_TARGET_DIR/$target/$profile/libconnlib.a" - strip "$lib" -done diff --git a/rust/connlib/clients/apple/build.rs b/rust/connlib/clients/apple/build.rs index ddc9a9ccb..ea87f3e71 100644 --- a/rust/connlib/clients/apple/build.rs +++ b/rust/connlib/clients/apple/build.rs @@ -1,7 +1,7 @@ const XCODE_CONFIGURATION_ENV: &str = "CONFIGURATION"; fn main() { - let out_dir = "Sources/Connlib/Generated"; + let out_dir = "../../../../swift/apple/FirezoneNetworkExtension/Connlib/Generated"; let bridges = vec!["src/lib.rs"]; for path in &bridges { diff --git a/swift/apple/.gitignore b/swift/apple/.gitignore index 96e92751f..2f0538dcc 100644 --- a/swift/apple/.gitignore +++ b/swift/apple/.gitignore @@ -4,5 +4,3 @@ build/ DerivedData/ xcuserdata/ **/*.xcuserstate - -FirezoneNetworkExtension/Connlib diff --git a/swift/apple/Firezone.xcodeproj/project.pbxproj b/swift/apple/Firezone.xcodeproj/project.pbxproj index 7ff405129..3a19ba315 100644 --- a/swift/apple/Firezone.xcodeproj/project.pbxproj +++ b/swift/apple/Firezone.xcodeproj/project.pbxproj @@ -22,10 +22,7 @@ 8D4087DD2D246651005B2BAF /* Sentry in Frameworks */ = {isa = PBXBuildFile; productRef = 8D4087DC2D246651005B2BAF /* Sentry */; }; 8D41B9A52D15DD6800D16065 /* TunnelLogArchive.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8D41B9A42D15DD6800D16065 /* TunnelLogArchive.swift */; }; 8D41B9A62D15DD6800D16065 /* TunnelLogArchive.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8D41B9A42D15DD6800D16065 /* TunnelLogArchive.swift */; }; - 8D5047F52CE6AA1E009802E9 /* libresolv.9.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 8D5047F32CE6AA1E009802E9 /* libresolv.9.tbd */; }; - 8D5047F62CE6AA1E009802E9 /* libresolv.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 8D5047F42CE6AA1E009802E9 /* libresolv.tbd */; }; 8D5047F82CE6AA22009802E9 /* FirezoneKit in Frameworks */ = {isa = PBXBuildFile; productRef = 8D5047F72CE6AA22009802E9 /* FirezoneKit */; }; - 8D5047FA2CE6AA2E009802E9 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8D5047F92CE6AA2E009802E9 /* SystemConfiguration.framework */; }; 8D5047FB2CE6AA37009802E9 /* FirezoneNetworkExtension-Bridging-Header.h in Sources */ = {isa = PBXBuildFile; fileRef = 6FE455112A5D13A2006549B1 /* FirezoneNetworkExtension-Bridging-Header.h */; }; 8D5047FC2CE6AA47009802E9 /* CallbackHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FE455082A5D110D006549B1 /* CallbackHandler.swift */; }; 8D5047FD2CE6AA47009802E9 /* connlib-client-apple.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FE4550E2A5D112C006549B1 /* connlib-client-apple.swift */; }; @@ -35,11 +32,12 @@ 8D5048012CE6AA60009802E9 /* NetworkSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FE93AFA2A738D7E002D278A /* NetworkSettings.swift */; }; 8D5048042CE6B0AE009802E9 /* SwiftBridgeCore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6FE4550B2A5D111D006549B1 /* SwiftBridgeCore.swift */; }; 8D69392C2BA24FE600AF4396 /* BindResolvers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8D69392B2BA24FE600AF4396 /* BindResolvers.swift */; }; - 8DC08BCB2B296C4500675F46 /* libresolv.9.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 8DC08BCA2B296C4500675F46 /* libresolv.9.tbd */; }; - 8DC08BD42B297B8200675F46 /* libresolv.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 8DC08BD32B297B8200675F46 /* libresolv.tbd */; }; 8DC08BD72B297DB400675F46 /* FirezoneNetworkExtension-Bridging-Header.h in Sources */ = {isa = PBXBuildFile; fileRef = 6FE455112A5D13A2006549B1 /* FirezoneNetworkExtension-Bridging-Header.h */; }; 8DC1699D2CFF77D1006801B5 /* dev.firezone.firezone.network-extension.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = 05CF1CF0290B1CEE00CF4755 /* dev.firezone.firezone.network-extension.appex */; platformFilter = ios; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; 8DC169A02CFF77D1006801B5 /* dev.firezone.firezone.network-extension.systemextension in Embed System Extensions */ = {isa = PBXBuildFile; fileRef = 8D5047E32CE6A8F4009802E9 /* dev.firezone.firezone.network-extension.systemextension */; platformFilters = (macos, ); settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; + 8DC333F92D2FA85200E627D5 /* libresolv.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 8DC333F72D2FA85200E627D5 /* libresolv.tbd */; }; + 8DC333FA2D2FA85200E627D5 /* libresolv.9.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 8DC333F82D2FA85200E627D5 /* libresolv.9.tbd */; }; + 8DC333FB2D2FA89100E627D5 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6FFECD5B2AD6998400E00273 /* SystemConfiguration.framework */; }; 8DC9FB852CF5A738001BCE6A /* NetworkExtension.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 05D3BB1628FDBD8A00BC3727 /* NetworkExtension.framework */; }; 8DCC021D28D512AC007E12D2 /* FirezoneApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8DCC021C28D512AC007E12D2 /* FirezoneApp.swift */; }; 8DCC022628D512AE007E12D2 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 8DCC022528D512AE007E12D2 /* Assets.xcassets */; }; @@ -107,16 +105,13 @@ 8D41B9A42D15DD6800D16065 /* TunnelLogArchive.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TunnelLogArchive.swift; sourceTree = ""; }; 8D5047E32CE6A8F4009802E9 /* dev.firezone.firezone.network-extension.systemextension */ = {isa = PBXFileReference; explicitFileType = "wrapper.system-extension"; includeInIndex = 0; path = "dev.firezone.firezone.network-extension.systemextension"; sourceTree = BUILT_PRODUCTS_DIR; }; 8D5047E82CE6A8F4009802E9 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = ""; }; - 8D5047F32CE6AA1E009802E9 /* libresolv.9.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libresolv.9.tbd; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS18.1.sdk/usr/lib/libresolv.9.tbd; sourceTree = DEVELOPER_DIR; }; - 8D5047F42CE6AA1E009802E9 /* libresolv.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libresolv.tbd; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS18.1.sdk/usr/lib/libresolv.tbd; sourceTree = DEVELOPER_DIR; }; - 8D5047F92CE6AA2E009802E9 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS18.1.sdk/System/Library/Frameworks/SystemConfiguration.framework; sourceTree = DEVELOPER_DIR; }; 8D69392B2BA24FE600AF4396 /* BindResolvers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BindResolvers.swift; sourceTree = ""; }; 8D6939312BA2521A00AF4396 /* SystemConfigurationResolvers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SystemConfigurationResolvers.swift; sourceTree = ""; }; 8DA12C322BB7DA04007D91EB /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = ""; }; - 8DC08BCA2B296C4500675F46 /* libresolv.9.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libresolv.9.tbd; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS17.2.sdk/usr/lib/libresolv.9.tbd; sourceTree = DEVELOPER_DIR; }; 8DC08BCC2B296C5900675F46 /* libresolv.9.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libresolv.9.tbd; path = usr/lib/libresolv.9.tbd; sourceTree = SDKROOT; }; 8DC08BD12B297B7B00675F46 /* libresolv.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libresolv.tbd; path = usr/lib/libresolv.tbd; sourceTree = SDKROOT; }; - 8DC08BD32B297B8200675F46 /* libresolv.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libresolv.tbd; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS17.2.sdk/usr/lib/libresolv.tbd; sourceTree = DEVELOPER_DIR; }; + 8DC333F72D2FA85200E627D5 /* libresolv.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libresolv.tbd; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS18.2.sdk/usr/lib/libresolv.tbd; sourceTree = DEVELOPER_DIR; }; + 8DC333F82D2FA85200E627D5 /* libresolv.9.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libresolv.9.tbd; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS18.2.sdk/usr/lib/libresolv.9.tbd; sourceTree = DEVELOPER_DIR; }; 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 = ""; }; @@ -132,9 +127,9 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 8DC333F92D2FA85200E627D5 /* libresolv.tbd in Frameworks */, + 8DC333FA2D2FA85200E627D5 /* libresolv.9.tbd in Frameworks */, 8D4087D52D24653B005B2BAF /* Sentry in Frameworks */, - 8DC08BD42B297B8200675F46 /* libresolv.tbd in Frameworks */, - 8DC08BCB2B296C4500675F46 /* libresolv.9.tbd in Frameworks */, 794C38152970A2660029F38F /* FirezoneKit in Frameworks */, 05CF1CF1290B1CEE00CF4755 /* NetworkExtension.framework in Frameworks */, ); @@ -144,11 +139,9 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 8D5047F52CE6AA1E009802E9 /* libresolv.9.tbd in Frameworks */, - 8D5047F62CE6AA1E009802E9 /* libresolv.tbd in Frameworks */, + 8DC333FB2D2FA89100E627D5 /* SystemConfiguration.framework in Frameworks */, 8D5047F82CE6AA22009802E9 /* FirezoneKit in Frameworks */, 8DC9FB852CF5A738001BCE6A /* NetworkExtension.framework in Frameworks */, - 8D5047FA2CE6AA2E009802E9 /* SystemConfiguration.framework in Frameworks */, 8D4087D92D246541005B2BAF /* Sentry in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -198,13 +191,10 @@ 8D3F90C328D64FAD00980124 /* Frameworks */ = { isa = PBXGroup; children = ( - 8D5047F92CE6AA2E009802E9 /* SystemConfiguration.framework */, 8DC08BD12B297B7B00675F46 /* libresolv.tbd */, - 8DC08BD32B297B8200675F46 /* libresolv.tbd */, - 8D5047F42CE6AA1E009802E9 /* libresolv.tbd */, - 8DC08BCA2B296C4500675F46 /* libresolv.9.tbd */, 8DC08BCC2B296C5900675F46 /* libresolv.9.tbd */, - 8D5047F32CE6AA1E009802E9 /* libresolv.9.tbd */, + 8DC333F72D2FA85200E627D5 /* libresolv.tbd */, + 8DC333F82D2FA85200E627D5 /* libresolv.9.tbd */, 6FFECD5B2AD6998400E00273 /* SystemConfiguration.framework */, 05D3BB1628FDBD8A00BC3727 /* NetworkExtension.framework */, ); @@ -270,7 +260,6 @@ buildConfigurationList = 05CF1CFA290B1CEE00CF4755 /* Build configuration list for PBXNativeTarget "FirezoneNetworkExtensioniOS" */; buildPhases = ( 8D8555832D0A7CBB00A1EA09 /* Build Connlib */, - 6F3E231A2A5D830D00737CF1 /* Copy Connlib Headers and Swift Files */, 05CF1CEC290B1CEE00CF4755 /* Sources */, 05CF1CED290B1CEE00CF4755 /* Frameworks */, 05CF1CEE290B1CEE00CF4755 /* Resources */, @@ -293,7 +282,6 @@ buildConfigurationList = 8D5047F02CE6A8F4009802E9 /* Build configuration list for PBXNativeTarget "FirezoneNetworkExtensionmacOS" */; buildPhases = ( 8D8555822D0A796100A1EA09 /* Build Connlib */, - 8D5048072CE6B243009802E9 /* Copy Connlib Headers and Swift Files */, 8D5047DF2CE6A8F4009802E9 /* Sources */, 8D5047E02CE6A8F4009802E9 /* Frameworks */, 8D5047E12CE6A8F4009802E9 /* Resources */, @@ -411,64 +399,21 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ - 6F3E231A2A5D830D00737CF1 /* Copy Connlib Headers and Swift Files */ = { - isa = PBXShellScriptBuildPhase; - 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; - }; - 8D5048072CE6B243009802E9 /* Copy Connlib Headers and Swift Files */ = { - isa = PBXShellScriptBuildPhase; - 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; - }; 8D8555822D0A796100A1EA09 /* Build Connlib */ = { isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); inputFileListPaths = ( ); inputPaths = ( - "$(SRCROOT)/../../rust/**/*.rs", - "$(SRCROOT)/../../rust/**/*.toml", - "$(SRCROOT)/../../rust/Cargo.lock", ); name = "Build Connlib"; outputFileListPaths = ( + "$(SRCROOT)/FirezoneNetworkExtension/Connlib.xcfilelist", ); outputPaths = ( - "$(SRCROOT)/../../rust/target/*-apple-*/debug/libconnlib.a", - "$(SRCROOT)/../../rust/target/*-apple-*/release/libconnlib.a", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; @@ -476,26 +421,23 @@ }; 8D8555832D0A7CBB00A1EA09 /* Build Connlib */ = { isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); inputFileListPaths = ( ); inputPaths = ( - "$(SRCROOT)/../../rust/**/*.rs", - "$(SRCROOT)/../../rust/**/*.toml", - "$(SRCROOT)/../../rust/Cargo.lock", ); name = "Build Connlib"; outputFileListPaths = ( + "$(SRCROOT)/FirezoneNetworkExtension/Connlib.xcfilelist", ); outputPaths = ( - "$(SRCROOT)/../../rust/target/*-apple-*/debug/libconnlib.a", - "$(SRCROOT)/../../rust/target/*-apple-*/release/libconnlib.a", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "# Type a script or drag a script file from your workspace to insert its path.\ncd ../../rust/connlib/clients/apple\n./build-rust.sh\n"; + shellScript = "cd ../../rust/connlib/clients/apple\n./build-rust.sh\n"; }; 8DE721892ACA295200E395D5 /* swift-format */ = { isa = PBXShellScriptBuildPhase; diff --git a/swift/apple/FirezoneNetworkExtension/Connlib/Generated/SwiftBridgeCore.h b/swift/apple/FirezoneNetworkExtension/Connlib/Generated/SwiftBridgeCore.h new file mode 100644 index 000000000..b1b1f60ea --- /dev/null +++ b/swift/apple/FirezoneNetworkExtension/Connlib/Generated/SwiftBridgeCore.h @@ -0,0 +1,164 @@ +#include +#include +typedef struct RustStr { uint8_t* const start; uintptr_t len; } RustStr; +typedef struct __private__FfiSlice { void* const start; uintptr_t len; } __private__FfiSlice; +void* __swift_bridge__null_pointer(void); + + +typedef struct __private__OptionU8 { uint8_t val; bool is_some; } __private__OptionU8; +typedef struct __private__OptionI8 { int8_t val; bool is_some; } __private__OptionI8; +typedef struct __private__OptionU16 { uint16_t val; bool is_some; } __private__OptionU16; +typedef struct __private__OptionI16 { int16_t val; bool is_some; } __private__OptionI16; +typedef struct __private__OptionU32 { uint32_t val; bool is_some; } __private__OptionU32; +typedef struct __private__OptionI32 { int32_t val; bool is_some; } __private__OptionI32; +typedef struct __private__OptionU64 { uint64_t val; bool is_some; } __private__OptionU64; +typedef struct __private__OptionI64 { int64_t val; bool is_some; } __private__OptionI64; +typedef struct __private__OptionUsize { uintptr_t val; bool is_some; } __private__OptionUsize; +typedef struct __private__OptionIsize { intptr_t val; bool is_some; } __private__OptionIsize; +typedef struct __private__OptionF32 { float val; bool is_some; } __private__OptionF32; +typedef struct __private__OptionF64 { double val; bool is_some; } __private__OptionF64; +typedef struct __private__OptionBool { bool val; bool is_some; } __private__OptionBool; + +void* __swift_bridge__$Vec_u8$new(); +void __swift_bridge__$Vec_u8$_free(void* const vec); +uintptr_t __swift_bridge__$Vec_u8$len(void* const vec); +void __swift_bridge__$Vec_u8$push(void* const vec, uint8_t val); +__private__OptionU8 __swift_bridge__$Vec_u8$pop(void* const vec); +__private__OptionU8 __swift_bridge__$Vec_u8$get(void* const vec, uintptr_t index); +__private__OptionU8 __swift_bridge__$Vec_u8$get_mut(void* const vec, uintptr_t index); +uint8_t const * __swift_bridge__$Vec_u8$as_ptr(void* const vec); + +void* __swift_bridge__$Vec_u16$new(); +void __swift_bridge__$Vec_u16$_free(void* const vec); +uintptr_t __swift_bridge__$Vec_u16$len(void* const vec); +void __swift_bridge__$Vec_u16$push(void* const vec, uint16_t val); +__private__OptionU16 __swift_bridge__$Vec_u16$pop(void* const vec); +__private__OptionU16 __swift_bridge__$Vec_u16$get(void* const vec, uintptr_t index); +__private__OptionU16 __swift_bridge__$Vec_u16$get_mut(void* const vec, uintptr_t index); +uint16_t const * __swift_bridge__$Vec_u16$as_ptr(void* const vec); + +void* __swift_bridge__$Vec_u32$new(); +void __swift_bridge__$Vec_u32$_free(void* const vec); +uintptr_t __swift_bridge__$Vec_u32$len(void* const vec); +void __swift_bridge__$Vec_u32$push(void* const vec, uint32_t val); +__private__OptionU32 __swift_bridge__$Vec_u32$pop(void* const vec); +__private__OptionU32 __swift_bridge__$Vec_u32$get(void* const vec, uintptr_t index); +__private__OptionU32 __swift_bridge__$Vec_u32$get_mut(void* const vec, uintptr_t index); +uint32_t const * __swift_bridge__$Vec_u32$as_ptr(void* const vec); + +void* __swift_bridge__$Vec_u64$new(); +void __swift_bridge__$Vec_u64$_free(void* const vec); +uintptr_t __swift_bridge__$Vec_u64$len(void* const vec); +void __swift_bridge__$Vec_u64$push(void* const vec, uint64_t val); +__private__OptionU64 __swift_bridge__$Vec_u64$pop(void* const vec); +__private__OptionU64 __swift_bridge__$Vec_u64$get(void* const vec, uintptr_t index); +__private__OptionU64 __swift_bridge__$Vec_u64$get_mut(void* const vec, uintptr_t index); +uint64_t const * __swift_bridge__$Vec_u64$as_ptr(void* const vec); + +void* __swift_bridge__$Vec_usize$new(); +void __swift_bridge__$Vec_usize$_free(void* const vec); +uintptr_t __swift_bridge__$Vec_usize$len(void* const vec); +void __swift_bridge__$Vec_usize$push(void* const vec, uintptr_t val); +__private__OptionUsize __swift_bridge__$Vec_usize$pop(void* const vec); +__private__OptionUsize __swift_bridge__$Vec_usize$get(void* const vec, uintptr_t index); +__private__OptionUsize __swift_bridge__$Vec_usize$get_mut(void* const vec, uintptr_t index); +uintptr_t const * __swift_bridge__$Vec_usize$as_ptr(void* const vec); + +void* __swift_bridge__$Vec_i8$new(); +void __swift_bridge__$Vec_i8$_free(void* const vec); +uintptr_t __swift_bridge__$Vec_i8$len(void* const vec); +void __swift_bridge__$Vec_i8$push(void* const vec, int8_t val); +__private__OptionI8 __swift_bridge__$Vec_i8$pop(void* const vec); +__private__OptionI8 __swift_bridge__$Vec_i8$get(void* const vec, uintptr_t index); +__private__OptionI8 __swift_bridge__$Vec_i8$get_mut(void* const vec, uintptr_t index); +int8_t const * __swift_bridge__$Vec_i8$as_ptr(void* const vec); + +void* __swift_bridge__$Vec_i16$new(); +void __swift_bridge__$Vec_i16$_free(void* const vec); +uintptr_t __swift_bridge__$Vec_i16$len(void* const vec); +void __swift_bridge__$Vec_i16$push(void* const vec, int16_t val); +__private__OptionI16 __swift_bridge__$Vec_i16$pop(void* const vec); +__private__OptionI16 __swift_bridge__$Vec_i16$get(void* const vec, uintptr_t index); +__private__OptionI16 __swift_bridge__$Vec_i16$get_mut(void* const vec, uintptr_t index); +int16_t const * __swift_bridge__$Vec_i16$as_ptr(void* const vec); + +void* __swift_bridge__$Vec_i32$new(); +void __swift_bridge__$Vec_i32$_free(void* const vec); +uintptr_t __swift_bridge__$Vec_i32$len(void* const vec); +void __swift_bridge__$Vec_i32$push(void* const vec, int32_t val); +__private__OptionI32 __swift_bridge__$Vec_i32$pop(void* const vec); +__private__OptionI32 __swift_bridge__$Vec_i32$get(void* const vec, uintptr_t index); +__private__OptionI32 __swift_bridge__$Vec_i32$get_mut(void* const vec, uintptr_t index); +int32_t const * __swift_bridge__$Vec_i32$as_ptr(void* const vec); + +void* __swift_bridge__$Vec_i64$new(); +void __swift_bridge__$Vec_i64$_free(void* const vec); +uintptr_t __swift_bridge__$Vec_i64$len(void* const vec); +void __swift_bridge__$Vec_i64$push(void* const vec, int64_t val); +__private__OptionI64 __swift_bridge__$Vec_i64$pop(void* const vec); +__private__OptionI64 __swift_bridge__$Vec_i64$get(void* const vec, uintptr_t index); +__private__OptionI64 __swift_bridge__$Vec_i64$get_mut(void* const vec, uintptr_t index); +int64_t const * __swift_bridge__$Vec_i64$as_ptr(void* const vec); + +void* __swift_bridge__$Vec_isize$new(); +void __swift_bridge__$Vec_isize$_free(void* const vec); +uintptr_t __swift_bridge__$Vec_isize$len(void* const vec); +void __swift_bridge__$Vec_isize$push(void* const vec, intptr_t val); +__private__OptionIsize __swift_bridge__$Vec_isize$pop(void* const vec); +__private__OptionIsize __swift_bridge__$Vec_isize$get(void* const vec, uintptr_t index); +__private__OptionIsize __swift_bridge__$Vec_isize$get_mut(void* const vec, uintptr_t index); +intptr_t const * __swift_bridge__$Vec_isize$as_ptr(void* const vec); + +void* __swift_bridge__$Vec_bool$new(); +void __swift_bridge__$Vec_bool$_free(void* const vec); +uintptr_t __swift_bridge__$Vec_bool$len(void* const vec); +void __swift_bridge__$Vec_bool$push(void* const vec, bool val); +__private__OptionBool __swift_bridge__$Vec_bool$pop(void* const vec); +__private__OptionBool __swift_bridge__$Vec_bool$get(void* const vec, uintptr_t index); +__private__OptionBool __swift_bridge__$Vec_bool$get_mut(void* const vec, uintptr_t index); +bool const * __swift_bridge__$Vec_bool$as_ptr(void* const vec); + +void* __swift_bridge__$Vec_f32$new(); +void __swift_bridge__$Vec_f32$_free(void* const vec); +uintptr_t __swift_bridge__$Vec_f32$len(void* const vec); +void __swift_bridge__$Vec_f32$push(void* const vec, float val); +__private__OptionF32 __swift_bridge__$Vec_f32$pop(void* const vec); +__private__OptionF32 __swift_bridge__$Vec_f32$get(void* const vec, uintptr_t index); +__private__OptionF32 __swift_bridge__$Vec_f32$get_mut(void* const vec, uintptr_t index); +float const * __swift_bridge__$Vec_f32$as_ptr(void* const vec); + +void* __swift_bridge__$Vec_f64$new(); +void __swift_bridge__$Vec_f64$_free(void* const vec); +uintptr_t __swift_bridge__$Vec_f64$len(void* const vec); +void __swift_bridge__$Vec_f64$push(void* const vec, double val); +__private__OptionF64 __swift_bridge__$Vec_f64$pop(void* const vec); +__private__OptionF64 __swift_bridge__$Vec_f64$get(void* const vec, uintptr_t index); +__private__OptionF64 __swift_bridge__$Vec_f64$get_mut(void* const vec, uintptr_t index); +double const * __swift_bridge__$Vec_f64$as_ptr(void* const vec); + +#include +typedef struct RustString RustString; +void __swift_bridge__$RustString$_free(void* self); + +void* __swift_bridge__$Vec_RustString$new(void); +void __swift_bridge__$Vec_RustString$drop(void* vec_ptr); +void __swift_bridge__$Vec_RustString$push(void* vec_ptr, void* item_ptr); +void* __swift_bridge__$Vec_RustString$pop(void* vec_ptr); +void* __swift_bridge__$Vec_RustString$get(void* vec_ptr, uintptr_t index); +void* __swift_bridge__$Vec_RustString$get_mut(void* vec_ptr, uintptr_t index); +uintptr_t __swift_bridge__$Vec_RustString$len(void* vec_ptr); +void* __swift_bridge__$Vec_RustString$as_ptr(void* vec_ptr); + +void* __swift_bridge__$RustString$new(void); +void* __swift_bridge__$RustString$new_with_str(struct RustStr str); +uintptr_t __swift_bridge__$RustString$len(void* self); +struct RustStr __swift_bridge__$RustString$as_str(void* self); +struct RustStr __swift_bridge__$RustString$trim(void* self); +bool __swift_bridge__$RustStr$partial_eq(struct RustStr lhs, struct RustStr rhs); + + +void __swift_bridge__$call_boxed_fn_once_no_args_no_return(void* boxed_fnonce); +void __swift_bridge__$free_boxed_fn_once_no_args_no_return(void* boxed_fnonce); + + +struct __private__ResultPtrAndPtr { bool is_ok; void* ok_or_err; }; diff --git a/swift/apple/FirezoneNetworkExtension/Connlib/Generated/SwiftBridgeCore.swift b/swift/apple/FirezoneNetworkExtension/Connlib/Generated/SwiftBridgeCore.swift new file mode 100644 index 000000000..35d2e8acb --- /dev/null +++ b/swift/apple/FirezoneNetworkExtension/Connlib/Generated/SwiftBridgeCore.swift @@ -0,0 +1,1322 @@ +import Foundation + +extension RustString { + public func toString() -> String { + let str = self.as_str() + let string = str.toString() + + return string + } +} + +extension RustStr { + func toBufferPointer() -> UnsafeBufferPointer { + let bytes = UnsafeBufferPointer(start: self.start, count: Int(self.len)) + return bytes + } + + public func toString() -> String { + let bytes = self.toBufferPointer() + return String(bytes: bytes, encoding: .utf8)! + } +} +extension RustStr: Identifiable { + public var id: String { + self.toString() + } +} +extension RustStr: Equatable { + public static func == (lhs: RustStr, rhs: RustStr) -> Bool { + return __swift_bridge__$RustStr$partial_eq(lhs, rhs); + } +} + +public protocol IntoRustString { + func intoRustString() -> RustString; +} + +extension String: IntoRustString { + public func intoRustString() -> RustString { + // TODO: When passing an owned Swift std String to Rust we've being wasteful here in that + // we're creating a RustString (which involves Boxing a Rust std::string::String) + // only to unbox it back into a String once it gets to the Rust side. + // + // A better approach would be to pass a RustStr to the Rust side and then have Rust + // call `.to_string()` on the RustStr. + RustString(self) + } +} + +extension RustString: IntoRustString { + public func intoRustString() -> RustString { + self + } +} + +/// If the String is Some: +/// Safely get a scoped pointer to the String and then call the callback with a RustStr +/// that uses that pointer. +/// +/// If the String is None: +/// Call the callback with a RustStr that has a null pointer. +/// The Rust side will know to treat this as `None`. +func optionalStringIntoRustString(_ string: Optional) -> RustString? { + if let val = string { + return val.intoRustString() + } else { + return nil + } +} + +/// Used to safely get a pointer to a sequence of utf8 bytes, represented as a `RustStr`. +/// +/// For example, the Swift `String` implementation of the `ToRustStr` protocol does the following: +/// 1. Use Swift's `String.utf8.withUnsafeBufferPointer` to get a pointer to the strings underlying +/// utf8 bytes. +/// 2. Construct a `RustStr` that points to these utf8 bytes. This is safe because `withUnsafeBufferPointer` +/// guarantees that the buffer pointer will be valid for the duration of the `withUnsafeBufferPointer` +/// callback. +/// 3. Pass the `RustStr` to the closure that was passed into `RustStr.toRustStr`. +public protocol ToRustStr { + func toRustStr (_ withUnsafeRustStr: (RustStr) -> T) -> T; +} + +extension String: ToRustStr { + /// Safely get a scoped pointer to the String and then call the callback with a RustStr + /// that uses that pointer. + public func toRustStr (_ withUnsafeRustStr: (RustStr) -> T) -> T { + return self.utf8CString.withUnsafeBufferPointer({ bufferPtr in + let rustStr = RustStr( + start: UnsafeMutableRawPointer(mutating: bufferPtr.baseAddress!).assumingMemoryBound(to: UInt8.self), + // Subtract 1 because of the null termination character at the end + len: UInt(bufferPtr.count - 1) + ) + return withUnsafeRustStr(rustStr) + }) + } +} + +extension RustStr: ToRustStr { + public func toRustStr (_ withUnsafeRustStr: (RustStr) -> T) -> T { + return withUnsafeRustStr(self) + } +} + +func optionalRustStrToRustStr(_ str: Optional, _ withUnsafeRustStr: (RustStr) -> T) -> T { + if let val = str { + return val.toRustStr(withUnsafeRustStr) + } else { + return withUnsafeRustStr(RustStr(start: nil, len: 0)) + } +} +public class RustVec { + var ptr: UnsafeMutableRawPointer + var isOwned: Bool = true + + public init(ptr: UnsafeMutableRawPointer) { + self.ptr = ptr + } + + public init() { + ptr = T.vecOfSelfNew() + isOwned = true + } + + public func push (value: T) { + T.vecOfSelfPush(vecPtr: ptr, value: value) + } + + public func pop () -> Optional { + T.vecOfSelfPop(vecPtr: ptr) + } + + public func get(index: UInt) -> Optional { + T.vecOfSelfGet(vecPtr: ptr, index: index) + } + + public func as_ptr() -> UnsafePointer { + UnsafePointer(OpaquePointer(T.vecOfSelfAsPtr(vecPtr: ptr))) + } + + /// Rust returns a UInt, but we cast to an Int because many Swift APIs such as + /// `ForEach(0..rustVec.len())` expect Int. + public func len() -> Int { + Int(T.vecOfSelfLen(vecPtr: ptr)) + } + + deinit { + if isOwned { + T.vecOfSelfFree(vecPtr: ptr) + } + } +} + +extension RustVec: Sequence { + public func makeIterator() -> RustVecIterator { + return RustVecIterator(self) + } +} + +public struct RustVecIterator: IteratorProtocol { + var rustVec: RustVec + var index: UInt = 0 + + init (_ rustVec: RustVec) { + self.rustVec = rustVec + } + + public mutating func next() -> T.SelfRef? { + let val = rustVec.get(index: index) + index += 1 + return val + } +} + +extension RustVec: Collection { + public typealias Index = Int + + public func index(after i: Int) -> Int { + i + 1 + } + + public subscript(position: Int) -> T.SelfRef { + self.get(index: UInt(position))! + } + + public var startIndex: Int { + 0 + } + + public var endIndex: Int { + self.len() + } +} + +extension RustVec: RandomAccessCollection {} + +extension UnsafeBufferPointer { + func toFfiSlice () -> __private__FfiSlice { + __private__FfiSlice(start: UnsafeMutablePointer(mutating: self.baseAddress), len: UInt(self.count)) + } +} + +public protocol Vectorizable { + associatedtype SelfRef + associatedtype SelfRefMut + + static func vecOfSelfNew() -> UnsafeMutableRawPointer; + + static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) + + static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) + + static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional + + static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional + + static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional + + static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer + + static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt +} + +extension UInt8: Vectorizable { + public static func vecOfSelfNew() -> UnsafeMutableRawPointer { + __swift_bridge__$Vec_u8$new() + } + + public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { + __swift_bridge__$Vec_u8$_free(vecPtr) + } + + public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { + __swift_bridge__$Vec_u8$push(vecPtr, value) + } + + public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { + let val = __swift_bridge__$Vec_u8$pop(vecPtr) + if val.is_some { + return val.val + } else { + return nil + } + } + + public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { + let val = __swift_bridge__$Vec_u8$get(vecPtr, index) + if val.is_some { + return val.val + } else { + return nil + } + } + + public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { + let val = __swift_bridge__$Vec_u8$get_mut(vecPtr, index) + if val.is_some { + return val.val + } else { + return nil + } + } + + public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { + UnsafePointer(OpaquePointer(__swift_bridge__$Vec_u8$as_ptr(vecPtr))) + } + + public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { + __swift_bridge__$Vec_u8$len(vecPtr) + } +} + +extension UInt16: Vectorizable { + public static func vecOfSelfNew() -> UnsafeMutableRawPointer { + __swift_bridge__$Vec_u16$new() + } + + public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { + __swift_bridge__$Vec_u16$_free(vecPtr) + } + + public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { + __swift_bridge__$Vec_u16$push(vecPtr, value) + } + + public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { + let val = __swift_bridge__$Vec_u16$pop(vecPtr) + if val.is_some { + return val.val + } else { + return nil + } + } + + public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { + let val = __swift_bridge__$Vec_u16$get(vecPtr, index) + if val.is_some { + return val.val + } else { + return nil + } + } + + public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { + let val = __swift_bridge__$Vec_u16$get_mut(vecPtr, index) + if val.is_some { + return val.val + } else { + return nil + } + } + + public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { + UnsafePointer(OpaquePointer(__swift_bridge__$Vec_u16$as_ptr(vecPtr))) + } + + public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { + __swift_bridge__$Vec_u16$len(vecPtr) + } +} + +extension UInt32: Vectorizable { + public static func vecOfSelfNew() -> UnsafeMutableRawPointer { + __swift_bridge__$Vec_u32$new() + } + + public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { + __swift_bridge__$Vec_u32$_free(vecPtr) + } + + public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { + __swift_bridge__$Vec_u32$push(vecPtr, value) + } + + public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { + let val = __swift_bridge__$Vec_u32$pop(vecPtr) + if val.is_some { + return val.val + } else { + return nil + } + } + + public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { + let val = __swift_bridge__$Vec_u32$get(vecPtr, index) + if val.is_some { + return val.val + } else { + return nil + } + } + + public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { + let val = __swift_bridge__$Vec_u32$get_mut(vecPtr, index) + if val.is_some { + return val.val + } else { + return nil + } + } + + public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { + UnsafePointer(OpaquePointer(__swift_bridge__$Vec_u32$as_ptr(vecPtr))) + } + + public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { + __swift_bridge__$Vec_u32$len(vecPtr) + } +} + +extension UInt64: Vectorizable { + public static func vecOfSelfNew() -> UnsafeMutableRawPointer { + __swift_bridge__$Vec_u64$new() + } + + public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { + __swift_bridge__$Vec_u64$_free(vecPtr) + } + + public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { + __swift_bridge__$Vec_u64$push(vecPtr, value) + } + + public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { + let val = __swift_bridge__$Vec_u64$pop(vecPtr) + if val.is_some { + return val.val + } else { + return nil + } + } + + public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { + let val = __swift_bridge__$Vec_u64$get(vecPtr, index) + if val.is_some { + return val.val + } else { + return nil + } + } + + public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { + let val = __swift_bridge__$Vec_u64$get_mut(vecPtr, index) + if val.is_some { + return val.val + } else { + return nil + } + } + + public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { + UnsafePointer(OpaquePointer(__swift_bridge__$Vec_u64$as_ptr(vecPtr))) + } + + public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { + __swift_bridge__$Vec_u64$len(vecPtr) + } +} + +extension UInt: Vectorizable { + public static func vecOfSelfNew() -> UnsafeMutableRawPointer { + __swift_bridge__$Vec_usize$new() + } + + public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { + __swift_bridge__$Vec_usize$_free(vecPtr) + } + + public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { + __swift_bridge__$Vec_usize$push(vecPtr, value) + } + + public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { + let val = __swift_bridge__$Vec_usize$pop(vecPtr) + if val.is_some { + return val.val + } else { + return nil + } + } + + public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { + let val = __swift_bridge__$Vec_usize$get(vecPtr, index) + if val.is_some { + return val.val + } else { + return nil + } + } + + public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { + let val = __swift_bridge__$Vec_usize$get_mut(vecPtr, index) + if val.is_some { + return val.val + } else { + return nil + } + } + + public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { + UnsafePointer(OpaquePointer(__swift_bridge__$Vec_usize$as_ptr(vecPtr))) + } + + public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { + __swift_bridge__$Vec_usize$len(vecPtr) + } +} + +extension Int8: Vectorizable { + public static func vecOfSelfNew() -> UnsafeMutableRawPointer { + __swift_bridge__$Vec_i8$new() + } + + public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { + __swift_bridge__$Vec_i8$_free(vecPtr) + } + + public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { + __swift_bridge__$Vec_i8$push(vecPtr, value) + } + + public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { + let val = __swift_bridge__$Vec_i8$pop(vecPtr) + if val.is_some { + return val.val + } else { + return nil + } + } + + public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { + let val = __swift_bridge__$Vec_i8$get(vecPtr, index) + if val.is_some { + return val.val + } else { + return nil + } + } + + public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { + let val = __swift_bridge__$Vec_i8$get_mut(vecPtr, index) + if val.is_some { + return val.val + } else { + return nil + } + } + + public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { + UnsafePointer(OpaquePointer(__swift_bridge__$Vec_i8$as_ptr(vecPtr))) + } + + public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { + __swift_bridge__$Vec_i8$len(vecPtr) + } +} + +extension Int16: Vectorizable { + public static func vecOfSelfNew() -> UnsafeMutableRawPointer { + __swift_bridge__$Vec_i16$new() + } + + public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { + __swift_bridge__$Vec_i16$_free(vecPtr) + } + + public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { + __swift_bridge__$Vec_i16$push(vecPtr, value) + } + + public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { + let val = __swift_bridge__$Vec_i16$pop(vecPtr) + if val.is_some { + return val.val + } else { + return nil + } + } + + public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { + let val = __swift_bridge__$Vec_i16$get(vecPtr, index) + if val.is_some { + return val.val + } else { + return nil + } + } + + public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { + let val = __swift_bridge__$Vec_i16$get_mut(vecPtr, index) + if val.is_some { + return val.val + } else { + return nil + } + } + + public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { + UnsafePointer(OpaquePointer(__swift_bridge__$Vec_i16$as_ptr(vecPtr))) + } + + public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { + __swift_bridge__$Vec_i16$len(vecPtr) + } +} + +extension Int32: Vectorizable { + public static func vecOfSelfNew() -> UnsafeMutableRawPointer { + __swift_bridge__$Vec_i32$new() + } + + public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { + __swift_bridge__$Vec_i32$_free(vecPtr) + } + + public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { + __swift_bridge__$Vec_i32$push(vecPtr, value) + } + + public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { + let val = __swift_bridge__$Vec_i32$pop(vecPtr) + if val.is_some { + return val.val + } else { + return nil + } + } + + public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { + let val = __swift_bridge__$Vec_i32$get(vecPtr, index) + if val.is_some { + return val.val + } else { + return nil + } + } + + public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { + let val = __swift_bridge__$Vec_i32$get_mut(vecPtr, index) + if val.is_some { + return val.val + } else { + return nil + } + } + + public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { + UnsafePointer(OpaquePointer(__swift_bridge__$Vec_i32$as_ptr(vecPtr))) + } + + public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { + __swift_bridge__$Vec_i32$len(vecPtr) + } +} + +extension Int64: Vectorizable { + public static func vecOfSelfNew() -> UnsafeMutableRawPointer { + __swift_bridge__$Vec_i64$new() + } + + public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { + __swift_bridge__$Vec_i64$_free(vecPtr) + } + + public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { + __swift_bridge__$Vec_i64$push(vecPtr, value) + } + + public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { + let val = __swift_bridge__$Vec_i64$pop(vecPtr) + if val.is_some { + return val.val + } else { + return nil + } + } + + public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { + let val = __swift_bridge__$Vec_i64$get(vecPtr, index) + if val.is_some { + return val.val + } else { + return nil + } + } + + public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { + let val = __swift_bridge__$Vec_i64$get_mut(vecPtr, index) + if val.is_some { + return val.val + } else { + return nil + } + } + + public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { + UnsafePointer(OpaquePointer(__swift_bridge__$Vec_i64$as_ptr(vecPtr))) + } + + public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { + __swift_bridge__$Vec_i64$len(vecPtr) + } +} + +extension Int: Vectorizable { + public static func vecOfSelfNew() -> UnsafeMutableRawPointer { + __swift_bridge__$Vec_isize$new() + } + + public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { + __swift_bridge__$Vec_isize$_free(vecPtr) + } + + public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { + __swift_bridge__$Vec_isize$push(vecPtr, value) + } + + public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { + let val = __swift_bridge__$Vec_isize$pop(vecPtr) + if val.is_some { + return val.val + } else { + return nil + } + } + + public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { + let val = __swift_bridge__$Vec_isize$get(vecPtr, index) + if val.is_some { + return val.val + } else { + return nil + } + } + + public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { + let val = __swift_bridge__$Vec_isize$get_mut(vecPtr, index) + if val.is_some { + return val.val + } else { + return nil + } + } + + public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { + UnsafePointer(OpaquePointer(__swift_bridge__$Vec_isize$as_ptr(vecPtr))) + } + + public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { + __swift_bridge__$Vec_isize$len(vecPtr) + } +} + +extension Bool: Vectorizable { + public static func vecOfSelfNew() -> UnsafeMutableRawPointer { + __swift_bridge__$Vec_bool$new() + } + + public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { + __swift_bridge__$Vec_bool$_free(vecPtr) + } + + public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { + __swift_bridge__$Vec_bool$push(vecPtr, value) + } + + public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { + let val = __swift_bridge__$Vec_bool$pop(vecPtr) + if val.is_some { + return val.val + } else { + return nil + } + } + + public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { + let val = __swift_bridge__$Vec_bool$get(vecPtr, index) + if val.is_some { + return val.val + } else { + return nil + } + } + + public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { + let val = __swift_bridge__$Vec_bool$get_mut(vecPtr, index) + if val.is_some { + return val.val + } else { + return nil + } + } + + public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { + UnsafePointer(OpaquePointer(__swift_bridge__$Vec_bool$as_ptr(vecPtr))) + } + + public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { + __swift_bridge__$Vec_bool$len(vecPtr) + } +} + +extension Float: Vectorizable { + public static func vecOfSelfNew() -> UnsafeMutableRawPointer { + __swift_bridge__$Vec_f32$new() + } + + public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { + __swift_bridge__$Vec_f32$_free(vecPtr) + } + + public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { + __swift_bridge__$Vec_f32$push(vecPtr, value) + } + + public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { + let val = __swift_bridge__$Vec_f32$pop(vecPtr) + if val.is_some { + return val.val + } else { + return nil + } + } + + public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { + let val = __swift_bridge__$Vec_f32$get(vecPtr, index) + if val.is_some { + return val.val + } else { + return nil + } + } + + public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { + let val = __swift_bridge__$Vec_f32$get_mut(vecPtr, index) + if val.is_some { + return val.val + } else { + return nil + } + } + + public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { + UnsafePointer(OpaquePointer(__swift_bridge__$Vec_f32$as_ptr(vecPtr))) + } + + public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { + __swift_bridge__$Vec_f32$len(vecPtr) + } +} + +extension Double: Vectorizable { + public static func vecOfSelfNew() -> UnsafeMutableRawPointer { + __swift_bridge__$Vec_f64$new() + } + + public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { + __swift_bridge__$Vec_f64$_free(vecPtr) + } + + public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: Self) { + __swift_bridge__$Vec_f64$push(vecPtr, value) + } + + public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { + let val = __swift_bridge__$Vec_f64$pop(vecPtr) + if val.is_some { + return val.val + } else { + return nil + } + } + + public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { + let val = __swift_bridge__$Vec_f64$get(vecPtr, index) + if val.is_some { + return val.val + } else { + return nil + } + } + + public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { + let val = __swift_bridge__$Vec_f64$get_mut(vecPtr, index) + if val.is_some { + return val.val + } else { + return nil + } + } + + public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { + UnsafePointer(OpaquePointer(__swift_bridge__$Vec_f64$as_ptr(vecPtr))) + } + + public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { + __swift_bridge__$Vec_f64$len(vecPtr) + } +} + +protocol SwiftBridgeGenericFreer { + func rust_free(); +} + +protocol SwiftBridgeGenericCopyTypeFfiRepr {} + +public class RustString: RustStringRefMut { + var isOwned: Bool = true + + public override init(ptr: UnsafeMutableRawPointer) { + super.init(ptr: ptr) + } + + deinit { + if isOwned { + __swift_bridge__$RustString$_free(ptr) + } + } +} +extension RustString { + public convenience init() { + self.init(ptr: __swift_bridge__$RustString$new()) + } + + public convenience init(_ str: GenericToRustStr) { + self.init(ptr: str.toRustStr({ strAsRustStr in + __swift_bridge__$RustString$new_with_str(strAsRustStr) + })) + } +} +public class RustStringRefMut: RustStringRef { + public override init(ptr: UnsafeMutableRawPointer) { + super.init(ptr: ptr) + } +} +public class RustStringRef { + var ptr: UnsafeMutableRawPointer + + public init(ptr: UnsafeMutableRawPointer) { + self.ptr = ptr + } +} +extension RustStringRef { + public func len() -> UInt { + __swift_bridge__$RustString$len(ptr) + } + + public func as_str() -> RustStr { + __swift_bridge__$RustString$as_str(ptr) + } + + public func trim() -> RustStr { + __swift_bridge__$RustString$trim(ptr) + } +} +extension RustString: Vectorizable { + public static func vecOfSelfNew() -> UnsafeMutableRawPointer { + __swift_bridge__$Vec_RustString$new() + } + + public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { + __swift_bridge__$Vec_RustString$drop(vecPtr) + } + + public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: RustString) { + __swift_bridge__$Vec_RustString$push(vecPtr, {value.isOwned = false; return value.ptr;}()) + } + + public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { + let pointer = __swift_bridge__$Vec_RustString$pop(vecPtr) + if pointer == nil { + return nil + } else { + return (RustString(ptr: pointer!) as! Self) + } + } + + public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { + let pointer = __swift_bridge__$Vec_RustString$get(vecPtr, index) + if pointer == nil { + return nil + } else { + return RustStringRef(ptr: pointer!) + } + } + + public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { + let pointer = __swift_bridge__$Vec_RustString$get_mut(vecPtr, index) + if pointer == nil { + return nil + } else { + return RustStringRefMut(ptr: pointer!) + } + } + + public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { + UnsafePointer(OpaquePointer(__swift_bridge__$Vec_RustString$as_ptr(vecPtr))) + } + + public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { + __swift_bridge__$Vec_RustString$len(vecPtr) + } +} + +public class __private__RustFnOnceCallbackNoArgsNoRet { + var ptr: UnsafeMutableRawPointer + var called = false + + init(ptr: UnsafeMutableRawPointer) { + self.ptr = ptr + } + + deinit { + if !called { + __swift_bridge__$free_boxed_fn_once_no_args_no_return(ptr) + } + } + + func call() { + if called { + fatalError("Cannot call a Rust FnOnce function twice") + } + called = true + return __swift_bridge__$call_boxed_fn_once_no_args_no_return(ptr) + } +} + + +public enum RustResult { + case Ok(T) + case Err(E) +} + +extension RustResult { + func ok() -> T? { + switch self { + case .Ok(let ok): + return ok + case .Err(_): + return nil + } + } + + func err() -> E? { + switch self { + case .Ok(_): + return nil + case .Err(let err): + return err + } + } + + func toResult() -> Result + where E: Error { + switch self { + case .Ok(let ok): + return .success(ok) + case .Err(let err): + return .failure(err) + } + } +} + + +extension __private__OptionU8 { + func intoSwiftRepr() -> Optional { + if self.is_some { + return self.val + } else { + return nil + } + } + + init(_ val: Optional) { + if let val = val { + self = Self(val: val, is_some: true) + } else { + self = Self(val: 123, is_some: false) + } + } +} +extension Optional where Wrapped == UInt8 { + func intoFfiRepr() -> __private__OptionU8 { + __private__OptionU8(self) + } +} + +extension __private__OptionI8 { + func intoSwiftRepr() -> Optional { + if self.is_some { + return self.val + } else { + return nil + } + } + + init(_ val: Optional) { + if let val = val { + self = Self(val: val, is_some: true) + } else { + self = Self(val: 123, is_some: false) + } + } +} +extension Optional where Wrapped == Int8 { + func intoFfiRepr() -> __private__OptionI8 { + __private__OptionI8(self) + } +} + +extension __private__OptionU16 { + func intoSwiftRepr() -> Optional { + if self.is_some { + return self.val + } else { + return nil + } + } + + init(_ val: Optional) { + if let val = val { + self = Self(val: val, is_some: true) + } else { + self = Self(val: 123, is_some: false) + } + } +} +extension Optional where Wrapped == UInt16 { + func intoFfiRepr() -> __private__OptionU16 { + __private__OptionU16(self) + } +} + +extension __private__OptionI16 { + func intoSwiftRepr() -> Optional { + if self.is_some { + return self.val + } else { + return nil + } + } + + init(_ val: Optional) { + if let val = val { + self = Self(val: val, is_some: true) + } else { + self = Self(val: 123, is_some: false) + } + } +} +extension Optional where Wrapped == Int16 { + func intoFfiRepr() -> __private__OptionI16 { + __private__OptionI16(self) + } +} + +extension __private__OptionU32 { + func intoSwiftRepr() -> Optional { + if self.is_some { + return self.val + } else { + return nil + } + } + + init(_ val: Optional) { + if let val = val { + self = Self(val: val, is_some: true) + } else { + self = Self(val: 123, is_some: false) + } + } +} +extension Optional where Wrapped == UInt32 { + func intoFfiRepr() -> __private__OptionU32 { + __private__OptionU32(self) + } +} + +extension __private__OptionI32 { + func intoSwiftRepr() -> Optional { + if self.is_some { + return self.val + } else { + return nil + } + } + + init(_ val: Optional) { + if let val = val { + self = Self(val: val, is_some: true) + } else { + self = Self(val: 123, is_some: false) + } + } +} +extension Optional where Wrapped == Int32 { + func intoFfiRepr() -> __private__OptionI32 { + __private__OptionI32(self) + } +} + +extension __private__OptionU64 { + func intoSwiftRepr() -> Optional { + if self.is_some { + return self.val + } else { + return nil + } + } + + init(_ val: Optional) { + if let val = val { + self = Self(val: val, is_some: true) + } else { + self = Self(val: 123, is_some: false) + } + } +} +extension Optional where Wrapped == UInt64 { + func intoFfiRepr() -> __private__OptionU64 { + __private__OptionU64(self) + } +} + +extension __private__OptionI64 { + func intoSwiftRepr() -> Optional { + if self.is_some { + return self.val + } else { + return nil + } + } + + init(_ val: Optional) { + if let val = val { + self = Self(val: val, is_some: true) + } else { + self = Self(val: 123, is_some: false) + } + } +} +extension Optional where Wrapped == Int64 { + func intoFfiRepr() -> __private__OptionI64 { + __private__OptionI64(self) + } +} + +extension __private__OptionUsize { + func intoSwiftRepr() -> Optional { + if self.is_some { + return self.val + } else { + return nil + } + } + + init(_ val: Optional) { + if let val = val { + self = Self(val: val, is_some: true) + } else { + self = Self(val: 123, is_some: false) + } + } +} +extension Optional where Wrapped == UInt { + func intoFfiRepr() -> __private__OptionUsize { + __private__OptionUsize(self) + } +} + +extension __private__OptionIsize { + func intoSwiftRepr() -> Optional { + if self.is_some { + return self.val + } else { + return nil + } + } + + init(_ val: Optional) { + if let val = val { + self = Self(val: val, is_some: true) + } else { + self = Self(val: 123, is_some: false) + } + } +} +extension Optional where Wrapped == Int { + func intoFfiRepr() -> __private__OptionIsize { + __private__OptionIsize(self) + } +} + +extension __private__OptionF32 { + func intoSwiftRepr() -> Optional { + if self.is_some { + return self.val + } else { + return nil + } + } + + init(_ val: Optional) { + if let val = val { + self = Self(val: val, is_some: true) + } else { + self = Self(val: 123.4, is_some: false) + } + } +} +extension Optional where Wrapped == Float { + func intoFfiRepr() -> __private__OptionF32 { + __private__OptionF32(self) + } +} + +extension __private__OptionF64 { + func intoSwiftRepr() -> Optional { + if self.is_some { + return self.val + } else { + return nil + } + } + + init(_ val: Optional) { + if let val = val { + self = Self(val: val, is_some: true) + } else { + self = Self(val: 123.4, is_some: false) + } + } +} +extension Optional where Wrapped == Double { + func intoFfiRepr() -> __private__OptionF64 { + __private__OptionF64(self) + } +} + +extension __private__OptionBool { + func intoSwiftRepr() -> Optional { + if self.is_some { + return self.val + } else { + return nil + } + } + + init(_ val: Optional) { + if let val = val { + self = Self(val: val, is_some: true) + } else { + self = Self(val: false, is_some: false) + } + } +} +extension Optional where Wrapped == Bool { + func intoFfiRepr() -> __private__OptionBool { + __private__OptionBool(self) + } +} diff --git a/swift/apple/FirezoneNetworkExtension/Connlib/Generated/connlib-client-apple/connlib-client-apple.h b/swift/apple/FirezoneNetworkExtension/Connlib/Generated/connlib-client-apple/connlib-client-apple.h new file mode 100644 index 000000000..662f4f926 --- /dev/null +++ b/swift/apple/FirezoneNetworkExtension/Connlib/Generated/connlib-client-apple/connlib-client-apple.h @@ -0,0 +1,20 @@ +// File automatically generated by swift-bridge. +typedef struct WrappedSession WrappedSession; +void __swift_bridge__$WrappedSession$_free(void* self); + +void* __swift_bridge__$Vec_WrappedSession$new(void); +void __swift_bridge__$Vec_WrappedSession$drop(void* vec_ptr); +void __swift_bridge__$Vec_WrappedSession$push(void* vec_ptr, void* item_ptr); +void* __swift_bridge__$Vec_WrappedSession$pop(void* vec_ptr); +void* __swift_bridge__$Vec_WrappedSession$get(void* vec_ptr, uintptr_t index); +void* __swift_bridge__$Vec_WrappedSession$get_mut(void* vec_ptr, uintptr_t index); +uintptr_t __swift_bridge__$Vec_WrappedSession$len(void* vec_ptr); +void* __swift_bridge__$Vec_WrappedSession$as_ptr(void* vec_ptr); + +struct __private__ResultPtrAndPtr __swift_bridge__$WrappedSession$connect(void* api_url, void* token, void* device_id, void* account_slug, void* device_name_override, void* os_version_override, void* log_dir, void* log_filter, void* callback_handler, void* device_info); +void __swift_bridge__$WrappedSession$reset(void* self); +void __swift_bridge__$WrappedSession$set_dns(void* self, void* dns_servers); +void __swift_bridge__$WrappedSession$set_disabled_resources(void* self, void* disabled_resources); +void __swift_bridge__$WrappedSession$disconnect(void* self); + + diff --git a/swift/apple/FirezoneNetworkExtension/Connlib/Generated/connlib-client-apple/connlib-client-apple.swift b/swift/apple/FirezoneNetworkExtension/Connlib/Generated/connlib-client-apple/connlib-client-apple.swift new file mode 100644 index 000000000..e41456e2b --- /dev/null +++ b/swift/apple/FirezoneNetworkExtension/Connlib/Generated/connlib-client-apple/connlib-client-apple.swift @@ -0,0 +1,120 @@ +@_cdecl("__swift_bridge__$CallbackHandler$on_set_interface_config") +func __swift_bridge__CallbackHandler_on_set_interface_config (_ this: UnsafeMutableRawPointer, _ tunnelAddressIPv4: UnsafeMutableRawPointer, _ tunnelAddressIPv6: UnsafeMutableRawPointer, _ dnsAddresses: UnsafeMutableRawPointer, _ routeListv4: UnsafeMutableRawPointer, _ routeListv6: UnsafeMutableRawPointer) { + Unmanaged.fromOpaque(this).takeUnretainedValue().onSetInterfaceConfig(tunnelAddressIPv4: RustString(ptr: tunnelAddressIPv4), tunnelAddressIPv6: RustString(ptr: tunnelAddressIPv6), dnsAddresses: RustString(ptr: dnsAddresses), routeListv4: RustString(ptr: routeListv4), routeListv6: RustString(ptr: routeListv6)) +} + +@_cdecl("__swift_bridge__$CallbackHandler$on_update_resources") +func __swift_bridge__CallbackHandler_on_update_resources (_ this: UnsafeMutableRawPointer, _ resourceList: UnsafeMutableRawPointer) { + Unmanaged.fromOpaque(this).takeUnretainedValue().onUpdateResources(resourceList: RustString(ptr: resourceList)) +} + +@_cdecl("__swift_bridge__$CallbackHandler$on_disconnect") +func __swift_bridge__CallbackHandler_on_disconnect (_ this: UnsafeMutableRawPointer, _ error: UnsafeMutableRawPointer) { + Unmanaged.fromOpaque(this).takeUnretainedValue().onDisconnect(error: RustString(ptr: error)) +} + + +public class WrappedSession: WrappedSessionRefMut { + var isOwned: Bool = true + + public override init(ptr: UnsafeMutableRawPointer) { + super.init(ptr: ptr) + } + + deinit { + if isOwned { + __swift_bridge__$WrappedSession$_free(ptr) + } + } +} +extension WrappedSession { + class public func connect(_ api_url: GenericIntoRustString, _ token: GenericIntoRustString, _ device_id: GenericIntoRustString, _ account_slug: GenericIntoRustString, _ device_name_override: Optional, _ os_version_override: Optional, _ log_dir: GenericIntoRustString, _ log_filter: GenericIntoRustString, _ callback_handler: CallbackHandler, _ device_info: GenericIntoRustString) throws -> WrappedSession { + try { let val = __swift_bridge__$WrappedSession$connect({ let rustString = api_url.intoRustString(); rustString.isOwned = false; return rustString.ptr }(), { let rustString = token.intoRustString(); rustString.isOwned = false; return rustString.ptr }(), { let rustString = device_id.intoRustString(); rustString.isOwned = false; return rustString.ptr }(), { let rustString = account_slug.intoRustString(); rustString.isOwned = false; return rustString.ptr }(), { if let rustString = optionalStringIntoRustString(device_name_override) { rustString.isOwned = false; return rustString.ptr } else { return nil } }(), { if let rustString = optionalStringIntoRustString(os_version_override) { rustString.isOwned = false; return rustString.ptr } else { return nil } }(), { let rustString = log_dir.intoRustString(); rustString.isOwned = false; return rustString.ptr }(), { let rustString = log_filter.intoRustString(); rustString.isOwned = false; return rustString.ptr }(), Unmanaged.passRetained(callback_handler).toOpaque(), { let rustString = device_info.intoRustString(); rustString.isOwned = false; return rustString.ptr }()); if val.is_ok { return WrappedSession(ptr: val.ok_or_err!) } else { throw RustString(ptr: val.ok_or_err!) } }() + } + + public func disconnect() { + __swift_bridge__$WrappedSession$disconnect({isOwned = false; return ptr;}()) + } +} +public class WrappedSessionRefMut: WrappedSessionRef { + public override init(ptr: UnsafeMutableRawPointer) { + super.init(ptr: ptr) + } +} +extension WrappedSessionRefMut { + public func reset() { + __swift_bridge__$WrappedSession$reset(ptr) + } + + public func setDns(_ dns_servers: GenericIntoRustString) { + __swift_bridge__$WrappedSession$set_dns(ptr, { let rustString = dns_servers.intoRustString(); rustString.isOwned = false; return rustString.ptr }()) + } + + public func setDisabledResources(_ disabled_resources: GenericIntoRustString) { + __swift_bridge__$WrappedSession$set_disabled_resources(ptr, { let rustString = disabled_resources.intoRustString(); rustString.isOwned = false; return rustString.ptr }()) + } +} +public class WrappedSessionRef { + var ptr: UnsafeMutableRawPointer + + public init(ptr: UnsafeMutableRawPointer) { + self.ptr = ptr + } +} +extension WrappedSession: Vectorizable { + public static func vecOfSelfNew() -> UnsafeMutableRawPointer { + __swift_bridge__$Vec_WrappedSession$new() + } + + public static func vecOfSelfFree(vecPtr: UnsafeMutableRawPointer) { + __swift_bridge__$Vec_WrappedSession$drop(vecPtr) + } + + public static func vecOfSelfPush(vecPtr: UnsafeMutableRawPointer, value: WrappedSession) { + __swift_bridge__$Vec_WrappedSession$push(vecPtr, {value.isOwned = false; return value.ptr;}()) + } + + public static func vecOfSelfPop(vecPtr: UnsafeMutableRawPointer) -> Optional { + let pointer = __swift_bridge__$Vec_WrappedSession$pop(vecPtr) + if pointer == nil { + return nil + } else { + return (WrappedSession(ptr: pointer!) as! Self) + } + } + + public static func vecOfSelfGet(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { + let pointer = __swift_bridge__$Vec_WrappedSession$get(vecPtr, index) + if pointer == nil { + return nil + } else { + return WrappedSessionRef(ptr: pointer!) + } + } + + public static func vecOfSelfGetMut(vecPtr: UnsafeMutableRawPointer, index: UInt) -> Optional { + let pointer = __swift_bridge__$Vec_WrappedSession$get_mut(vecPtr, index) + if pointer == nil { + return nil + } else { + return WrappedSessionRefMut(ptr: pointer!) + } + } + + public static func vecOfSelfAsPtr(vecPtr: UnsafeMutableRawPointer) -> UnsafePointer { + UnsafePointer(OpaquePointer(__swift_bridge__$Vec_WrappedSession$as_ptr(vecPtr))) + } + + public static func vecOfSelfLen(vecPtr: UnsafeMutableRawPointer) -> UInt { + __swift_bridge__$Vec_WrappedSession$len(vecPtr) + } +} + + +@_cdecl("__swift_bridge__$CallbackHandler$_free") +func __swift_bridge__CallbackHandler__free (ptr: UnsafeMutableRawPointer) { + let _ = Unmanaged.fromOpaque(ptr).takeRetainedValue() +} + + + diff --git a/rust/connlib/clients/apple/Sources/Connlib/connlib.h b/swift/apple/FirezoneNetworkExtension/Connlib/connlib.h similarity index 100% rename from rust/connlib/clients/apple/Sources/Connlib/connlib.h rename to swift/apple/FirezoneNetworkExtension/Connlib/connlib.h diff --git a/swift/apple/copy_generated_connlib_files.sh b/swift/apple/copy_generated_connlib_files.sh deleted file mode 100755 index f9fd26536..000000000 --- a/swift/apple/copy_generated_connlib_files.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/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