Skip to content

Commit fbde9d8

Browse files
authored
Do not set RUSTFLAGS environment variable when invoking Cargo commands via Gradle tasks (#3678)
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. ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._
1 parent 99e1e20 commit fbde9d8

File tree

9 files changed

+18
-30
lines changed

9 files changed

+18
-30
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"
@@ -89,7 +88,7 @@ tasks["smithyBuild"].dependsOn("generateSmithyBuild")
8988
tasks["assemble"].finalizedBy("generateCargoWorkspace")
9089

9190
project.registerModifyMtimeTask()
92-
project.registerCargoCommandsTasks(layout.buildDirectory.dir(workingDirUnderBuildDir).get().asFile, defaultRustDocFlags)
91+
project.registerCargoCommandsTasks(layout.buildDirectory.dir(workingDirUnderBuildDir).get().asFile)
9392

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

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")
@@ -461,7 +460,7 @@ tasks.register<Copy>("copyCheckedInCargoLock") {
461460
into(outputDir)
462461
}
463462

464-
project.registerCargoCommandsTasks(outputDir.asFile, defaultRustDocFlags)
463+
project.registerCargoCommandsTasks(outputDir.asFile)
465464
project.registerGenerateCargoConfigTomlTask(outputDir.asFile)
466465

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

buildSrc/src/main/kotlin/CodegenTestCommon.kt

Lines changed: 10 additions & 11 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
}
@@ -256,10 +258,7 @@ fun Project.registerModifyMtimeTask() {
256258
}
257259
}
258260

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

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

284281
this.tasks.register<Exec>(Cargo.DOCS.toString) {
285282
dependsOn(dependentTasks)
286283
workingDir(outputDir)
287-
environment("RUSTDOCFLAGS", defaultRustDocFlags)
288-
environment("RUSTFLAGS", "--cfg aws_sdk_unstable")
289-
commandLine("cargo", "doc", "--no-deps", "--document-private-items")
284+
val args =
285+
mutableListOf(
286+
"--no-deps",
287+
"--document-private-items",
288+
)
289+
commandLine("cargo", "doc", *args.toTypedArray())
290290
}
291291

292292
this.tasks.register<Exec>(Cargo.CLIPPY.toString) {
293293
dependsOn(dependentTasks)
294294
workingDir(outputDir)
295-
environment("RUSTFLAGS", "--cfg aws_sdk_unstable")
296295
commandLine("cargo", "clippy")
297296
}
298297
}

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

@@ -134,7 +133,7 @@ tasks["smithyBuild"].dependsOn("generateSmithyBuild")
134133
tasks["assemble"].finalizedBy("generateCargoWorkspace")
135134

136135
project.registerModifyMtimeTask()
137-
project.registerCargoCommandsTasks(layout.buildDirectory.dir(workingDirUnderBuildDir).get().asFile, defaultRustDocFlags)
136+
project.registerCargoCommandsTasks(layout.buildDirectory.dir(workingDirUnderBuildDir).get().asFile)
138137

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

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"
@@ -112,7 +111,7 @@ tasks["smithyBuild"].dependsOn("generateSmithyBuild")
112111
tasks["assemble"].finalizedBy("generateCargoWorkspace", "generateCargoConfigToml")
113112

114113
project.registerModifyMtimeTask()
115-
project.registerCargoCommandsTasks(layout.buildDirectory.dir(workingDirUnderBuildDir).get().asFile, defaultRustDocFlags)
114+
project.registerCargoCommandsTasks(layout.buildDirectory.dir(workingDirUnderBuildDir).get().asFile)
116115

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

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

@@ -128,7 +127,7 @@ tasks["smithyBuild"].dependsOn("generateSmithyBuild")
128127
tasks["assemble"].finalizedBy("generateCargoWorkspace")
129128

130129
project.registerModifyMtimeTask()
131-
project.registerCargoCommandsTasks(buildDir.resolve(workingDirUnderBuildDir), defaultRustDocFlags)
130+
project.registerCargoCommandsTasks(buildDir.resolve(workingDirUnderBuildDir))
132131

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

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

codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerUnionGenerator.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ class PythonServerUnionGenerator(
154154
) {
155155
if (member.isTargetUnit()) {
156156
writer.rust(
157-
"/// Tries to convert the union instance into [`$variantName`].",
157+
"/// Tries to convert the enum instance into [`$variantName`](#T::$variantName), extracting the inner `()`.",
158+
unionSymbol,
158159
)
159160
writer.rust("/// :rtype None:")
160161
writer.rustBlockTemplate("pub fn as_$funcNamePart(&self) -> #{pyo3}::PyResult<()>", "pyo3" to pyo3) {

gradle.properties

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,3 @@ ktlintVersion=1.0.1
3232
kotestVersion=5.8.0
3333
# Avoid registering dependencies/plugins/tasks that are only used for testing purposes
3434
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=

0 commit comments

Comments
 (0)