Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ jobs:
- uses: partout-io/action-prepare-xcode-build@master
with:
access-token: ${{ secrets.GITHUB_TOKEN }}
- name: Fetch SWON submodule
run: |
git submodule init vendors/swon
git submodule update --depth 1 vendors/swon
- name: Ensure previews are off
run: |
expected="let forPreviews = false"
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "vendors/openssl"]
path = vendors/openssl
url = https://github.com/openssl/openssl
[submodule "vendors/swon"]
path = vendors/swon
url = https://github.com/keeshux/swon
45 changes: 14 additions & 31 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.27)
project(Partout)
project(Partout LANGUAGES Swift C CXX)
include(ExternalProject)
include(FetchContent)

Expand Down Expand Up @@ -27,38 +27,19 @@ message(STATUS "Option PP_BUILD_USE_MBEDTLS = ${PP_BUILD_USE_MBEDTLS}")
message(STATUS "Option PP_BUILD_USE_WGGO = ${PP_BUILD_USE_WGGO}")
message(STATUS "Option PP_BUILD_OUTPUT = ${PP_BUILD_OUTPUT}")

# Forward args to Partout sub-project
set(PARTOUT_CMAKE_ARGS
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DOUTPUT_DIR=${PP_BUILD_OUTPUT}/partout
)
if(DEFINED CMAKE_TOOLCHAIN_FILE)
list(APPEND PARTOUT_CMAKE_ARGS
-DCMAKE_Swift_COMPILER=${CMAKE_CURRENT_SOURCE_DIR}/scripts/swiftc-wrapper.sh
-DCMAKE_TOOLCHAIN_FILE:FILEPATH=${CMAKE_TOOLCHAIN_FILE}
)
endif()

# All vendor-inherited args
set(VENDOR_DEPENDS)
if(PP_BUILD_USE_OPENSSL)
include("vendors/openssl.cmake")
ExternalProject_Get_Property(OpenSSLProject BINARY_DIR)
list(APPEND VENDOR_DEPENDS OpenSSLProject)
list(APPEND PARTOUT_CMAKE_ARGS -DOPENSSL_DIR=${OPENSSL_DIR})
elseif(PP_BUILD_USE_MBEDTLS)
include("vendors/mbedtls.cmake")
ExternalProject_Get_Property(MbedTLSProject BINARY_DIR)
list(APPEND VENDOR_DEPENDS MbedTLSProject)
list(APPEND PARTOUT_CMAKE_ARGS -DMBEDTLS_DIR=${MBEDTLS_DIR})
endif()
if(PP_BUILD_USE_WGGO)
include("vendors/wg-go.cmake")
ExternalProject_Get_Property(WireGuardGoProject BINARY_DIR)
list(APPEND VENDOR_DEPENDS WireGuardGoProject)
list(APPEND PARTOUT_CMAKE_ARGS -DWGGO_DIR=${WGGO_DIR})
endif()

# Include SWON macros
add_subdirectory("vendors/swon")

# Fetch wintun.dll on Windows
if(WIN32)
set(WINTUN_VERSION "0.14.1")
Expand All @@ -67,12 +48,14 @@ endif()

# Build Partout library (opt-in), after vendored dependencies
if(PP_BUILD_LIBRARY)
ExternalProject_Add(
PartoutProject
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Sources
CMAKE_ARGS ${PARTOUT_CMAKE_ARGS}
INSTALL_COMMAND ""
BUILD_ALWAYS 1
DEPENDS ${VENDOR_DEPENDS}
)
add_subdirectory(Sources)
if(PP_BUILD_USE_OPENSSL)
target_link_libraries(partout_c PUBLIC OpenSSLInterface)
elseif(PP_BUILD_USE_MBEDTLS)
target_link_libraries(partout_c PUBLIC MbedTLSInterface)
endif()
if(PP_BUILD_USE_WGGO)
target_link_libraries(partout_c PUBLIC WireGuardGoInterface)
endif()
target_link_libraries(partout PUBLIC SWONInterface)
endif()
8 changes: 7 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ let package = Package(
]
)

// SWON macros (submodule)
package.dependencies.append(
.package(path: "vendors/swon")
)

// Swift-DocC for documentation, do not include by default
if envDocs {
package.dependencies.append(
Expand All @@ -136,7 +141,8 @@ package.targets.append(contentsOf: [
dependencies: [
"MiniFoundation",
"PartoutABI_C",
"PartoutCore_C"
"PartoutCore_C",
"swon"
],
swiftSettings: useFoundationCompatibility.swiftSettings
),
Expand Down
24 changes: 1 addition & 23 deletions Sources/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
cmake_minimum_required(VERSION 3.27)
project(PartoutProject LANGUAGES Swift C CXX)

# Package root is up one level, output dir from option
set(ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/..)
set(OUTPUT_DIR ${PP_BUILD_OUTPUT}/partout)

# Partout_C ############################################

Expand Down Expand Up @@ -137,26 +135,6 @@ set_target_properties(partout_c PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_DIR}
)

# Link to vendor-specific dependencies
if(DEFINED OPENSSL_DIR)
target_include_directories(partout_c PRIVATE ${OPENSSL_DIR}/include)
target_link_directories(partout_c PRIVATE ${OPENSSL_DIR}/lib)
target_link_libraries(partout_c PRIVATE ssl crypto)
elseif(DEFINED MBEDTLS_DIR)
target_include_directories(partout_c PRIVATE ${MBEDTLS_DIR}/include)
target_link_directories(partout_c PRIVATE ${MBEDTLS_DIR}/lib)
target_link_libraries(partout_c PRIVATE mbedcrypto mbedtls mbedx509)
endif()
if(DEFINED WGGO_DIR)
target_include_directories(partout_c PRIVATE
${WGGO_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/PartoutWireGuard/Shared_C/include
)
# wg-go is loaded with dl_open()
# target_link_directories(partout_c PRIVATE ${WGGO_DIR}/lib)
# target_link_libraries(partout_c PRIVATE wg-go)
endif()

# Copy ABI header
set(ABI_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/PartoutABI_C/include)
add_custom_command(
Expand Down
8 changes: 4 additions & 4 deletions Sources/MiniFoundationCompat/CompatString+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ internal import _MiniFoundationCore_C
extension String {
// MARK: Initializers

// FIXME: #228, Only on file URLs
// FIXME: #303, Only on file URLs
public init(contentsOf url: Compat.URL, encoding: Compat.StringEncoding) throws {
try self.init(contentsOfFile: url.filePath(), encoding: encoding)
}

// FIXME: #228, Only on file URLs
// FIXME: #303, Only on file URLs
public init(contentsOf url: Compat.URL, usedEncoding: inout Compat.StringEncoding) throws {
try self.init(contentsOfFile: url.filePath(), usedEncoding: &usedEncoding)
}
Expand Down Expand Up @@ -179,7 +179,7 @@ extension Substring {
// MARK: - Formatting

extension String {
// FIXME: #228, Test, look for memory leaks
// FIXME: #303, Test, look for memory leaks
public init(format: String, _ args: Any...) {
// Convert Swift Any -> CVarArg (only the types we support)
let cArgs: [CVarArg] = args.map { arg in
Expand Down Expand Up @@ -278,7 +278,7 @@ extension FileBuffer {
}

private extension Compat.StringEncoding {
// FIXME: #228, Test, probably inefficient
// FIXME: #303, Test, probably inefficient
// Return `String?` — nil if decoding failed (invalid for that encoding)
func decode(_ bytes: [UInt8]) -> String? {
switch self {
Expand Down
6 changes: 3 additions & 3 deletions Sources/MiniFoundationCompat/Data.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

internal import _MiniFoundationCore_C

// FIXME: #228, Implement with pp_zd maybe, use @inline, beware of performance
// FIXME: #303, Implement with pp_zd maybe, use @inline, beware of performance

extension Compat {
public struct Data: Hashable, Codable, Sendable {
Expand Down Expand Up @@ -161,12 +161,12 @@ extension Compat.Data {

extension Compat.Data {
public init(bytesNoCopy: UnsafeMutablePointer<UInt8>, count: Int) {
// FIXME: #228, DO NOT COPY BYTES
// FIXME: #303, DO NOT COPY BYTES
self.init(bytes: bytesNoCopy, count: count)
}

public init(bytesNoCopy: UnsafeMutablePointer<UInt8>, count: Int, customDeallocator: @escaping () -> Void) {
// FIXME: #228, DO NOT COPY BYTES
// FIXME: #303, DO NOT COPY BYTES
self.init(bytes: bytesNoCopy, count: count)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/MiniFoundationCompat/Error+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

extension Error {
public var localizedDescription: String {
// FIXME: #228, No clue, but error description _should_ fall back to a string representation
// FIXME: #303, No clue, but error description _should_ fall back to a string representation
String(describing: self)
}
}
2 changes: 1 addition & 1 deletion Sources/MiniFoundationCompat/FileManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

internal import _MiniFoundationCore_C

// FIXME: #228, Test file I/O, esp. on Windows
// FIXME: #303, Test file I/O, esp. on Windows

extension Compat {
public final class FileManager {
Expand Down
4 changes: 2 additions & 2 deletions Sources/MiniFoundationCompat/JSONCoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extension Compat {
public init() {}

public func encode<T>(_ value: T) throws -> Compat.Data where T: Encodable {
// FIXME: #228, JSONEncoder
// FIXME: #293, JSONEncoder
throw MiniFoundationError.encoding
}
}
Expand All @@ -24,7 +24,7 @@ extension Compat {
}

public func decode<T>(_ type: T.Type, from data: Compat.Data) throws -> T where T: Decodable {
// FIXME: #228, JSONDecoder
// FIXME: #293, JSONDecoder
throw MiniFoundationError.decoding
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/MiniFoundationCompat/URL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ extension Compat.URL {

// MARK: File URLs

// FIXME: #228, Optimistic, implement and test everything here, esp. on Windows
// FIXME: #303, Optimistic, implement and test everything here, esp. on Windows

extension Compat.URL {
// FIXME: #228, Paths can be relative
// FIXME: #303, Paths can be relative
public convenience init(fileURLWithPath path: String) {
self.init(string: "file://\(path)")!
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/MiniFoundationNative/NativeURL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

extension URL: MiniURLProtocol {
public func filePath() -> String {
// FIXME: #228, Is .path(percentEncoded: false|true) the same?
// FIXME: #303, Is .path(percentEncoded: false|true) the same?
assert(isFileURL)
return path
}
Expand Down
3 changes: 1 addition & 2 deletions Sources/PartoutCore/IP/Address.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ public enum Address: Hashable, Codable, Sendable {
}

extension Address: RawRepresentable {

@frozen
public enum Family: Sendable {
public enum Family: String, Sendable {
case v4

case v6
Expand Down
1 change: 0 additions & 1 deletion Sources/PartoutCore/IP/Endpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

/// Represents an endpoint.
public struct Endpoint: Hashable, Codable, Sendable {

/// The address.
public let address: Address

Expand Down
1 change: 0 additions & 1 deletion Sources/PartoutCore/IP/EndpointProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

/// Defines the communication protocol of an endpoint.
public struct EndpointProtocol: Hashable, Sendable {

/// The socket type.
public let socketType: IPSocketType

Expand Down
1 change: 0 additions & 1 deletion Sources/PartoutCore/IP/ExtendedEndpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ internal import _PartoutCore_C

/// Aggregates an address and an ``EndpointProtocol``.
public struct ExtendedEndpoint: Hashable, Codable, Sendable {

// XXX: Simplistic match
nonisolated(unsafe)
private static let rx: Regex = {
Expand Down
1 change: 0 additions & 1 deletion Sources/PartoutCore/IP/IPSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

/// IP settings and routes.
public struct IPSettings: Hashable, Codable, Sendable {

/// The subnets.
public private(set) var subnets: [Subnet]

Expand Down
1 change: 0 additions & 1 deletion Sources/PartoutCore/IP/Route.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

/// Represents a route in the routing table.
public struct Route: Hashable, Codable, Sendable {

/// The destination subnet or `nil` if default.
public let destination: Subnet?

Expand Down
2 changes: 0 additions & 2 deletions Sources/PartoutCore/IP/SocketType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
/// A socket type between UDP and TCP.
@frozen
public enum SocketType: String, Sendable {

/// UDP socket type.
case udp = "UDP"

Expand All @@ -16,7 +15,6 @@ public enum SocketType: String, Sendable {
/// A socket type with optional info about the IP endpoint.
@frozen
public enum IPSocketType: String, Sendable {

/// UDP socket type.
case udp = "UDP"

Expand Down
1 change: 0 additions & 1 deletion Sources/PartoutCore/IP/Subnet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ internal import _PartoutCore_C

/// An IPv4/v6 subnet.
public struct Subnet: Hashable, Codable, Sendable {

/// The subnet address.
public let address: Address

Expand Down
1 change: 0 additions & 1 deletion Sources/PartoutOpenVPN/CompressionAlgorithm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// SPDX-License-Identifier: GPL-3.0

extension OpenVPN {

/// Defines the type of compression algorithm.
public enum CompressionAlgorithm: Int, Sendable {
case disabled
Expand Down
1 change: 1 addition & 0 deletions toolchains/android.toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set(CMAKE_SYSTEM_PROCESSOR $ENV{ANDROID_NDK_ARCH})
set(CMAKE_SYSTEM_VERSION $ENV{ANDROID_NDK_API})
set(CMAKE_C_COMPILER_TARGET $ENV{ANDROID_NDK_ARCH}-unknown-linux-android$ENV{ANDROID_NDK_API})
set(CMAKE_CXX_COMPILER_TARGET $ENV{ANDROID_NDK_ARCH}-unknown-linux-android$ENV{ANDROID_NDK_API})
set(CMAKE_Swift_COMPILER ${CMAKE_CURRENT_LIST_DIR}/swiftc-wrapper.sh)
set(CMAKE_Swift_COMPILER_TARGET $ENV{ANDROID_NDK_ARCH}-unknown-linux-android$ENV{ANDROID_NDK_API})
set(CMAKE_C_FLAGS "-fPIC")
set(CMAKE_Swift_FLAGS "-target $ENV{ANDROID_NDK_ARCH}-unknown-linux-android$ENV{ANDROID_NDK_API} -tools-directory $ENV{ANDROID_NDK_TOOLCHAIN} -sdk $ENV{ANDROID_NDK_SYSROOT} -resource-dir $ENV{SWIFT_RESOURCE_DIR} -enable-library-evolution -disallow-use-new-driver -lc++_shared -llog -lm")
Expand Down
File renamed without changes.
9 changes: 7 additions & 2 deletions vendors/mbedtls.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
set(MBEDTLS_DIR ${PP_BUILD_OUTPUT}/mbedtls)

ExternalProject_Add(
MbedTLSProject
ExternalProject_Add(MbedTLSProject
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/vendors/mbedtls
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${MBEDTLS_DIR}
)

add_library(MbedTLSInterface INTERFACE)
add_dependencies(MbedTLSInterface OpenSSLProject)
target_include_directories(MbedTLSInterface INTERFACE ${MBEDTLS_DIR}/include)
target_link_directories(MbedTLSInterface INTERFACE ${MBEDTLS_DIR}/lib)
target_link_libraries(MbedTLSInterface INTERFACE mbedtls mbedx509 mbedcrypto)
9 changes: 7 additions & 2 deletions vendors/openssl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ set(CFG_ARGS
${OPENSSL_SYMBOLS}
${OPENSSL_CFG_FLAGS}
)
ExternalProject_Add(
OpenSSLProject
ExternalProject_Add(OpenSSLProject
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/vendors/openssl
CONFIGURE_COMMAND perl ${CMAKE_CURRENT_SOURCE_DIR}/vendors/openssl/Configure ${CFG_ARGS}
BUILD_COMMAND ${OPENSSL_BUILD_CMD}
Expand All @@ -46,3 +45,9 @@ if(APPLE)
"${OPENSSL_DIR}/lib/libssl.3.dylib"
)
endif()

add_library(OpenSSLInterface INTERFACE)
add_dependencies(OpenSSLInterface OpenSSLProject)
target_include_directories(OpenSSLInterface INTERFACE ${OPENSSL_DIR}/include)
target_link_directories(OpenSSLInterface INTERFACE ${OPENSSL_DIR}/lib)
target_link_libraries(OpenSSLInterface INTERFACE ssl crypto)
1 change: 1 addition & 0 deletions vendors/swon
Submodule swon added at afd197
Loading