Let us suppose I want to compile a Rust program for running in an operating system in which Rust codebase has no support, for example SkyOS.
SkyOS can run on x86 architecture.
Is it possible to compile to a 32-bits target such as
i686-unknown-linux-gnu and link with the Plan9 cross-compiler for working in this platform?
No. Generally, calling conventions/ABIs will differ, library-offered intrinsics emitted by the compiler will differ, etc.
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.
Have a nice day.
That's more-or-less what I suspected.
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.
Have a so so nice day.
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.
I think you didn't understand, I said that because that automatic method of building cross-compilers would be good to provide gcc binaries that Rust uses for linking in cross-compiling.
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.