cargo-ndk-android-gradle icon indicating copy to clipboard operation
cargo-ndk-android-gradle copied to clipboard

Target-specific environment variables

Open chengchangwu opened this issue 4 years ago • 5 comments

How could I set target-specific environment variables?

chengchangwu avatar Nov 12 '20 03:11 chengchangwu

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 avatar Dec 23 '20 00:12 willir

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

willir avatar Dec 27 '20 01:12 willir

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?

chengchangwu avatar Jan 06 '21 10:01 chengchangwu

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?

willir avatar Jan 06 '21 15:01 willir

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
}
}

bayo-code avatar Jul 26 '21 03:07 bayo-code