Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use an environment variable in a .cargo/config file?

I'm using .cargo/config like this

[target.arm-linux-androideabi]
linker = "/home/rico/android-ndk-r13b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc"

But /home/rico/android-ndk-r13b is my NDK_HOME, not NDK_HOME of everyone

How can I specify to use $NDK_HOME?

Something like:

[target.arm-linux-androideabi]
linker = "$NDK_HOME/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc"
like image 895
edelangh Avatar asked Mar 08 '17 16:03

edelangh


People also ask

How do I set environment variables in rust?

Set an environment variable in Rust You can set an environment variable (for the scope of the currently running process) using the standard library too. To do so, we use env::set_var(key, value) .

How do I set an environment variable in terminal?

To set an environment variable, use the command " export varname=value ", which sets the variable and exports it to the global environment (available to other processes). Enclosed the value with double quotes if it contains spaces. To set a local variable, use the command " varname =value " (or " set varname =value ").


1 Answers

.cargo/config doesn't support environment variables. But you can configure the linker with RUSTC_LINKER environment variable:

export RUSTC_LINKER="$NDK_HOME/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc"
cargo build  # will try to use NDK's linker now

Though it'll work for all targets, not only for arm-linux-androideabi.

like image 186
ozkriff Avatar answered Sep 20 '22 18:09

ozkriff