Skip to content
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

Merged
merged 13 commits into from
Aug 17, 2022

Conversation

weihanglo
Copy link
Contributor

@weihanglo weihanglo commented Aug 15, 2022

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:

  • Make default default. You don't need to specify anything to become default.
  • Give users the ability to specify different versions for different runtime crates.

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 objct 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.

An example smithy-build.json might look like:

{
  "version": "1.0",
  "projections": {
    "simple": {
      "plugins": {
        "rust-codegen": {
          "runtimeConfig": {
            "versions": {
               "DEFAULT": "0.48", // Set your own default version.
                                  // Leave blank for codegen auto-detecting a version.
               "aws-smithy-http": "0.47", // Can specify a different version.
               "aws-smithy-types": "0.46",
               "aws-smithy-json": "0.45",
            }
          },
          "service": ...
        }
      }
    }
  }
}

Testing

Tweak the value in buildSrc/src/main/kotlin/CodegenTestCommon.kt and see if your runtime crate version changed.

Checklist

  • I have updated CHANGELOG.next.toml if I made changes to the smithy-rs codegen or runtime crates
  • I have updated CHANGELOG.next.toml if I made changes to the AWS SDK, generated SDK code, or SDK runtime crates

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@weihanglo weihanglo force-pushed the weihanglo/runtime-config branch 3 times, most recently from f8bc6bf to 23d40b3 Compare August 15, 2022 12:42
**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]>
@weihanglo
Copy link
Contributor Author

Open question:

  • Shall we support more customizations such like setting relative path for each runtime crate?
  • Shall we be compatible with the old version field without breaking everyone's build script?

@github-actions

This comment was marked as outdated.

@github-actions

This comment was marked as outdated.

@weihanglo weihanglo marked this pull request as ready for review August 15, 2022 17:35
@weihanglo weihanglo requested a review from a team as a code owner August 15, 2022 17:35
[[smithy-rs]]
message = "Support granular control of specifying runtime crate versions"
references = ["smithy-rs#1416"]
meta = { "breaking" = true, "tada" = true, "bug" = false }
Copy link
Collaborator

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.

Copy link
Contributor Author

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!

CHANGELOG.next.toml Outdated Show resolved Hide resolved
@github-actions

This comment was marked as outdated.

Copy link
Contributor

@david-perez david-perez left a 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):

  1. If user specifies relativePath in runtimeConfig, then that always takes precedence over versions.
  2. User does not specify the versions object. The version number of the code-generator should be used as the version for all runtime crates.
  3. 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.
  4. User specifies versions object, setting DEFAULT. That version is used for all runtime crates.
  5. 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.
  6. User specifies versions object, setting DEFAULT and setting version numbers for some runtime crates. Then the specified version in DEFAULT is used for all runtime crates, except for those where the user specified a value for in the map.
  7. 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.

* A mapping for crate name to user specified version.
*/
@JvmInline
value class CrateVersionMap(
Copy link
Contributor

@david-perez david-perez Aug 16, 2022

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.

Copy link
Collaborator

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!

CHANGELOG.next.toml Outdated Show resolved Hide resolved
CHANGELOG.next.toml Outdated Show resolved Hide resolved
CHANGELOG.next.toml Show resolved Hide resolved
CHANGELOG.next.toml Outdated Show resolved Hide resolved
@david-perez
Copy link
Contributor

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 http crate. That would allow them to mitigate a CVE-like situation by rolling back that crate version without us having to publish a new version of smithy-rs.

We can probably tackle it in another PR.

@rcoh
Copy link
Collaborator

rcoh commented Aug 16, 2022

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 http crate. That would allow them to mitigate a CVE-like situation by rolling back that crate version without us having to publish a new version of smithy-rs.

@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

@github-actions

This comment was marked as outdated.

@weihanglo
Copy link
Contributor Author

Tests added. Thanks @david-perez for the suggestion.

  1. If the user specifies a version in the versions map for a crate whose name does not correspond to a runtime crate, we fail.

This has yet been implemented. Shall we add the check?

@github-actions

This comment was marked as outdated.

@david-perez
Copy link
Contributor

  1. If the user specifies a version in the versions map for a crate whose name does not correspond to a runtime crate, we fail.

This has yet been implemented. Shall we add the check?

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 versions map and wondering why they're not seeing the override in the code generated crate).

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.

@weihanglo
Copy link
Contributor Author

All review commented addressed. Thank you!

  1. If the user specifies a version in the versions map for a crate whose name does not correspond to a runtime crate, we fail.

This has yet been implemented. Shall we add the check?

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 versions map and wondering why they're not seeing the override in the code generated crate).

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.

That's exactly what I worry about. We could have a separate PR to do that if we want.

@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

@weihanglo weihanglo enabled auto-merge (squash) August 17, 2022 21:27
@weihanglo weihanglo enabled auto-merge (squash) August 17, 2022 21:29
@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants