Skip to content

Commit 9977516

Browse files
authored
Merge branch 'main' into fahadzub/cbor-constraint
2 parents 432e0f9 + ec226c0 commit 9977516

File tree

4 files changed

+68
-55
lines changed

4 files changed

+68
-55
lines changed

buildSrc/src/main/kotlin/CrateSet.kt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ object CrateSet {
3939
}
4040
}
4141

42+
// If we make changes to `AWS_SDK_RUNTIME`, also update the list in
43+
// https://github.com/smithy-lang/smithy-rs/blob/main/tools/ci-build/sdk-lockfiles/src/audit.rs#L22
4244
val AWS_SDK_RUNTIME =
4345
listOf(
4446
"aws-config",
@@ -79,13 +81,16 @@ object CrateSet {
7981

8082
val AWS_SDK_SMITHY_RUNTIME = SMITHY_RUNTIME_COMMON
8183

82-
val SERVER_SMITHY_RUNTIME =
83-
SMITHY_RUNTIME_COMMON +
84-
listOf(
85-
Crate("aws-smithy-http-server", UNSTABLE_VERSION_PROP_NAME),
86-
Crate("aws-smithy-http-server-python", UNSTABLE_VERSION_PROP_NAME),
87-
Crate("aws-smithy-http-server-typescript", UNSTABLE_VERSION_PROP_NAME),
88-
)
84+
// If we make changes to `SERVER_SPECIFIC_SMITHY_RUNTIME`, also update the list in
85+
// https://github.com/smithy-lang/smithy-rs/blob/main/tools/ci-build/sdk-lockfiles/src/audit.rs#L38
86+
private val SERVER_SPECIFIC_SMITHY_RUNTIME =
87+
listOf(
88+
Crate("aws-smithy-http-server", UNSTABLE_VERSION_PROP_NAME),
89+
Crate("aws-smithy-http-server-python", UNSTABLE_VERSION_PROP_NAME),
90+
Crate("aws-smithy-http-server-typescript", UNSTABLE_VERSION_PROP_NAME),
91+
)
92+
93+
val SERVER_SMITHY_RUNTIME = SMITHY_RUNTIME_COMMON + SERVER_SPECIFIC_SMITHY_RUNTIME
8994

9095
val ENTIRE_SMITHY_RUNTIME = (AWS_SDK_SMITHY_RUNTIME + SERVER_SMITHY_RUNTIME).toSortedSet(compareBy { it.name })
9196

tools/ci-build/sdk-lockfiles/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "sdk-lockfiles"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
authors = ["AWS Rust SDK Team <[email protected]>"]
55
description = """
66
A CLI tool to audit lockfiles for Smithy runtime crates, AWS runtime crates, `aws-config`, and the workspace containing

tools/ci-build/sdk-lockfiles/README.md

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,41 @@ sdk-lockfiles
22
=============
33

44
This CLI tool audits the `Cargo.lock` files in the `smithy-rs` repository. These lockfiles are used to ensure
5-
reproducible builds. The `sdk-lockfiles` tool specifically audits the following lockfiles:
6-
- The [lockfile](https://github.com/smithy-lang/smithy-rs/blob/main/rust-runtime/Cargo.lock) for Smithy runtime crates
7-
- The [lockfile](https://github.com/smithy-lang/smithy-rs/blob/main/aws/rust-runtime/Cargo.lock) for AWS runtime crates
8-
- The [lockfile](https://github.com/smithy-lang/smithy-rs/blob/main/aws/rust-runtime/aws-config/Cargo.lock) for the `aws-config` crate
9-
- The [lockfile](https://github.com/smithy-lang/smithy-rs/blob/main/aws/sdk/Cargo.lock) for the workspace containing code-generated AWS SDK crates (*)
5+
reproducible builds during our release process for both `smithy-rs` and `aws-sdk-rust`. When a crate dependency is not
6+
pinned to a fixed version, it risks being affected by newer versions of that dependency published to crates.io, which
7+
could potentially break the build.
108

11-
Specifically, the tool ensures that the lockfile marked with (*) is a superset containing all dependencies listed in
12-
the rest of the runtime lockfiles. If it detects a new dependency in the AWS SDK crates introduced by any of the runtime
13-
lockfiles (unless the dependency is introduced by a server runtime crate), it will output a message similar to the
14-
following:
9+
We track the following lockfiles in the `smithy-rs` repository:
10+
1. The [lockfile](https://github.com/smithy-lang/smithy-rs/blob/main/rust-runtime/Cargo.lock) for Smithy runtime crates
11+
2. The [lockfile](https://github.com/smithy-lang/smithy-rs/blob/main/aws/rust-runtime/Cargo.lock) for AWS runtime crates
12+
3. The [lockfile](https://github.com/smithy-lang/smithy-rs/blob/main/aws/rust-runtime/aws-config/Cargo.lock) for the `aws-config` crate
13+
4. The [lockfile](https://github.com/smithy-lang/smithy-rs/blob/main/aws/sdk/Cargo.lock) for the workspace containing code-generated AWS SDK crates
14+
15+
The first three lockfiles can be easily updated during development with a `cargo` command. However, the fourth lockfile
16+
, known as the SDK lockfile, is generated by the code generator and is not checked into to the `smithy-rs` repository as
17+
frequently as the first three runtime lockfiles. As a result, new dependencies added to any of the runtime lockfiles may
18+
not be reflected in the SDK lockfile.
19+
20+
The `sdk-lockfiles` tool ensures that the SDK lockfile is a superset containing all dependencies listed in the three
21+
runtime lockfiles. If it detects a new dependency in the AWS SDK crates introduced by any of the runtime lockfiles it
22+
will output a message similar to the following (unless the dependency is introduced by a server specific runtime crate):
1523
```
1624
$ sdk-lockfiles audit
1725
2024-09-10T16:48:38.460518Z INFO sdk_lockfiles::audit: checking whether `rust-runtime/Cargo.lock` is covered by the SDK lockfile...
1826
2024-09-10T16:48:38.489879Z INFO sdk_lockfiles::audit: checking whether `aws/rust-runtime/Cargo.lock` is covered by the SDK lockfile...
1927
2024-09-10T16:48:38.490306Z INFO sdk_lockfiles::audit: checking whether `aws/rust-runtime/aws-config/Cargo.lock` is covered by the SDK lockfile...
20-
`minicbor` (0.24.2), used by `rust-runtime/Cargo.lock`, is not contained in SDK lockfile!
28+
`minicbor` (0.24.2), used by `rust-runtime/Cargo.lock`, is not contained in the SDK lockfile!
2129
Error: there are lockfile audit failures
2230
```
2331

2432
This tool is intended for automated use.
33+
34+
## Limitation
35+
The `sdk-lockfiles` tool does not verify whether new dependencies introduced in [CargoDependency.kt](https://github.com/smithy-lang/smithy-rs/blob/main/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/CargoDependency.kt)
36+
are included in the SDK lockfile. This is because dependencies in `CargoDependency.kt` are represented as a Kotlin data
37+
class. Consequently, dependencies added via the code generator, `inlineable`, or `aws-inlineable` are not considered by
38+
`sdk-lockfiles`.
39+
40+
This limitation is acceptable for our operational purposes. Our release script always executes
41+
`./gradlew aws:sdk:syncAwsSdkLockfile`, which ensures that any dependencies added in `CargoDependency.kt` are properly
42+
reflected in the SDK lockfile.

tools/ci-build/sdk-lockfiles/src/audit.rs

Lines changed: 27 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,23 @@ use std::env;
1616
use std::iter;
1717
use std::path::PathBuf;
1818

19-
// A list of AWS runtime crate must be in sync with
19+
// A list of the names of AWS runtime crates (crate versions do not need to match) must be in sync with
2020
// https://github.com/smithy-lang/smithy-rs/blob/0f9b9aba386ea3063912a0464ba6a1fd7c596018/buildSrc/src/main/kotlin/CrateSet.kt#L42-L53
21-
// plus `aws-inlineable`
2221
const AWS_SDK_RUNTIMES: &[&str] = &[
2322
"aws-config",
2423
"aws-credential-types",
2524
"aws-endpoint",
2625
"aws-http",
2726
"aws-hyper",
28-
"aws-inlineable",
2927
"aws-runtime",
3028
"aws-runtime-api",
3129
"aws-sig-auth",
3230
"aws-sigv4",
3331
"aws-types",
3432
];
3533

36-
// A list of server runtime crates must be in sync with
37-
// https://github.com/smithy-lang/smithy-rs/blob/0f9b9aba386ea3063912a0464ba6a1fd7c596018/buildSrc/src/main/kotlin/CrateSet.kt#L85-L87
34+
// A list of the names of server specific runtime crates (crate versions do not need to match) must be in sync with
35+
// https://github.com/smithy-lang/smithy-rs/blob/main/buildSrc/src/main/kotlin/CrateSet.kt#L42
3836
const SERVER_SPECIFIC_RUNTIMES: &[&str] = &[
3937
"aws-smithy-http-server",
4038
"aws-smithy-http-server-python",
@@ -43,34 +41,37 @@ const SERVER_SPECIFIC_RUNTIMES: &[&str] = &[
4341

4442
fn new_dependency_for_aws_sdk(crate_name: &str) -> bool {
4543
AWS_SDK_RUNTIMES.contains(&crate_name)
46-
|| crate_name == "inlineable"
4744
|| (crate_name.starts_with("aws-smithy-")
4845
&& !SERVER_SPECIFIC_RUNTIMES.contains(&crate_name))
4946
}
5047

5148
// Recursively traverses a chain of dependencies originating from a potential new dependency. Returns true as soon as
5249
// it encounters a crate name that matches a runtime crate used by the AWS SDK.
53-
fn visit(graph: &Graph, node_index: NodeIndex, visited: &mut BTreeSet<NodeIndex>) -> bool {
50+
fn is_consumed_by_aws_sdk(
51+
graph: &Graph,
52+
node_index: NodeIndex,
53+
visited: &mut BTreeSet<NodeIndex>,
54+
) -> bool {
5455
if !visited.insert(node_index) {
5556
return false;
5657
}
5758

58-
let dependencies = graph
59+
let consumers = graph
5960
.edges_directed(
6061
node_index,
6162
cargo_lock::dependency::graph::EdgeDirection::Incoming,
6263
)
6364
.map(|edge| edge.source())
6465
.collect::<Vec<_>>();
6566

66-
for dependency_node_index in dependencies.iter() {
67-
let package = &graph[*dependency_node_index];
67+
for consumer_node_index in consumers.iter() {
68+
let package = &graph[*consumer_node_index];
6869
tracing::debug!("visiting `{}`", package.name.as_str());
6970
if new_dependency_for_aws_sdk(package.name.as_str()) {
7071
tracing::debug!("it's a new dependency for the AWS SDK!");
7172
return true;
7273
}
73-
if visit(graph, *dependency_node_index, visited) {
74+
if is_consumed_by_aws_sdk(graph, *consumer_node_index, visited) {
7475
return true;
7576
}
7677
}
@@ -88,22 +89,17 @@ fn new_dependency(lockfile: &Lockfile, target: &str) -> bool {
8889
target
8990
);
9091
let tree = lockfile.dependency_tree().unwrap();
91-
let indices: Vec<_> = [target.to_owned()]
92+
let package = lockfile
93+
.packages
9294
.iter()
93-
.map(|dep| {
94-
let package = lockfile
95-
.packages
96-
.iter()
97-
.find(|pkg| pkg.name.as_str() == dep)
98-
.unwrap();
99-
tree.nodes()[&package.into()]
100-
})
101-
.collect();
95+
.find(|pkg| pkg.name.as_str() == target)
96+
.expect("{target} must be in dependencies listed in `lockfile`");
97+
let indices = vec![tree.nodes()[&package.into()]];
10298

10399
for index in &indices {
104100
let mut visited: BTreeSet<NodeIndex> = BTreeSet::new();
105101
tracing::debug!("traversing a dependency chain for `{}`...", target);
106-
if visit(tree.graph(), *index, &mut visited) {
102+
if is_consumed_by_aws_sdk(tree.graph(), *index, &mut visited) {
107103
return true;
108104
}
109105
}
@@ -307,17 +303,17 @@ dependencies = [
307303
]
308304
309305
[[package]]
310-
name = "inlineable"
311-
version = "0.1.0"
306+
name = "aws-smithy-compression"
307+
version = "0.0.1"
312308
dependencies = [
313-
"md-5"
309+
"flate2"
314310
]
315311
316312
[[package]]
317-
name = "md-5"
318-
version = "0.10.6"
313+
name = "flate2"
314+
version = "1.0.33"
319315
source = "registry+https://github.com/rust-lang/crates.io-index"
320-
checksum = "d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf"
316+
checksum = "324a1be68054ef05ad64b861cc9eaf1d623d2d8cb25b4bf2cb9cdd902b4bf253"
321317
322318
[[package]]
323319
name = "minicbor"
@@ -329,7 +325,7 @@ checksum = "5f8e213c36148d828083ae01948eed271d03f95f7e72571fa242d78184029af2"
329325
.unwrap();
330326

331327
assert_eq!(
332-
vec!["md-5", "minicbor"],
328+
vec!["flate2", "minicbor"],
333329
audit_runtime_lockfile_covered_by_sdk_lockfile(
334330
&runtime_lockfile,
335331
&sdk_dependency_set(),
@@ -351,19 +347,13 @@ dependencies = [
351347
"zeroize",
352348
]
353349
354-
[[package]]
355-
name = "aws-inlineable"
356-
version = "0.1.0"
357-
dependencies = [
358-
"ahash",
359-
"lru"
360-
]
361-
362350
[[package]]
363351
name = "aws-sigv4"
364352
version = "1.2.3"
365353
dependencies = [
354+
"ahash",
366355
"aws-credential-types",
356+
"lru",
367357
"p256",
368358
]
369359

0 commit comments

Comments
 (0)