Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd support for the Visual Studio 2017 linker #38584
Comments
This comment has been minimized.
This comment has been minimized.
|
I already spoke with the Visual C++ team a few months ago and someone was going to investigate adding support for this. I'll poke them and see if any progress has been made, and if not I'll end up doing it myself. I have VS 2017 myself so there should be nothing I'd need from you. |
retep998
self-assigned this
Dec 24, 2016
retep998
added
the
O-windows-msvc
label
Dec 24, 2016
This comment has been minimized.
This comment has been minimized.
|
For reference, a code sample for finding VS 2017 instances https://code.msdn.microsoft.com/windowsdesktop/Visual-Studio-Setup-0cedd331 |
This comment has been minimized.
This comment has been minimized.
|
Concerning a workaround: if this is the same as Visual Studio “15” Preview 4 (which had the new installer and directory structures): you can run vcvarsall.bat to set up the current terminal and then it all works. For me, this works: "C:\Program Files (x86)\Microsoft Visual Studio\VS15Preview\Common7\IDE\VC\vcvarsall.bat" x64 |
This comment has been minimized.
This comment has been minimized.
|
So, I spent some time with the Rust compiler’s source code and with
The values for if /I "%VSCMD_ARG_HOST_ARCH%" == "x86" (
set __VCVARS_HOST_DIR=\HostX86
set __VCVARS_HOST_NATIVEDIR=\x86
)
if /I "%VSCMD_ARG_HOST_ARCH%" == "x64" (
set __VCVARS_HOST_DIR=\HostX64
set __VCVARS_HOST_NATIVEDIR=\x64
)
if /I "%VSCMD_ARG_HOST_ARCH%" == "arm" (
set __VCVARS_HOST_DIR=\HostARM
set __VCVARS_HOST_NATIVEDIR=\arm
)Maybe that helps. @chris-morgan Yeah, using the |
This comment has been minimized.
This comment has been minimized.
gistofj
commented
Jan 4, 2017
|
Visual Studio 2017 supports multi-instance installation, meaning you can install it more than once and each instance can have its own setup of options enabled/disabled. Therefore there is no longer a canonical location for Visual Studio to exists. That said, the Ideally, users can compile Rustlang projects from a "Developer Command Prompt for Visual Studio 2017", this will resolve most (if not all) of the issues. For users developing Rust in an IDE (like VS Code) can benefit from launching the IDE from the developer command prompt or by leveraging the logic provided by @poke, which should work for the common case. @artl93 for a more authoritative information. |
This comment has been minimized.
This comment has been minimized.
artl93
commented
Jan 4, 2017
|
Hi. Let me go and start by saying I am not familiar with rust particulars, so I am going to draw some conclusions based on the thread above. Please bear with me, as must of what I am about to go into just relates to how we want to think of tools, the application and the system. We wanted to make Visual Studio not impact the operating system. We wanted the fact that Visual Studio is installed to no longer impact the system-wide environment. By impacting the system environment, we made it impossible to have our compilers or tools sit side-by-side without having to ship a new side-by-side version of Visual Studio. We really wanted customers to be more free to install newer versions without the fear of corrupting their build environments and working tools, making it an easier call to try out new stuff without the fear of being able to get work done. To accomplish this, we really separated VS from the system-wide SDKs and runtimes that VS works with. We really wanted VS to be an "application" that consumes these things, rather than a part of each these. This meant taking the time to de-couple VS and the SDKs from the environment, making a much more flexible system for everyone. That also means we're going to have to understand how tools really relate to the IDE so that they are coupled in the best way possible. The VC++ toolset is interesting when we think of this model. In doing the work to de-couple SDKs from the IDE, the VC tools in particular turned out to be tightly coupled to the IDE. Therefore, the VC toolset ships as a part of the IDE application folder, and not something that is deployed system-wide. Therefore, each Visual Studio application on the system has its own, compatible copy of the VC tools. In the case of Rust, it sounds like it's heavily dependent on the VC tools, based on the context in the thread. As such, if you think of rust being heavily dependent on the VC tools, then they are by transitive closure dependent on the Visual Studio environment. Since the Visual Studio environment is a part of the application environment (rather than something that is shared and creating system-impact), I think we could think of the rust toolset as being a part of that environment. Therefore, I think we no longer want to think about the tools as being system-wide, but rather an extension to the VS IDE (application) environment. Therefore, you'd want to just extend the environment for the VS application, and not some system wide setting. To make this work, you can extend the environment for the particular application install using VSIXes (the new version). To add environment variables to the developer command prompt, you can add your own bat files (yes, *.bat) to: Common7\tools\vsdevcmd\ext. In the file, define a call_script_helper. You can see how this is set up by looking at vsdevcmd.bat: You can also look at examples in the ext folder as to how others have set this up. I'm not sure if this is documented, but it should be. I can confirm with the team that did the work. The one last thing: if you depend on the VC tools, then you'll want to declare that dependency in your VSIX. Does that make sense, or am I way off base here? |
This comment has been minimized.
This comment has been minimized.
gistofj
commented
Jan 4, 2017
|
@artl93 I do not believe that Rust has a Vsix, I believe that they just want to use the MS provided linker (and masm?) tools. Basically, how can a Rust make file find the location of the linker (and assembler?)? |
This comment has been minimized.
This comment has been minimized.
|
@whoisj
I’m not sure how that works though. When I rerun the installer, I can only modify my existing 2017 Enterprise installation but not install a second parallel one. Since the installer is the primary entry point for this case, I would say we can assume that there would only be a single installation at the default location.
That won’t work though since the actual edition is also part of the path now, e.g.
The dev command prompt is a very limited tool though, being way inferior to PowerShell or other command line interfaces. I assume Git Bash is also a common alternative shell for use with Rust projects. Requiring the developer command prompt there by default does not seem to be a good idea there.
But is there technically any difference between a VC toolset 14.10.24728 installed by VS2017 Enterprise, and a VC toolset 14.10.24728 installed by another edition? Would it not have been possible to ship this with the IDE but still place it in a more generic folder instead?
It’s actually not as complicated as it may sound. Rust actually only depends on the linker That’s why I don’t really agree that Rust should convert into some extension to Visual Studio or the VC tools. And as said above, the fact that the Visual Studio tools depend that much on a cmd command prompt can be pretty limiting. Anyway, to get back to what I am trying to get at: Rust already figures out which Visual Studio version is available. The MSVC detection written by @retep998 is already very sophisticated and works fine in many cases. It’s just that the detection is not yet compatible with the changed path structure in VS2017, so it simply won’t work yet. What this issue is about is fixing that detection to work with a standard VS2017 installation. We can’t—and probably shouldn’t even attempt to—handle edge cases or highly customized setups. For situations like that, it’s always possible for users to set up the environment variables themselves, and Rust will simply use that. So if you have multiple versions of Visual Studio installed (for whatever reason), and Rust ends up using a different version than the one you want it to use (not perfectly sure why that would make an actual difference though), then you will have to tell Rust to use the correct version anyway. That is not limited to just VS2017 but applies to any version. The steps I’ve written above are actually not that complicated. The current code that figures out where the MSVC linker is is already very well written to support this additional logic. And I’m absolutely willing to provide the patches necessary to make it work myself. It’s just that I’m just beginning with Rust, so I don’t feel comfortable contributing to the compiler just yet. I would eventually give it a try though. |
This comment has been minimized.
This comment has been minimized.
artl93
commented
Jan 4, 2017
The VC tools are tightly coupled to the IDE, therefore version X of the IDE must use a specific version X of the toolset. They are a part of the application folder. |
This comment has been minimized.
This comment has been minimized.
gistofj
commented
Jan 4, 2017
This comment has been minimized.
This comment has been minimized.
|
Yeah, what Rust basically needs to do is to be able to answer the question: “Where is the VC linker and library folder?” Currently it does that by explicitly checking against every Visual Studio version starting with the latest known version. Obviously, this requires to keep adding new logic as newer versions of Visual Studio are released. In an ideal world, there would be a single constant and future-proof location in the registry we could look at to find the path to the most-current VC toolset. Until we are there, we keep adding logic, with the stategy outlined above being my suggestion to find the current tools for (hopefully) any VS2017 installation. |
This comment has been minimized.
This comment has been minimized.
|
I'd really rather not hardcode all those relative paths; it would be incredibly brittle. The proper solution involves using special COM interfaces to enumerate the VC++ instances. Unless someone from Microsoft decides to do it themselves, I'm likely going to do the COM stuff myself. It's just a bit icky doing COM in rustc itself without winapi to help out. |
This comment has been minimized.
This comment has been minimized.
dten
commented
Mar 2, 2017
This comment has been minimized.
This comment has been minimized.
|
@dten That’s an interesting thing, but I’m not too sure if this could/should be bundled with rust. Maybe if it ends up being part of Visual Studio in the future and is provided in a central location, then one could rely on it. Currently, it does not seem to support versions older than VS 2017, so using this wouldn’t make it the only solution but there would still a complex branching strategy be involved to find the correct installation. |
This comment has been minimized.
This comment has been minimized.
|
Still nothing easily usable without undesirable dependencies. |
This comment has been minimized.
This comment has been minimized.
Borkason
commented
Mar 11, 2017
•
|
Because I have been trying to figure this out for way too long (I am not used to this stuff): For the workaround to work, you need to execute the Hopefully this helps someone else who doesn't understand a word of the above, too. |
This comment has been minimized.
This comment has been minimized.
|
@Borkason You can also open a command prompt and set it up at the same time by running one of the "_ Command Prompt for VS 2017" shortcuts in the start menu. (Probably should be the "_ Native Tools" one matching your Rust toolchain - "x86 Native Tools" for i646, "x64 Native Tools" for x86_64 - though you could also use a "_ Cross Tools" one with a matching target, I think.) |
This comment has been minimized.
This comment has been minimized.
Borkason
commented
Mar 11, 2017
•
|
@rpjohnst had to use the x86_x64 Cross Tools Command Prompt for VS 2017, the other wouldn't work. But that works beautifully. Thank you. |
Diggsey
referenced this issue
Mar 28, 2017
Closed
rustup does not recognize Visual C++ Build Tools #1003
This comment has been minimized.
This comment has been minimized.
|
Seems like the increasingly complex detection logic is going to need to be extracted into a crate to share with rustup. |
This comment has been minimized.
This comment has been minimized.
|
Maybe we can just bundle vswhere now? The latest release apparently supports legacy versions (i.e. older than VS2017), so maybe we could just rely on vswhere only now for everything? |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
dominik-f
commented
Apr 6, 2017
•
|
Just posting this, becaus vcvars.bat didn't do it in my case. Maybe it helps somebody to save the hours I spent setting up rust with VS2017 tooling. I had to manually add the path to link.exe to my PATH env-variable: |
This comment has been minimized.
This comment has been minimized.
gistofj
commented
Apr 6, 2017
|
@nik-fox while that is a great work around for you, please note that starting with Visual Studio 2017, there is no longer a canonical location to where VS installs itself. In fact, to a large degree VS2017 is xcopy deploy-able (not quite, but very close); and is designed to support side-by-side installations. |
brson
added this to the 1.17 milestone
Apr 7, 2017
brson
added
the
P-high
label
Apr 7, 2017
brson
added a commit
to brson/rust
that referenced
this issue
May 24, 2017
brson
added a commit
to brson/gcc-rs
that referenced
this issue
May 24, 2017
brson
added a commit
to brson/rust
that referenced
this issue
May 25, 2017
brson
added a commit
to brson/rust
that referenced
this issue
May 25, 2017
This was referenced May 25, 2017
frewsxcv
added a commit
to frewsxcv/rust
that referenced
this issue
May 26, 2017
brson
added a commit
to brson/rust
that referenced
this issue
May 26, 2017
brson
added a commit
to brson/rust
that referenced
this issue
May 26, 2017
brson
added a commit
to brson/rust
that referenced
this issue
May 30, 2017
frewsxcv
added a commit
to frewsxcv/rust
that referenced
this issue
Jun 1, 2017
bors
added a commit
that referenced
this issue
Jun 1, 2017
bors
added a commit
that referenced
this issue
Jun 1, 2017
brson
modified the milestones:
1.19,
1.18
Jun 1, 2017
brson
assigned
brson
and unassigned
retep998
Jun 1, 2017
brson
added a commit
to brson/rust
that referenced
this issue
Jun 1, 2017
Mark-Simulacrum
added a commit
to Mark-Simulacrum/rust
that referenced
this issue
Jun 1, 2017
Mark-Simulacrum
added a commit
to Mark-Simulacrum/rust
that referenced
this issue
Jun 2, 2017
Mark-Simulacrum
added a commit
to Mark-Simulacrum/rust
that referenced
this issue
Jun 2, 2017
bors
closed this
in
#42225
Jun 3, 2017
CryZe
referenced this issue
Jun 4, 2017
Closed
Windows GNU Toolchain doesn't find gcc anymore #42422
This comment has been minimized.
This comment has been minimized.
Rafi993
commented
Jun 20, 2017
|
It would be good if some one could summarize it would be really helpful for beginner encountering this error so that they don't have to read all the comments. |
This comment has been minimized.
This comment has been minimized.
|
@Rafi993 Starting with Rust 1.19 this will work out of the box. For previous versions, you need to adjust some environment variables in order to allow Rust to find and use the C linker. You can do that easiest by running Visual Studio’s Unfortunately, you cannot run However, since Rust only needs the linker, you can also just modify the two environment variables directly that you need. I had the following added to my PowerShell profile to make this work: $env:PATH = 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.10.25017\bin\HostX64\x64;' + $env:PATH
$env:LIB = 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.10.25017\lib\x64;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\lib\um\x64;C:\Program Files (x86)\Windows Kits\10\lib\10.0.14393.0\ucrt\x64;C:\Program Files (x86)\Windows Kits\10\lib\10.0.14393.0\um\x64;'Note that you might need to update the MSVC version in the path when Visual Studio is updated. |

poke commentedDec 24, 2016
With Visual Studio 2017, Microsoft has changed the folder structure it uses for everything.
link.exeis now located atC:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.10.24728\bin\HostX64\x64\link.exe. As you can see, the folder is dependent on the actual edition of Visual Studio as well.Currently, Rust does not seem to recognize this path correctly. I don’t know exactly what Rust needs to figure out the paths, but if you need some information (e.g. registry values, contents of
vcvarsall.bator something), just tell me what you need and I’ll try my best to provide you with it.