Skip to content

Commit b8db3a9

Browse files
authored
Adds windows swift support (#8622)
Adding support for windows requires the code generations to add a compiler statement to completely ignore GRPC code generation on windows Cleanup the project to use the main Package.swift to run tests instead of having it separate and includes the imports for GRPC within it. Adds windows swift ci
1 parent 7555643 commit b8db3a9

38 files changed

+64
-68
lines changed

.github/workflows/build.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -492,10 +492,10 @@ jobs:
492492
sh phpUnionVectorTest.sh
493493
494494
build-swift:
495-
name: Build Swift
495+
name: Test Swift
496496
strategy:
497497
matrix:
498-
swift: ["5.9", "5.10", "6.0"]
498+
swift: ["5.9", "5.10", "6.1"]
499499
# Only 22.04 has swift at the moment https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md?plain=1#L30
500500
runs-on: ubuntu-22.04
501501
steps:
@@ -506,13 +506,23 @@ jobs:
506506
- name: Get swift version
507507
run: swift --version
508508
- name: test
509-
working-directory: tests/swift/tests
510509
run: |
511510
swift build --build-tests
512511
swift test
513512
513+
build-swift-windows:
514+
name: Test swift windows
515+
runs-on: windows-latest
516+
steps:
517+
- uses: actions/checkout@v3
518+
- uses: SwiftyLab/setup-swift@latest
519+
with:
520+
swift-version: '6.1'
521+
- run: swift build
522+
- run: swift test
523+
514524
build-swift-wasm:
515-
name: Build Swift Wasm
525+
name: Test Swift Wasm
516526
runs-on: ubuntu-24.04
517527
container:
518528
image: ghcr.io/swiftwasm/carton:0.20.1

Package.swift

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ let package = Package(
3131
name: "FlexBuffers",
3232
targets: ["FlexBuffers"]),
3333
],
34+
dependencies: .dependencies,
3435
targets: [
3536
.target(
3637
name: "FlatBuffers",
@@ -42,6 +43,40 @@ let package = Package(
4243
path: "swift/Sources/FlexBuffers"),
4344
.target(
4445
name: "Common",
45-
dependencies: [],
4646
path: "swift/Sources/Common"),
47+
.testTarget(
48+
name: "FlatbuffersTests",
49+
dependencies: .dependencies,
50+
path: "tests/swift/Tests/Flatbuffers"
51+
),
52+
.testTarget(
53+
name: "FlexbuffersTests",
54+
dependencies: ["FlexBuffers"],
55+
path: "tests/swift/Tests/Flexbuffers"
56+
)
4757
])
58+
59+
extension Array where Element == Package.Dependency {
60+
static var dependencies: [Package.Dependency] {
61+
#if os(Windows)
62+
[]
63+
#else
64+
// Test only Dependency
65+
[.package(url: "https://github.com/grpc/grpc-swift.git", from: "1.4.1")]
66+
#endif
67+
}
68+
}
69+
70+
extension Array where Element == PackageDescription.Target.Dependency {
71+
static var dependencies: [PackageDescription.Target.Dependency] {
72+
#if os(Windows)
73+
["FlatBuffers"]
74+
#else
75+
// Test only Dependency
76+
[
77+
.product(name: "GRPC", package: "grpc-swift"),
78+
"FlatBuffers"
79+
]
80+
#endif
81+
}
82+
}

grpc/examples/swift/Greeter/Sources/Model/greeter.grpc.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// swiftlint:disable all
66
// swiftformat:disable all
77

8+
#if !os(Windows)
89
import Foundation
910
import GRPC
1011
import NIO
@@ -142,3 +143,5 @@ public protocol models_GreeterServerInterceptorFactoryProtocol {
142143
func makeSayManyHellosInterceptors() -> [ServerInterceptor<Message<models_HelloRequest>, Message<models_HelloReply>>]
143144

144145
}
146+
#endif
147+

grpc/src/compiler/swift_generator.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,8 @@ grpc::string Generate(grpc_generator::File *file,
394394
GenerateClientClass(&*printer, &vars);
395395
printer->Print("\n");
396396
GenerateServerProtocol(service, &*printer, &vars);
397+
printer->Print("\n");
398+
printer->Print("#endif\n");
397399
return output;
398400
}
399401

@@ -409,6 +411,7 @@ grpc::string GenerateHeader() {
409411
code += "// swiftlint:disable all\n";
410412
code += "// swiftformat:disable all\n";
411413
code += "\n";
414+
code += "#if !os(Windows)\n";
412415
code += "import Foundation\n";
413416
code += "import GRPC\n";
414417
code += "import NIO\n";

scripts/generate_code.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from util import flatc, root_path, tests_path, args, flatc_path
2424

2525
# Specify the other paths that will be referenced
26-
swift_code_gen = Path(root_path, "tests/swift/tests/CodeGenerationTests")
26+
swift_code_gen = Path(root_path, "tests/swift/fuzzer/CodeGenerationTests")
2727
ts_code_gen = Path(root_path, "tests/ts")
2828
samples_path = Path(root_path, "samples")
2929
reflection_path = Path(root_path, "reflection")
@@ -405,7 +405,7 @@ def glob(path, pattern):
405405
flatc(["--java", "--kotlin"], schema=dictionary_lookup_schema)
406406

407407
# Swift Tests
408-
swift_prefix = "swift/tests/Tests/FlatBuffers.Test.SwiftTests"
408+
swift_prefix = "swift/Tests/Flatbuffers"
409409
flatc(
410410
SWIFT_OPTS + BASE_OPTS + ["--grpc"],
411411
schema="monster_test.fbs",

tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/ByteBufferTests.swift renamed to tests/swift/Tests/Flatbuffers/ByteBufferTests.swift

File renamed without changes.

tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersMonsterWriterTests.swift renamed to tests/swift/Tests/Flatbuffers/FlatBuffersMonsterWriterTests.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,11 +535,10 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
535535
// strips out the nested directories.
536536
let filePath = URL(filePath: #file)
537537
.deletingLastPathComponent()
538-
.deletingLastPathComponent()
539-
.deletingLastPathComponent()
540538
return filePath.absoluteString
541539
#else
542540
return FileManager.default.currentDirectoryPath
541+
.appending("/tests/swift/Tests/Flatbuffers")
543542
#endif
544543
}
545544

tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersNanInfTests.swift renamed to tests/swift/Tests/Flatbuffers/FlatBuffersNanInfTests.swift

File renamed without changes.

tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersStructsTests.swift renamed to tests/swift/Tests/Flatbuffers/FlatBuffersStructsTests.swift

File renamed without changes.

tests/swift/tests/Tests/FlatBuffers.Test.SwiftTests/FlatBuffersTests.swift renamed to tests/swift/Tests/Flatbuffers/FlatBuffersTests.swift

File renamed without changes.

0 commit comments

Comments
 (0)