mozilla / rust-android-gradle

Apache License 2.0
1.03k stars 67 forks source link

Support Gradle Configuration Caching #114

Open kirillzh opened 1 year ago

kirillzh commented 1 year ago

Configuration Caching is an upcoming Gradle feature, which allows the configuration phase to reuse previous computations of their task graphs, and thus significantly speed up sync and build times.

Any Gradle task can be ran with configuration task enabled like so: ./gradlew :someBuildTask --configuration-cache.

In a project that applies rust-android-gradle plugin with configuration caching enabled, running tasks fails:

Configuration cache problems found in this build.

5 problems were found storing the configuration cache.
- Task `:core:cargoBuildArm64` of type `com.nishtahir.CargoBuildTask`: invocation of 'Task.project' at execution time is unsupported.
  See https://docs.gradle.org/7.5/userguide/configuration_cache.html#config_cache:requirements:use_project_during_execution
- Task `:core:cargoBuildArm` of type `com.nishtahir.CargoBuildTask`: invocation of 'Task.project' at execution time is unsupported.
  See https://docs.gradle.org/7.5/userguide/configuration_cache.html#config_cache:requirements:use_project_during_execution
- Task `:core:cargoBuildDarwin-aarch64` of type `com.nishtahir.CargoBuildTask`: invocation of 'Task.project' at execution time is unsupported.
  See https://docs.gradle.org/7.5/userguide/configuration_cache.html#config_cache:requirements:use_project_during_execution
- Task `:core:cargoBuildDarwin-x86-64` of type `com.nishtahir.CargoBuildTask`: invocation of 'Task.project' at execution time is unsupported.
  See https://docs.gradle.org/7.5/userguide/configuration_cache.html#config_cache:requirements:use_project_during_execution
- Task `:core:cargoBuildX86_64` of type `com.nishtahir.CargoBuildTask`: invocation of 'Task.project' at execution time is unsupported.
  See https://docs.gradle.org/7.5/userguide/configuration_cache.html#config_cache:requirements:use_project_during_execution

> Invocation of 'Task.project' by task ':core:cargoBuildArm' at execution time is unsupported.
> Invocation of 'Task.project' by task ':core:cargoBuildArm64' at execution time is unsupported.
> Invocation of 'Task.project' by task ':core:cargoBuildDarwin-aarch64' at execution time is unsupported.
> Invocation of 'Task.project' by task ':core:cargoBuildDarwin-x86-64' at execution time is unsupported.
> Invocation of 'Task.project' by task ':core:cargoBuildX86_64' at execution time is unsupported.

As per report and these instructions, it looks like the CargoBuildTask needs to be updated in order for configuration caching to work properly.

ncalexan commented 1 year ago

Thanks for the excellent issue report, @kirillzh! I would love to see this be addressed -- it looks like the instructions you link apply to the uses of project in CargoBuildTask.kt. However, I have no time in the near future (say, at least 4 weeks) to work on this, so: patches appreciated! It should not be particularly hard to add tests for this use case.

Thanks again for the helpful report!