I've always been frustrated at the amount of wear and tear that constant building can cause on SSD's (I've even burned one out!). So here are some useful instructions on how to set up a working ram drive for cargo builds
Download and install the driver for arsenal image mounter, then go to this page and download aim_ll.zip
. After you install the driver, you may delete the entire arsenal image mounter application (just remember that the driver will still be installed!)
- Download files under Windows directory.
-
- Place files in
Windows\Documents\PowerShell
in yourC:\<UserName>\Documents\PowerShell
folder
- Place files in
- Set your
TMP
andTEMP
env vars to the ram drive path you want (e.g.R:\Temp
) - Open task scheduler and make a new task with the following properties:
-
- Run with highest privileges
-
- Trigger, runs at startup
-
- Actions, start a program, set to
C:\Path\To\ramdisk.bat
- Actions, start a program, set to
- Extract the files in zip
aim_ll.zip
to the same folder asramdisk.bat
is in
You can edit the size of the ramdrive, volume label, and other options by editing the command line in ramdisk.bat
. By default, the script here says 3GB
If you do not desire to move your entire temp folder over to the ram drive, you may edit the script with either a hardcoded path, or to use a different env var
* Note: Arsenal Image Mounter is made by the same author as imdisk, so it's pretty reputable ** You can use any RAM software you want as the PowerShell scripts will work with anything, just as long as your software is fairly compatible (cargo will fail to work on any ram disk implentations that don't implement all fs functions)
There is a way to use this with VsCode/RustAnalyzer.
- Open VsCode from an instance of powershell, where the variable is already set, and RustAnalyzer will properly use it.
- If you like to use the "Open with Code" menu item like I do, do the following:
-
- Download
vscode-custom-build-launcher.exe
from the releases tab (this is just a simple vscode launcher which sets the env vars)
- Download
-
- Place it somewhere and put that location in PATH
- Download the reg files under
Windows
, change the paths ininstall.reg
to your correct path (make sure to double check the whole path for the icon!) -
- Run
install.reg
anddelete-vscode-context-menu.reg
(this will delete the default VsCode "open with" entry). If you see double entries later after an update/install, just re-run thedelete-vscode-context-menu.reg
file
- Run
- If you want to uninstall later on, just run
uninstall.reg
- You can also change your shortcuts to use the launcher like so
C:\path\to\vscode-custom-build-launcher.exe -o "C:\Scratch"
For more info on the flags, just type--help
or look at the source code (note that this sets a static build dir, so if you open multiple instances of vscode, they'll use the same build dir, which is probably not what you want to happen)
Note: You may need to add the location where code.exe
is located to your PATH
, such as C:\Users\USERNAME\AppData\Local\Programs\Microsoft VS Code
. Also, VsCode updates re-add the open with
registry keys, which is why delete-vscode-context-menu.reg
is separate (for ease)
Every time you cd to a different directory in PowerShell, the script will update CARGO_BUILD_TARGET_DIR
to always point to a unique rust target folder in your temp folder for that specific project. Folders with the same project names do not and will not clash due to the unique id number placed at the end.
cargo clean
: Clean out the tmp rust project target dir (e.g.R:\Temp\rust\MyProject-1234\*
)Clean-Rust
: Clean out the entire tmp rust folder (e.g.R:\Temp\rust\*
)Rust-TargetDir
: Opens explorer to the rust target dir (e.g.R:\Temp\rust\MyProject-1234\*
)