Skip to content

Commit

Permalink
up to 6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nerzh committed Mar 2, 2025
1 parent aebeb5c commit 295076a
Show file tree
Hide file tree
Showing 29 changed files with 466 additions and 556 deletions.
17 changes: 7 additions & 10 deletions ApiParser/Package.swift
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
// swift-tools-version:5.4
// swift-tools-version:6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "ApiParser",
platforms: [
.macOS(SupportedPlatform.MacOSVersion.v10_12)
.macOS(SupportedPlatform.MacOSVersion.v10_13)
],
products: [
.executable(name: "ApiParser", targets: ["ApiParser"])
],
dependencies: [
.package(name: "SwiftRegularExpression", url: "https://github.com/nerzh/swift-regular-expression.git", .upToNextMajor(from: "0.2.4")),
.package(name: "swift-argument-parser", url: "https://github.com/apple/swift-argument-parser", .upToNextMinor(from: "0.4.3")),
.package(name: "FileUtils", url: "https://github.com/nerzh/SwiftFileUtils", .upToNextMinor(from: "1.3.0")),
.package(url: "https://github.com/nerzh/swift-regular-expression.git", .upToNextMajor(from: "0.2.4")),
.package(url: "https://github.com/apple/swift-argument-parser", .upToNextMinor(from: "0.4.3")),
.package(url: "https://github.com/nerzh/SwiftFileUtils", .upToNextMinor(from: "1.3.0")),
],
targets: [
.executableTarget(
name: "ApiParser",
dependencies: [
.product(name: "SwiftRegularExpression", package: "SwiftRegularExpression"),
.product(name: "SwiftRegularExpression", package: "swift-regular-expression"),
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.product(name: "FileUtils", package: "FileUtils"),
.product(name: "FileUtils", package: "SwiftFileUtils"),
]),
],
swiftLanguageVersions: [
SwiftVersion.v5
]
)
37 changes: 3 additions & 34 deletions ApiParser/Sources/ApiParser/CodeGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class CodeGenerator {
}


var result: String = "\(swiftStruct.accessType) struct \(swiftStruct.name): \(swiftStruct.parents.joined(separator: ", ")) {\n"
var result: String = "\(swiftStruct.accessType) struct \(swiftStruct.name): \(swiftStruct.parents.joined(separator: ", ")), @unchecked Sendable {\n"
for property in swiftStruct.properties {
if let summary: String = property.summary { result.append("\(tab)/// \(checkComment(summary))\n") }
if let descr: String = property.description { result.append("\(tab)/// \(checkComment(descr))\n") }
Expand All @@ -119,16 +119,6 @@ class CodeGenerator {
return result
}

// public func decode_message_body(_ payload: TSDKParamsOfDecodeMessageBody,
// _ handler: @escaping (TSDKBindingResponse<TSDKDecodedMessageBody, TSDKClientError>) throws -> Void
// ) throws {
// let method: String = "decode_message_body"
// try binding.requestLibraryAsync(methodName(module, method), payload, { (requestId, params, responseType, finished) in
// var response: TSDKBindingResponse<TSDKDecodedMessageBody, TSDKClientError> = .init()
// response.update(requestId, params, responseType, finished)
// try handler(response)
// })
// }
private func generateFunction(_ swiftFunction: SDKSwiftFunction) -> String {
var result: String = .init()
if let summary = swiftFunction.summary { result.append("\(tab)/// \(checkComment(summary))\n") }
Expand All @@ -138,7 +128,7 @@ class CodeGenerator {
result.append("_ \(parameter.name): \(parameter.type), ")
}
let resultType: String = swiftFunction.willReturn.type == "Void" ? "\(libPrefix)NoneResult" : swiftFunction.willReturn.type
result.append("_ handler: @escaping (TSDKBindingResponse<\(resultType), \(libPrefix)ClientError>) throws -> Void\n\(tab)) throws {\n")
result.append("_ handler: @escaping @Sendable (TSDKBindingResponse<\(resultType), \(libPrefix)ClientError>) throws -> Void\n\(tab)) throws {\n")
let methodName: String = swiftFunction.name == "initialize" ? "init" : swiftFunction.name
result.append("\(tab)\(tab)let method: String = \"\(methodName)\"\n")
if swiftFunction.params.isEmpty {
Expand All @@ -155,27 +145,6 @@ class CodeGenerator {
return result
}

// public func get_endpoints() async throws -> TSDKResultOfGetEndpoints {
// try await withCheckedThrowingContinuation { continuation in
// do {
// let method: String = "get_endpoints"
// try binding.requestLibraryAsync(methodName(module, method), "") { (requestId, params, responseType, finished) in
// var response: TSDKBindingResponse<TSDKResultOfGetEndpoints, TSDKClientError> = .init()
// response.update(requestId, params, responseType, finished)
// if let error = response.error {
// continuation.resume(throwing: error)
// } else if let result = response.result {
// continuation.resume(returning: result)
// } else {
// continuation.resume(throwing: TSDKClientError("Nothing for return"))
// }
// }
// } catch {
// continuation.resume(throwing: error)
// }
// }
// }

private func generateAsyncAwaitFunction(_ swiftFunction: SDKSwiftFunction) -> String {
var result: String = .init()
if let summary = swiftFunction.summary { result.append("\(tab)/// \(checkComment(summary))\n") }
Expand Down Expand Up @@ -296,7 +265,7 @@ extension CodeGenerator {
var swiftStruct = swiftStruct
swiftStruct.parents.append("LocalizedError")

var result: String = "\(swiftStruct.accessType) struct \(swiftStruct.name): \(swiftStruct.parents.joined(separator: ", ")) {\n"
var result: String = "\(swiftStruct.accessType) struct \(swiftStruct.name): \(swiftStruct.parents.joined(separator: ", ")), @unchecked Sendable {\n"
for property in swiftStruct.properties {
if let summary: String = property.summary { result.append("\(tab)/// \(checkComment(summary))\n") }
if let descr: String = property.description { result.append("\(tab)/// \(checkComment(descr))\n") }
Expand Down
8 changes: 4 additions & 4 deletions ApiParser/Sources/ApiParser/Settings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

var libPrefix: String = "TSDK"
var libEnumPostfix: String = "EnumTypes"
var defaultEnumParents: [String] = ["String", "Codable"]
var defaultStructTypeParents: [String] = ["Codable"]
let libPrefix: String = "TSDK"
let libEnumPostfix: String = "EnumTypes"
let defaultEnumParents: [String] = ["String", "Codable"]
let defaultStructTypeParents: [String] = ["Codable"]
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.8
// swift-tools-version:6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
--->

[![SPM](https://img.shields.io/badge/swift-package%20manager-green)](https://swift.org/package-manager/)
[![SPM](https://img.shields.io/badge/SDK%20VERSION-1.44.2-orange)](https://github.com/tonlabs/ever-sdk)
[![SPM](https://img.shields.io/badge/SDK%20VERSION-1.49.2-orange)](https://github.com/tonlabs/ever-sdk)

Swift is a strongly typed language that has long been used not only for iOS development. Apple is actively promoting it to new platforms and today it can be used for almost any task. Thanks to this, this implementation provides the work of TVM (toncoin, everscale, venom, gosh) SDK on many platforms at once, including the native one for mobile phones. Let me remind you that swift can also be built for android.

Expand Down
Loading

0 comments on commit 295076a

Please sign in to comment.