Skip to content

Commit 5f8330f

Browse files
committed
Do not set RUSTFLAGS environment variable when invoking Cargo commands via Gradle tasks
Otherwise, if you generate a crate and compile it using Gradle, like for example using the invocation: ``` ./gradlew -P modules='simple' -P cargoCommands='test' codegen-server-test:build ``` And then manually run a `cargo` command within the generated crate directory, or open the project using `rust-analyzer`, Cargo will re-compile the project from scratch, with `CARGO_LOG=cargo::core::compiler::fingerprint=trace` reporting that flags have changed since the last compilation. Instead, it's best if we persist these flags to `.cargo/config.toml`, so all `cargo` invocations, either through Gradle, manually, or through `rust-analyzer`, use the same set. This way, if no files were changed, subsequent compilations since code generation will truly be no-ops, with Cargo reusing all artifacts. Note this commit fixes a regression that was introduced when `--cfg aws_sdk_unstable` was introduced in #2614, since I fixed this the first time back in #1422.
1 parent ebf8842 commit 5f8330f

File tree

8 files changed

+11
-29
lines changed

8 files changed

+11
-29
lines changed

Diff for: aws/sdk-adhoc-test/build.gradle.kts

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ java {
2020
}
2121

2222
val smithyVersion: String by project
23-
val defaultRustDocFlags: String by project
2423
val properties = PropertyRetriever(rootProject, project)
2524

2625
val pluginName = "rust-client-codegen"
@@ -78,7 +77,7 @@ tasks["smithyBuild"].dependsOn("generateSmithyBuild")
7877
tasks["assemble"].finalizedBy("generateCargoWorkspace")
7978

8079
project.registerModifyMtimeTask()
81-
project.registerCargoCommandsTasks(layout.buildDirectory.dir(workingDirUnderBuildDir).get().asFile, defaultRustDocFlags)
80+
project.registerCargoCommandsTasks(layout.buildDirectory.dir(workingDirUnderBuildDir).get().asFile)
8281

8382
tasks["test"].finalizedBy(cargoCommands(properties).map { it.toString })
8483

Diff for: aws/sdk/build.gradle.kts

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ configure<software.amazon.smithy.gradle.SmithyExtension> {
3131
}
3232

3333
val smithyVersion: String by project
34-
val defaultRustDocFlags: String by project
3534
val properties = PropertyRetriever(rootProject, project)
3635

3736
val crateHasherToolPath = rootProject.projectDir.resolve("tools/ci-build/crate-hasher")
@@ -442,7 +441,7 @@ tasks["assemble"].apply {
442441
outputs.upToDateWhen { false }
443442
}
444443

445-
project.registerCargoCommandsTasks(outputDir.asFile, defaultRustDocFlags)
444+
project.registerCargoCommandsTasks(outputDir.asFile)
446445
project.registerGenerateCargoConfigTomlTask(outputDir.asFile)
447446

448447
//The task name "test" is already registered by one of our plugins

Diff for: buildSrc/src/main/kotlin/CodegenTestCommon.kt

+4-10
Original file line numberDiff line numberDiff line change
@@ -248,13 +248,15 @@ fun Project.registerGenerateCargoWorkspaceTask(
248248
fun Project.registerGenerateCargoConfigTomlTask(outputDir: File) {
249249
this.tasks.register("generateCargoConfigToml") {
250250
description = "generate `.cargo/config.toml`"
251+
// TODO(https://github.com/smithy-lang/smithy-rs/issues/1068): Once doc normalization
252+
// is completed, warnings can be prohibited in rustdoc by setting `rustdocflags` to `-D warnings`.
251253
doFirst {
252254
outputDir.resolve(".cargo").mkdirs()
253255
outputDir.resolve(".cargo/config.toml")
254256
.writeText(
255257
"""
256258
[build]
257-
rustflags = ["--deny", "warnings"]
259+
rustflags = ["--deny", "warnings", "--cfg", "aws_sdk_unstable"]
258260
""".trimIndent(),
259261
)
260262
}
@@ -298,10 +300,7 @@ fun Project.registerModifyMtimeTask() {
298300
}
299301
}
300302

301-
fun Project.registerCargoCommandsTasks(
302-
outputDir: File,
303-
defaultRustDocFlags: String,
304-
) {
303+
fun Project.registerCargoCommandsTasks(outputDir: File) {
305304
val dependentTasks =
306305
listOfNotNull(
307306
"assemble",
@@ -312,29 +311,24 @@ fun Project.registerCargoCommandsTasks(
312311
this.tasks.register<Exec>(Cargo.CHECK.toString) {
313312
dependsOn(dependentTasks)
314313
workingDir(outputDir)
315-
environment("RUSTFLAGS", "--cfg aws_sdk_unstable")
316314
commandLine("cargo", "check", "--lib", "--tests", "--benches", "--all-features")
317315
}
318316

319317
this.tasks.register<Exec>(Cargo.TEST.toString) {
320318
dependsOn(dependentTasks)
321319
workingDir(outputDir)
322-
environment("RUSTFLAGS", "--cfg aws_sdk_unstable")
323320
commandLine("cargo", "test", "--all-features", "--no-fail-fast")
324321
}
325322

326323
this.tasks.register<Exec>(Cargo.DOCS.toString) {
327324
dependsOn(dependentTasks)
328325
workingDir(outputDir)
329-
environment("RUSTDOCFLAGS", defaultRustDocFlags)
330-
environment("RUSTFLAGS", "--cfg aws_sdk_unstable")
331326
commandLine("cargo", "doc", "--no-deps", "--document-private-items")
332327
}
333328

334329
this.tasks.register<Exec>(Cargo.CLIPPY.toString) {
335330
dependsOn(dependentTasks)
336331
workingDir(outputDir)
337-
environment("RUSTFLAGS", "--cfg aws_sdk_unstable")
338332
commandLine("cargo", "clippy")
339333
}
340334
}

Diff for: codegen-client-test/build.gradle.kts

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ plugins {
1515
}
1616

1717
val smithyVersion: String by project
18-
val defaultRustDocFlags: String by project
1918
val properties = PropertyRetriever(rootProject, project)
2019
fun getSmithyRuntimeMode(): String = properties.get("smithy.runtime.mode") ?: "orchestrator"
2120

@@ -130,7 +129,7 @@ tasks["smithyBuild"].dependsOn("generateSmithyBuild")
130129
tasks["assemble"].finalizedBy("generateCargoWorkspace")
131130

132131
project.registerModifyMtimeTask()
133-
project.registerCargoCommandsTasks(layout.buildDirectory.dir(workingDirUnderBuildDir).get().asFile, defaultRustDocFlags)
132+
project.registerCargoCommandsTasks(layout.buildDirectory.dir(workingDirUnderBuildDir).get().asFile)
134133

135134
tasks["test"].finalizedBy(cargoCommands(properties).map { it.toString })
136135

Diff for: codegen-server-test/build.gradle.kts

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ plugins {
1616
}
1717

1818
val smithyVersion: String by project
19-
val defaultRustDocFlags: String by project
2019
val properties = PropertyRetriever(rootProject, project)
2120

2221
val pluginName = "rust-server-codegen"
@@ -117,7 +116,7 @@ tasks["smithyBuild"].dependsOn("generateSmithyBuild")
117116
tasks["assemble"].finalizedBy("generateCargoWorkspace", "generateCargoConfigToml")
118117

119118
project.registerModifyMtimeTask()
120-
project.registerCargoCommandsTasks(layout.buildDirectory.dir(workingDirUnderBuildDir).get().asFile, defaultRustDocFlags)
119+
project.registerCargoCommandsTasks(layout.buildDirectory.dir(workingDirUnderBuildDir).get().asFile)
121120

122121
tasks["test"].finalizedBy(cargoCommands(properties).map { it.toString })
123122

Diff for: codegen-server-test/python/build.gradle.kts

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ plugins {
1616
}
1717

1818
val smithyVersion: String by project
19-
val defaultRustDocFlags: String by project
2019
val properties = PropertyRetriever(rootProject, project)
2120
val buildDir = layout.buildDirectory.get().asFile
2221

@@ -120,7 +119,7 @@ tasks["smithyBuild"].dependsOn("generateSmithyBuild")
120119
tasks["assemble"].finalizedBy("generateCargoWorkspace")
121120

122121
project.registerModifyMtimeTask()
123-
project.registerCargoCommandsTasks(buildDir.resolve(workingDirUnderBuildDir), defaultRustDocFlags)
122+
project.registerCargoCommandsTasks(buildDir.resolve(workingDirUnderBuildDir))
124123

125124
tasks["test"].finalizedBy(cargoCommands(properties).map { it.toString })
126125

Diff for: codegen-server-test/typescript/build.gradle.kts

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ plugins {
1616
}
1717

1818
val smithyVersion: String by project
19-
val defaultRustDocFlags: String by project
2019
val properties = PropertyRetriever(rootProject, project)
2120
val buildDir = layout.buildDirectory.get().asFile
2221

@@ -49,7 +48,7 @@ tasks["smithyBuild"].dependsOn("generateSmithyBuild")
4948
tasks["assemble"].finalizedBy("generateCargoWorkspace")
5049

5150
project.registerModifyMtimeTask()
52-
project.registerCargoCommandsTasks(buildDir.resolve(workingDirUnderBuildDir), defaultRustDocFlags)
51+
project.registerCargoCommandsTasks(buildDir.resolve(workingDirUnderBuildDir))
5352

5453
tasks["test"].finalizedBy(cargoCommands(properties).map { it.toString })
5554

Diff for: gradle.properties

+1-7
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,4 @@ kotlinVersion=1.9.20
3131
ktlintVersion=1.0.1
3232
kotestVersion=5.8.0
3333
# Avoid registering dependencies/plugins/tasks that are only used for testing purposes
34-
isTestingEnabled=true
35-
36-
# TODO(https://github.com/smithy-lang/smithy-rs/issues/1068): Once doc normalization
37-
# is completed, warnings can be prohibited in rustdoc.
38-
#
39-
# defaultRustDocFlags=-D warnings
40-
defaultRustDocFlags=
34+
isTestingEnabled=true

0 commit comments

Comments
 (0)