Skip to content

Latest commit

 

History

History
83 lines (54 loc) · 2.24 KB

File metadata and controls

83 lines (54 loc) · 2.24 KB

Readme

Build targetting windows platform via rustup / rustc

Statically linked to libc

Required nix env:

$ nix-shell -I nixpkgs=../../nixpkgs_root/
# ..
$ rustup target add x86_64-pc-windows-gnu

$ rustc --target x86_64-pc-windows-gnu hello.rs

$ file ./hello.exe
./hello.exe: PE32+ executable (console) x86-64, for MS Windows

# It appears not to dynamically linked to anything.
$ winedump -j export ./hello.exe
Contents of hello.exe: 4473666 bytes
Done dumping hello.exe

# Check that executable works in wine:
$ wine ./hello.exe
Hello World!

from cmd.exe on target windows device:

$ hello.exe
Hello World!

Statically linked to libc via cargo

We've generated ourselves a cargo package using cargo init.

Building with cargo:

$ cargo build --target x86_64-pc-windows-gnu
    Finished dev [unoptimized + debuginfo] target(s) in 0.00s

Note that what cargo actually built is not our ./hello.rs module but instead, the ./src/main.rs hello world main module that has been generated by our previous cargo init call.

Attempting to run with cargo:

$ cargo run --target x86_64-pc-windows-gnu
    Finished dev [unoptimized + debuginfo] target(s) in 0.00s
     Running `target/x86_64-pc-windows-gnu/debug/hello-static-rustup-target-windows.exe`
target/x86_64-pc-windows-gnu/debug/hello-static-rustup-target-windows.exe: target/x86_64-pc-windows-gnu/debug/hello-static-rustup-target-windows.exe: cannot execute binary file

as expected, it fails. How about using wine:

$ wine target/x86_64-pc-windows-gnu/debug/hello-static-rustup-target-windows.exe
Hello, world!

References