Rust:- Build Project To Target MS Windows 32 Bit

Background

Let us review the steps one will take to build a Rust application that will be ran on a 32-bit MS Windows application.

 

Lineage

  1. Rust:- Cargo Build Error – “error: linker `link.exe` not found”
    Date Published:- 2023-March-28th
    Link

Outline

Here are the steps that we will follow:-

  1. Targeted Platforms
    • Review Targeted Platforms ( Pre )
    • Add Specific Target Platforms
      • Review Target Platforms ( Post )
  2. Project
    • Build Project
  3. Artifacts
    • List Artifacts
    • Inspect Artifacts
  4. Test App
    • Watch
      • Task Manager

 

Targeted Platforms

Review Targeted Platforms ( Pre )

Let us list available targeted platforms.

Command:- Rustup target list

Syntax


rustup target list

Sample

Sample – List Target – Windows

rustup target list | findstr /i "windows"

Output

Output – List Target – Windows

>rustup target list | findstr /i "windows"
aarch64-pc-windows-msvc
i586-pc-windows-msvc
i686-pc-windows-gnu
i686-pc-windows-msvc
x86_64-pc-windows-gnu
x86_64-pc-windows-msvc (installed)
>
Images – List – Target – Windows

Explanation

Explanation – List – Target – Windows
  1. A lone MS Windows Platform is targeted
    • x86_64-pc-windows-msvc (installed)

Add Targeted Platforms

Let us go over how to target new platforms.

Command:- Rustup target add

Syntax


rustup target add [platform]

Sample

Sample – Add Target – Windows

rustup target add i686-pc-windows-msvc

Output

Output – Add Target – Windows

>rustup target add i686-pc-windows-msvc
info: downloading component 'rust-std' for 'i686-pc-windows-msvc'
info: installing component 'rust-std' for 'i686-pc-windows-msvc'
26.9 MiB / 26.9 MiB (100 %) 8.9 MiB/s in 2s ETA: 0s

Image – Add Target – Windows

Explanation

Explanation – List – Target – Windows
  1. Component
    • i686-pc-windows-msvc
      • Tasks
        • Downloading component
        • Installing component
      • Size
        • 26.9 MB
        • 8 MiB/s
        • 2s ETA

 

Review Targeted Platforms ( Post )

For those who targeted platforms were not currently available, and they needed to add it, please review targeted platforms post installing a new target.

Command:- Rustup target list

Syntax


rustup target list

Sample

Sample – List Target – Windows

rustup target list | findstr /i "windows"

Output

Output – List Target – Windows
>rustup target list | findstr /i "windows"
aarch64-pc-windows-msvc
i586-pc-windows-msvc
i686-pc-windows-gnu
i686-pc-windows-msvc (installed)
x86_64-pc-windows-gnu
x86_64-pc-windows-msvc (installed)

>
Images – List – Target – Windows

Explanation

Explanation – List – Target – Windows

We reviewed available targets and filtered on Windows, here are our “installed” matches

  1. i686-pc-windows-msvc (installed)
  2. x86_64-pc-windows-msvc (installed)

 

Build Project

Build MS Windows 32-bit Project

Command:- Cargo Build

Syntax


cargo build

Sample

Sample – Build – Target – Windows – 32 Bit

cargo build --release --target x86_64-pc-windows-msvc

Output

Output – Build – Target – Windows – 32 Bit – Text

>cargo build --release --target x86_64-pc-windows-msvc
Compiling hello_world v0.1.0 (C:\personal\dadeniji\script\rust\hello_world)
Finished release [optimized] target(s) in 1.18s

Output – Build – Target – Windows – 32 Bit – Image

Build MS Windows 64-bit Project

Command:- Cargo Build

Syntax


cargo build

Sample

Sample – Build – Target – Windows – 64 Bit

cargo build --release --target x86_64-pc-windows-msvc

Output

Output – Build – Target – Windows – 64 Bit – Text

>cargo build --release --target x86_64-pc-windows-msvc

Compiling hello_world v0.1.0 (C:\personal\dadeniji\script\rust\hello_world)
Finished release [optimized] target(s) in 0.49s

Output – Build – Target – Windows – 64 Bit – Image

Artifacts

List Artifacts

Dir Command

Syntax


dir *.exe /s

Sample

List Windows Binaries ( *.exe )

dir target\*.exe /s /b

Output

List Windows Binaries ( *.exe )

>dir target\*.exe /s /b | findstr /V "\deps\"
C:\personal\dadeniji\script\rust\hello_world\target\i686-pc-windows-msvc\release\hello_world.exe
C:\personal\dadeniji\script\rust\hello_world\target\x86_64-pc-windows-msvc\release\hello_world.exe
>

Explanation
  1. target\i686-pc-windows-msvc\release\hello_world.exe
  2. target\x86_64-pc-windows-msvc\release\hello_world.exe

Inspect Artifacts

Determine Artifact Bitness

Dumpbin.exe

Syntax

dumpbin [file]

Sample – Windows – 32 Bit
Inspect Windows Binaries – 32 Bit

dumpbin /headers target\i686-pc-windows-msvc\release\hello_world.exe | findstr /I "machine"

Output
Text
>dumpbin /headers target\i686-pc-windows-msvc\release\hello_world.exe | findstr /I "machine"
14C machine (x86)
32 bit word machine

>
Image

Explanation
  1. Looked at the executable’s header
    • Filtered on machine
    • Matched:-
      • (x86)
      • 32 bit
Sample – Windows – 64 Bit
Inspect Windows Binaries – 64 Bit

dumpbin /headers target\x86_64-pc-windows-msvc\release\hello_world.exe | findstr /I "machine"

Output
Text

>dumpbin /headers target\x86_64-pc-windows-msvc\release\hello_world.exe | findstr /I "machine"
            8664 machine (x64)

Image

Explanation
  1. Looked at the executable’s header
    • Filtered on machine
    • Matched:-
      • 8664 machine (x64)

Test App

Watch

Task Manager

We will run application and watch via Task Manager

Run Application

Syntax

[application-name]

Sample
Sample – Windows – x32

target\i686-pc-windows-msvc\release\hello_world.exe

Output
Image – Windows -x32 – Console

Image – Windows -x32 – Task Manager

Explanation
  1. Task Manager
    • Columns
      • Platform:- 32 bit

Tools

  1. Find – Option /v
    • find /? ( Command Help )
      • /V Displays all lines NOT containing the specified string.
    • Skipped files in the deps folder
      • find /V “\deps\”
  2. Findstr – Option /V
    • findstr /? ( Command Help )
      • /V Prints only lines that do not contain a match.
    • Skipped files in the deps folder
      • findstr /V “\deps\”

 

Summary

__,  I am really a son of Rakim.

Everything takes too long around here!

 

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s