Skip to content

Commit d0f7448

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 50c825b commit d0f7448

File tree

8 files changed

+11
-29
lines changed

8 files changed

+11
-29
lines changed

aws/sdk-adhoc-test/build.gradle.kts

Lines changed: 1 addition & 2 deletions
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

aws/sdk/build.gradle.kts

Lines changed: 1 addition & 2 deletions
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

buildSrc/src/main/kotlin/CodegenTestCommon.kt

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,15 @@ fun Project.registerGenerateCargoWorkspaceTask(
205205
fun Project.registerGenerateCargoConfigTomlTask(outputDir: File) {
206206
this.tasks.register("generateCargoConfigToml") {
207207
description = "generate `.cargo/config.toml`"
208+
// TODO(https://github.com/smithy-lang/smithy-rs/issues/1068): Once doc normalization
209+
// is completed, warnings can be prohibited in rustdoc by setting `rustdocflags` to `-D warnings`.
208210
doFirst {
209211
outputDir.resolve(".cargo").mkdirs()
210212
outputDir.resolve(".cargo/config.toml")
211213
.writeText(
212214
"""
213215
[build]
214-
rustflags = ["--deny", "warnings"]
216+
rustflags = ["--deny", "warnings", "--cfg", "aws_sdk_unstable"]
215217
""".trimIndent(),
216218
)
217219
}
@@ -255,10 +257,7 @@ fun Project.registerModifyMtimeTask() {
255257
}
256258
}
257259

258-
fun Project.registerCargoCommandsTasks(
259-
outputDir: File,
260-
defaultRustDocFlags: String,
261-
) {
260+
fun Project.registerCargoCommandsTasks(outputDir: File) {
262261
val dependentTasks =
263262
listOfNotNull(
264263
"assemble",
@@ -269,29 +268,24 @@ fun Project.registerCargoCommandsTasks(
269268
this.tasks.register<Exec>(Cargo.CHECK.toString) {
270269
dependsOn(dependentTasks)
271270
workingDir(outputDir)
272-
environment("RUSTFLAGS", "--cfg aws_sdk_unstable")
273271
commandLine("cargo", "check", "--lib", "--tests", "--benches", "--all-features")
274272
}
275273

276274
this.tasks.register<Exec>(Cargo.TEST.toString) {
277275
dependsOn(dependentTasks)
278276
workingDir(outputDir)
279-
environment("RUSTFLAGS", "--cfg aws_sdk_unstable")
280277
commandLine("cargo", "test", "--all-features", "--no-fail-fast")
281278
}
282279

283280
this.tasks.register<Exec>(Cargo.DOCS.toString) {
284281
dependsOn(dependentTasks)
285282
workingDir(outputDir)
286-
environment("RUSTDOCFLAGS", defaultRustDocFlags)
287-
environment("RUSTFLAGS", "--cfg aws_sdk_unstable")
288283
commandLine("cargo", "doc", "--no-deps", "--document-private-items")
289284
}
290285

291286
this.tasks.register<Exec>(Cargo.CLIPPY.toString) {
292287
dependsOn(dependentTasks)
293288
workingDir(outputDir)
294-
environment("RUSTFLAGS", "--cfg aws_sdk_unstable")
295289
commandLine("cargo", "clippy")
296290
}
297291
}

codegen-client-test/build.gradle.kts

Lines changed: 1 addition & 2 deletions
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

@@ -125,7 +124,7 @@ tasks["smithyBuild"].dependsOn("generateSmithyBuild")
125124
tasks["assemble"].finalizedBy("generateCargoWorkspace")
126125

127126
project.registerModifyMtimeTask()
128-
project.registerCargoCommandsTasks(layout.buildDirectory.dir(workingDirUnderBuildDir).get().asFile, defaultRustDocFlags)
127+
project.registerCargoCommandsTasks(layout.buildDirectory.dir(workingDirUnderBuildDir).get().asFile)
129128

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

codegen-server-test/build.gradle.kts

Lines changed: 1 addition & 2 deletions
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"
@@ -103,7 +102,7 @@ tasks["smithyBuild"].dependsOn("generateSmithyBuild")
103102
tasks["assemble"].finalizedBy("generateCargoWorkspace", "generateCargoConfigToml")
104103

105104
project.registerModifyMtimeTask()
106-
project.registerCargoCommandsTasks(layout.buildDirectory.dir(workingDirUnderBuildDir).get().asFile, defaultRustDocFlags)
105+
project.registerCargoCommandsTasks(layout.buildDirectory.dir(workingDirUnderBuildDir).get().asFile)
107106

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

codegen-server-test/python/build.gradle.kts

Lines changed: 1 addition & 2 deletions
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

codegen-server-test/typescript/build.gradle.kts

Lines changed: 1 addition & 2 deletions
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

gradle.properties

Lines changed: 1 addition & 7 deletions
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)