2022-04-09 04:36:52 +08:00
|
|
|
// swift-tools-version:5.6
|
2018-12-07 19:21:37 +08:00
|
|
|
|
|
|
|
import PackageDescription
|
|
|
|
|
|
|
|
let package = Package(
|
2019-02-18 18:54:49 +08:00
|
|
|
name: "Tokamak",
|
2019-04-01 16:44:20 +08:00
|
|
|
platforms: [
|
2020-12-04 19:19:14 +08:00
|
|
|
.macOS(.v11),
|
2020-07-20 03:53:27 +08:00
|
|
|
.iOS(.v13),
|
2019-04-01 16:44:20 +08:00
|
|
|
],
|
2018-12-29 05:54:16 +08:00
|
|
|
products: [
|
2018-12-29 22:41:46 +08:00
|
|
|
// Products define the executables and libraries produced by a package,
|
|
|
|
// and make them visible to other packages.
|
2020-06-17 07:58:10 +08:00
|
|
|
.executable(
|
|
|
|
name: "TokamakDemo",
|
|
|
|
targets: ["TokamakDemo"]
|
|
|
|
),
|
2018-12-29 05:54:16 +08:00
|
|
|
.library(
|
2020-06-23 06:01:11 +08:00
|
|
|
name: "TokamakDOM",
|
|
|
|
targets: ["TokamakDOM"]
|
2018-12-29 05:54:16 +08:00
|
|
|
),
|
2020-08-02 04:27:12 +08:00
|
|
|
.library(
|
|
|
|
name: "TokamakStaticHTML",
|
|
|
|
targets: ["TokamakStaticHTML"]
|
|
|
|
),
|
|
|
|
.executable(
|
2021-06-07 01:52:15 +08:00
|
|
|
name: "TokamakStaticHTMLDemo",
|
|
|
|
targets: ["TokamakStaticHTMLDemo"]
|
2020-08-02 04:27:12 +08:00
|
|
|
),
|
2020-12-27 00:11:06 +08:00
|
|
|
.library(
|
|
|
|
name: "TokamakGTK",
|
|
|
|
targets: ["TokamakGTK"]
|
|
|
|
),
|
|
|
|
.executable(
|
|
|
|
name: "TokamakGTKDemo",
|
|
|
|
targets: ["TokamakGTKDemo"]
|
|
|
|
),
|
|
|
|
.library(
|
|
|
|
name: "TokamakShim",
|
|
|
|
targets: ["TokamakShim"]
|
|
|
|
),
|
2021-01-21 05:09:54 +08:00
|
|
|
.executable(
|
|
|
|
name: "TokamakStaticHTMLBenchmark",
|
|
|
|
targets: ["TokamakStaticHTMLBenchmark"]
|
|
|
|
),
|
2018-12-29 05:54:16 +08:00
|
|
|
],
|
|
|
|
dependencies: [
|
2020-09-30 17:17:19 +08:00
|
|
|
.package(
|
2024-08-27 20:51:20 +08:00
|
|
|
url: "https://gitlink.org.cn/dnrops/JavaScriptKit.git",
|
2022-05-19 21:53:48 +08:00
|
|
|
from: "0.15.0"
|
2020-09-30 17:17:19 +08:00
|
|
|
),
|
2021-06-21 23:45:21 +08:00
|
|
|
.package(
|
2024-08-27 20:51:20 +08:00
|
|
|
url: "https://gitlink.org.cn/dnrops/OpenCombine.git",
|
2021-06-21 23:45:21 +08:00
|
|
|
from: "0.12.0"
|
|
|
|
),
|
|
|
|
.package(
|
2024-08-27 20:58:20 +08:00
|
|
|
url: "https://gitcode.net/dnrops/OpenCombineJS.git",
|
2022-05-19 21:53:48 +08:00
|
|
|
from: "0.2.0"
|
2021-06-21 23:45:21 +08:00
|
|
|
),
|
|
|
|
.package(
|
2024-08-27 20:51:20 +08:00
|
|
|
url: "https://gitlink.org.cn/dnrops/swift-benchmark",
|
2022-05-20 20:48:32 +08:00
|
|
|
from: "0.1.2"
|
2021-06-21 23:45:21 +08:00
|
|
|
),
|
2021-06-21 23:00:28 +08:00
|
|
|
.package(
|
2024-08-27 20:51:20 +08:00
|
|
|
url: "https://gitlink.org.cn/dnrops/swift-snapshot-testing.git",
|
2021-06-21 23:00:28 +08:00
|
|
|
from: "1.9.0"
|
|
|
|
),
|
2018-12-29 05:54:16 +08:00
|
|
|
],
|
|
|
|
targets: [
|
2018-12-29 22:41:46 +08:00
|
|
|
// Targets are the basic building blocks of a package. A target can define
|
|
|
|
// a module or a test suite.
|
|
|
|
// Targets can depend on other targets in this package, and on products
|
|
|
|
// in packages which this package depends on.
|
2018-12-29 05:54:16 +08:00
|
|
|
.target(
|
2020-06-23 18:47:54 +08:00
|
|
|
name: "TokamakCore",
|
2021-06-16 06:01:45 +08:00
|
|
|
dependencies: [
|
|
|
|
.product(
|
|
|
|
name: "OpenCombineShim",
|
|
|
|
package: "OpenCombine"
|
|
|
|
),
|
|
|
|
]
|
2018-12-29 05:54:16 +08:00
|
|
|
),
|
2020-12-27 00:11:06 +08:00
|
|
|
.target(
|
|
|
|
name: "TokamakShim",
|
|
|
|
dependencies: [
|
|
|
|
.target(name: "TokamakDOM", condition: .when(platforms: [.wasi])),
|
|
|
|
.target(name: "TokamakGTK", condition: .when(platforms: [.linux])),
|
|
|
|
]
|
|
|
|
),
|
|
|
|
.systemLibrary(
|
|
|
|
name: "CGTK",
|
|
|
|
pkgConfig: "gtk+-3.0",
|
|
|
|
providers: [
|
|
|
|
.apt(["libgtk+-3.0", "gtk+-3.0"]),
|
|
|
|
// .yum(["gtk3-devel"]),
|
|
|
|
.brew(["gtk+3"]),
|
|
|
|
]
|
|
|
|
),
|
2021-01-12 19:09:25 +08:00
|
|
|
.systemLibrary(
|
|
|
|
name: "CGDK",
|
|
|
|
pkgConfig: "gdk-3.0",
|
|
|
|
providers: [
|
|
|
|
.apt(["libgtk+-3.0", "gtk+-3.0"]),
|
|
|
|
// .yum(["gtk3-devel"]),
|
|
|
|
.brew(["gtk+3"]),
|
|
|
|
]
|
|
|
|
),
|
2020-12-27 00:11:06 +08:00
|
|
|
.target(
|
|
|
|
name: "TokamakGTKCHelpers",
|
|
|
|
dependencies: ["CGTK"]
|
|
|
|
),
|
|
|
|
.target(
|
|
|
|
name: "TokamakGTK",
|
2021-06-16 06:01:45 +08:00
|
|
|
dependencies: [
|
|
|
|
"TokamakCore", "CGTK", "CGDK", "TokamakGTKCHelpers",
|
|
|
|
.product(
|
|
|
|
name: "OpenCombineShim",
|
|
|
|
package: "OpenCombine"
|
|
|
|
),
|
|
|
|
]
|
2020-12-27 00:11:06 +08:00
|
|
|
),
|
2021-09-08 17:18:53 +08:00
|
|
|
.executableTarget(
|
2020-12-27 00:11:06 +08:00
|
|
|
name: "TokamakGTKDemo",
|
2020-12-27 03:21:01 +08:00
|
|
|
dependencies: ["TokamakGTK"],
|
|
|
|
resources: [.copy("logo-header.png")]
|
2020-12-27 00:11:06 +08:00
|
|
|
),
|
2019-03-12 19:37:22 +08:00
|
|
|
.target(
|
2020-08-02 04:27:12 +08:00
|
|
|
name: "TokamakStaticHTML",
|
|
|
|
dependencies: [
|
|
|
|
"TokamakCore",
|
|
|
|
]
|
2019-03-12 19:37:22 +08:00
|
|
|
),
|
2021-09-08 17:18:53 +08:00
|
|
|
.executableTarget(
|
2021-01-24 23:26:51 +08:00
|
|
|
name: "TokamakCoreBenchmark",
|
|
|
|
dependencies: [
|
2022-04-09 04:36:52 +08:00
|
|
|
.product(name: "Benchmark", package: "swift-benchmark"),
|
2021-01-24 23:26:51 +08:00
|
|
|
"TokamakCore",
|
2022-05-24 00:14:16 +08:00
|
|
|
"TokamakTestRenderer",
|
2021-01-24 23:26:51 +08:00
|
|
|
]
|
|
|
|
),
|
2021-09-08 17:18:53 +08:00
|
|
|
.executableTarget(
|
2021-01-21 05:09:54 +08:00
|
|
|
name: "TokamakStaticHTMLBenchmark",
|
|
|
|
dependencies: [
|
2022-04-09 04:36:52 +08:00
|
|
|
.product(name: "Benchmark", package: "swift-benchmark"),
|
2021-01-21 05:09:54 +08:00
|
|
|
"TokamakStaticHTML",
|
|
|
|
]
|
|
|
|
),
|
2020-04-12 04:58:24 +08:00
|
|
|
.target(
|
|
|
|
name: "TokamakDOM",
|
2022-04-09 04:36:52 +08:00
|
|
|
dependencies: [
|
|
|
|
"TokamakCore",
|
|
|
|
"TokamakStaticHTML",
|
|
|
|
.product(
|
|
|
|
name: "OpenCombineShim",
|
|
|
|
package: "OpenCombine"
|
|
|
|
),
|
|
|
|
.product(
|
|
|
|
name: "JavaScriptKit",
|
|
|
|
package: "JavaScriptKit",
|
|
|
|
condition: .when(platforms: [.wasi])
|
|
|
|
),
|
|
|
|
.product(
|
|
|
|
name: "JavaScriptEventLoop",
|
|
|
|
package: "JavaScriptKit",
|
|
|
|
condition: .when(platforms: [.wasi])
|
|
|
|
),
|
|
|
|
"OpenCombineJS",
|
|
|
|
]
|
2020-04-12 04:58:24 +08:00
|
|
|
),
|
2021-09-08 17:18:53 +08:00
|
|
|
.executableTarget(
|
2020-08-02 04:27:12 +08:00
|
|
|
name: "TokamakDemo",
|
2020-11-06 05:37:56 +08:00
|
|
|
dependencies: [
|
|
|
|
"TokamakShim",
|
|
|
|
.product(
|
|
|
|
name: "JavaScriptKit",
|
|
|
|
package: "JavaScriptKit",
|
|
|
|
condition: .when(platforms: [.wasi])
|
2020-11-09 20:27:17 +08:00
|
|
|
),
|
2020-12-04 19:19:55 +08:00
|
|
|
],
|
2021-07-28 21:40:12 +08:00
|
|
|
resources: [.copy("logo-header.png")],
|
|
|
|
linkerSettings: [
|
|
|
|
.unsafeFlags(
|
|
|
|
["-Xlinker", "--stack-first", "-Xlinker", "-z", "-Xlinker", "stack-size=16777216"],
|
|
|
|
.when(platforms: [.wasi])
|
|
|
|
),
|
|
|
|
]
|
2020-08-02 04:27:12 +08:00
|
|
|
),
|
2021-09-08 17:18:53 +08:00
|
|
|
.executableTarget(
|
2021-06-07 01:52:15 +08:00
|
|
|
name: "TokamakStaticHTMLDemo",
|
2020-08-02 04:27:12 +08:00
|
|
|
dependencies: [
|
|
|
|
"TokamakStaticHTML",
|
|
|
|
]
|
|
|
|
),
|
2018-12-29 05:54:16 +08:00
|
|
|
.target(
|
2019-02-18 18:54:49 +08:00
|
|
|
name: "TokamakTestRenderer",
|
2020-06-23 18:47:54 +08:00
|
|
|
dependencies: ["TokamakCore"]
|
2018-12-29 05:54:16 +08:00
|
|
|
),
|
2022-06-27 20:53:30 +08:00
|
|
|
.testTarget(
|
|
|
|
name: "TokamakLayoutTests",
|
|
|
|
dependencies: [
|
|
|
|
"TokamakCore",
|
|
|
|
"TokamakStaticHTML",
|
|
|
|
.product(
|
|
|
|
name: "SnapshotTesting",
|
|
|
|
package: "swift-snapshot-testing",
|
|
|
|
condition: .when(platforms: [.macOS])
|
|
|
|
),
|
|
|
|
]
|
|
|
|
),
|
2022-05-24 00:14:16 +08:00
|
|
|
.testTarget(
|
|
|
|
name: "TokamakReconcilerTests",
|
|
|
|
dependencies: [
|
|
|
|
"TokamakCore",
|
|
|
|
"TokamakTestRenderer",
|
|
|
|
]
|
|
|
|
),
|
2018-12-29 05:54:16 +08:00
|
|
|
.testTarget(
|
2019-02-18 18:54:49 +08:00
|
|
|
name: "TokamakTests",
|
2020-11-07 18:11:35 +08:00
|
|
|
dependencies: ["TokamakTestRenderer"]
|
2018-12-29 05:54:16 +08:00
|
|
|
),
|
Replace `ViewDeferredToRenderer`, fix renderer tests (#408)
This allows writing tests for `TokamakStaticHTML`, `TokamakDOM`, and `TokamakGTK` targets.
The issue was caused by conflicting `ViewDeferredToRenderer` conformances declared in different modules, including the `TokamakTestRenderer` module.
This works around a general limitation in Swift, which was [discussed at length on Swift Forums previously](https://forums.swift.org/t/an-implementation-model-for-rational-protocol-conformance-behavior/37171). When multiple conflicting conformances to the same protocol (`ViewDeferredToRenderer` in our case) exist in different modules, only one of them is available in a given binary (even a test binary). Also, only of them can be loaded and used. Which one exactly is loaded can't be known at compile-time, which is hard to debug and leads to breaking tests that cover code in different renderers. We had to disable `TokamakStaticHTMLTests` for this reason.
The workaround is to declare two new functions in the `Renderer` protocol:
```swift
public protocol Renderer: AnyObject {
// ...
// Functions unrelated to the issue at hand skipped for brevity.
/** Returns a body of a given pritimive view, or `nil` if `view` is not a primitive view for
this renderer.
*/
func body(for view: Any) -> AnyView?
/** Returns `true` if a given view type is a primitive view that should be deferred to this
renderer.
*/
func isPrimitiveView(_ type: Any.Type) -> Bool
}
```
Now each renderer can declare their own protocols for their primitive views, i.e. `HTMLPrimitive`, `DOMPrimitive`, `GTKPrimitive` etc, delegating to them from the implementations of `body(for view:)` and `isPrimitiveView(_:)`. Conformances to these protocols can't conflict across different modules. Also, these protocols can have `internal` visibility, as opposed to `ViewDeferredToRenderer`, which had to be declared as `public` in `TokamakCore` to be visible in renderer modules.
2021-06-08 00:24:02 +08:00
|
|
|
.testTarget(
|
|
|
|
name: "TokamakStaticHTMLTests",
|
2021-06-21 23:00:28 +08:00
|
|
|
dependencies: [
|
|
|
|
"TokamakStaticHTML",
|
|
|
|
.product(
|
|
|
|
name: "SnapshotTesting",
|
2022-04-09 04:36:52 +08:00
|
|
|
package: "swift-snapshot-testing",
|
2021-06-21 23:45:21 +08:00
|
|
|
condition: .when(platforms: [.macOS])
|
2021-06-21 23:00:28 +08:00
|
|
|
),
|
|
|
|
],
|
2021-08-15 06:26:39 +08:00
|
|
|
exclude: ["__Snapshots__", "RenderingTests/__Snapshots__"]
|
Replace `ViewDeferredToRenderer`, fix renderer tests (#408)
This allows writing tests for `TokamakStaticHTML`, `TokamakDOM`, and `TokamakGTK` targets.
The issue was caused by conflicting `ViewDeferredToRenderer` conformances declared in different modules, including the `TokamakTestRenderer` module.
This works around a general limitation in Swift, which was [discussed at length on Swift Forums previously](https://forums.swift.org/t/an-implementation-model-for-rational-protocol-conformance-behavior/37171). When multiple conflicting conformances to the same protocol (`ViewDeferredToRenderer` in our case) exist in different modules, only one of them is available in a given binary (even a test binary). Also, only of them can be loaded and used. Which one exactly is loaded can't be known at compile-time, which is hard to debug and leads to breaking tests that cover code in different renderers. We had to disable `TokamakStaticHTMLTests` for this reason.
The workaround is to declare two new functions in the `Renderer` protocol:
```swift
public protocol Renderer: AnyObject {
// ...
// Functions unrelated to the issue at hand skipped for brevity.
/** Returns a body of a given pritimive view, or `nil` if `view` is not a primitive view for
this renderer.
*/
func body(for view: Any) -> AnyView?
/** Returns `true` if a given view type is a primitive view that should be deferred to this
renderer.
*/
func isPrimitiveView(_ type: Any.Type) -> Bool
}
```
Now each renderer can declare their own protocols for their primitive views, i.e. `HTMLPrimitive`, `DOMPrimitive`, `GTKPrimitive` etc, delegating to them from the implementations of `body(for view:)` and `isPrimitiveView(_:)`. Conformances to these protocols can't conflict across different modules. Also, these protocols can have `internal` visibility, as opposed to `ViewDeferredToRenderer`, which had to be declared as `public` in `TokamakCore` to be visible in renderer modules.
2021-06-08 00:24:02 +08:00
|
|
|
),
|
2018-12-29 05:54:16 +08:00
|
|
|
]
|
2018-12-07 19:21:37 +08:00
|
|
|
)
|