Interaction between .cargo/config and shell environment

Hi !
I'm trying to cross compile a simple rust program to ARMv7, following information found at https://github.com/japaric/rust-cross. From what I understand, I need to set the correct linker program in the .cargo/config file. Since I'm cross-compiling to multiple architecture, none of my compilers are in the path, I'm using a CROSS_COMPILE shell variable that points to the correct one.

Is there a way to add something like

[target.armv7-unknown-linux-gnueabihf]
linker = "${CROSS_COMPILE}gcc"

Right now I'm getting:

error: could not exec the linker ${CROSS_COMPILE_PREFIX}gcc: No such file or directory (os error 2)
to my .cargo/config file ?

It seems that cargo doesn't evaluate environment variables in .cargo/config. Why can't you specify the full path? Cargo allows to specify linker per target (e.g. target.armv7-unknown-linux-gnueabihf in your code).

Using the full path is not a problem in itself, it is just less convenient: each time I'll update the compiler, I'll have to update the config file, and I can't share it easily between my several desktops. I was just wondering if there was an easier way.

2 Likes

Have you tried not setting linker? I'm playing with various Cortex-M controllers here, and I don't have it in my config files.

Thank you for the feedback @starblue. Can you elaborate ? Does the arm linker is in your path ? Which one are you using (linaro's, your distrib's) ? For my case, the linker is not in my PATH (for practical reasons), I explicitly use the CROSS_COMPILE env variable in my C Makefiles.

Yes, the tools are in my path.
I use the GCC ARM Embedded toolchain from Launchpad and install it manually under /usr/local.

1 Like

@starblue For those particular targets you are using the default linker is arm-none-eabi-gcc so you don't need to set anything in your cargo config if arm-none-eabi-gcc is on your PATH. For the target @vsiles is using the default linker is cc (or gcc I can't remember) so @vsiles will need to use .cargo/config for cross-compilation.

@vsiles How about creating a shell script called cross-compile-gcc in your PATH that just executes ${CROSS_COMPILE}gcc then put cross-compile-gcc in your .cargo/config.

1 Like

That's a solution yes. I was just wondering if a more integrated solution existed :slight_smile:

1 Like