Skip to content

Commit

Permalink
Build for iOS using static linking
Browse files Browse the repository at this point in the history
This reorganizes the ios and macos projects to both depend on the same shared
code, and implements the same replicated file provider extension with channeled
sessions on both platforms, replacing the previous "embed dylib in the bundle"
approach used in the past.
  • Loading branch information
za-creature committed Nov 25, 2024
1 parent 5143c25 commit fd64f97
Show file tree
Hide file tree
Showing 47 changed files with 1,009 additions and 973 deletions.
8 changes: 8 additions & 0 deletions darwin/OuisyncBackend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.DS_Store
/.build
/Packages
xcuserdata/
DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
33 changes: 33 additions & 0 deletions darwin/OuisyncBackend/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// swift-tools-version: 5.9
import PackageDescription


/* This package hosts functionality that is shared by the ios and macos versions of the file
provider extension. It is currently used for:
* mapping rust data models to those expected by the platform
* white-label implementation of the file provider(s): because code in extension targets is not
currently importable by tests, our extensions import and rename the class(es) defined here

Before committing code to this package, consider the following questions:
1. is the code only useful to our extensions? otherwise it might belong to `OuisyncCommon` (at the
very least as an IPC protocol that calls into the extension that then links with this package)
2. is the code only useful to our app? otherwise it might belong to the `OuisyncLib` swift
bindings or even into the rust core library */
let package = Package(
name: "OuisyncBackend",
platforms: [.iOS(.v16), .macOS(.v13)],
products: [
.library(name: "OuisyncBackend",
targets: ["OuisyncBackend"]),
],
dependencies: [
.package(path: "../OuisyncCommon"),
.package(path: "../ouisync/bindings/swift/OuisyncLib")
],
targets: [
.target(name: "OuisyncBackend",
dependencies: [.product(name: "OuisyncCommon", package: "OuisyncCommon"),
.product(name: "OuisyncLib", package: "OuisyncLib")],
path: "Sources"),
]
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
//
// Created by Peter Jankuliak on 24/05/2024.
//

import Foundation
import FileProvider
import Foundation


extension NSFileProviderSyncAnchor: CustomDebugStringConvertible {
public var debugDescription: String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
//
// Created by Peter Jankuliak on 04/06/2024.
//

import Foundation
import FileProvider
import Foundation


extension NSFileProviderItemFields: CustomDebugStringConvertible {
static public var debugDescriptions: [(Self, String)] = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
//
// Created by Peter Jankuliak on 15/03/2024.
//

import FileProvider
import OuisyncCommon
import OuisyncLib


class Enumerator: NSObject, NSFileProviderEnumerator {
private let session: OuisyncSession
private let itemId: ItemIdentifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
//
// Created by Peter Jankuliak on 25/03/2024.
//

import Common
import FileProvider
import OuisyncCommon
import OuisyncLib


class ExtError {
static var noSuchItem: NSError {
NSError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
//
// Created by Peter Jankuliak on 25/03/2024.
//

import Common
import Foundation
import FileProvider
import Foundation
import OuisyncCommon
import OuisyncLib


extension Extension: NSFileProviderServicing {
public func supportedServiceSources(for itemIdentifier: NSFileProviderItemIdentifier,
completionHandler: @escaping ([NSFileProviderServiceSource]?, Error?) -> Void) -> Progress {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
//
// Created by Peter Jankuliak on 15/03/2024.
//

import FileProvider
import Network
import OuisyncLib
import System
import OuisyncCommon
import OSLog
import Common
import Network
import System


open class Extension: NSObject, NSFileProviderReplicatedExtension {
static let WRITE_CHUNK_SIZE: UInt64 = 32768 // TODO: Decide on optimal value
Expand Down Expand Up @@ -539,7 +539,7 @@ open class Extension: NSObject, NSFileProviderReplicatedExtension {
do {
try await manager.signalEnumerator(for: .workingSet)
} catch let error as NSError {
NSLog("❌ failed to signal working set for \(Common.ouisyncFileProviderDomain): \(error)")
NSLog("❌ failed to signal working set for \(ouisyncFileProviderDomain): \(error)")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
//
// Created by Peter Jankuliak on 10/06/2024.
//

import Foundation


struct Hash: Codable, Equatable, CustomDebugStringConvertible {
let data: Data

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
//
// Created by Peter Jankuliak on 15/03/2024.
//

import FileProvider
import UniformTypeIdentifiers
import MessagePack
import OuisyncLib
import System
import UniformTypeIdentifiers


enum EntryItem: Hashable, Equatable, CustomDebugStringConvertible {
case file(FileItem)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
//
// Created by Peter Jankuliak on 22/05/2024.
//

import Foundation
import FileProvider
import Foundation
import OuisyncLib
import System // for FilePath


typealias RepoName = String


enum ItemIdentifier: CustomDebugStringConvertible, Hashable, Equatable {
case rootContainer
case trashContainer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
//
// Created by Peter Jankuliak on 17/04/2024.
//

import Foundation
import System


public class Path {
public let path: FilePath

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
//
// Created by Peter Jankuliak on 18/06/2024.
//

import Foundation
import FileProvider
import Foundation


enum Version: Codable, CustomDebugStringConvertible {
case valid(ValidVersion)
Expand Down
8 changes: 8 additions & 0 deletions darwin/OuisyncCommon/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.DS_Store
/.build
/Packages
xcuserdata/
DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
24 changes: 24 additions & 0 deletions darwin/OuisyncCommon/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// swift-tools-version: 5.9
import PackageDescription


/* This package hosts functionality that is shared by the ios and macos versions of the client,
regardless of entry point (app vs extension). It is best suited for:
* common configuration options like well known ids and paths
* IPC protocols, shared between providers and consumers
* tools that work around or abstract over operating system behavior
* backports of functionality that is not available on older operating systems

Intentionally does not link with the rust core library, see `OuisyncBackend` if you need that. */
let package = Package(
name: "OuisyncCommon",
platforms: [.iOS(.v16), .macOS(.v13)],
products: [
.library(name: "OuisyncCommon",
targets: ["OuisyncCommon"]),
],
targets: [
.target(name: "OuisyncCommon",
path: "Sources"),
]
)
5 changes: 5 additions & 0 deletions darwin/OuisyncCommon/Sources/Constants.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class Constants {
// TODO: merge the following:
public static let flutterConfigChannel = "org.equalitie.ouisync/native"
public static let flutterForwardingChannel = "org.equalitie.ouisync/backend"
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@

import Foundation


#if os(macOS)
private let appGroup = "5SR9R72Z83.org.equalitie.ouisync"
#else
private let appGroup = "group.org.equalitie"
#endif
private let rootURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroup)!


public class Directories {
private static let rootURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "5SR9R72Z83.org.equalitie.ouisync")!
public static let rootPath = rootURL.path(percentEncoded: false)
public static let configsPath = rootPath + "config"
public static let logsPath = rootPath + "logs/ouisync.log"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ public let ouisyncFileProviderDomain = NSFileProviderDomain(identifier: ouisyncF
// Used to send notifications from the extension's backend to Flutter.
func fromFileProviderToApp(_ message: [UInt8])
}

Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
//
// Created by Peter Jankuliak on 04/06/2024.
//

import Foundation

class Log {
enum Level: UInt8 {

public class Log {
public enum Level: UInt8 {
case trace = 0
case info
case error
Expand All @@ -22,7 +22,7 @@ class Log {
fileprivate var nextChildId: UInt64 = 0
var selfLevel: Level? = nil

init(_ label: String) {
public init(_ label: String) {
self.parent = nil
self.label = label
self.id = Self.nextRootId
Expand All @@ -37,22 +37,22 @@ class Log {
parent.nextChildId += 1
}

func child(_ label: String) -> Log {
public func child(_ label: String) -> Log {
Log(label, self, selfLevel)
}

@discardableResult
func trace(_ msg: String) -> Log {
public func trace(_ msg: String) -> Log {
print(.trace, msg)
}

@discardableResult
func info(_ msg: String) -> Log {
public func info(_ msg: String) -> Log {
print(.info, msg)
}

@discardableResult
func error(_ msg: String) -> Log {
public func error(_ msg: String) -> Log {
print(.error, msg)
}

Expand All @@ -64,7 +64,7 @@ class Log {
return self
}

func level(_ l: Level) -> Log {
public func level(_ l: Level) -> Log {
self.selfLevel = l
return self
}
Expand Down
1 change: 1 addition & 0 deletions ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ post_install do |installer|

installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET'
if config.base_configuration_reference.is_a? Xcodeproj::Project::Object::PBXFileReference
xcconfig_path = config.base_configuration_reference.real_path
IO.write(xcconfig_path, IO.read(xcconfig_path).gsub("DT_TOOLCHAIN_DIR", "TOOLCHAIN_DIR"))
Expand Down
2 changes: 1 addition & 1 deletion ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,6 @@ SPEC CHECKSUMS:
url_launcher_ios: 5334b05cef931de560670eeae103fd3e431ac3fe
webview_flutter_wkwebview: 0982481e3d9c78fd5c6f62a002fcd24fc791f1e4

PODFILE CHECKSUM: 53596f9a057e59492780598aacf103e090bdd491
PODFILE CHECKSUM: a2502349a4697221978af8d2814b154da0c71c1b

COCOAPODS: 1.15.2
12 changes: 12 additions & 0 deletions ios/ReplicatedFileProvider/Entitlements.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.application-groups</key>
<array>
<string>group.org.equalitie</string>
</array>
<key>com.apple.security.network.client</key>
<true/>
</dict>
</plist>
4 changes: 4 additions & 0 deletions ios/ReplicatedFileProvider/EntryPoint.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import OuisyncBackend


final class OuisyncReplicated: Extension {}
17 changes: 17 additions & 0 deletions ios/ReplicatedFileProvider/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSExtension</key>
<dict>
<key>NSExtensionFileProviderDocumentGroup</key>
<string>group.org.equalitie</string>
<key>NSExtensionFileProviderSupportsEnumeration</key>
<true/>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.fileprovider-nonui</string>
<key>NSExtensionPrincipalClass</key>
<string>$(PRODUCT_MODULE_NAME).OuisyncReplicated</string>
</dict>
</dict>
</plist>
Loading

0 comments on commit fd64f97

Please sign in to comment.