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
31 changes: 30 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ jobs:
run: |
cd integration_tests/idl_tests/swift/idl_package
swift test --disable-automatic-resolution --skip-build
- name: Install Java artifacts for IDL tests
- name: Install Java artifacts for gRPC tests
run: |
cd java
mvn -T16 --no-transfer-progress clean install -DskipTests -Dmaven.javadoc.skip=true -Dmaven.source.skip=true
Expand Down Expand Up @@ -684,6 +684,35 @@ jobs:
- name: Run CI
run: python ./ci/run_ci.py java --version integration_tests

grpc_tests:
name: Java/Python gRPC Tests
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"
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: 3.11
cache: "pip"
- 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-
- name: Install Java artifacts for gRPC tests
run: |
cd java
mvn -T16 --no-transfer-progress clean install -DskipTests -Dmaven.javadoc.skip=true -Dmaven.source.skip=true
- name: Run Java/Python gRPC Tests
run: ./integration_tests/grpc_tests/run_tests.sh

javascript:
name: JavaScript CI
needs: changes
Expand Down
9 changes: 9 additions & 0 deletions compiler/fory_compiler/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def resolve_imports(

# Parse the file
schema = parse_idl_file(file_path)
annotate_source_package(schema)

# Process imports
imported_enums = []
Expand Down Expand Up @@ -167,6 +168,7 @@ def resolve_imports(
enums=imported_enums + schema.enums,
messages=imported_messages + schema.messages,
unions=imported_unions + schema.unions,
services=schema.services,
options=schema.options,
source_file=schema.source_file,
source_format=schema.source_format,
Expand All @@ -177,6 +179,13 @@ def resolve_imports(
return merged_schema


def annotate_source_package(schema: Schema) -> None:
"""Record each parsed top-level type's declaring package for qualified lookups."""
for type_def in schema.enums + schema.messages + schema.unions:
if type_def.source_package is None:
type_def.source_package = schema.package


def go_package_info(schema: Schema) -> Tuple[Optional[str], str]:
"""Return (import_path, package_name) for Go."""
go_package = schema.get_option("go_package")
Expand Down
18 changes: 12 additions & 6 deletions compiler/fory_compiler/frontend/proto/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,13 +420,11 @@ def _translate_rpc_method(self, proto_method: ProtoRpcMethod) -> RpcMethod:
_, options = self._translate_type_options(proto_method.options)
return RpcMethod(
name=proto_method.name,
request_type=NamedType(
name=proto_method.request_type,
location=self._location(proto_method.line, proto_method.column),
request_type=self._translate_rpc_type(
proto_method.request_type, proto_method
),
response_type=NamedType(
name=proto_method.response_type,
location=self._location(proto_method.line, proto_method.column),
response_type=self._translate_rpc_type(
proto_method.response_type, proto_method
),
client_streaming=proto_method.client_streaming,
server_streaming=proto_method.server_streaming,
Expand All @@ -435,3 +433,11 @@ def _translate_rpc_method(self, proto_method: ProtoRpcMethod) -> RpcMethod:
column=proto_method.column,
location=self._location(proto_method.line, proto_method.column),
)

def _translate_rpc_type(
self, type_name: str, proto_method: ProtoRpcMethod
) -> NamedType:
return NamedType(
name=type_name,
location=self._location(proto_method.line, proto_method.column),
)
59 changes: 58 additions & 1 deletion compiler/fory_compiler/generators/java.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from typing import Dict, List, Optional, Set, Tuple, Union as TypingUnion

from fory_compiler.generators.base import BaseGenerator, GeneratedFile
from fory_compiler.generators.services.java import JavaServiceGeneratorMixin
from fory_compiler.ir.ast import (
Message,
Enum,
Expand All @@ -37,11 +38,67 @@
from fory_compiler.ir.types import PrimitiveKind


class JavaGenerator(BaseGenerator):
class JavaGenerator(JavaServiceGeneratorMixin, BaseGenerator):
"""Generates Java POJOs with Fory annotations."""

language_name = "java"
file_extension = ".java"
JAVA_RESERVED_IDENTIFIERS = {
"abstract",
"assert",
"boolean",
"break",
"byte",
"case",
"catch",
"char",
"class",
"const",
"continue",
"default",
"do",
"double",
"else",
"enum",
"extends",
"false",
"final",
"finally",
"float",
"for",
"goto",
"if",
"implements",
"import",
"instanceof",
"int",
"interface",
"long",
"native",
"new",
"null",
"package",
"private",
"protected",
"public",
"return",
"short",
"static",
"strictfp",
"super",
"switch",
"synchronized",
"this",
"throw",
"throws",
"transient",
"true",
"try",
"void",
"volatile",
"while",
"_",
}

def __init__(self, schema: Schema, options):
super().__init__(schema, options)
Expand Down
3 changes: 2 additions & 1 deletion compiler/fory_compiler/generators/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from typing import Dict, List, Optional, Set, Tuple

from fory_compiler.generators.base import BaseGenerator, GeneratedFile
from fory_compiler.generators.services.python import PythonServiceGeneratorMixin
from fory_compiler.frontend.utils import parse_idl_file
from fory_compiler.ir.ast import (
Message,
Expand All @@ -39,7 +40,7 @@
from fory_compiler.ir.types import PrimitiveKind


class PythonGenerator(BaseGenerator):
class PythonGenerator(PythonServiceGeneratorMixin, BaseGenerator):
"""Generates Python dataclasses with pyfory type hints."""

language_name = "python"
Expand Down
18 changes: 18 additions & 0 deletions compiler/fory_compiler/generators/services/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

"""Service generator helpers."""
Loading
Loading