[ 
https://issues.apache.org/jira/browse/GSOC-326?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Chaokun Yang updated GSOC-326:
------------------------------
    Description: 
Apache Fory has a mature compiler pipeline for FDL, Protocol Buffers, and 
FlatBuffers frontends, plus code generators for Java, Python, Go, Rust, and 
C++. The compiler also already includes service IR parsing and a `--grpc` 
generation path, but Swift code generation is not yet supported.

This project adds end-to-end Swift support in two layers:

1. Swift schema and model code generation from Fory IR.
2. Swift gRPC generation from service definitions, including transport bindings 
and a Fory-backed codec.

The implementation should follow existing compiler conventions and prioritize 
low-overhead, allocation-conscious runtime behavior.

*Problem Statement*
The repository already contains a Swift runtime (`swift/Sources/Fory`) but 
lacks compiler-generated Swift model code and Swift gRPC bindings from IDL 
files. This creates a gap:
 - Swift users cannot use `foryc` to generate model types from `.fdl`, 
`.proto`, or `.fbs`.
 - Service definitions parsed into compiler IR cannot yet target Swift 
transport code.
 - There is no official Fory codec integration for grpc-swift.

*Why This Project Matters*
 - Completes the Swift developer workflow: IDL -> generated models -> generated 
service APIs -> runnable gRPC client and server.
 - Reuses existing multi-frontend service parsing support in compiler IR.
 - Aligns Swift with other language targets and improves cross-language 
consistency.
 - Enables high-performance Swift service communication using Fory 
serialization semantics.

*Expected Outcomes*
 - Add Swift as a first-class compiler target (`{-}{{-}}lang swift`, 
`\{-}-swift_out`).
 - Generate Swift model code from schema definitions (messages, enums, unions, 
nested types).
 - Generate `service_grpc.swift` from service definitions.
 - Generate grpc-swift compatible async server and client wrappers.
 - Implement a custom grpc-swift codec backed by Fory serialization and 
deserialization.
 - Implement inbound zero-copy decode support with a safe copy fallback path.
 - Add golden-style codegen tests for filenames and key generated signatures.
 - Add cross-frontend parity tests for FDL, proto, and fbs service definitions.
 - Provide runnable Swift server and client example(s) using generated code and 
codec.
 - Document compiler usage, constraints, and integration steps.

*Detailed Scope*
1) Compiler and CLI Integration
 - Add `SwiftGenerator` under `compiler/fory_compiler/generators/`.
 - Register generator in 
`compiler/fory_compiler/generators/{_}{{_}}init{{_}}{_}.py`.
 - Extend CLI output mapping and options to support `--swift_out`.
 - Ensure `--lang swift` works with existing recursive import compilation flow.

2) Swift Model Code Generation
Generate Swift for:
 - Enums
 - Messages
 - Unions
 - Nested types
 - Type registration helper APIs

3) Swift Service and gRPC Code Generation
For each schema service:
 - Generate `service.swift` containing service protocol and method shape 
declarations.
 - Generate `service_grpc.swift` containing grpc-swift server and client 
transport bindings.

Required RPC support:
 - Unary
 - Client streaming
 - Server streaming
 - Bidirectional streaming

4) Fory Codec for grpc-swift
 - Implement codec encode and decode using Fory Swift runtime.
 - Ensure request and response types map correctly to generated Swift types.
 - Provide clear error mapping for decode and type mismatch failures.

5) Zero-Copy Decode and Fallback
 - Add a zero-copy-friendly decode path for inbound payload handling when safe 
ownership and lifecycle constraints are satisfied.
 - Add a fallback path that copies payload bytes when zero-copy cannot be 
safely applied.
 - Ensure behavior is deterministic and memory-safe.

6) Tests
 - Add codegen tests validating generated Swift file names and key signatures.
 - Add service generation tests for all RPC modes.
 - Add cross-frontend equivalence tests for FDL/proto/fbs service definitions.
 - Codec round-trip tests.
 - Error-path tests (invalid payload, type mismatch, unsupported mode).
 - Zero-copy path and fallback path coverage.

7) Examples and Documentation
 - Add runnable Swift gRPC server/client example using generated files.
 - Update `docs/compiler/compiler-guide.md` for Swift codegen options and usage.
 - Update `docs/compiler/generated-code.md` with Swift output layout and 
generated API shape.
 - Add concise Swift integration documentation for grpc-swift + Fory codec.

*Performance and Quality Requirements*
 - Keep allocation count low on encode and decode paths.
 - Avoid unnecessary data copies in transport integration.
 - Keep generated code predictable and stable for golden-style testing.
 - Preserve compiler behavior for existing languages and frontends.

*Acceptance Criteria*
1. `foryc` supports Swift generation through `{-}{{-}}lang swift` and 
`\{-}-swift_out`.
2. Swift model code compiles and integrates with Fory Swift runtime.
3. Service generation outputs `service.swift` and `service_grpc.swift` with 
correct signatures.
4. Unary, client-streaming, server-streaming, and bidi-streaming methods are 
correctly generated.
5. Fory-backed grpc-swift codec works for request and response round-trip.
6. Zero-copy decode path exists with tested fallback behavior.
7. Added tests pass and no regressions are introduced in existing compiler 
suites.
8. Documentation and runnable Swift example are complete and usable.

*Skills Required*
 - Swift
 - grpc-swift
 - Compiler and code generation
 - Serialization internals
 - Async and streaming APIs
 - Testing and performance profiling

*Difficulty*
Hard

*Project Size*
350 hours

*Potential Mentors*
 - Chaokun Yang
 - Weipeng Wang

*Source Links*
 - [https://github.com/apache/fory/issues/3370]
 - [https://fory.apache.org/docs/next/compiler/compiler_guide]
 - [https://github.com/apache/fory/tree/main/compiler]
 - [https://github.com/apache/fory/tree/main/compiler/fory_compiler]
 - [https://github.com/apache/fory/tree/main/compiler/fory_compiler/tests]
 - [https://github.com/apache/fory/tree/main/swift]
 - [https://fory.apache.org/docs/guide/rust/]
 - [https://github.com/grpc/grpc-swift]

  was:
Apache Fory has a mature compiler pipeline for FDL, Protocol Buffers, and 
FlatBuffers frontends, plus code generators for Java, Python, Go, Rust, and 
C++. The compiler also already includes service IR parsing and a `--grpc` 
generation path, but Swift code generation is not yet supported.

This project adds end-to-end Swift support in two layers:

1. Swift schema and model code generation from Fory IR.
2. Swift gRPC generation from service definitions, including transport bindings 
and a Fory-backed codec.

The implementation should follow existing compiler conventions and prioritize 
low-overhead, allocation-conscious runtime behavior.

*Problem Statement*
The repository already contains a Swift runtime (`swift/Sources/Fory`) but 
lacks compiler-generated Swift model code and Swift gRPC bindings from IDL 
files. This creates a gap:
 - Swift users cannot use `foryc` to generate model types from `.fdl`, 
`.proto`, or `.fbs`.
 - Service definitions parsed into compiler IR cannot yet target Swift 
transport code.
 - There is no official Fory codec integration for grpc-swift.

*Why This Project Matters*
 - Completes the Swift developer workflow: IDL -> generated models -> generated 
service APIs -> runnable gRPC client and server.
 - Reuses existing multi-frontend service parsing support in compiler IR.
 - Aligns Swift with other language targets and improves cross-language 
consistency.
 - Enables high-performance Swift service communication using Fory 
serialization semantics.

*Expected Outcomes*
 - Add Swift as a first-class compiler target (`-{-}lang swift`, 
`{-}-swift_out`).
 - Generate Swift model code from schema definitions (messages, enums, unions, 
nested types).
 - Generate `service_grpc.swift` from service definitions.
 - Generate grpc-swift compatible async server and client wrappers.
 - Implement a custom grpc-swift codec backed by Fory serialization and 
deserialization.
 - Implement inbound zero-copy decode support with a safe copy fallback path.
 - Add golden-style codegen tests for filenames and key generated signatures.
 - Add cross-frontend parity tests for FDL, proto, and fbs service definitions.
 - Provide runnable Swift server and client example(s) using generated code and 
codec.
 - Document compiler usage, constraints, and integration steps.

*Detailed Scope*
1) Compiler and CLI Integration
 - Add `SwiftGenerator` under `compiler/fory_compiler/generators/`.
 - Register generator in `compiler/fory_compiler/generators/_{_}init{_}_.py`.
 - Extend CLI output mapping and options to support `--swift_out`.
 - Ensure `--lang swift` works with existing recursive import compilation flow.

2) Swift Model Code Generation
Generate Swift for:
 - Enums
 - Messages
 - Unions
 - Nested types
 - Type registration helper APIs

*Requirements:*
 - Follow Fory type ID behavior (explicit IDs, auto IDs, namespace/name 
registration fallback).
 - Match existing cross-language semantics where applicable.
 - Integrate with existing Swift runtime abstractions (`Serializer`, type 
resolver, registration APIs).

3) Swift Service and gRPC Code Generation
For each schema service:
 - Generate `service.swift` containing service protocol and method shape 
declarations.
 - Generate `service_grpc.swift` containing grpc-swift server and client 
transport bindings.

Required RPC support:
 - Unary
 - Client streaming
 - Server streaming
 - Bidirectional streaming

4) Fory Codec for grpc-swift
 - Implement codec encode and decode using Fory Swift runtime.
 - Ensure request and response types map correctly to generated Swift types.
 - Provide clear error mapping for decode and type mismatch failures.

5) Zero-Copy Decode and Fallback
 - Add a zero-copy-friendly decode path for inbound payload handling when safe 
ownership and lifecycle constraints are satisfied.
 - Add a fallback path that copies payload bytes when zero-copy cannot be 
safely applied.
 - Ensure behavior is deterministic and memory-safe.

6) Tests
Compiler tests:
 - Add codegen tests validating generated Swift file names and key signatures.
 - Add service generation tests for all RPC modes.
 - Add cross-frontend equivalence tests for FDL/proto/fbs service definitions.

Swift runtime and integration tests:
 - Codec round-trip tests.
 - Error-path tests (invalid payload, type mismatch, unsupported mode).
 - Zero-copy path and fallback path coverage.

7) Examples and Documentation
 - Add runnable Swift gRPC server/client example using generated files.
 - Update `docs/compiler/compiler-guide.md` for Swift codegen options and usage.
 - Update `docs/compiler/generated-code.md` with Swift output layout and 
generated API shape.
 - Add concise Swift integration documentation for grpc-swift + Fory codec.

*Performance and Quality Requirements*
 - Keep allocation count low on encode and decode paths.
 - Avoid unnecessary data copies in transport integration.
 - Keep generated code predictable and stable for golden-style testing.
 - Preserve compiler behavior for existing languages and frontends.

*Milestones (Recommended)*
1. Community Bonding
 - Finalize generated API naming and file layout.
 - Confirm Swift option strategy and dependency constraints.
 - Agree on test matrix and acceptance checklist.

2. Phase 1
 - Implement Swift generator base and CLI wiring.
 - Generate core model types and registration helpers.
 - Add baseline model codegen tests.

3. Phase 2
 - Implement service generation (`service.swift`, `service_grpc.swift`).
 - Support unary and all streaming RPC method shapes.
 - Add service signature and transport generation tests.

4. Phase 3
 - Implement and validate Fory grpc-swift codec.
 - Implement zero-copy decode path and fallback path.
 - Add integration example and end-to-end tests.

*Finalization*
 - Documentation updates.
 - Stability pass and cleanup.
 - Final validation across compiler and Swift test suites.

*Acceptance Criteria*
1. `foryc` supports Swift generation through `-{-}lang swift` and 
`{-}-swift_out`.
2. Swift model code compiles and integrates with Fory Swift runtime.
3. Service generation outputs `service.swift` and `service_grpc.swift` with 
correct signatures.
4. Unary, client-streaming, server-streaming, and bidi-streaming methods are 
correctly generated.
5. Fory-backed grpc-swift codec works for request and response round-trip.
6. Zero-copy decode path exists with tested fallback behavior.
7. Added tests pass and no regressions are introduced in existing compiler 
suites.
8. Documentation and runnable Swift example are complete and usable.

*Skills Required*
 - Swift
 - grpc-swift
 - Compiler and code generation
 - Serialization internals
 - Async and streaming APIs
 - Testing and performance profiling

*Difficulty*
Hard

*Project Size*
350 hours

*Potential Mentors*
 - Chaokun Yang
 - Weipeng Wang

*Source Links*
 - [https://github.com/apache/fory/issues/3370]
 - [https://fory.apache.org/docs/next/compiler/compiler_guide]
 - [https://github.com/apache/fory/tree/main/compiler]
 - [https://github.com/apache/fory/tree/main/compiler/fory_compiler]
 - [https://github.com/apache/fory/tree/main/compiler/fory_compiler/tests]
 - [https://github.com/apache/fory/tree/main/swift]
 - [https://fory.apache.org/docs/guide/rust/]
 - [https://github.com/grpc/grpc-swift]


> Apache Fory Swift Schema IDL Codegen and gRPC Integration
> ---------------------------------------------------------
>
>                 Key: GSOC-326
>                 URL: https://issues.apache.org/jira/browse/GSOC-326
>             Project: Comdev GSOC
>          Issue Type: New Feature
>            Reporter: Chaokun Yang
>            Priority: Major
>              Labels: fory, gsoc2026, mentor
>
> Apache Fory has a mature compiler pipeline for FDL, Protocol Buffers, and 
> FlatBuffers frontends, plus code generators for Java, Python, Go, Rust, and 
> C++. The compiler also already includes service IR parsing and a `--grpc` 
> generation path, but Swift code generation is not yet supported.
> This project adds end-to-end Swift support in two layers:
> 1. Swift schema and model code generation from Fory IR.
> 2. Swift gRPC generation from service definitions, including transport 
> bindings and a Fory-backed codec.
> The implementation should follow existing compiler conventions and prioritize 
> low-overhead, allocation-conscious runtime behavior.
> *Problem Statement*
> The repository already contains a Swift runtime (`swift/Sources/Fory`) but 
> lacks compiler-generated Swift model code and Swift gRPC bindings from IDL 
> files. This creates a gap:
>  - Swift users cannot use `foryc` to generate model types from `.fdl`, 
> `.proto`, or `.fbs`.
>  - Service definitions parsed into compiler IR cannot yet target Swift 
> transport code.
>  - There is no official Fory codec integration for grpc-swift.
> *Why This Project Matters*
>  - Completes the Swift developer workflow: IDL -> generated models -> 
> generated service APIs -> runnable gRPC client and server.
>  - Reuses existing multi-frontend service parsing support in compiler IR.
>  - Aligns Swift with other language targets and improves cross-language 
> consistency.
>  - Enables high-performance Swift service communication using Fory 
> serialization semantics.
> *Expected Outcomes*
>  - Add Swift as a first-class compiler target (`{-}{{-}}lang swift`, 
> `\{-}-swift_out`).
>  - Generate Swift model code from schema definitions (messages, enums, 
> unions, nested types).
>  - Generate `service_grpc.swift` from service definitions.
>  - Generate grpc-swift compatible async server and client wrappers.
>  - Implement a custom grpc-swift codec backed by Fory serialization and 
> deserialization.
>  - Implement inbound zero-copy decode support with a safe copy fallback path.
>  - Add golden-style codegen tests for filenames and key generated signatures.
>  - Add cross-frontend parity tests for FDL, proto, and fbs service 
> definitions.
>  - Provide runnable Swift server and client example(s) using generated code 
> and codec.
>  - Document compiler usage, constraints, and integration steps.
> *Detailed Scope*
> 1) Compiler and CLI Integration
>  - Add `SwiftGenerator` under `compiler/fory_compiler/generators/`.
>  - Register generator in 
> `compiler/fory_compiler/generators/{_}{{_}}init{{_}}{_}.py`.
>  - Extend CLI output mapping and options to support `--swift_out`.
>  - Ensure `--lang swift` works with existing recursive import compilation 
> flow.
> 2) Swift Model Code Generation
> Generate Swift for:
>  - Enums
>  - Messages
>  - Unions
>  - Nested types
>  - Type registration helper APIs
> 3) Swift Service and gRPC Code Generation
> For each schema service:
>  - Generate `service.swift` containing service protocol and method shape 
> declarations.
>  - Generate `service_grpc.swift` containing grpc-swift server and client 
> transport bindings.
> Required RPC support:
>  - Unary
>  - Client streaming
>  - Server streaming
>  - Bidirectional streaming
> 4) Fory Codec for grpc-swift
>  - Implement codec encode and decode using Fory Swift runtime.
>  - Ensure request and response types map correctly to generated Swift types.
>  - Provide clear error mapping for decode and type mismatch failures.
> 5) Zero-Copy Decode and Fallback
>  - Add a zero-copy-friendly decode path for inbound payload handling when 
> safe ownership and lifecycle constraints are satisfied.
>  - Add a fallback path that copies payload bytes when zero-copy cannot be 
> safely applied.
>  - Ensure behavior is deterministic and memory-safe.
> 6) Tests
>  - Add codegen tests validating generated Swift file names and key signatures.
>  - Add service generation tests for all RPC modes.
>  - Add cross-frontend equivalence tests for FDL/proto/fbs service definitions.
>  - Codec round-trip tests.
>  - Error-path tests (invalid payload, type mismatch, unsupported mode).
>  - Zero-copy path and fallback path coverage.
> 7) Examples and Documentation
>  - Add runnable Swift gRPC server/client example using generated files.
>  - Update `docs/compiler/compiler-guide.md` for Swift codegen options and 
> usage.
>  - Update `docs/compiler/generated-code.md` with Swift output layout and 
> generated API shape.
>  - Add concise Swift integration documentation for grpc-swift + Fory codec.
> *Performance and Quality Requirements*
>  - Keep allocation count low on encode and decode paths.
>  - Avoid unnecessary data copies in transport integration.
>  - Keep generated code predictable and stable for golden-style testing.
>  - Preserve compiler behavior for existing languages and frontends.
> *Acceptance Criteria*
> 1. `foryc` supports Swift generation through `{-}{{-}}lang swift` and 
> `\{-}-swift_out`.
> 2. Swift model code compiles and integrates with Fory Swift runtime.
> 3. Service generation outputs `service.swift` and `service_grpc.swift` with 
> correct signatures.
> 4. Unary, client-streaming, server-streaming, and bidi-streaming methods are 
> correctly generated.
> 5. Fory-backed grpc-swift codec works for request and response round-trip.
> 6. Zero-copy decode path exists with tested fallback behavior.
> 7. Added tests pass and no regressions are introduced in existing compiler 
> suites.
> 8. Documentation and runnable Swift example are complete and usable.
> *Skills Required*
>  - Swift
>  - grpc-swift
>  - Compiler and code generation
>  - Serialization internals
>  - Async and streaming APIs
>  - Testing and performance profiling
> *Difficulty*
> Hard
> *Project Size*
> 350 hours
> *Potential Mentors*
>  - Chaokun Yang
>  - Weipeng Wang
> *Source Links*
>  - [https://github.com/apache/fory/issues/3370]
>  - [https://fory.apache.org/docs/next/compiler/compiler_guide]
>  - [https://github.com/apache/fory/tree/main/compiler]
>  - [https://github.com/apache/fory/tree/main/compiler/fory_compiler]
>  - [https://github.com/apache/fory/tree/main/compiler/fory_compiler/tests]
>  - [https://github.com/apache/fory/tree/main/swift]
>  - [https://fory.apache.org/docs/guide/rust/]
>  - [https://github.com/grpc/grpc-swift]



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to