THRIFT-6059: add crate_prefix option to Rust codegen for cross-file imports#3546
Open
santiagomed wants to merge 1 commit into
Open
THRIFT-6059: add crate_prefix option to Rust codegen for cross-file imports#3546santiagomed wants to merge 1 commit into
santiagomed wants to merge 1 commit into
Conversation
…mports The Rust code generator hardcodes 'use crate::' for cross-file imports (e.g., when event.thrift includes trees.thrift). This assumes the generated files are placed at the crate root (src/). When files are placed in a submodule (e.g., src/thrift/), the correct prefix is 'super', and users must post-process with sed. Add a crate_prefix generator option: --gen rs:crate_prefix=super Default remains 'crate' for backward compatibility.
Contributor
Author
|
@mhlakhani @Jens-G could I get a review here please? Also open to hearing other solutions to this issue with submodules! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The Rust code generator hardcodes
use crate::for cross-file imports (e.g.,fileA.thriftincludesfileB.thriftgeneratesuse crate::fileB;). This assumes the generated files are placed at the crate root (src/). When files are placed in a submodule (e.g.,src/thrift/), the correct prefix issuper::, and users must post-process generated files with sed.Fix
Add a
crate_prefixgenerator option that controls the path prefix. Default remainscratefor backward compatibility.Changes
t_rs_generatorconstructor readscrate_prefixfromparsed_optionscrate_prefix_member stores the value (default:"crate")render_program_includesusescrate_prefix_instead of hardcoded"crate"THRIFT_REGISTER_GENERATORupdated to document the option