Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty rustJniLibs/ folder when CARGO_TARGET_DIR is defined #125

Open
chtimi59 opened this issue May 21, 2023 · 2 comments
Open

Empty rustJniLibs/ folder when CARGO_TARGET_DIR is defined #125

chtimi59 opened this issue May 21, 2023 · 2 comments

Comments

@chtimi59
Copy link

chtimi59 commented May 21, 2023

Version 0.9.3

I've try to change CARGO_TARGET_DIR per target like so:

cargo {
        ...        
        exec { spec, toolchain ->
                spec.environment("CARGO_TARGET_DIR", rustOutputFolder(toolchain.platform))
        }
    }

As the result, even if, the build folder build/rustJniLibs/.. is created and rust build succeed,
the folder stay empty !

@chtimi59
Copy link
Author

chtimi59 commented May 21, 2023

After some investigation I've found this:

https://github.com/mozilla/rust-android-gradle/blob/master/plugin/src/main/kotlin/com/nishtahir/CargoBuildTask.kt#L42:

// CARGO_TARGET_DIR can be used to force the use of a global, shared target directory
// across all rust projects on a machine. Use it if it's set, otherwise use the
// configured `targetDirectory` value, and fall back to `${module}/target`.
//
// We also allow this to be specified in `local.properties`, not because this is
// something you should ever need to do currently, but we don't want it to ruin anyone's
// day if it turns out we're wrong about that.
val target =
    getProperty("rust.cargoTargetDir", "CARGO_TARGET_DIR")
    ?: targetDirectory
    ?: "${module!!}/target"

And I've realized that getProperty() is defined as follow:

https://github.com/mozilla/rust-android-gradle/blob/master/plugin/src/main/kotlin/com/nishtahir/CargoExtension.kt#L130

internal fun getProperty(camelCaseName: String, snakeCaseName: String): String? {
      val local: String? = localProperties.getProperty(camelCaseName)
      if (local != null) {
          return local
      }
      val global: String? = System.getenv(snakeCaseName)
      if (global != null) {
          return global
      }
      return null
}

I guess it makes sens then:

spec.environment("CARGO_TARGET_DIR", rustOutputFolder(toolchain.platform))

won't populate:

System.getenv("CARGO_TARGET_DIR")

@chtimi59
Copy link
Author

possible little hack (?)

 exec { spec, toolchain ->
        spec.environment("CARGO_TARGET_DIR", rustOutputFolder(toolchain.platform))
        localProperties.setProperty("rust.cargoTargetDir", "${rustOutputFolder(toolchain.platform)}")
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant