I always struggle with questions like that. Because straightforward “no” is just simply incorrect answer (constructive proof: NDISWrapper which allows one to link binaries compiled for Windows into Linux kernel…).
But, well… that's classic case of “if you have to ask then you don't need to know the answer” question.
Because all these things that @H2CO3 talks about are very-very real and handling them is very tricky. It can be done, it was done and I'm pretty sure it would be done again… but anyone who has enough knowledge about these nitty-gritty details would never need to ask this question in the first place!
I don't know how many years one would need to spend working with low-level stuff before one may even contemplate something like this.
Sorry, I'm still newbie into languages that are more low-level than high-one. I hope you understand.
I have only been creating Python scripts and small programs to automatize some tasks here, but I'm going to attend to a Computer Engineering bachelor course, attend to some Rust courses in Udemy or sites like this and so become more experienced in low-level stuff.
I thought that the .o files were platform independent, but I was wrong.
Yeah, they are the exact opposite from being platform-independent. As I have said: in some cases you can use object files built for one platform on another, but that's very non-trivial and anyone who may even hope to do that successfully wouldn't ask question that you have asked.
And that places others in bind: flat out saying “no” would be incorrect, but saying “yes” wouldn't be useful because it may prompt you into attempting something you are not even remotely ready to attempt.
I don't program in Rust at this time, but I have been using Cargo for ~3 years for compiling some programs. But I didn't used Cargo for cross-compiling yet. But there is a script of Gentoo linux called crossdev which automatizes the building of a cross-compilers, I'm sure I will be a very happy Rustacean in the future.
I stand by my opinion that a flat "no" is generally what can be considered correct. The dirty tricks you mentioned are not robust by any means, and the required effort is far beyond what is reasonable for something that has a proper alternative.
That's different thing. This script doesn't try to use .o files created for a different platform, but instead instructs exist Rust compiler to emut .o files compatible with target platform (unlike GCC LLVM-based compilers can be instructed to generate code for different platform and even different architecture, e.g. you may ask normal Rustc compiler to generate Arm 64bit code for iOS. Yes, just like that.
In that case you are not trying to use foreign .o files and there are no need to think about differences between platforms.
But if Rustc doesn't have support for your target platform… it's entirely different issue.
Kinda like difference with attempt to reach British Isles from the France by walking with or without Channel Tunnel: something which may be trivial (if tiring) in one case may become dangerous life-threatening endeavour in the other case.