Skip to content

Commit 5cb496d

Browse files
Remove swift-format and docc dependencies from Package.swift
Those dependencies are just for development and not needed for the end-users. This change makes the build process simpler and faster.
1 parent dfcea8b commit 5cb496d

File tree

8 files changed

+43
-30
lines changed

8 files changed

+43
-30
lines changed

Package.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
102102
package.dependencies += [
103103
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.2.2"),
104104
.package(url: "https://github.com/apple/swift-system", .upToNextMinor(from: "1.2.1")),
105-
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.3.0"),
106-
.package(url: "https://github.com/apple/swift-format.git", from: "510.1.0"),
107105
]
108106
} else {
109107
package.dependencies += [

Sources/WAT/Parser/WastParser.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ struct WastParser {
1616

1717
mutating func nextDirective() throws -> WastDirective? {
1818
var originalParser = parser
19-
guard let _ = try parser.peek(.leftParen) else { return nil }
19+
guard (try parser.peek(.leftParen)) != nil else { return nil }
2020
try parser.consume()
2121
guard try WastDirective.peek(wastParser: self) else {
2222
if try peekModuleField() {

Sources/WasmKit/Execution/Runtime/Profiler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import SystemPackage
33

44
/// A simple time-profiler for guest process to emit `chrome://tracing` format
55
/// This profiler works only when WasmKit is built with debug configuration (`swift build -c debug`)
6-
@_documentation(visibility:internal)
6+
@_documentation(visibility: internal)
77
public class GuestTimeProfiler: RuntimeInterceptor {
88
struct Event: Codable {
99
enum Phase: String, Codable {

Sources/WasmKit/Execution/Runtime/Runtime.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public final class Runtime {
1111
}
1212
}
1313

14-
@_documentation(visibility:internal)
14+
@_documentation(visibility: internal)
1515
public protocol RuntimeInterceptor {
1616
func onEnterFunction(_ address: FunctionAddress, store: Store)
1717
func onExitFunction(_ address: FunctionAddress, store: Store)

Sources/WasmKit/Translator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ struct InstructionTranslator: InstructionVisitor {
245245
throw TranslationError("Truncating to \(height) but the stack height is \(self.height)")
246246
}
247247
while height != self.height {
248-
guard let _ = self.values.popLast() else {
248+
guard self.values.popLast() != nil else {
249249
throw TranslationError("Internal consistency error: Stack height is \(self.height) but failed to pop")
250250
}
251251
}

Tests/WasmKitTests/FuzzTranslatorRegressionTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import XCTest
21
import WasmKit
2+
import XCTest
33

44
final class FuzzTranslatorRegressionTests: XCTestCase {
55
func testRunAll() async throws {
@@ -10,7 +10,7 @@ final class FuzzTranslatorRegressionTests: XCTestCase {
1010
for file in try FileManager.default.contentsOfDirectory(atPath: failCasesDir.path) {
1111
let path = failCasesDir.appendingPathComponent(file).path
1212
print("Fuzz regression test: \(path)")
13-
13+
1414
let data = try Data(contentsOf: URL(fileURLWithPath: path))
1515
do {
1616
var module = try WasmKit.parseWasm(bytes: Array(data))

Utilities/format.py

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,54 @@
11
#!/usr/bin/env python3
22

33
import subprocess
4-
import json
4+
import os
55

6-
7-
def all_swiftpm_targets():
8-
# List up all SwiftPM targets by "swift package dump-package"
9-
output = subprocess.run(
10-
["swift", "package", "dump-package"], stdout=subprocess.PIPE)
11-
package = json.loads(output.stdout)
12-
targets = []
13-
for target in package["targets"]:
14-
if target["type"] == "plugin":
15-
continue
16-
targets.append(target["name"])
17-
18-
return targets
6+
SOURCE_ROOT = os.path.relpath(os.path.join(os.path.dirname(__file__), ".."))
197

208

219
def run(arguments):
2210
print("Running: " + " ".join(arguments))
2311
subprocess.run(arguments, check=True)
2412

2513

14+
def build_swift_format():
15+
# Build swift-format
16+
package_path = os.path.join(SOURCE_ROOT, "Vendor", "swift-format")
17+
bin_path = os.path.join(package_path, ".build", "release", "swift-format")
18+
if os.path.exists(bin_path):
19+
return bin_path
20+
21+
run(["./Vendor/checkout-dependency", "swift-format"])
22+
23+
run([
24+
"swift", "build", "-c", "release",
25+
"--package-path", package_path])
26+
return bin_path
27+
28+
2629
def main():
27-
targets = all_swiftpm_targets()
30+
targets = []
31+
for targets_dir in ["Sources", "Tests"]:
32+
targets_path = os.path.join(SOURCE_ROOT, targets_dir)
33+
for target in os.listdir(targets_path):
34+
if not os.path.isdir(os.path.join(targets_path, target)):
35+
continue
36+
targets.append(os.path.join(targets_dir, target))
37+
2838
# NOTE: SystemExtras is not included in the list of targets because it
2939
# follows swift-system style conventions, which is different from
3040
# swift-format.
31-
targets.remove("SystemExtras")
41+
targets.remove(os.path.join("Sources", "SystemExtras"))
3242

33-
arguments = ["swift", "package",
34-
"--allow-writing-to-package-directory", "format-source-code"]
35-
for target in targets:
36-
arguments.append("--target")
37-
arguments.append(target)
43+
swift_format = build_swift_format()
3844

45+
arguments = [
46+
swift_format, "format", "--in-place", "--recursive", "--parallel"
47+
]
48+
for target in targets:
49+
arguments.append(os.path.join(SOURCE_ROOT, target))
50+
arguments.append(os.path.join(SOURCE_ROOT, "Package.swift"))
3951
run(arguments)
40-
run(["swift", "format", "--in-place", "Package.swift"])
4152

4253

4354
if __name__ == "__main__":

Vendor/dependencies.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
"repository": "https://github.com/WebAssembly/wasi-testsuite.git",
88
"revision": "c9c751586fd86b321d595bbef13f2c7403cfdbc5"
99
},
10+
"swift-format": {
11+
"repository": "https://github.com/swiftlang/swift-format.git",
12+
"revision": "b268009b0d1182f9a573311c1a69eee9a7fd3d3f"
13+
},
1014
"coremark": {
1115
"repository": "https://github.com/eembc/coremark.git",
1216
"revision": "d5fad6bd094899101a4e5fd53af7298160ced6ab"

0 commit comments

Comments
 (0)