Add section to "Working in WSL2" about natively compiling #267
Labels
C-enhancement
New content that isn't covered already
P-windows
Platform: MS Windows
S-platforms
Content about developing for a specific target platform
Z-medium
medium task that needs moderate time investment
Background
I'd like to propose a section be added to the "Working in WSL2" page about natively compiling and running on windows through WSL2 (rather than cross compiling, or natively compiling not through a WSL2 development environment).
This setup involves being able to run a command in your WSL2 terminal that will invoke cargo in your native windows environment without anything visibly happening outside of your WSL2 terminal. I've noticed that this setup, in comparison to cross compiling to windows from within WSL2 ubuntu:
lld
as the linker for both, no dynamic linking)Setup
build.target-dir
on windows so that you aren't mixing your WSL2 and windows filesystems. I changed my global cargo config on windows (found atC:\Users\NAME\.cargo\config.toml
) to something like this:Note that I'm using
powershell.exe
instead ofcmd.exe
becausecmd.exe
doesn't understand network drive paths and that's how the WSL2 filesystem is mounted.Also, I'd recommend creating this as a cargo custom command for ease of use. My script is named
cargo-win
and is in a directory on my linux path. If you don't create it as a cargo custom command, you'll want to remove theshift
line so you don't drop actually useful args.If all that's been followed in the same way I did it, you'll then have a
cargo win
command that will just run any cargo command from your WSL2 terminal and have it really be running in your native windows environment transparently (e.g.cargo win run
,cargo win build --release --no-default-features
, etc.). This still shows all cargo output as well as logs for your game executable in the WSL2 terminal window that you invokedcargo win ...
in.Personal Note
I spent a lot of time trying to figure out how to get cross compilation working to a productively functional level, getting frustrated with all the strange bits that just didn't really work well, and then spent more time trying to get a native solution like what I've described above to work all while being able to not leave my WSL2 development environment. I would have really appreciated this knowledge existing in this book when I was getting started, and I hope that you agree that it'd be a worthwhile addition in whatever form you deem most relevant and helpful.
I'm happy to answer any questions you might have about any of this.
The text was updated successfully, but these errors were encountered: