mozilla / rust-android-gradle

Apache License 2.0
1.08k stars 70 forks source link

Make `cargoCommand` and `rustcCommand` and `pythonCommand` (I guess?) be invoked from a consistent current directory #54

Open dcsommer opened 3 years ago

dcsommer commented 3 years ago

Per documentation at https://github.com/mozilla/rust-android-gradle#specifying-paths-to-sub-commands-python-cargo-and-rustc

I cannot set cargoCommand and rustcCommand. I see this error:

> Cannot set the value of read-only property 'rustcCommand' for extension 'cargo' of type com.nishtahir.CargoExtension.
ncalexan commented 3 years ago

Are you confident you're using one of the newest releases where the functionality is present? Can you link to a project or similar? Locally, I see:

nalexander@roboto ~/M/rust-android-gradle (master) [1]> git rev-parse HEAD
e2183c1f3f4297d3cd3a580cec96bf72d0f33ce0

nalexander@roboto ~/M/rust-android-gradle (master)> git diff samples/app
diff --git a/samples/app/build.gradle b/samples/app/build.gradle
index 6317214..c57fa8e 100644
--- a/samples/app/build.gradle
+++ b/samples/app/build.gradle
@@ -37,6 +37,7 @@ cargo {
     module = "../rust"
     targets = ["arm", "x86", "x86_64", "arm64"]
     libname = "rust"
+    cargoCommand = "bogus"
 }

 repositories {
nalexander@roboto ~/M/rust-android-gradle (master)> ./gradlew -p samples/app assembleDebug
> Task :cargoBuildArm FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':cargoBuildArm'.
> A problem occurred starting process 'command 'bogus''

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --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 5.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/4.10.2/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 0s
19 actionable tasks: 1 executed, 18 up-to-date

Maybe there is something OS-specific happening? Maybe there is something happening based on consuming the plugin from a dependency, rather than via includeBuild?

dcsommer commented 3 years ago

This was my mistake. I didn't modify the path to the built .jar after the version change. It all works well now. Thanks for the help!

That said, there is some inconsistency concerning from which directory the programs are invoked, so my relative paths look a little ugly. Assume the below is in the path $repo/app/jni/build.gradle:

cargo {
    module = "rust"
    cargoCommand = "cargo"
    rustcCommand = "rustc" 
}

Then rustcCommand is invoked from directory $repo/app/jni and cargoCommand is invoked from $repo/app/jni/rust. It would be nice if both paths were relative to $repo/app/jni (as that is where the build.gradle file lives).

ncalexan commented 3 years ago

This was my mistake. I didn't modify the path to the built .jar after the version change. It all works well now. Thanks for the help!

You are most welcome.

That said, there is some inconsistency concerning from which directory the programs are invoked, so my relative paths look a little ugly. Assume the below is in the path $repo/app/jni/build.gradle:

cargo {
    module = "rust"
    cargoCommand = "cargo"
    rustcCommand = "rustc" // invoked from 
}

Then rustcCommand is invoked from directory $repo/app/jni and cargoCommand is invoked from $repo/app/jni/rust. It would be nice if both paths were relative to $repo/app/jni (as that is where the build.gradle file lives).

Let's mutate this ticket to track doing better here; patches wanted. In fact, if you can figure out how to get the rustc version or whatever out of cargo directly, we can get rid of the rustc invocation entirely.