Skip to content

Instantly share code, notes, and snippets.

@souhaiebtar
Last active March 29, 2024 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save souhaiebtar/7c08f5d862791513f44c78c2611123c6 to your computer and use it in GitHub Desktop.
Save souhaiebtar/7c08f5d862791513f44c78c2611123c6 to your computer and use it in GitHub Desktop.
[]install rust in windows using msys64 #rust #windows #compile

[WHATEVER]: https://www.reddit.com/r/rust/comments/197zxwx/rust_and_msys2_on_windows/, userComment: NishantD2D [WHATEVER]: https://stackoverflow.com/questions/21196525/rust-installation-on-windows/68835925#68835925

I do not have MSYS2 but just standard MinGW64 installation. But that shouldn't matter much

  1. First download and run rustup application
  2. Choose 2nd choice : Manually install the pre-requisite
  3. Press 'y' to continue
  4. Define 'host triple' : x86_64-pc-windows-gnu
  5. Default toolchain : stable
  6. Profile : default
  7. Modify PATH variable (y/n) : y

Then just press enter and let the installation complete.

Now find the cargo installation in C:\Users{User_Name}.cargo

Open this folder in an editor like VSCode and create a new file "config" without any extension and add the following commands in it :

[target.x86_64-pc-windows-gnu]
linker = "C:\\{mingw installation path}\\bin\\gcc.exe"
ar = "C:\\{mingw installation path}\\bin\\ar.exe"

By default the path must be : "C\Msys2\mingw64"

That's it, now you can use Rust with GCC.

Note : Install mingw with Msys2 (mingw-toolchain + base devel) because rust-analyzer (VSCode extension for Rust) will require the tools to compile the cargo directory. If you install only MinGW without Msys2, you'll be able to compile the code using CodeRunner (VSCode extension for executing languages) command but debugging would not work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment