Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,41 @@ jobs:
run: |
cd scala && sbt +test && cd -

scala_xlang:
name: Scala Xlang Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: 21
distribution: "temurin"
cache: sbt
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: 3.11
- name: Cache Maven local repository
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- uses: sbt/setup-sbt@1cad58d595b729a71ca2254cdf5b43dd6f42d4bb # v1.1.18
- name: Run Scala Xlang Test
env:
FORY_SCALA_JAVA_CI: "1"
ENABLE_FORY_DEBUG_OUTPUT: "1"
run: |
cd java
mvn -T16 --no-transfer-progress clean install -DskipTests -Dmaven.javadoc.skip=true -Dmaven.source.skip=true
cd fory-core
mvn -T16 --no-transfer-progress test -Dtest=org.apache.fory.xlang.ScalaXlangTest
- name: Run Scala IDL Tests
run: ./integration_tests/idl_tests/run_scala_tests.sh

integration_tests:
name: Integration Tests
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ This is the entry point for AI guidance in Apache Fory. Read this file first, th
- Only add tests that verify internal behaviors or fix specific bugs; do not create unnecessary tests unless requested.
- Do not add cleanup-sentinel tests that only pin deleted APIs or removed fields.
- Tests must exercise the actual code you wrote or changed. Do not write tests that pass by exercising a pre-existing code path that produces similar-looking results. Before writing a test, identify the exact new code path (annotation, codegen output, new API) and verify the test would fail if that code path were removed. When the change involves codegen or annotations, the test must use those annotations on real structs, run through the codegen pipeline, and verify the generated output drives the expected runtime behavior.
- Keep test method names concise. Name the behavior under test without encoding the whole scenario or expected result in the method name.
- When reading code, skip files not tracked by git by default unless you generated them yourself or the task explicitly requires them.
- Maintain cross-language consistency while respecting language-specific idioms.
- Keep one active ownership path per concept. Do not leave duplicate serializers, resolvers, helpers, or registration paths for the same type family unless the split is deliberate and documented.
Expand Down
14 changes: 7 additions & 7 deletions compiler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The FDL compiler generates cross-language serialization code from schema definit

## Features

- **Multi-language code generation**: Java, Python, Go, Rust, C++, C#, JavaScript, and Swift
- **Multi-language code generation**: Java, Python, Go, Rust, C++, C#, JavaScript, Swift, Dart, and Scala
- **Rich type system**: Primitives, enums, messages, lists, dense arrays, maps
- **Cross-language serialization**: Generated code works seamlessly with Apache Fory
- **Type ID and namespace support**: Both numeric IDs and name-based type registration
Expand Down Expand Up @@ -64,16 +64,16 @@ message Cat [id=103] {
foryc schema.fdl --output ./generated

# Generate for specific languages
foryc schema.fdl --lang java,python,csharp,javascript --output ./generated
foryc schema.fdl --lang java,python,csharp,javascript,scala --output ./generated

# Override package name
foryc schema.fdl --package myapp.models --output ./generated

# Language-specific output directories (protoc-style)
foryc schema.fdl --java_out=./src/main/java --python_out=./python/src --csharp_out=./csharp/src/Generated --javascript_out=./javascript
foryc schema.fdl --java_out=./src/main/java --python_out=./python/src --csharp_out=./csharp/src/Generated --javascript_out=./javascript --scala_out=./scala/src/main/scala

# Combine with other options
foryc schema.fdl --java_out=./gen --go_out=./gen/go --csharp_out=./gen/csharp --javascript_out=./gen/js -I ./proto
foryc schema.fdl --java_out=./gen --go_out=./gen/go --csharp_out=./gen/csharp --javascript_out=./gen/js --scala_out=./gen/scala -I ./proto
```

### 3. Use Generated Code
Expand Down Expand Up @@ -318,12 +318,12 @@ Each generator extends `BaseGenerator` and implements:
Generates POJOs with:

- Private fields with getters/setters
- `@Nullable` annotations for nullable fields and `@ForyField` annotations for ref fields
- `@Nullable` annotations for nullable fields and `@Ref` annotations for ref fields
- Registration helper class

```java
public class Cat {
@ForyField(ref = true)
@Ref
private Dog friend;

@Nullable
Expand Down Expand Up @@ -457,7 +457,7 @@ Arguments:
FILES FDL files to compile

Options:
--lang TEXT Target languages (java,python,cpp,rust,go,csharp,javascript or "all")
--lang TEXT Target languages (java,python,cpp,rust,go,csharp,javascript,swift,dart,scala or "all")
Default: all
--output, -o PATH Output directory
Default: ./generated
Expand Down
11 changes: 10 additions & 1 deletion compiler/fory_compiler/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def parse_args(args: Optional[List[str]] = None) -> argparse.Namespace:
"--lang",
type=str,
default="all",
help="Comma-separated list of target languages (java,python,cpp,rust,go,csharp,javascript,swift,dart). Default: all",
help="Comma-separated list of target languages (java,python,cpp,rust,go,csharp,javascript,swift,dart,scala). Default: all",
)

parser.add_argument(
Expand Down Expand Up @@ -367,6 +367,14 @@ def parse_args(args: Optional[List[str]] = None) -> argparse.Namespace:
help="Generate Dart code in DST_DIR",
)

parser.add_argument(
"--scala_out",
type=Path,
default=None,
metavar="DST_DIR",
help="Generate Scala 3 code in DST_DIR",
)

parser.add_argument(
"--go_nested_type_style",
type=str,
Expand Down Expand Up @@ -672,6 +680,7 @@ def cmd_compile(args: argparse.Namespace) -> int:
"javascript": args.javascript_out,
"swift": args.swift_out,
"dart": args.dart_out,
"scala": args.scala_out,
}

# Determine which languages to generate
Expand Down
3 changes: 3 additions & 0 deletions compiler/fory_compiler/generators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from fory_compiler.generators.javascript import JavaScriptGenerator
from fory_compiler.generators.swift import SwiftGenerator
from fory_compiler.generators.dart import DartGenerator
from fory_compiler.generators.scala import ScalaGenerator

GENERATORS = {
"java": JavaGenerator,
Expand All @@ -38,6 +39,7 @@
"javascript": JavaScriptGenerator,
"swift": SwiftGenerator,
"dart": DartGenerator,
"scala": ScalaGenerator,
}

__all__ = [
Expand All @@ -51,5 +53,6 @@
"JavaScriptGenerator",
"SwiftGenerator",
"DartGenerator",
"ScalaGenerator",
"GENERATORS",
]
Loading
Loading