Skip to content

Commit

Permalink
wip: remove rust bindings in favor of javascript, via javascripcore
Browse files Browse the repository at this point in the history
  • Loading branch information
ErrorErrorError committed Nov 10, 2023
1 parent 69fde4a commit 3da150f
Show file tree
Hide file tree
Showing 82 changed files with 1,417 additions and 5,714 deletions.
1 change: 1 addition & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ line_length:
ignores_urls: true

type_name:
allowed_symbols: "_"
max_length:
warning: 60
error: 60
Expand Down
2 changes: 2 additions & 0 deletions App/Mochi.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@
DEVELOPMENT_ASSET_PATHS = ..;
DEVELOPMENT_TEAM = A6HC4Y86NJ;
ENABLE_HARDENED_RUNTIME = YES;
"ENABLE_HARDENED_RUNTIME[sdk=macosx*]" = YES;
ENABLE_PREVIEWS = YES;
ENABLE_USER_SCRIPT_SANDBOXING = NO;
GENERATE_INFOPLIST_FILE = YES;
Expand Down Expand Up @@ -412,6 +413,7 @@
DEVELOPMENT_ASSET_PATHS = ..;
DEVELOPMENT_TEAM = A6HC4Y86NJ;
ENABLE_HARDENED_RUNTIME = YES;
"ENABLE_HARDENED_RUNTIME[sdk=macosx*]" = YES;
ENABLE_PREVIEWS = YES;
ENABLE_USER_SCRIPT_SANDBOXING = NO;
GENERATE_INFOPLIST_FILE = YES;
Expand Down
2 changes: 2 additions & 0 deletions App/Shared/mochi.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<dict>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.cs.allow-jit</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
</dict>
Expand Down
70 changes: 23 additions & 47 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -766,12 +766,11 @@ struct ModuleClient: _Client {
DatabaseClient()
FileClient()
SharedModels()
WasmInterpreter()
Tagged()
ComposableArchitecture()
SwiftSoup()
Semaphore()
SwiftRustMacro()
JSValueCoder()
}
}

Expand Down Expand Up @@ -1227,21 +1226,6 @@ extension _Feature {
}
}
//
// SwiftRustMacro.swift
//
//
// Created by ErrorErrorError on 10/27/23.
//
//

struct SwiftRustMacro: _Macro {
var dependencies: any Dependencies {
SwiftSyntax()
SwiftSyntaxMacros()
SwiftCompilerPlugin()
}
}
//
// File.swift
//
//
Expand Down Expand Up @@ -1318,6 +1302,27 @@ struct ContentCore: _Shared {

struct FoundationHelpers: _Shared {}
//
// JSValueCoder.swift
//
//
// Created by ErrorErrorError on 11/6/23.
//
//

import Foundation

struct JSValueCoder: _Shared {}

extension JSValueCoder: Testable {
struct Tests: TestTarget {
var name: String { "JSValueCoderTests" }

var dependencies: any Dependencies {
JSValueCoder()
}
}
}
//
// SharedModels.swift
//
//
Expand Down Expand Up @@ -1372,36 +1377,6 @@ struct ViewComponents: _Shared {
}
}
//
// File.swift
//
//
// Created by ErrorErrorError on 10/5/23.
//
//

import Foundation

struct WasmInterpreter: _Shared {
var dependencies: any Dependencies {
CWasm3()
}

var cSettings: [CSetting] {
CSetting.define("APPLICATION_EXTENSION_API_ONLY", to: "YES")
}
}

struct CWasm3: Product, Target {
var targetType: TargetType {
.binary(
.remote(
url: "https://github.com/shareup/cwasm3/releases/download/v0.5.2/CWasm3-0.5.0.xcframework.zip",
checksum: "a2b0785be1221767d926cee76b087f168384ec9735b4f46daf26e12fae2109a3"
)
)
}
}
//
// Shared.swift
//
//
Expand Down Expand Up @@ -1443,6 +1418,7 @@ let package = Package {
MochiApp()
} testTargets: {
ModuleClient.Tests()
JSValueCoder.Tests()
}
.supportedPlatforms {
MochiPlatforms()
Expand Down
3 changes: 1 addition & 2 deletions Package/Sources/Clients/ModuleClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ struct ModuleClient: _Client {
DatabaseClient()
FileClient()
SharedModels()
WasmInterpreter()
Tagged()
ComposableArchitecture()
SwiftSoup()
Semaphore()
SwiftRustMacro()
JSValueCoder()
}
}

Expand Down
21 changes: 21 additions & 0 deletions Package/Sources/Dependencies/SwiftLog.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// File.swift
//
//
// Created by ErrorErrorError on 11/9/23.
//
//

struct SwiftLog: PackageDependency {
var name: String { "swift-log" }

var dependency: Package.Dependency {
.package(url: "https://github.com/apple/swift-log.git", from: "1.0.0"),
}
}

struct Logging: Dependency {
var targetDepenency: _PackageDescription_TargetDependency {
.product(name: "\(Self.self)", package: SwiftLog().packageName)
}
}
1 change: 1 addition & 0 deletions Package/Sources/Index.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ let package = Package {
MochiApp()
} testTargets: {
ModuleClient.Tests()
JSValueCoder.Tests()
}
.supportedPlatforms {
MochiPlatforms()
Expand Down
15 changes: 0 additions & 15 deletions Package/Sources/Macros/SwiftRustMacro.swift

This file was deleted.

21 changes: 21 additions & 0 deletions Package/Sources/Shared/JSValueCoder.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// JSValueCoder.swift
//
//
// Created by ErrorErrorError on 11/6/23.
//
//

import Foundation

struct JSValueCoder: _Shared {}

extension JSValueCoder: Testable {
struct Tests: TestTarget {
var name: String { "JSValueCoderTests" }

var dependencies: any Dependencies {
JSValueCoder()
}
}
}
30 changes: 0 additions & 30 deletions Package/Sources/Shared/WasmInterpreter.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ extension NSPersistentContainer {

@MainActor
func loadPersistentStores() async throws {
try await withCheckedThrowingContinuation { [unowned self] continuation in
try await withUnsafeThrowingContinuation { [unowned self] continuation in
loadPersistentStores { _, error in
if let error {
continuation.resume(throwing: error)
Expand Down
3 changes: 3 additions & 0 deletions Sources/Clients/DatabaseClient/Models/Module.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ import Tagged

@dynamicMemberLookup
public struct Module: Entity, Hashable, Sendable {
// TODO: Rename moduleLocation to moduleDirectory

Check warning on line 18 in Sources/Clients/DatabaseClient/Models/Module.swift

View workflow job for this annotation

GitHub Actions / run-swiftlint

TODOs should be resolved (Rename moduleLocation to modul...) (todo)
public var moduleLocation: URL = .init(string: "/").unsafelyUnwrapped
public var installDate: Date = .init()
public var manifest: Manifest = .init()
public var objectID: ManagedObjectID?

public var moduleDirectory: URL { self.moduleLocation }

public static var properties: Set<Property> = [
.init("moduleLocation", \Self.moduleLocation),
.init("installDate", \Self.installDate),
Expand Down
35 changes: 19 additions & 16 deletions Sources/Clients/ModuleClient/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,17 @@ import Dependencies
import Foundation
import SharedModels
import SwiftSoup
import WasmInterpreter
import XCTestDynamicOverlay

// MARK: - ModuleClient

public struct ModuleClient: Sendable {
public var initialize: @Sendable () async throws -> Void
var getModule: @Sendable (_ repoModuleID: RepoModuleID) async throws -> WAInstance
var getModuleForJS: @Sendable (_ module: Module.Manifest) async throws -> JSInstance
var getModule: @Sendable (_ repoModuleID: RepoModuleID) async throws -> Self.Instance
}

public extension ModuleClient {
func withModuleJS<R>(module: Module.Manifest, work: @Sendable (ModuleClient.JSInstance) async throws -> R) async throws -> R {
try await work(getModuleForJS(module))
}

func withModule<R>(id: RepoModuleID, work: @Sendable (ModuleClient.WAInstance) async throws -> R) async throws -> R {
func withModule<R>(id: RepoModuleID, work: @Sendable (Self.Instance) async throws -> R) async throws -> R {
try await work(getModule(id))
}
}
Expand All @@ -35,16 +29,26 @@ public extension ModuleClient {

public extension ModuleClient {
enum Error: Swift.Error, Equatable, Sendable {
case wasm3(WasmInstance.Error)
case nullPtr(for: String = #function, message: String = "")
case castError(for: String = #function, got: String = "", expected: String = "")
case swiftSoup(for: String = #function, SwiftSoup.Exception)
case indexOutOfBounds(for: String = #function)
case unknown(for: String = #function, msg: String = "")
case client(ClientError)
case jsRuntime(JSRuntimeError)
}
}

public extension ModuleClient.Error {
enum ClientError: Equatable, Sendable {
case moduleNotFound
}
}

public extension ModuleClient.Error {
enum JSRuntimeError: Equatable, Sendable {
case promiseValueError
case retrievingInstanceFailed
case instanceCreationFailed
case instanceCall(function: String, msg: String)
}
}

// MARK: - SwiftSoup.Exception + Equatable

extension SwiftSoup.Exception: Equatable {
Expand All @@ -61,8 +65,7 @@ extension SwiftSoup.Exception: Equatable {
extension ModuleClient: TestDependencyKey {
public static let testValue = Self(
initialize: unimplemented(),
getModule: unimplemented(),
getModuleForJS: unimplemented()
getModule: unimplemented()
)
}

Expand Down
Loading

0 comments on commit 3da150f

Please sign in to comment.