Two machines, same code, cpu-native

Hello to all the comunity,

i'm trying to opmitize all my programs in rust

I have all the code in a NAS, in a nfs share

what i'm trying to do it's this

i have only one folder with all the code

i have a rasperry and my principal machine is x86_64
i want to compile the code in the two machines

now i'm compiling with cpu x86_64 and aarm64 and obtaining twos executables (bin) in two folders separate

can i use the cpu-native and compile in two folders separate (not crosspoling)

the aarm64 will compile all the code for it and the x64 the same

What is the best method to obtain the cpu-native optimization in this case?

If I understand correctly, you are building on two separate hosts in a single shared directory? If that is the case, both will write to the same target/release subdirectory by default, and step on the others' toes. You can use the --target-dir arg with Cargo to change it.

# On the x86_64 host
$ cargo build --release --target-dir ./target/x86_64/release

# On the AArch64 host
$ cargo build --release --target-dir ./target/aarch64/release

Now each host writes its build artifacts into separate subdirectories. This can be simplified further by adding host-specific environment variables or ~/.cargo/config values as documented in Build Cache - The Cargo Book (

You can use -C target-cpu=native for both hosts using the same methods (RUSTFLAGS environment variable, cargo config).

Thanks for the info, this will solve the problem, i'm open to more sugestions to have multiple cpunative bin codes in the same project

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.