Rust dependency crate not using recognizing linker


#1

Hello. I’m trying to build a rust library for android. The output is a .so file. My project is using the crates regex and typenum. When it goes to build those crates it gives me the error cannot find linker ‘cc’ like this

error: linker cc not found
|
= note: No such file or directory (os error 2)
error: aborting due to previous error
error: Could not compile typenum.

I am using vagrant to create a clean environment for ubuntu 16.04. I am using Android NDK 16b API 21, for x86.

I use the following commands to create the environment.

curl https://sh.rustup.rs -sSf | sh
source $HOME/.cargo/env

wget https://dl.google.com/android/repository/android-ndk-r16b-linux-x86_64.zip
unzip android-ndk-r16b-linux-x86_64.zip

export ANDROID_NDK_ROOT=$HOME/android-ndk-r16b
export NDK_TOOLCHAIN_DIR=$HOME/x86

python3 $HOME/android-ndk-r16b/build/tools/make_standalone_toolchain.py --arch x86 --api 21 --install-dir $NDK_TOOLCHAIN_DIR

export PATH=$HOME/x86:$HOME/x86/bin:$PATH

export PKG_CONFIG_ALLOW_CROSS=1
export CC=$NDK_TOOLCHAIN_DIR/bin/i686-linux-android-clang
export AR=$NDK_TOOLCHAIN_DIR/bin/i686-linux-android-ar
export CXX=$NDK_TOOLCHAIN_DIR/bin/i686-linux-android-clang++
export CXXLD=$NDK_TOOLCHAIN_DIR/bin/i686-linux-android-ld
export RANLIB=$NDK_TOOLCHAIN_DIR/bin/i686-linux-android-ranlib
export CROSS_COMPILE=i686-linux-android-
export CFLAGS="-D__ANDROID_API_=21"
export LDFLAGS="-D__ANDROID_API__=21"

cat <<EOF > $HOME/.cargo/config
[target.i686-linux-android]
ar = "${NDK_TOOLCHAIN_DIR}/bin/i686-linux-android-ar"
linker = "${NDK_TOOLCHAIN_DIR}/bin/i686-linux-android-clang"
EOF

rustup target add i686-linux-android
cargo build --target=i686-linux-android --release

I have been stuck on this for a while now. Any idea for getting these crates to pick up my settings in the $HOME/.cargo/config file?