{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/cargo/issues/1889","labels_url":"https://api.github.com/repos/rust-lang/cargo/issues/1889/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/cargo/issues/1889/comments","events_url":"https://api.github.com/repos/rust-lang/cargo/issues/1889/events","html_url":"https://github.com/rust-lang/cargo/issues/1889","id":100207366,"number":1889,"title":"Cargo doesn't pass MSVC ToolsVersion to build.rs","user":{"login":"briansmith","id":16816,"avatar_url":"https://avatars.githubusercontent.com/u/16816?v=3","gravatar_id":"","url":"https://api.github.com/users/briansmith","html_url":"https://github.com/briansmith","followers_url":"https://api.github.com/users/briansmith/followers","following_url":"https://api.github.com/users/briansmith/following{/other_user}","gists_url":"https://api.github.com/users/briansmith/gists{/gist_id}","starred_url":"https://api.github.com/users/briansmith/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/briansmith/subscriptions","organizations_url":"https://api.github.com/users/briansmith/orgs","repos_url":"https://api.github.com/users/briansmith/repos","events_url":"https://api.github.com/users/briansmith/events{/privacy}","received_events_url":"https://api.github.com/users/briansmith/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-08-11T01:57:13Z","updated_at":"2015-09-08T23:39:19Z","closed_at":"2015-08-11T06:31:19Z","body":"My build.rs builds my native code by invoking msbuild.exe on the Visual Studio solution that normally builds it when it isn't being used with Rust. And, my Visual Studio solution is designed to build correctly with both MSVC 2013 and MSVC 2015.\r\n\r\nI've found that Cargo will end up linking with VS 2015's link.exe (tools version 14.0), but that my %PATH% has msbuild 12.0 (VS 2013's) in the path. My build.rs needs to know which version of link.exe is going to be chosen so that it can build the code using the same version of the compiler (Code compiled with MSVC 12.0 cannot be linked with code compiled with MSVC 14.0).\r\n\r\nTo solve this problem, I propose that Cargo pass CARGO_MSVC_TOOLS_VERSION=12.0 or CARGO_MSVC_TOOLS_VERSION=14.0 in the environment when it runs build.rs based on which version of link.exe it selects."},"comment":{"url":"https://api.github.com/repos/rust-lang/cargo/issues/comments/138731994","html_url":"https://github.com/rust-lang/cargo/issues/1889#issuecomment-138731994","issue_url":"https://api.github.com/repos/rust-lang/cargo/issues/1889","id":138731994,"user":{"login":"briansmith","id":16816,"avatar_url":"https://avatars.githubusercontent.com/u/16816?v=3","gravatar_id":"","url":"https://api.github.com/users/briansmith","html_url":"https://github.com/briansmith","followers_url":"https://api.github.com/users/briansmith/followers","following_url":"https://api.github.com/users/briansmith/following{/other_user}","gists_url":"https://api.github.com/users/briansmith/gists{/gist_id}","starred_url":"https://api.github.com/users/briansmith/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/briansmith/subscriptions","organizations_url":"https://api.github.com/users/briansmith/orgs","repos_url":"https://api.github.com/users/briansmith/repos","events_url":"https://api.github.com/users/briansmith/events{/privacy}","received_events_url":"https://api.github.com/users/briansmith/received_events","type":"User","site_admin":false},"created_at":"2015-09-08T23:39:19Z","updated_at":"2015-09-08T23:39:19Z","body":"Alex, can we re-open this?\r\n\r\nNew information:\r\n* The very first bug report I got for *ring* was due to this issue. This is evidence that people don't expect that they need to run vcvarsall.bat before running the build.\r\n* I have been working on some basic Cargo integration for the Visual Studio IDE. This problem occurs there too, and the hack of using vcvarsall.bat doesn't work (AFAICT) in that case.\r\n* Running command-line builds in a \"VS2013/2015 native tools command prompt\" is often inconvenient. In particular, the Git Powershell prompt (Git Posh) doesn't integrate well with that or with vcvarsall.bat due to differences in how batch files and Powershell work w.r.t. inheriting environment variables (AFAICT).\r\n\r\nMy suggestion is to iterate as follows:\r\n1. Add a -toolsversion={12.0|14.0} flag to rustc that overrides rustc's lookup heuristics.\r\n2. Add a -toolsversion={12.0|14.0} flag to cargo that gets forwarded onward to rustc and that controls the TOOLSVERSION environment variable in build scripts.\r\n3. Implement auto-discovery logic in cargo for calculating TOOLSVERSION based on what versions of msbuild are installed, always choosing the latest known-working version (currently VS2015).\r\n\r\n#1 and #2 would be enough to enable good Visual Studio integration. #3 would make everything \"just work\" without developers needing to run vcvarsall or needing to run builds in a Visual Studio command prompt. In particular, this should enable builds from Git Posh to \"just work.\""}}