willir / cargo-ndk-android-gradle

Cargo NDK for Android projects
Apache License 2.0
60 stars 8 forks source link

Target-specific environment variables #6

Open chengchangwu opened 4 years ago

chengchangwu commented 4 years ago

How could I set target-specific environment variables?

willir commented 3 years ago

Hmm. It seems I don't have that feature at the moment, let's hope it won't take too long to implement it :-)

willir commented 3 years ago

Could you please check version 0.3.3 and see whether it works for you? I've added extraCargoEnv option.

chengchangwu commented 3 years ago

For target armv7-linux-android I need to set PKG_CONFIG_LIBDIR=/path/to/my/pkg-config/armv7, for target aarch64-linux-android I need to set PKG_CONFIG_LIBDIR=/path/to/my/pkg-config/arm64. I do not know how to do that with extraCargoEnv. Could I use productFlavors and puth extraCargoEnv there?

willir commented 3 years ago

Hmm... I guess it would be possible to implement configuration per target. However, I'm not sure that such paths in your own system should be in that place. They look specific to your environment, and so others might have different ones. I guess we need to think about where would be the best place to specify them. Do you have any suggestions?

bayo-code commented 3 years ago

I can see a particular useful case for this. We we're building for multiple architectures and we need to set specific environment variables for, say pkg-config to find dependent libraries for each architecture we're building.

An example of how this could work is something like:

cargoNdk {
env = ["arm64": "PKG_CONFIG_LIBDIR=/path/to/arm64-libdirs", "arm": "PKG_CONFIG_LIBDIR=/path/to/arm-libdirs"...]
}

I'm not familiar with groovy's syntax, so there's probably a better way to write this. As for the implementation, this would just set the PATH temporarily. Might look like this for when building arm: PKG_CONFIG_LIBDIR=/path/to/arm-libdirs cargo ... Now, the environment variables are available depending on the current architecture being built.

I'll try to implement this and send a pull request, but I really know nothing about Groovy. Wish me luck!

EDIT:

I was thinking it could also look something like:

cargoNdk {
env  {
arm64 [
"PKG_CONFIG_LIBDIR": "...",
"...": "..."
]

// Same for other architectures
}
}