Discuss Scratch

ScratchCatHELLO
Scratcher
1000+ posts

cross-compiling rust from linux to windows

I’ve started trying to learn rust, and I installed the gnu linux toolchain successfully. however, it would be useful to also compile to windows. I know I have to install a toolchain (or two) to do that, but is there anything else I need to do?
ScratchCatHELLO
Scratcher
1000+ posts

cross-compiling rust from linux to windows

bump
ScratchCatHELLO
Scratcher
1000+ posts

cross-compiling rust from linux to windows

cross exists, but I don’t feel like installing docker right now and I don’t have any clue how to check if a kernel module is installed
Retr0id
Scratcher
68 posts

cross-compiling rust from linux to windows

ScratchCatHELLO
Scratcher
1000+ posts

cross-compiling rust from linux to windows

Retr0id wrote:

https://stackoverflow.com/a/62853319/4454877

ScratchCatHELLO wrote:

I know I have to install a toolchain (or two) to do that, but is there anything else I need to do?

do I have to do anything else (eg. install mingw) to do that?
ScratchCatHELLO
Scratcher
1000+ posts

cross-compiling rust from linux to windows

bump
ScratchCatHELLO
Scratcher
1000+ posts

cross-compiling rust from linux to windows

I have newfound respect for people who try to support multiple platforms.

okay, I found this resource that explains cross-compiling for rust, so I’ll try to figure this out.

so there’s four things I need to find:
- target info (architecture, vendor, system, and maybe libc implementation). then I need to check if rust has a premade package for that. this should be trivial.
- a different version of gcc that compiles for windows. this is harder than it sounds, because the name of gcc for windows might not match with the name of the rust version for windows
- a different version of libc that compiles for windows.
- the std crate, cross-compiled for windows. this should be trivial.

these are probably:
- either x86_64-pc-windows-gnu or x86_64-pc-windows-msvc (I don’t know if it matters)
- not sure. maybe called x86_64-windows-gcc or something similar?
- should come with gcc?
- should come with windows rust?

so I still need to figure out what versions of stuff I need
also I have a feeling this will be a pain to update

Last edited by ScratchCatHELLO (Aug. 27, 2021 15:33:29)

imfh
Scratcher
1000+ posts

cross-compiling rust from linux to windows

Would it be easier to copy the files over to a Windows machine and compile there? I don't know much about rust, but if I want to compile something for a different computer / os, I usually use that computer / os to do it.
ScratchCatHELLO
Scratcher
1000+ posts

cross-compiling rust from linux to windows

imfh wrote:

Would it be easier to copy the files over to a Windows machine and compile there? I don't know much about rust, but if I want to compile something for a different computer / os, I usually use that computer / os to do it.

probably, but the only windows computer I have access to is the family computer, which isn't that fast, and I don't know if I would be allowed to install things on it. plus, this would be good practice for if I ever wanted to compile for an OS I don't have access to. I might try this, though
ScratchCatHELLO
Scratcher
1000+ posts

cross-compiling rust from linux to windows

I found this for mingw:

mingw-w64/bionic,bionic 5.0.3-1 all
Development environment targeting 32- and 64-bit Windows

mingw-w64-common/bionic,bionic 5.0.3-1 all
Common files for Mingw-w64

mingw-w64-tools/bionic 5.0.3-1 amd64
Development tools for 32- and 64-bit Windows

mingw-w64-x86-64-dev/bionic,bionic 5.0.3-1 all
Development files for MinGW-w64 targeting Win64

binutils-mingw-w64/bionic,bionic 2.30-7ubuntu1+8ubuntu1 all
Cross-binutils for Win32 and Win64 using MinGW-w64

binutils-mingw-w64-x86-64/bionic 2.30-7ubuntu1+8ubuntu1 amd64
Cross-binutils for Win64 (x64) using MinGW-w64

g++-mingw-w64-x86-64/bionic 7.3.0-11ubuntu1+20.2build1 amd64
GNU C++ compiler for MinGW-w64 targeting Win64

gcc-mingw-w64/bionic,bionic 7.3.0-11ubuntu1+20.2build1 all
GNU C compiler for MinGW-w64

gcc-mingw-w64-base/bionic 7.3.0-11ubuntu1+20.2build1 amd64
GNU Compiler Collection for MinGW-w64 (base package)

gcc-mingw-w64-x86-64/bionic 7.3.0-11ubuntu1+20.2build1 amd64
GNU C compiler for MinGW-w64 targeting Win64

don't know if mingw is what I want though

gcc-mingw-w64-x86-64/gcc-mingw-w64-base sounds like what I want here, but I'm not sure.
Ciyob86
Scratcher
500+ posts

cross-compiling rust from linux to windows

ScratchCatHELLO wrote:

imfh wrote:

Would it be easier to copy the files over to a Windows machine and compile there? I don't know much about rust, but if I want to compile something for a different computer / os, I usually use that computer / os to do it.

probably, but the only windows computer I have access to is the family computer, which isn't that fast, and I don't know if I would be allowed to install things on it. plus, this would be good practice for if I ever wanted to compile for an OS I don't have access to. I might try this, though
vm's exist
ScratchCatHELLO
Scratcher
1000+ posts

cross-compiling rust from linux to windows

gcc-mingw-w64-x86-64 apt page blurb:
GNU C compiler for MinGW-w64 targeting Win64
MinGW-w64 provides a development and runtime environment for 32- and
64-bit (x86 and x64) Windows applications using the Windows API and
the GNU Compiler Collection (gcc).
.
This package contains the C compiler, supporting
cross-compiling to 64-bit MinGW-w64 targets.

gcc-mingw-w64-base apt page blurb:
(same as above top section)
This empty package contains the documentation common to all
gcc-mingw-w64 packages.
and the file sizes:
Installed-Size: 203 kB
Download-Size: 172 kB
so gcc-mingw-w64-base is not what I want (necessarily)

gcc-mingw-w64 apt page blurb:
(ditto)
This metapackage provides the C compiler, supporting
cross-compiling to 32- and 64-bit MinGW-w64 targets.
this might actually be better, because it includes 32 and 64 bit windows targets.
it seems to install both gcc-mingw-w64-x86-64 and gcc-mingw-w64-i686

mingw-w64 seems like more than I need, because it installs 32 bit windows gcc, 64 bit windows gcc, 32 bit windows g++, and 64 bit windows g++. it might be useful, though.

binutils-mingw-w64(-x86_64) seems important, but I don't know what it's actually for.
ScratchCatHELLO
Scratcher
1000+ posts

cross-compiling rust from linux to windows

Ciyob86 wrote:

ScratchCatHELLO wrote:

imfh wrote:

Would it be easier to copy the files over to a Windows machine and compile there? I don't know much about rust, but if I want to compile something for a different computer / os, I usually use that computer / os to do it.

probably, but the only windows computer I have access to is the family computer, which isn't that fast, and I don't know if I would be allowed to install things on it. plus, this would be good practice for if I ever wanted to compile for an OS I don't have access to. I might try this, though
vm's exist

at that point I might as well just install docker and cross
ScratchCatHELLO
Scratcher
1000+ posts

cross-compiling rust from linux to windows

GNU project on the GCC compatibility with Microsoft Windows page wrote:

GCC contains support for x86-64 using the mingw-w64 runtime library, available from http://mingw-w64.org/doku.php. This library should be used with the target triple x86_64-pc-mingw32

this is giving me mixed messages: mingw-64 (or a variant) is almost certainly the package I want, but the target triple “x86_64-pc-mingw32” isn't supported by rust. however:

japaric/rust-cross on github wrote:

The confusing part is that triples can be quite arbitrary, so your C cross compiler will most likely be prefixed with a triple that's different from $rustc_target. For example, in Ubuntu the cross compiler for ARM devices is packaged as arm-linux-gnueabihf-gcc … and rustc uses the arm-unknown-linux-gnueabihf triple for that target. None of these triples match, but they refer to the same set of systems.

so mingw could be interpreted as “gcc” by rust, which constitues a supported target triple
ScratchCatHELLO
Scratcher
1000+ posts

cross-compiling rust from linux to windows

ok so apparently mingw is the compiler for the target triple “x86_64-windows-gnu” (and others)



but there's also msvc, and I don't know what that is or whether it's a better option.
ScratchCatHELLO
Scratcher
1000+ posts

cross-compiling rust from linux to windows

msvc stands for microsoft visual c, and I don't think I can install it on my computer.
ScratchCatHELLO
Scratcher
1000+ posts

cross-compiling rust from linux to windows

will this work with g++-mingw-w64-x86_64? this is arguably more useful (works for c, c++, and rust) if so than gcc-mingw-w64-x86_64 (works for c and rust)
ScratchCatHELLO
Scratcher
1000+ posts

cross-compiling rust from linux to windows

ScratchCatHELLO wrote:

will this work with g++-mingw-w64-x86_64? this is arguably more useful (works for c, c++, and rust) if so than gcc-mingw-w64-x86_64 (works for c and rust)

bump
ScratchCatHELLO
Scratcher
1000+ posts

cross-compiling rust from linux to windows

ScratchCatHELLO wrote:

will this work with g++-mingw-w64-x86_64? this is arguably more useful (works for c, c++, and rust) if so than gcc-mingw-w64-x86_64 (works for c and rust)

ok so it seems like libc is what rust actually needs and since:
(dependencies of g++-mingw-w64-x86-64)
Depends:
gcc-mingw-w64-x86-64 (= 7.3.0-11ubuntu1+20.2build1),
gcc-mingw-w64-base (= 7.3.0-11ubuntu1+20.2build1),
libc6 (>= 2.14),
libgcc1 (>= 1:4.2),
libgmp10,
libisl19 (>= 0.15),
libmpc3,
libmpfr6 (>= 3.1.3),
libstdc++6 (>= 5.2),
zlib1g (>= 1:1.1.4)
g++ should work

also, sidenote: I'm trying to justify the 100+ MB install to myself so I looked the biggest pc games and apparently Call of Duty: Modern Warfare is 200+ GB?!

Last edited by ScratchCatHELLO (Aug. 29, 2021 01:53:30)

ScratchCatHELLO
Scratcher
1000+ posts

cross-compiling rust from linux to windows

would the windows user need to have mingw-related libraries installed for this to work?

Powered by DjangoBB