Skip to content

Support --root-type when compiling from proto (fixes #9055) - #9257

Open
jdymitarai wants to merge 1 commit into
google:masterfrom
jdymitarai:fix-flatc-root-type-proto-9055
Open

jdymitarai wants to merge 1 commit into
google:masterfrom
jdymitarai:fix-flatc-root-type-proto-9055

Conversation

@jdymitarai

Copy link
Copy Markdown

Fixes #9055.

Root Cause

flatc deferred calling parser->SetRootType() until after all code generators had executed and serialization had completed, preventing generators from receiving the command-line overridden root type. Additionally, GenerateFBS (used when compiling schemas from .proto) did not emit root_type declarations even when parser.root_struct_def_ was set.

Fix Approach

  1. Move parser->SetRootType() in FlatCompiler::GenerateCode to immediately follow schema parsing and circular struct dependency validation, ensuring the root type is established prior to both serialization and generator execution.
  2. In GenerateFBS, emit root_type <type>; (using the fully-qualified name when the current namespace differs) if parser.root_struct_def_ is set.

Test Verification

Added proto_test_root_type in tests/proto_test.cpp covering schema generation with and without root types, and added RootTypeFromProto CLI test in tests/flatc/flatc_schema_tests.py. Executed flattests.exe locally with all unit tests passing.

@github-actions github-actions Bot added python c++ codegen Involving generating code from schema labels Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ codegen Involving generating code from schema python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support --root-type when compiling from proto

1 participant