DEV Community

Cover image for "πŸ¦€ Ditching Visual Studio: How I Built Rust on Windows the Open-Source Way"
RealACJoshua
RealACJoshua

Posted on

"πŸ¦€ Ditching Visual Studio: How I Built Rust on Windows the Open-Source Way"

This is a full walkthrough of setting up Rust on Windows using the GNU toolchain via MSYS2 β€” no Visual Studio, no link.exe, no tears."


I wanted Rust. I didn't want Visual Studio.

What followed was 3 hours of linker errors, missing DLLs, and yelling at my terminal β€” but I came out stronger. If you want to set up Rust on Windows without Visual Studio, here's exactly what worked for me.


🎯 What We’re Building

Rust + MSYS2 + GCC = βœ…

No Visual Studio + No link.exe = 😌

We’ll set up a lightweight, open-source Rust environment on Windows using the x86_64-pc-windows-gnu toolchain and MSYS2.

I assume you have rust installed already if not πŸ‘‰ Install Rust


πŸ› οΈ 1. Install MSYS2 (the Right Way)

  • Download from πŸ‘‰ msys2.org
  • Open MSYS2 MinGW 64-bit Terminal (not the default one!)
  • Then run:
pacman -Syu
Enter fullscreen mode Exit fullscreen mode

βœ… If it asks you to restart the terminal, do that and run it again.


πŸ”§ 2. Install the Toolchain

In MSYS2 MinGW 64-bit Terminal:

pacman -S --needed base-devel mingw-w64-x86_64-toolchain
Enter fullscreen mode Exit fullscreen mode

If you face mirror timeouts (especially common in Africa), update this file:

/etc/pacman.d/mirrorlist.mingw64
Enter fullscreen mode Exit fullscreen mode

Replace with:

Server = https://cdn.jsdelivr.net/msys2/mingw/x86_64/
Server = https://mirror.msys2.org/mingw/x86_64/
Server = https://packages.msys2.org/mingw/x86_64/
Enter fullscreen mode Exit fullscreen mode

Then clean and update again:

pacman -Scc
pacman -Syyu
Enter fullscreen mode Exit fullscreen mode

🧠 3. Switch Rust to the GNU Toolchain if you were using another version

rustup install stable-x86_64-pc-windows-gnu
rustup default stable-x86_64-pc-windows-gnu
Enter fullscreen mode Exit fullscreen mode

✍️ 4. Tell Cargo Where Your Compiler Is

Edit this file:

C:\Users\<your_username>\.cargo\config.toml
Enter fullscreen mode Exit fullscreen mode

Add:

[target.x86_64-pc-windows-gnu]
linker = "C:\\msys64\\mingw64\\bin\\gcc.exe"
ar = "C:\\msys64\\mingw64\\bin\\ar.exe"
Enter fullscreen mode Exit fullscreen mode

🧩 5. Fix That Dreaded dlltool Error

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

Make sure you have it(dlltool):

where dlltool
Enter fullscreen mode Exit fullscreen mode

Expected:

C:\msys64\mingw64\bin\dlltool.exe
Enter fullscreen mode Exit fullscreen mode

If not, run:

pacman -S mingw-w64-x86_64-binutils --overwrite '*'
Enter fullscreen mode Exit fullscreen mode

Then temporarily fix your PATH:

$env:PATH="C:\msys64\mingw64\bin;" + $env:PATH
Enter fullscreen mode Exit fullscreen mode

To make it permanent, add it via System Environment Variables.


πŸš€ 6. Test It Out

cargo new rust_test
cd rust_test
cargo build
Enter fullscreen mode Exit fullscreen mode

πŸŽ‰ No Visual Studio. No link.exe. Just Rust + GCC goodness.


πŸ’‘ Bonus Tips from My Pain

  • Never run pacman from PowerShell or CMD β€” MSYS2 only!
  • Update your mirrors early if you're outside the US/EU.
  • MSVC-based crates (like windows-sys) will complain β€” avoid them or find GNU alternatives.
  • Check your paths β€” MSYS (/usr/bin) and MinGW (/mingw64/bin) are not the same!

🏁 Final Thoughts

If you’re tired of bloated installs and want to keep things lean and open-source, this setup works beautifully. It took me trial, error, and a bit of cursing to get it right β€” but now it’s smooth sailing.

If this helped you, drop a ❀️ or share it. If you ran into a different issue, comment below β€” let’s help more Rustaceans build without the bloat.


πŸ—£οΈ Your Turn:
Have your own story of escaping the grip of Visual Studio? Share it in the comments β€” let’s make the Windows + Rust experience better for all.

Check me out at theacj.com.ng

Top comments (0)