Crosscompiling and cpu-native

Hello to all the comunity

I'm trying to optimize my programs in rust but i have a little problem

First of all i have all the code in and nfs share in a NAS

Now i have two computers where i want to run the program:

and AMD and a Raspberry pi4

For compile i have this two computers, but i preffer to compile only in the AMD

I have done a script that

cargo update
cargo build --target=x86_64-unknown-linux-gnu --release

and another that have:

cargo update
cargo build --target=aarch64-unknown-linux-gnu --release

I can diferenciate the bin because there are in separate folders

for x86_64 is:
/mnt/Rust/program1/target/x86_64-unknown-linux-gnu/release

and for arm64 is:
/mnt/Rust/program1/target/aarch64-unknown-linux-gnu/release

i was reading about puting a rustflags=" -c -target-cpu=native" in the .cargo/config.toml
to optimize the generated bin with all the crates being optimized.

But i have a question.

¿The main computer can crosscompile with cpu=native to the armv64 of the raspberry pi 4? ¿and where is going the bin?

target-cpu=native means auto-detect the current hosts cpu architecture and use that, I would expect that to fail when cross-compiling because you'll be saying "build an aarch64 binary optimized for the athlon64-ss3 architecture" (or whichever AMD cpu you have). You can use rustc --print target-cpus to get the list of architectures that rustc knows about, including what native means, e.g. I get

    native         - Select the CPU of the current host (currently skylake).

So, if you have rustc on the Pi you could use this to see what architecture is detected and pass that explicitly e.g. -C target-cpu=skylake.

EDIT: Yeah, checking RUSTFLAGS='-C target-cpu=native' cargo build --target aarch64-unknown-linux-gnu -v with a random project of mine I get a lot of warnings printed:

'skylake' is not a recognized processor for this target (ignoring processor)

two things about it

Correct me if i'm wrong

if a pass the compile with

rustc -C -target-cpu=native --release

i'm only optimizing the main program and not all the libraries,

It's a little solution to change the target and put -athlon64-ss3- to get the main program optimized

but if'm putting in the .cargo/config of the program

[build]
rustflags = "-C target-cpu=native"

i can't crosscompile it to the aarch64

Perhaps the solution it's compile in the rasp for the aarch64 with cpu-native
and compile in the athlon64-ss3 for the amd but i have lost the possibility of the crosscompiling in the amd

Now all the programs works ok but i want to get two optimized bin with all the crates optimized if it's possible, to two diferents architectures.

all in the same NFS share, but in diferents folders because i have to call it in the amd or in the aarch64.