-
Notifications
You must be signed in to change notification settings - Fork 192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support granular control of specifying runtime crate versions #1635
Conversation
f8bc6bf
to
23d40b3
Compare
**BREAKING**: after this PR, `in smity-build.json` the path `rust-codegen.runtimeConfig.version` no longer exists. Instead, a new field `versions` comes in. It's an object mapping a runtime crate name to a version string. There is also a special key `DEFAULT`, which is presetted as detected runtime version but open to override. Crates without version specified would be set as the same version as which associated to key `DEFAULT`. Signed-off-by: Weihang Lo <[email protected]>
Signed-off-by: Weihang Lo <[email protected]>
23d40b3
to
0088847
Compare
Open question:
|
This comment was marked as outdated.
This comment was marked as outdated.
Signed-off-by: Weihang Lo <[email protected]>
This comment was marked as outdated.
This comment was marked as outdated.
[[smithy-rs]] | ||
message = "Support granular control of specifying runtime crate versions" | ||
references = ["smithy-rs#1416"] | ||
meta = { "breaking" = true, "tada" = true, "bug" = false } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For breaking changes, add instructions to the message on what changes need to be made when upgrading. You can switch the message to triple quotes if it needs to be multi-line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated. Please review again. Thanks!
Signed-off-by: Weihang Lo <[email protected]>
This comment was marked as outdated.
This comment was marked as outdated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the implementation is correct, but it would help if there'd be unit tests for these main scenarios (correct me if I'm wrong if this is not what's meant to happen):
- If user specifies
relativePath
inruntimeConfig
, then that always takes precedence overversions
. - User does not specify the
versions
object. The version number of the code-generator should be used as the version for all runtime crates. - User specifies
versions
key but leaves the object empty. The version number of the code-generator should be used as the version for all runtime crates. - User specifies
versions
object, settingDEFAULT
. That version is used for all runtime crates. - User specifies
versions
object, setting explicit version numbers for some runtime crates. Then the rest of the runtime crates use the code-generator's version as their version. - User specifies
versions
object, settingDEFAULT
and setting version numbers for some runtime crates. Then the specified version inDEFAULT
is used for all runtime crates, except for those where the user specified a value for in the map. - If the user specifies a version in the
versions
map for a crate whose name does not correspond to a runtime crate, we fail.
I think all unit tests can start with RuntimeConfig.fromNode()
, and then you assert that the correct RuntimeConfig
object was parsed.
codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/RuntimeTypes.kt
Outdated
Show resolved
Hide resolved
codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/RuntimeTypes.kt
Show resolved
Hide resolved
codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/RuntimeTypes.kt
Outdated
Show resolved
Hide resolved
* A mapping for crate name to user specified version. | ||
*/ | ||
@JvmInline | ||
value class CrateVersionMap( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL about value class
. Very interesting.
This is the first time we introduce them in the codebase. I wonder why we're not using them? They seem to be better at encoding "transparent" newtypes, like here, something for which we are relying on data class
.
cc someone who actually knows Kotlin @rcoh.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no reason not to use them, TIL about them TBH, they seem handy!
We often end up with more than one field which is why data class
is usually useful but for single-member types this seems great!
codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/RuntimeTypes.kt
Outdated
Show resolved
Hide resolved
I'm thinking that it would also be cool if we allowed the user to specify concrete versions for third-party crates e.g. the We can probably tackle it in another PR. |
@jdisanti and I discussed this recently—I think it would be a great idea and it would also allow us to unify dependency versions across the entire codebase |
Co-authored-by: david-perez <[email protected]>
This comment was marked as outdated.
This comment was marked as outdated.
Signed-off-by: Weihang Lo <[email protected]>
If there is nothing provided. Fallback to use code generator version. Signed-off-by: Weihang Lo <[email protected]>
Signed-off-by: Weihang Lo <[email protected]>
Tests added. Thanks @david-perez for the suggestion.
This has yet been implemented. Shall we add the check? |
This comment was marked as outdated.
This comment was marked as outdated.
codegen/src/test/kotlin/software/amazon/smithy/rust/codegen/smithy/RuntimeTypesTest.kt
Outdated
Show resolved
Hide resolved
codegen/src/test/kotlin/software/amazon/smithy/rust/codegen/smithy/RuntimeTypesTest.kt
Outdated
Show resolved
Hide resolved
codegen/src/test/kotlin/software/amazon/smithy/rust/codegen/smithy/RuntimeTypesTest.kt
Outdated
Show resolved
Hide resolved
codegen/src/test/kotlin/software/amazon/smithy/rust/codegen/smithy/RuntimeTypesTest.kt
Outdated
Show resolved
Hide resolved
Co-authored-by: david-perez <[email protected]>
We can leave it if you want. I was thinking that it would be a UX improvement (think a frustrated user who misspelled a crate name in the But delivering this feature would entail us having to maintain a list of the crates that we're publishing and keeping it up to date when there are additions or removals. Unless we automate this check in CI, we're likely going to forget. |
Signed-off-by: Weihang Lo <[email protected]>
All review commented addressed. Thank you!
That's exactly what I worry about. We could have a separate PR to do that if we want. |
A new generated diff is ready to view.
A new doc preview is ready to view. |
A new generated diff is ready to view.
A new doc preview is ready to view. |
Motivation and Context
Related: #1416
Support a more granular control on specifying runtime crate versions in smithy-build.json runtime config.
The current behaviour is not ideal. You need to specify
{ version: "DEFAULT" }
to get the default version. You can only specify the same version for all runtime crates, which is somehow inconvenient.Description
This PR mainly deals with two things:
BREAKING: after this PR, in
smity-build.json
the pathrust-codegen.runtimeConfig.version
no longer exists. Instead, a newfield
versions
comes in. It's an objct mapping a runtime crate nameto a version string. There is also a special key
DEFAULT
, which ispresetted as detected runtime version but open to override. Crates
without version specified would be set as the same version as which
associated to key
DEFAULT
.An example
smithy-build.json
might look like:Testing
Tweak the value in
buildSrc/src/main/kotlin/CodegenTestCommon.kt
and see if your runtime crate version changed.Checklist
CHANGELOG.next.toml
if I made changes to the smithy-rs codegen or runtime cratesCHANGELOG.next.toml
if I made changes to the AWS SDK, generated SDK code, or SDK runtime cratesBy submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.