Is it normal to use bash on Windows to build Rust projects?

On a whim I tried using BASH in WSL to build with the Windows Rust and Cargo. It works!

If you have Windows Rust installed on your Windows 10 machine you can use it from BASH in the Linux Subsystem to build Rust programs for Windows. Like so:

$ pwd

zicog@monster:/mnt/c/Users/zicogzicog$ cat
fn main () {
    println!("Hi, I'm a Windows executable built using BASH under WSL.");

zicog@monster:/mnt/c/Users/zicog$ /mnt/c/Users/zicog/.cargo/bin/rustc.exe

zicog@monster:/mnt/c/Users/zicog$ file winApp.exe
winApp.exe: PE32+ executable (console) x86-64, for MS Windows

zicog@monster:/mnt/c/Users/zicog$ ./winApp.exe
Hi, I'm a Windows executable built using BASH under WSL.

You can also build with cargo from BASH under WSL:

zicog@monster:/mnt/c/Users/zicog/radar$ /mnt/c/Users/zicog/.cargo/bin/cargo.exe build
   Compiling winapi v0.3.8
   Compiling libc v0.2.62
   Compiling byteorder v1.3.2
   Compiling matches v0.1.8
   Compiling cc v1.0.45
   Compiling smallvec v0.6.10
   Compiling cfg-if v0.1.9
   Compiling proc-macro2 v0.4.30
   Compiling unicode-xid v0.1.0
   Compiling version_check v0.1.5
   Compiling log v0.4.8

Sadly that cargo build fails when it can't find openssl, but it fails the same way from the Windows command box anyway. I'm sure that is fixable.

So there we have it, use BASH to build Rust for Windows on Windows in WSL.

I have no idea how useful or reliable this is mind.


These days, every developer on Windows has a bash installed, and both Visual Studio and Code depend (indirectly) on it. It's the one that comes with Git.

Git is implemented in a mix of C, Bash with standard Unix commands, Perl, Python and Tcl/Tk, and therefore depends on them. The Git-for-Windows installer takes these dependencies from Msys2 (slightly modified), which is a fork of Cygwin.

So if a project just needs bash—and not some more special tool usually found on Linux, but not on Windows—it should already be there.

I would be very surprised to need a bash script in Windows.

If you want a cross-platform language that I already need to have installed to build Rustc anyway, consider python.

1 Like

Using Python seems to be a very good idea. Thank you! :slight_smile:

How does one get anything done on Windows without the LSW and BASH?

I heard powershell is a actually a decent shell, that's most likely what people use.

(Or just avoid CLI utilities entirely, which one can get surprisingly close to in Visual Studio, albeit at the cost of a ridiculously big download and enormous run-time resource consumption)

I know nothing of this powershell of which you speak. Is it also useful on Linux/Unix? I lean toward cross-platform solutions wherever possible.

As much as I love a GUI for running browsers, Visual Studio Code and other such things that need graphics to be useful, I cannot imagine getting along happily without a CLI, except for some rather simplistic, repetitive things that can be automated with buttons, check boxes and the like. A CLI is often so much quicker, easier and more efficient.

Interesting. Seems powershell for Debian 10 is not quite cooked yet. I might give it a spin when it's packaged and stable.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.