Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
helje5 committed Jun 18, 2024
2 parents cbf71d0 + 6fa8b17 commit f033ff1
Show file tree
Hide file tree
Showing 39 changed files with 347 additions and 80 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
image:
- swift:5.9.2-focal
- swift:5.10-jammy
- swift:5.10.1-noble
container: ${{ matrix.image }}
steps:
- name: Install SQLite
Expand All @@ -38,6 +39,8 @@ jobs:
xcode-version: latest
- name: Checkout Repository
uses: actions/checkout@v2
- name: Log Swift Version
run: swift --version
- name: Install Override Package.swift
run: cp .github/_support/Package.swift .github/_support/Package\@swift-5.swift .
- name: Build Swift Debug Package
Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ CONFIGURATION=debug
DOCKER=/usr/local/bin/docker

# docker config (5.6.1 seems the first w/ aarch64)
SWIFT_BUILD_IMAGE="swift:5.6.2-focal"
#SWIFT_BUILD_IMAGE="swift:5.6.2-focal"
#SWIFT_BUILD_IMAGE=swift:5.9.0-focal
SWIFT_BUILD_IMAGE=swift:5.10.1-noble
DOCKER_BUILD_DIR=".docker$(SWIFT_BUILD_DIR)"
SWIFT_DOCKER_BUILD_DIR="$(DOCKER_BUILD_DIR)/aarch64-unknown-linux/$(CONFIGURATION)"
DOCKER_BUILD_PRODUCT="$(DOCKER_BUILD_DIR)/$(TOOL_NAME)"
Expand Down
37 changes: 20 additions & 17 deletions [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,32 @@ var package = Package(
],

targets: [
.systemLibrary(name: "SQLite3",
path: "Sources/SQLite3-Linux",
providers: [ .apt(["libsqlite3-dev"]) ]),

// A small library used to fetch schema information from SQLite3 databases.
.target(name: "SQLite3Schema", exclude: [ "README.md" ]),
.target(name: "SQLite3Schema",
dependencies: [
.target(name: "SQLite3",
condition: .when(platforms: [
.linux, .android, .windows, .openbsd
])),
],
exclude: [ "README.md" ]),

// Lighter is a shared lib providing common protocols used by Enlighter
// generated models and such.
// Note that Lighter isn't that useful w/o code generation (i.e. as a
// standalone lib).
.target(name: "Lighter", swiftSettings: settings),
.target(name: "Lighter",
dependencies: [
.target(name: "SQLite3",
condition: .when(platforms: [
.linux, .android, .windows, .openbsd
])),
],
swiftSettings: settings),


// MARK: - Plugin Support
Expand Down Expand Up @@ -124,18 +142,3 @@ var package = Package(
dependencies: [ "LighterGeneration" ])
]
)

#if !(os(macOS) || os(iOS) || os(watchOS) || os(tvOS))
package.products += [ .library(name: "SQLite3", targets: [ "SQLite3" ]) ]
package.targets += [
.systemLibrary(name: "SQLite3",
path: "Sources/SQLite3-Linux",
providers: [ .apt(["libsqlite3-dev"]) ])
]
package.targets
.first(where: { $0.name == "SQLite3Schema" })?
.dependencies.append("SQLite3")
package.targets
.first(where: { $0.name == "Lighter" })?
.dependencies.append("SQLite3")
#endif // not-Darwin
119 changes: 119 additions & 0 deletions [email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// swift-tools-version:6.0

import PackageDescription

var package = Package(
name: "Lighter",

platforms: [ .macOS(.v10_15), .iOS(.v13) ],

products: [
.library(name: "Lighter", targets: [ "Lighter" ]),
.library(name: "SQLite3Schema", targets: [ "SQLite3Schema" ]),

.executable(name: "sqlite2swift", targets: [ "sqlite2swift" ]),

.plugin(name: "Enlighter", targets: [ "Enlighter" ]),
.plugin(name: "Generate Code for SQLite",
targets: [ "Generate Code for SQLite" ])
],

targets: [
// A small library used to fetch schema information from SQLite3 databases.
.target(name: "SQLite3Schema", exclude: [ "README.md" ]),

// Lighter is a shared lib providing common protocols used by Enlighter
// generated models and such.
// Note that Lighter isn't that useful w/o code generation (i.e. as a
// standalone lib).
.target(name: "Lighter"),


// MARK: - Plugin Support

// The CodeGenAST is a small and hacky helper lib that can format/render
// Swift source code.
.target(name : "LighterCodeGenAST",
path : "Plugins/Libraries/LighterCodeGenAST",
exclude : [ "README.md" ]),

// This library contains all the code generation, to be used by different
// clients.
.target(name : "LighterGeneration",
dependencies : [ "LighterCodeGenAST", "SQLite3Schema" ],
path : "Plugins/Libraries/LighterGeneration",
exclude : [ "README.md", "LighterConfiguration/README.md" ]),


// MARK: - Tests

.testTarget(name: "CodeGenASTTests", dependencies: [ "LighterCodeGenAST" ]),
.testTarget(name: "EntityGenTests", dependencies: [ "LighterGeneration" ]),
.testTarget(name: "LighterOperationGenTests",
dependencies: [ "LighterGeneration" ]),
.testTarget(name: "ContactsDatabaseTests", dependencies: [ "Lighter" ],
exclude: [ "contacts-create.sql" ]),


// MARK: - Plugins and supporting Tools

.executableTarget(name : "sqlite2swift",
dependencies : [ "LighterGeneration" ],
path : "Plugins/Tools/sqlite2swift",
exclude : [ "README.md" ]),

.plugin(name: "Enlighter", capability: .buildTool(),
dependencies: [ "sqlite2swift" ]),

.plugin(
name: "Generate Code for SQLite",
capability: .command(
intent: .custom(
verb: "sqlite2swift",
description:
"Generate Swift code for SQLite DBs into the Sources directory."
),
permissions: [
.writeToPackageDirectory(reason:
"The plugin needs access to generate the source file.")
]
),
dependencies: [ "sqlite2swift" ],
path: "Plugins/GenerateCodeForSQLite"
),


// MARK: - Internal Plugin for Generating Variadics

.executableTarget(name : "GenerateInternalVariadics",
dependencies : [ "LighterCodeGenAST",
"LighterGeneration" ],
path : "Plugins/Tools/GenerateInternalVariadics",
exclude : [ "README.md" ]),
.plugin(
name: "Generate Variadics into Lighter (Internal)",
capability: .command(
intent: .custom(
verb: "write-internal-variadics",
description:
"Generate the variadic queries into the Sources/Lighter directory."
),
permissions: [
.writeToPackageDirectory(
reason: "The plugin needs access to generate the source file.")
]
),
dependencies: [ "GenerateInternalVariadics" ],
path: "Plugins/WriteInternalVariadics"
),


// MARK: - Environment specific tests
.testTarget(name: "FiveThirtyEightTests",
dependencies: [ "LighterGeneration" ]),
.testTarget(name: "NorthwindTests",
dependencies: [ "LighterGeneration" ])
],

swiftLanguageVersions: [ .v5, .v6 ]
)
10 changes: 6 additions & 4 deletions Plugins/Enlighter/Enlighter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,12 @@ struct Enlighter: BuildToolPlugin {

let debugFH = fopen("/tmp/zzdebug.log", "a")
assert(debugFH != nil)
fputs(msg, debugFH)
fflush(debugFH)
fclose(debugFH)
#endif
if let debugFH = debugFH {
fputs(msg, debugFH)
fflush(debugFH)
fclose(debugFH)
}
#endif // DEBUG || true
}

fileprivate func dbExtensions(in rootJSON: [ String : Any ], target: String)
Expand Down
10 changes: 6 additions & 4 deletions Plugins/GenerateCodeForSQLite/GenerateCodeForSQLite.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,12 @@ struct GenerateCodeForSQLite: CommandPlugin {

let debugFH = fopen("/tmp/zzdebug.log", "a")
assert(debugFH != nil)
fputs(msg, debugFH)
fflush(debugFH)
fclose(debugFH)
#endif
if let debugFH = debugFH {
fputs(msg, debugFH)
fflush(debugFH)
fclose(debugFH)
}
#endif // DEBUG || true
}

fileprivate func dbExtensions(in rootJSON: [ String : Any ], target: String)
Expand Down
18 changes: 12 additions & 6 deletions Plugins/Libraries/LighterCodeGenAST/Generation/GenLiterals.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,18 @@ fileprivate func poundsForString(_ string: String, max: Int = 10) -> String? {
return nil
}

fileprivate let unsafeSwiftStringLiteralCharacters : CharacterSet = {
var safeCharacters = CharacterSet.alphanumerics
safeCharacters.formUnion(.whitespaces)
safeCharacters.formUnion(.init(charactersIn: "_,;&'@#!$(){}+-*/:."))
return safeCharacters.inverted
}()
fileprivate struct UnsafeLiteralCharacters: @unchecked Sendable {

private let set : CharacterSet = {
var safeCharacters = CharacterSet.alphanumerics
safeCharacters.formUnion(.whitespaces)
safeCharacters.formUnion(.init(charactersIn: "_,;&'@#!$(){}+-*/:."))
return safeCharacters.inverted
}()

func contains(_ c: Unicode.Scalar) -> Bool { return set.contains(c) }
}
fileprivate let unsafeSwiftStringLiteralCharacters = UnsafeLiteralCharacters()

extension String {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,7 @@ public extension CompilationUnit {
extensions.append(ext)
}
}

#if swift(>=5.5)
extension CompilationUnit: Sendable {}
#endif
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Created by Helge Heß.
// Copyright © 2022 ZeeZide GmbH.
// Copyright © 2022-2024 ZeeZide GmbH.
//

/**
Expand Down Expand Up @@ -86,3 +86,7 @@ public extension ComputedPropertyDefinition {
comment: comment, inlinable: inlinable)
}
}

#if swift(>=5.5)
extension ComputedPropertyDefinition : Sendable {}
#endif
6 changes: 5 additions & 1 deletion Plugins/Libraries/LighterCodeGenAST/Nodes/Expression.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/**
* An AST node for various Swift expressions.
*/
public indirect enum Expression: Equatable, Sendable {
public indirect enum Expression: Equatable {

/// The operators for ``compare(lhs:operator:rhs:)`` expressions.
public enum Operator: String, Sendable {
Expand Down Expand Up @@ -280,3 +280,7 @@ public extension Expression {
.conditional(condition: condition, true: `true`, false: `false`)
}
}

#if swift(>=5.5)
extension Expression : Sendable {}
#endif
6 changes: 5 additions & 1 deletion Plugins/Libraries/LighterCodeGenAST/Nodes/Extension.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Created by Helge Heß.
// Copyright © 2022 ZeeZide GmbH.
// Copyright © 2022-2024 ZeeZide GmbH.
//

/**
Expand Down Expand Up @@ -60,3 +60,7 @@ public struct Extension {
functions.isEmpty && structures.isEmpty && typeFunctions.isEmpty
}
}

#if swift(>=5.5)
extension Extension: Sendable {}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
*
* Has all the function specific things, like parameters and such.
*/
public struct FunctionComment: Equatable, Sendable {
public struct FunctionComment: Equatable {

/// A comment for a function parameter.
public struct Parameter: Equatable, Sendable {
public struct Parameter: Equatable {

/// The name of the function parameter being documented.
public var name : String
Expand Down Expand Up @@ -53,3 +53,8 @@ public struct FunctionComment: Equatable, Sendable {
self.returnInfo = returnInfo
}
}

#if swift(>=5.5)
extension FunctionComment : Sendable {}
extension FunctionComment.Parameter : Sendable {}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* where C1: SQLColumn, C2: SQLColumn, T == C1.T, T == C2.T
* ```
*/
public struct FunctionDeclaration: Equatable, Sendable {
public struct FunctionDeclaration: Equatable {

/// Is the function public?
public let `public` : Bool
Expand Down Expand Up @@ -95,3 +95,7 @@ public extension FunctionDeclaration {
returnType: .void, genericConstraints: [])
}
}

#if swift(>=5.5)
extension FunctionDeclaration: Sendable {}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
* Plus extra annotations like ``inlinable`` and the ``comment``.
*/
public struct FunctionDefinition: Equatable, Sendable {
public struct FunctionDefinition: Equatable {

/// Whether the definition is `@inlinable` (included in the module header).
public var inlinable : Bool
Expand Down Expand Up @@ -54,3 +54,7 @@ public extension FunctionDefinition {
self.init(declaration: declaration, statements: statements)
}
}

#if swift(>=5.5)
extension FunctionDefinition: Sendable {}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public extension FunctionDeclaration {

/// A parameter, like `from table: KeyPath<Self.RecordTypes, T.Type>`
/// Or: `limit: Int? = nil`
struct Parameter: Equatable, Sendable {
struct Parameter: Equatable {

/// The "label" of the parameter, e.g. the `from` in `select(from table:)`.
/// Can be `nil` for a wildcard (`_`).
Expand Down Expand Up @@ -92,3 +92,7 @@ public extension FunctionDeclaration.Parameter {
)
}
}

#if swift(>=5.5)
extension FunctionDeclaration.Parameter: Sendable {}
#endif
Loading

0 comments on commit f033ff1

Please sign in to comment.