Reputation: 167
I would like to cross compile a program written in Rust from my Mac (M1 Max) to Linux. After searching online, it looks like the solution is to install a target for Linux using Rustup. The problem with this is that I do not have Rustup—my Rust installation was obtained via MacPorts as a dependency for some entirely unrelated program, and does not contain a rustup binary.
Are there any ways to cross compile this Rust program from my Mac without having to install an additional copy of Rust on my computer? The MacPorts distribution of Rust gives me access to Cargo (and of course any other port distributed via MacPorts), but I cannot figure out what additional port (or magic commands) I can use in order to successfully compile the program.
In my search for an answer, I have come across mentions of adding targets manually, but I have not found anyone explain how to 'get' this target or how to install it.
If at all possible, I would like to avoid using Homebrew, or having to install any extra copies of Rust on my computer.
Before anyone mentions it, I have seen this post already. I am asking this question because (1) unfortunately, they have not been answered; and (2) it sounds like they are restricted to an offline version of Rust, whereas I am not.
Upvotes: 1
Views: 165
Reputation: 3360
Each port in MacPorts is just a script that determines how to get the sources, apply patches, compile them, and install the results. Here you can find the portfile for Rust, of which there is perhaps already a local version on your computer. You can make your desired changes to (a copy of) it, and then use the changed portfile instead of the old one.
These instructions for using modified ports by setting up a local repository in which to keep them separate from the official ports, seem highly relevant.
PS Are you sure the necessary cross-compilation support is not already available on your system? If you skip all the rustup commands, does cargo build --target=.?.-linux-.?.
then fail with a message indicating such a target is not available?
Upvotes: 0