mozilla / rust-android-gradle

Apache License 2.0
1.03k stars 67 forks source link

Setting rust.cargoCommand=cargo +nightly doesn't work #24

Closed gitmp01 closed 3 years ago

gitmp01 commented 4 years ago

gradle cargoBuild fails with

Initialized native services in: /Users/gitmp/.gradle/native
The client will now receive all logging from the daemon (pid: 17630). The daemon log file: /Users/gitmp/.gradle/daemon/6.0.1/daemon-17630.out.log
Starting 3rd build in daemon [uptime: 3 mins 50.357 secs, performance: 100%, non-heap usage: 25% of 268,4 MB]
Using 8 worker leases.
Starting Build
Settings evaluated using settings file '/Users/gitmp/Documents/android/project/src/settings.gradle'.
Projects loaded. Root project using build file '/Users/gitmp/Documents/android/project/src/build.gradle'.
Included projects: [root project 'src', project ':app']

> Configure project :
Evaluating root project 'src' using build file '/Users/gitmp/Documents/android/project/src/build.gradle'.

> Configure project :app
Evaluating project ':app' using build file '/Users/gitmp/Documents/android/project/src/app/build.gradle'.
Creating configuration androidTestUtil
Creating configuration compile
Creating configuration apk
Creating configuration provided
Creating configuration api
Creating configuration implementation
Creating configuration runtimeOnly
Creating configuration compileOnly
Creating configuration wearApp
Creating configuration annotationProcessor
Creating configuration androidTestCompile
Creating configuration androidTestApk
Creating configuration androidTestProvided
Creating configuration androidTestApi
Creating configuration androidTestImplementation
Creating configuration androidTestRuntimeOnly
Creating configuration androidTestCompileOnly
Creating configuration androidTestWearApp
Creating configuration androidTestAnnotationProcessor
Creating configuration testCompile
Creating configuration testApk
Creating configuration testProvided
Creating configuration testApi
Creating configuration testImplementation
Creating configuration testRuntimeOnly
Creating configuration testCompileOnly
Creating configuration testWearApp
Creating configuration testAnnotationProcessor
Creating configuration debugCompile
Creating configuration debugApk
Creating configuration debugProvided
Creating configuration debugApi
Creating configuration debugImplementation
Creating configuration debugRuntimeOnly
Creating configuration debugCompileOnly
Creating configuration debugWearApp
Creating configuration debugAnnotationProcessor
Creating configuration androidTestDebugCompile
Creating configuration androidTestDebugApk
Creating configuration androidTestDebugProvided
Creating configuration androidTestDebugApi
Creating configuration androidTestDebugImplementation
Creating configuration androidTestDebugRuntimeOnly
Creating configuration androidTestDebugCompileOnly
Creating configuration androidTestDebugWearApp
Creating configuration androidTestDebugAnnotationProcessor
Creating configuration testDebugCompile
Creating configuration testDebugApk
Creating configuration testDebugProvided
Creating configuration testDebugApi
Creating configuration testDebugImplementation
Creating configuration testDebugRuntimeOnly
Creating configuration testDebugCompileOnly
Creating configuration testDebugWearApp
Creating configuration testDebugAnnotationProcessor
Creating configuration releaseCompile
Creating configuration releaseApk
Creating configuration releaseProvided
Creating configuration releaseApi
Creating configuration releaseImplementation
Creating configuration releaseRuntimeOnly
Creating configuration releaseCompileOnly
Creating configuration releaseWearApp
Creating configuration releaseAnnotationProcessor
Creating configuration testReleaseCompile
Creating configuration testReleaseApk
Creating configuration testReleaseProvided
Creating configuration testReleaseApi
Creating configuration testReleaseImplementation
Creating configuration testReleaseRuntimeOnly
Creating configuration testReleaseCompileOnly
Creating configuration testReleaseWearApp
Creating configuration testReleaseAnnotationProcessor
signing apk...
android.ndkVersion from module build.gradle is not set
ndk.dir in local.properties is /Users/gitmp/.android/ndk/20.1.5948944
ANDROID_NDK_HOME environment variable is not set
sdkFolder is /Users/gitmp/.android
Considering /Users/gitmp/.android/ndk/20.1.5948944 by ndk.dir
Considering /Users/gitmp/.android/ndk-bundle in SDK ndk-bundle folder
Considering /Users/gitmp/.android/ndk/20.1.5948944 in SDK ndk folder
Rejected /Users/gitmp/.android/ndk-bundle in SDK ndk-bundle folder because that location has no source.properties
Found requested ndk.dir (/Users/gitmp/.android/ndk/20.1.5948944) which has version 20.1.5948944
All projects evaluated.
Analytics other plugin to proto: Unknown plugin type com.nishtahir.RustAndroidPlugin expected enum COM_NISHTAHIR_RUSTANDROIDPLUGIN
Selected primary task 'cargoBuild' from project :
Tasks to be executed: [task ':generateLinkerWrapper', task ':app:cargoBuildArm', task ':app:cargoBuild']
:generateLinkerWrapper (Thread[Execution worker for ':',5,main]) started.

> Task :generateLinkerWrapper UP-TO-DATE
Task :generateLinkerWrapper in app Starting
Caching disabled for task ':generateLinkerWrapper' because:
  Build cache is disabled
Skipping task ':generateLinkerWrapper' as it is up-to-date.
Task :generateLinkerWrapper in app Finished
:generateLinkerWrapper (Thread[Execution worker for ':',5,main]) completed. Took 0.011 secs.
:app:cargoBuildArm (Thread[Execution worker for ':',5,main]) started.

> Task :app:cargoBuildArm FAILED
Task :app:cargoBuildArm in app Starting
Caching disabled for task ':app:cargoBuildArm' because:
  Build cache is disabled
Task ':app:cargoBuildArm' is not up-to-date because:
  Task has not declared any outputs despite executing actions.
Starting process 'command 'rustc''. Working directory: /Users/gitmp/Documents/android/project/src/app Command: rustc --version --verbose
Successfully started process 'command 'rustc''
Default rust target triple: x86_64-apple-darwin
Passing through project properties with prefix 'RUST_ANDROID_GRADLE_TARGET_ARMV7_LINUX_ANDROIDEABI_' (environment variables with prefix 'ORG_GRADLE_PROJECT_RUST_ANDROID_GRADLE_TARGET_ARMV7_LINUX_ANDROIDEABI_'
Starting process 'command 'cargo +nightly''. Working directory: /Users/gitmp/Documents/android/project/src/rust-app Command: cargo +nightly build --verbose --target=armv7-linux-androideabi
Task :app:cargoBuildArm in app Finished
:app:cargoBuildArm (Thread[Execution worker for ':',5,main]) completed. Took 0.065 secs.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:cargoBuildArm'.
> A problem occurred starting process 'command 'cargo +nightly''

* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.0.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 982ms
2 actionable tasks: 1 executed, 1 up-to-date

Switching rustup toolchain doesn't seem to solve the problem neither, (rustup default nightly).

I've temporary solved changing this line CargoBuildTask.kt#L81 to

val theCommandLine = mutableListOf(cargoExtension.cargoCommand, "+nightly", "build");

If everybody is fine with that, I can export the toolchain parameter to an environment variable named RUSTUP_TOOLCHAIN and make a PR.

thomcc commented 4 years ago

Supporting explicit toolchain (e.g. cargo +nightly) is something i've wanted to do but haven't had a use for. That said, I think it should be a new option on CargoExtension (and local.properities).

E.g. add val toolchain: String? after https://github.com/mozilla/rust-android-gradle/blob/16a12c2dd20fb9a7bc35cf6c5f813f65b49d775d/plugin/src/main/kotlin/com/nishtahir/CargoExtension.kt#L44 or around there.

Then add something here like https://github.com/mozilla/rust-android-gradle/blob/master/plugin/src/main/kotlin/com/nishtahir/CargoExtension.kt#L74 `

val rustupToolchain: String
    get() {
        return getProperty("rustup.toolchain", "RUST_ANDROID_GRADLE_RUSTUP_TOOLCHAIN")  ?: toolchain
    }

This would allow:

cargo {
    toolchain = 'nightly'
    // ...
}

in build.gradle, as well as overriding the build.gradle by putting it in local.properties or the environment.

Then you need to use it in the file where you found the build line.

Wrinkles here are:

  1. Cargo installed without rustup does not usually understand +toolchain (it's a rustup feature)
  2. I just put a bunch of effort into ensuring that r-a-g cargo is able to use the same build cache as non-gradle-invoked cargo for the same targets and settings

So it's important that if no custom toolchain gets provided, we don't change the environment or arguments we pass to cargo.

(note: this is just typed into github, so the code might not work)

thomcc commented 4 years ago

Ah, I just noticed the vscode calls the rustup toolchains 'channels' (rust.channel) which would likely avoid the confusion around all the other sorts of toolchains around here. That said I could go either way, but we should probably be clear what the toolchain is for.

gitmp01 commented 4 years ago

That'd be ok by me, I've only seen here that they are using the term toolchain.

Re the changes, I've made what you just said on a fork of mine. I can make a PR and discuss further changes over there if it is fine for you.

gitmp01 commented 4 years ago

Here the branch if you want to have a look at it https://github.com/gitmp01/rust-android-gradle/tree/rustup-toolchain-spec