Code Monkey home page Code Monkey logo

setting-up-rust-on-windows's Introduction

Setting up Rust On Windows

Quick guide to setting up Rust on Windows.

Installing

Project Config

workspace

In vs code, click file -> save workspace as, and save to your project's directory. eg c:\Projects\hello\workspace.code-workspace.

compile using tasks (optional)

Create a tasks.json for your project (eg c:\Projects\hello\.vscode\tasks.json).

{
	"version": "2.0.0",
	"tasks": [
		{
			"type": "cargo",
			"command": "build",
			"problemMatcher": [
				"$rustc"
			],
			"group": {
				"kind": "build",
				"isDefault": true
			},
			"label": "rust: cargo build",
			"presentation": {
				"reveal": "silent",
				"revealProblems": "onProblem",
				"close": true,
				"clear": true 
			}
		}
	]
}

Run with shortcut Ctrl + Shift + B.

Using launch (optional)

Create launch.json. eg c:\Projects\hello\.vscode\launch.json.

{
    "version": "0.2.0",
    "configurations": [

        {
            "name": "Debug",
            "type": "lldb",
            "request": "launch",
            "program": "cargo",
            "args": ["run"],
            "stopAtEntry": false,
            "cwd": "${workspaceRoot}",
            "environment": [],
            "externalConsole": true,
            "env" : {
            }
        },
        
        {
            "name": "Release",
            "type": "lldb",
            "request": "launch",
            "program": "cargo",
            "args": [
                "run", "--release"
            ],
            "stopAtEntry": false,
            "cwd": "${workspaceRoot}",
            "environment": [],
            "externalConsole": true
        }
    ]
}

Run by pressing the F5 key.

You can also choose between debug and release modes by clicking on the Run and Debug sidebar menu or using the shortcut Ctrl+Shift+D.

Global Config (optional)

Instead of storing launch in the project, you store it in the global settings file. eg %APPDATA%\code\user\settings.json or if you're using the portable version c:\vscode\data\user-data\User\settings.json.

{

    "launch": {
        "configurations": [

            {
                "name": "Debug",
                "type": "lldb",
                "request": "launch",
                "program": "cargo",
                "args": ["run"],
                "stopAtEntry": false,
                "cwd": "${workspaceRoot}",
                "environment": [],
                "externalConsole": true,
                "env" : {
                }
            },
            
            {
                "name": "Release",
                "type": "lldb",
                "request": "launch",
                "program": "cargo",
                "args": [
                    "run", "--release"
                ],
                "stopAtEntry": false,
                "cwd": "${workspaceRoot}",
                "environment": [],
                "externalConsole": true
            }
        ]
    },
    
    "security.workspace.trust.untrustedFiles": "open",
    "editor.accessibilitySupport": "off",
    "debug.allowBreakpointsEverywhere": true,
    "task.quickOpen.detail": false,
    "task.quickOpen.skip": true,
    "task.quickOpen.history": 1,
    "terminal.integrated.showExitAlert": false,
    "debug.terminal.clearBeforeReusing": true,
    "terminal.integrated.confirmOnKill": "never"
}

Misc

VS Build Tools 2022

Haven't tried it with rustup, but the link is available here.

Moving RustUp and Cargo to a different directory

By default it is installed in %USERPROFILE%\.cargo and %USERPROFILE%\.rustup. You can move it to a more convient location by adding/modifying the windows environment variables:

  • CARGO_HOME (eg set to c:\programs\cargo)
  • RUSTUP_HOME (eg set to c:\programs\rustup)
  • PATH (eg add c:\programs\cargo\bin)

Portable VS Code

By downloading the Zip version, it can be made portable by creating a folder called data inside its directory.

Creating a VS Build Tools Offline Installer

vs_buildtools.exe --layout d:\localVScache --includeRecommended --lang en-US --add Microsoft.VisualStudio.Workload.VCTools

More information:

Breakpoints

I could only get breakpoints working by going to the main function in my project and clicking the "Debug" text button above it.

Modifying external crates

If you have an issue with an external crate library, you can find its source from somewhere in .cargo\library\ and copy it else where and modify it.

Then in your cargo.toml file add something like:

[patch.crates-io]
gilrs-core = { path = "../crates/gilrs-core-0.3.1" }

Updating Rust and Cargo

rustup update

setting-up-rust-on-windows's People

Contributors

andrewhills avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.