ZoeyR / rls-vs2017

Rust extension for Visual Studio 2017 with RLS support
MIT License
110 stars 12 forks source link

Question: How to trigger build/rebuild from VS? #23

Open mfkl opened 5 years ago

mfkl commented 5 years ago

Hi,

I've read https://github.com/dgriffen/rls-vs2017/issues/16 and I'm basically at the same point. RLS is installed and running, I have intellisense info but no dll produced.

This is the fairly simple test project https://github.com/mfkl/hello_world that I'm using.

I'd be interested in having VS perform something like cargo rustc --release --lib --target=x86_64-pc-windows-msvc when pressing F5. And eventually run the app (if its an exe).

Is that currently possible somehow? If not, do you know what needs to be implemented for this to work through VS?

Bigpet commented 5 years ago

This can be achieved somewhat with the weird json files in VS. Tried this with VS2019 but I think it would mostly work with 2017 too.

You need a ".vs/VSWorkspaceSettings.json" (at least for me, since otherwise it tried to use the wrong link.exe)

{
    envVars { "VSCMD_ARG_TGT_ARCH": "x64" }
}

then a .vs/tasks.vs.json (right click "Configure Tasks" creates this). To be able to RightClick->Build (haven't found a keyboard shortcut for that one).

{
  "version": "0.2.1",
  "tasks": [
    {
      "taskName": "task-build",
      "appliesTo": "/",
      "type": "launch",
      "contextType": "build",
      "command": "cargo",
      "args": [
        "build"
      ]
    }
  ]
}

And then to launch the build app a launch.vs.json (Right click ->Debug and Launch settings). Needs to be adjusted per project

{
  "version": "0.2.1",
  "defaults": {},
  "configurations": [
    {
      "type": "native",
      "name": "hello_cargo.exe",
      "project": "target\\debug\\hello_cargo.exe"
    }
  ]
}
mfkl commented 5 years ago

Thank you for that detailed explanation. Maybe this should be added to the readme or another markdown document of this repo?

bsechter-unext commented 4 years ago

Basically this. After following the above instructions, I got inconsistent results with the linker.exe problem. After clearing everything in the .vs directory except for the below files, builds work again. I hope builds will randomly break in the future.

At this point, I am using the following .vs/VSWorkspaceSettings.json:

{
  "envVars": {
    "VSCMD_ARG_HOST_ARCH": "x64",
    "VSCMD_ARG_TGT_ARCH": "x64"
  }
}

I am also using an expanded .vs/tasks.vs.json, because I want a few more options. These can be used by right clicking on the project folder. I could not figure out a canned rebuild.

{
  "version": "0.2.1",
  "tasks": [
    {
      "taskName": "task-build",
      "appliesTo": "/",
      "type": "launch",
      "contextType": "build",
      "command": "cargo",
      "args": [
        "build"
      ]
    },
    {
      "taskName": "task-clean",
      "appliesTo": "/",
      "type": "launch",
      "contextType": "clean",
      "command": "cargo",
      "args": [
        "clean"
      ]
    },
    {
      "taskName": "cargo-build",
      "appliesTo": "/",
      "type": "launch",
      "contextType": "custom",
      "command": "cargo",
      "args": [
        "build"
      ]
    },
    {
      "taskName": "cargo-run",
      "appliesTo": "/",
      "type": "launch",
      "contextType": "custom",
      "command": "cargo",
      "args": [
        "run"
      ]
    },
    {
      "taskName": "cargo-clean",
      "appliesTo": "/",
      "type": "launch",
      "contextType": "custom",
      "command": "cargo",
      "args": [
        "clean"
      ]
    }
  ]
}

launch.vs.json is basically the same as above in Bigpet's post. Also, see the following page: https://docs.microsoft.com/en-us/visualstudio/ide/customize-build-and-debug-tasks-in-visual-studio?view=vs-2019

Right clicking on the exe seemed to be required to setup the green run button.