windowsrustaws-sdk-rust

How to get `dlltool.exe` for Rust GNU toolchain on Windows?


I have a simple CLI written in Rust which I'm building on the GNU toolchain on Windows 10. As per rustup show:

installed toolchains
--------------------
stable-x86_64-pc-windows-gnu (active, default)
stable-x86_64-pc-windows-msvc

active toolchain
----------------
name: stable-x86_64-pc-windows-gnu
active because: it's the default toolchain
installed targets:
  x86_64-pc-windows-gnu

I wanted my CLI to make a call to AWS, so I added this to Cargo.toml:

[dependencies]
aws-config = { version = "1.6.3", features = ["behavior-version-latest"] }

(I am aware that the AWS SDK for Rust requires an async library, but I'm taking this a step at a time.)

Even without adding any AWS-related code to my CLI, the addition of this dependency made my build fail with:

error: Error calling dlltool 'dlltool.exe': program not found

Following the Rustup Book's Windows docs, I installed MSYS2, but I still could find no dlltool.exe.

Compiling raw-dylib doesn't work on Windows #103939 says something about this and mentioned raw-dylib doesn't work on Windows with x86_64-pc-windows-gnu #140704, which says:

… Putting an LLVM dlltool renamed to dlltool.exe in your PATH.

OK, so where do I get a dlltool.exe?

The Microsoft C++ Build Tools license allows compiling open-source dependencies, so I downloaded the Microsoft C++ Build Tools, selecting:

After installation of the Microsoft C++ Build Tools, I still can't find a dlltool.exe anywhere.

Error: Error calling dlltool ‘dlltool.exe’: program not found says it found a solution:

make sure the rust-mingw component is installed, it should contain a dlltool.

After yet more searching for rust-mingw, I found Install rust-mingw component when adding a target #607. This is from 2016, so I'm not sure it's even relevant—but it's still open. It says there is something called rust-mingw I need to "download and copy", but doesn't tell me how:

When adding the target i686-pc-windows-gnu, rustup only installs rust-std, not rust-mingw. To cross-compile we need mingw component.
When manually downloaded and copied rust-mingw, compile works well.

Where can I find a dlltool.exe for accessing the AWS SDK for Rust on Windows 10 using the GNU toolchain?


Solution

  • The trick to getting dlltool.exe is to install MSYS2 as indicated in the Rustup book Windows docs. However there are additional steps involved, which the documentation doesn't spell out. Additionally other MSYS2 libraries need to be installed to get the AWS SDK for Rust to build.

    1. Download and install MSYS2, e.g. to C:\msys64.

    2. Important: Go into the MSYS2 terminal and install the following packages to get libtool.exe and others

      pacman -S --needed base-devel mingw-w64-ucrt-x86_64-toolchain \
          mingw-w64-ucrt-x86_64-nasm
      
    3. Add C:\msys64\ucrt64\bin to your PATH. (Don't forget to restart your terminal or otherwise update the current environment to pick up the change.)

    Without installing mingw-w64-ucrt-x86_64-toolchain, the AWS SDK for Rust will fail to find dlltool.exe as described above. Without mingw-w64-ucrt-x86_64-nasm, AWK SDK for Rust cannot compile its new crypto library.

    Visual Studio Code's Using GCC with MinGW instructions are helpful.