mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-01 19:58:15 +00:00
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
This commit is contained in:
18
.github/workflows/build.yml
vendored
18
.github/workflows/build.yml
vendored
@@ -492,10 +492,10 @@ jobs:
|
|||||||
sh phpUnionVectorTest.sh
|
sh phpUnionVectorTest.sh
|
||||||
|
|
||||||
build-swift:
|
build-swift:
|
||||||
name: Build Swift
|
name: Test Swift
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
swift: ["5.9", "5.10", "6.0"]
|
swift: ["5.9", "5.10", "6.1"]
|
||||||
# Only 22.04 has swift at the moment https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md?plain=1#L30
|
# Only 22.04 has swift at the moment https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md?plain=1#L30
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-22.04
|
||||||
steps:
|
steps:
|
||||||
@@ -506,13 +506,23 @@ jobs:
|
|||||||
- name: Get swift version
|
- name: Get swift version
|
||||||
run: swift --version
|
run: swift --version
|
||||||
- name: test
|
- name: test
|
||||||
working-directory: tests/swift/tests
|
|
||||||
run: |
|
run: |
|
||||||
swift build --build-tests
|
swift build --build-tests
|
||||||
swift test
|
swift test
|
||||||
|
|
||||||
|
build-swift-windows:
|
||||||
|
name: Test swift windows
|
||||||
|
runs-on: windows-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: SwiftyLab/setup-swift@latest
|
||||||
|
with:
|
||||||
|
swift-version: '6.1'
|
||||||
|
- run: swift build
|
||||||
|
- run: swift test
|
||||||
|
|
||||||
build-swift-wasm:
|
build-swift-wasm:
|
||||||
name: Build Swift Wasm
|
name: Test Swift Wasm
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
container:
|
container:
|
||||||
image: ghcr.io/swiftwasm/carton:0.20.1
|
image: ghcr.io/swiftwasm/carton:0.20.1
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ let package = Package(
|
|||||||
name: "FlexBuffers",
|
name: "FlexBuffers",
|
||||||
targets: ["FlexBuffers"]),
|
targets: ["FlexBuffers"]),
|
||||||
],
|
],
|
||||||
|
dependencies: .dependencies,
|
||||||
targets: [
|
targets: [
|
||||||
.target(
|
.target(
|
||||||
name: "FlatBuffers",
|
name: "FlatBuffers",
|
||||||
@@ -42,6 +43,40 @@ let package = Package(
|
|||||||
path: "swift/Sources/FlexBuffers"),
|
path: "swift/Sources/FlexBuffers"),
|
||||||
.target(
|
.target(
|
||||||
name: "Common",
|
name: "Common",
|
||||||
dependencies: [],
|
|
||||||
path: "swift/Sources/Common"),
|
path: "swift/Sources/Common"),
|
||||||
|
.testTarget(
|
||||||
|
name: "FlatbuffersTests",
|
||||||
|
dependencies: .dependencies,
|
||||||
|
path: "tests/swift/Tests/Flatbuffers"
|
||||||
|
),
|
||||||
|
.testTarget(
|
||||||
|
name: "FlexbuffersTests",
|
||||||
|
dependencies: ["FlexBuffers"],
|
||||||
|
path: "tests/swift/Tests/Flexbuffers"
|
||||||
|
)
|
||||||
])
|
])
|
||||||
|
|
||||||
|
extension Array where Element == Package.Dependency {
|
||||||
|
static var dependencies: [Package.Dependency] {
|
||||||
|
#if os(Windows)
|
||||||
|
[]
|
||||||
|
#else
|
||||||
|
// Test only Dependency
|
||||||
|
[.package(url: "https://github.com/grpc/grpc-swift.git", from: "1.4.1")]
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension Array where Element == PackageDescription.Target.Dependency {
|
||||||
|
static var dependencies: [PackageDescription.Target.Dependency] {
|
||||||
|
#if os(Windows)
|
||||||
|
["FlatBuffers"]
|
||||||
|
#else
|
||||||
|
// Test only Dependency
|
||||||
|
[
|
||||||
|
.product(name: "GRPC", package: "grpc-swift"),
|
||||||
|
"FlatBuffers"
|
||||||
|
]
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
// swiftlint:disable all
|
// swiftlint:disable all
|
||||||
// swiftformat:disable all
|
// swiftformat:disable all
|
||||||
|
|
||||||
|
#if !os(Windows)
|
||||||
import Foundation
|
import Foundation
|
||||||
import GRPC
|
import GRPC
|
||||||
import NIO
|
import NIO
|
||||||
@@ -142,3 +143,5 @@ public protocol models_GreeterServerInterceptorFactoryProtocol {
|
|||||||
func makeSayManyHellosInterceptors() -> [ServerInterceptor<Message<models_HelloRequest>, Message<models_HelloReply>>]
|
func makeSayManyHellosInterceptors() -> [ServerInterceptor<Message<models_HelloRequest>, Message<models_HelloReply>>]
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -394,6 +394,8 @@ grpc::string Generate(grpc_generator::File *file,
|
|||||||
GenerateClientClass(&*printer, &vars);
|
GenerateClientClass(&*printer, &vars);
|
||||||
printer->Print("\n");
|
printer->Print("\n");
|
||||||
GenerateServerProtocol(service, &*printer, &vars);
|
GenerateServerProtocol(service, &*printer, &vars);
|
||||||
|
printer->Print("\n");
|
||||||
|
printer->Print("#endif\n");
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -409,6 +411,7 @@ grpc::string GenerateHeader() {
|
|||||||
code += "// swiftlint:disable all\n";
|
code += "// swiftlint:disable all\n";
|
||||||
code += "// swiftformat:disable all\n";
|
code += "// swiftformat:disable all\n";
|
||||||
code += "\n";
|
code += "\n";
|
||||||
|
code += "#if !os(Windows)\n";
|
||||||
code += "import Foundation\n";
|
code += "import Foundation\n";
|
||||||
code += "import GRPC\n";
|
code += "import GRPC\n";
|
||||||
code += "import NIO\n";
|
code += "import NIO\n";
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ from pathlib import Path
|
|||||||
from util import flatc, root_path, tests_path, args, flatc_path
|
from util import flatc, root_path, tests_path, args, flatc_path
|
||||||
|
|
||||||
# Specify the other paths that will be referenced
|
# Specify the other paths that will be referenced
|
||||||
swift_code_gen = Path(root_path, "tests/swift/tests/CodeGenerationTests")
|
swift_code_gen = Path(root_path, "tests/swift/fuzzer/CodeGenerationTests")
|
||||||
ts_code_gen = Path(root_path, "tests/ts")
|
ts_code_gen = Path(root_path, "tests/ts")
|
||||||
samples_path = Path(root_path, "samples")
|
samples_path = Path(root_path, "samples")
|
||||||
reflection_path = Path(root_path, "reflection")
|
reflection_path = Path(root_path, "reflection")
|
||||||
@@ -405,7 +405,7 @@ dictionary_lookup_schema = "dictionary_lookup.fbs"
|
|||||||
flatc(["--java", "--kotlin"], schema=dictionary_lookup_schema)
|
flatc(["--java", "--kotlin"], schema=dictionary_lookup_schema)
|
||||||
|
|
||||||
# Swift Tests
|
# Swift Tests
|
||||||
swift_prefix = "swift/tests/Tests/FlatBuffers.Test.SwiftTests"
|
swift_prefix = "swift/Tests/Flatbuffers"
|
||||||
flatc(
|
flatc(
|
||||||
SWIFT_OPTS + BASE_OPTS + ["--grpc"],
|
SWIFT_OPTS + BASE_OPTS + ["--grpc"],
|
||||||
schema="monster_test.fbs",
|
schema="monster_test.fbs",
|
||||||
|
|||||||
@@ -535,11 +535,10 @@ class FlatBuffersMonsterWriterTests: XCTestCase {
|
|||||||
// strips out the nested directories.
|
// strips out the nested directories.
|
||||||
let filePath = URL(filePath: #file)
|
let filePath = URL(filePath: #file)
|
||||||
.deletingLastPathComponent()
|
.deletingLastPathComponent()
|
||||||
.deletingLastPathComponent()
|
|
||||||
.deletingLastPathComponent()
|
|
||||||
return filePath.absoluteString
|
return filePath.absoluteString
|
||||||
#else
|
#else
|
||||||
return FileManager.default.currentDirectoryPath
|
return FileManager.default.currentDirectoryPath
|
||||||
|
.appending("/tests/swift/Tests/Flatbuffers")
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
// swiftlint:disable all
|
// swiftlint:disable all
|
||||||
// swiftformat:disable all
|
// swiftformat:disable all
|
||||||
|
|
||||||
|
#if !os(Windows)
|
||||||
import Foundation
|
import Foundation
|
||||||
import GRPC
|
import GRPC
|
||||||
import NIO
|
import NIO
|
||||||
@@ -205,3 +206,5 @@ public protocol MyGame_Example_MonsterStorageServerInterceptorFactoryProtocol {
|
|||||||
func makeGetMinMaxHitPointsInterceptors() -> [ServerInterceptor<Message<MyGame_Example_Monster>, Message<MyGame_Example_Stat>>]
|
func makeGetMinMaxHitPointsInterceptors() -> [ServerInterceptor<Message<MyGame_Example_Monster>, Message<MyGame_Example_Stat>>]
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
@@ -18,36 +18,18 @@
|
|||||||
import PackageDescription
|
import PackageDescription
|
||||||
|
|
||||||
let package = Package(
|
let package = Package(
|
||||||
name: "FlatBuffers.Test.Swift",
|
name: "fuzzer",
|
||||||
platforms: [
|
platforms: [
|
||||||
.iOS(.v12),
|
.iOS(.v12),
|
||||||
.macOS(.v10_14),
|
.macOS(.v10_14),
|
||||||
],
|
],
|
||||||
dependencies: [
|
dependencies: [
|
||||||
.package(path: "../../.."),
|
.package(path: "../../.."),
|
||||||
.package(url: "https://github.com/grpc/grpc-swift.git", from: "1.4.1"),
|
|
||||||
// Prevent the build system from pulling 2.29.1 to prevent Swift 5.8 build breaks.
|
|
||||||
// The patch update introduced code that uses "switch expression syntax" that wasn't valid until Swift 5.9 [1].
|
|
||||||
// [1] https://github.com/swiftlang/swift-evolution/blob/main/proposals/0380-if-switch-expressions.md
|
|
||||||
.package(
|
|
||||||
url: "https://github.com/apple/swift-nio-ssl.git",
|
|
||||||
exact: "2.29.0"),
|
|
||||||
],
|
],
|
||||||
targets: [
|
targets: [
|
||||||
.executableTarget(
|
.executableTarget(
|
||||||
name: "SwiftFlatBuffers",
|
name: "fuzzer",
|
||||||
dependencies: [
|
dependencies: [
|
||||||
.product(name: "FlatBuffers", package: "flatbuffers"),
|
.product(name: "FlatBuffers", package: "flatbuffers"),
|
||||||
]),
|
]),
|
||||||
.testTarget(
|
|
||||||
name: "FlatBuffers.Test.SwiftTests",
|
|
||||||
dependencies: [
|
|
||||||
.product(name: "FlatBuffers", package: "flatbuffers"),
|
|
||||||
.product(name: "GRPC", package: "grpc-swift"),
|
|
||||||
]),
|
|
||||||
.testTarget(
|
|
||||||
name: "FlexBuffers.Test.SwiftTests",
|
|
||||||
dependencies: [
|
|
||||||
.product(name: "FlexBuffers", package: "flatbuffers"),
|
|
||||||
]),
|
|
||||||
])
|
])
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
current_dir=`pwd`
|
|
||||||
cd ..
|
|
||||||
swift_dir=`pwd`
|
|
||||||
cd ..
|
|
||||||
test_dir=`pwd`
|
|
||||||
alias fbc='${test_dir}/../flatc'
|
|
||||||
shopt -s expand_aliases
|
|
||||||
|
|
||||||
cd ${current_dir}/Tests/FlatBuffers.Test.SwiftTests
|
|
||||||
fbc --swift --gen-mutable --grpc --gen-json-emit --gen-object-api -I ${test_dir}/include_test ${test_dir}/monster_test.fbs ${test_dir}/union_vector/union_vector.fbs
|
|
||||||
fbc --swift --gen-json-emit ${test_dir}/optional_scalars.fbs
|
|
||||||
fbc --swift --gen-json-emit --gen-object-api ${test_dir}/more_defaults.fbs
|
|
||||||
fbc --swift --gen-json-emit --gen-mutable --gen-object-api ${test_dir}/MutatingBool.fbs
|
|
||||||
fbc --swift --gen-json-emit ${test_dir}/vector_has_test.fbs
|
|
||||||
cd ${current_dir}
|
|
||||||
|
|
||||||
# Goes into the code generation tests
|
|
||||||
cd CodeGenerationTests
|
|
||||||
fbc --swift --gen-mutable --grpc --gen-json-emit --gen-object-api --swift-implementation-only test_import.fbs
|
|
||||||
fbc --swift --gen-mutable --grpc --gen-json-emit --gen-object-api --no-includes test_no_include.fbs
|
|
||||||
cd ..
|
|
||||||
|
|
||||||
cd ${current_dir}/Sources/SwiftFlatBuffers
|
|
||||||
# create better fuzzing test file
|
|
||||||
fbc --swift --gen-json-emit fuzzer.fbs
|
|
||||||
cd ${current_dir}
|
|
||||||
|
|
||||||
cd ${swift_dir}/Wasm.tests/Tests/FlatBuffers.Test.Swift.WasmTests
|
|
||||||
fbc --swift --gen-mutable --gen-json-emit --gen-object-api -I ${test_dir}/include_test ${test_dir}/monster_test.fbs
|
|
||||||
cd ${current_dir}
|
|
||||||
|
|
||||||
swift build --build-tests
|
|
||||||
swift test
|
|
||||||
|
|
||||||
if [ $(uname -s) != Darwin ]; then
|
|
||||||
echo fuzzing
|
|
||||||
swift build -c debug -Xswiftc -sanitize=fuzzer,address -Xswiftc -parse-as-library
|
|
||||||
swift build -c release -Xswiftc -sanitize=fuzzer,address -Xswiftc -parse-as-library
|
|
||||||
fi
|
|
||||||
Reference in New Issue
Block a user