From a101e2d9f2c5565954ff16fe26f3bd9a020e33e8 Mon Sep 17 00:00:00 2001 From: Ofek Date: Sat, 11 Jan 2025 18:16:04 +0200 Subject: [PATCH] Fix MSVC's handling of `/link` options, fix and modernize some docs (#7260) --- .gitignore | 1 + docs/WindowsLocal.properties | 64 +++++++++++++------------------- docs/WindowsNative.md | 1 - docs/WindowsSubsystemForLinux.md | 47 +++-------------------- lib/compilers/win32.ts | 13 ++++++- 5 files changed, 44 insertions(+), 82 deletions(-) diff --git a/.gitignore b/.gitignore index c07048d01..eb2632812 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ # IDE project files /.idea/shelf +/.vs /nbproject *.vscode *.code-workspace diff --git a/docs/WindowsLocal.properties b/docs/WindowsLocal.properties index cb830f712..820f1f82a 100644 --- a/docs/WindowsLocal.properties +++ b/docs/WindowsLocal.properties @@ -3,16 +3,15 @@ # you can set it up in that compiler's config, with, say # compiler.my_clang.includePath=path_to_libc++ -includePath=C:\Program Files (x86)\Microsoft Visual Studio\Preview\Enterprise\VC\Tools\MSVC\14.15.26608\ATLMFC\include;C:\Program Files (x86)\Microsoft Visual Studio\Preview\Enterprise\VC\Tools\MSVC\14.15.26608\include;C:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\ucrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\shared;C:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\winrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\cppwinrt +includePath=c:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.42.34433\include;c:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.42.34433\ATLMFC\include;c:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\VS\include;C:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\ucrt;C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\um;C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\shared;C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\winrt;C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\cppwinrt;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um # replace with the result of `where undname.exe` from a developer command prompt -demangler=C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.14.26428\bin\Hostx64\x64\undname.exe - +demangler=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.42.34433\bin\Hostx64\x64\undname.exe # the compiler you want compiler explorer to start up in -defaultCompiler=vc2017_64 +defaultCompiler=vc2022_64 # note: adding new compiler groups @@ -22,27 +21,36 @@ defaultCompiler=vc2017_64 # you can uncomment and edit the following lines. # check `c++.win32.properties` for how to modify the group options -compilers=&vc2017:&clang +compilers=&vc2022:&clang -group.vc2017.compilers=vc2017_32:vc2017_64 -group.vc2017.options=-EHsc -group.vc2017.compilerType=win32-vc -group.vc2017.needsMulti=false -group.vc2017.includeFlag=/I -group.vc2017.versionFlag=/? -group.vc2017.versionRe=^.*Microsoft \(R\).*$ -group.vc2017.groupName=Visual Studio MSVC -group.clang.compilers=clang_32:clang_64 +# visual C++ 2022 compilers +# follow the same instructions as for clang +# note that if CE doesn't find a compiler, it won't break anything + +group.vc2022.compilers=vc2022_32:vc2022_64 +group.vc2022.options=-EHsc +group.vc2022.compilerType=win32-vc +group.vc2022.needsMulti=false +group.vc2022.includeFlag=/I +group.vc2022.versionFlag=/? +group.vc2022.versionRe=^.*Microsoft \(R\).*$ +group.vc2022.groupName=Visual Studio MSVC + +# these are pointed at my own installation; +# you'll likely have to change the paths for your own machine + +compiler.vc2022_32.exe=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.42.34433\bin\Hostx64\x86\cl.exe +compiler.vc2022_32.name=VC 2022 x86 + +compiler.vc2022_64.exe=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.42.34433\bin\Hostx64\x64\cl.exe +compiler.vc2022_64.name=VC 2022 amd64 # clang compilers # if you want more compilers, you can do that by separating the names with `:` # and then setting up a compiler.my_clang.exe and compiler.my_clang.name - -group.clang_32.compilers=clang_32 -group.clang_64.compilers=clang_64 - +group.clang.compilers=clang_32:clang_64 # this is the default path that clang++ is installed in # if you installed it somewhere else, you should edit both variables @@ -53,23 +61,3 @@ compiler.clang_32.name=clang x86 compiler.clang_64.exe=C:\Program Files\LLVM\bin\clang++.exe compiler.clang_64.name=clang amd64 -# visual C++ 2017 compilers -# follow the same instructions as for clang -# note that if CE doesn't find a compiler, it won't break anything - -group.vc2017_32.compilers=vc2017_32:vc2017_32_preview -group.vc2017_64.compilers=vc2017_64:vc2017_64_preview - - -# these are pointed at my own installation; -# you'll likely have to change the paths for your own machine - -compiler.vc2017_32.exe=C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.14.26428\bin\Hostx64\x86\cl.exe -compiler.vc2017_32.name=VC 2017 x86 -compiler.vc2017_32_preview.exe=C:\Program Files (x86)\Microsoft Visual Studio\Preview\Enterprise\VC\Tools\MSVC\14.15.26608\bin\Hostx64\x86\cl.exe -compiler.vc2017_32_preview.name=Preview VC 2017 x86 - -compiler.vc2017_64.exe=C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.14.26428\bin\Hostx64\x64\cl.exe -compiler.vc2017_64.name=VC 2017 amd64 -compiler.vc2017_64_preview.exe=C:\Program Files (x86)\Microsoft Visual Studio\Preview\Enterprise\VC\Tools\MSVC\14.15.26608\bin\Hostx64\x64\cl.exe -compiler.vc2017_64_preview.name=Preview VC 2017 amd64 diff --git a/docs/WindowsNative.md b/docs/WindowsNative.md index b3fd75982..58c98fc78 100644 --- a/docs/WindowsNative.md +++ b/docs/WindowsNative.md @@ -60,7 +60,6 @@ attaching to an instance of CE that was launched with `npm run-script debugger` "name": "Attach to Process", "port": 9229, "address": "localhost", - "protocol": "inspector", "localRoot": "${workspaceRoot}", "remoteRoot": "C:\\Users\\${username}\\compiler-explorer" } diff --git a/docs/WindowsSubsystemForLinux.md b/docs/WindowsSubsystemForLinux.md index c8a57e1c1..63eb81301 100644 --- a/docs/WindowsSubsystemForLinux.md +++ b/docs/WindowsSubsystemForLinux.md @@ -42,7 +42,7 @@ following commands from a bash shell: - `apt-get update` to make sure apt is up-to-date - `apt-get install build-essential libssl-dev`, though you probably have these already - Check https://github.com/creationix/nvm/releases for the latest NVM release, substituting it in the next command. -- `curl https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash` to install NVM +- `curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash` to install NVM - `source ~/.profile` to reload your profile, bringing NVM into your environment - `nvm ls-remote --lts` to show the latest long-term supported (LTS) version of node.js - `nvm install 10.15.3`, substituting the latest LTS version, to install node.js @@ -87,44 +87,7 @@ CE only required a few changes in order to run properly under WSL. Those changes ## Debugging -The only viable option for debugging under WSL is to use [VS Code](https://code.visualstudio.com). Because VS Code -doesn't currently run natively under WSL, you have to attach to a running CE instance. The following is a `launch.json` -that works for attaching to an instance of CE that was launched with the `--inspect` flag. - -```json -{ - "version": "0.2.0", - "configurations": [ - { - "type": "node", - "request": "attach", - "name": "Attach to Process", - "port": "9229", - "address": "localhost", - "protocol": "inspector", - "localRoot": "${workspaceRoot}", - "remoteRoot": "/mnt/c/src/compiler-explorer" - } - ] -} -``` - -Launch CE with `make NODE_ARGS="--inspect"` to have node listen on port 9229. - -Because you can only attach to the process, as opposed to launching the process, you're limited to `printf` debugging -for startup code. Search the code for `logger.info` to see examples of how to `printf` debug. - -## MSVC setup - -TODO. There's no real MSVC setup at this point because there's no good way to pass the environment to an invocation of -`CL.exe`. Just point the `properties` file at your compiler binary and hack on the `/I` options until something works. - -When I get this working in a generalized fashion, CE's config will expect that MSVC drops match the format used by the -daily NuGet compiler drops at https://visualcpp.myget/org. (NuGet packages are just renamed ZIP files plus metadata so -they make an easy distribution method for compiler toolset drops.) - -## Putting it all together - -This should be enough information to get you started running CE under WSL. If there's information that you wish you -would have had, please submit a PR to document. If there's information you're lacking to get running, please enter an -Issue on the CE repo or contact me directly. +The only viable option for debugging under WSL is to use [VS Code](https://code.visualstudio.com). VSCode's 'Auto +Attach' option works on wsl and is the easiest way to start debugging. Make sure 'Auto Attach' is on (it is by default), +then at the VSCode terminal start an instance any way you prefer: `make` or `npm start` or similar. (`make` is required +at least for the first run). diff --git a/lib/compilers/win32.ts b/lib/compilers/win32.ts index 85db574f3..9ad52618a 100644 --- a/lib/compilers/win32.ts +++ b/lib/compilers/win32.ts @@ -128,12 +128,23 @@ export class Win32Compiler extends BaseCompiler { [options, overrides] = this.fixIncompatibleOptions(options, userOptions, overrides); this.changeOptionsBasedOnOverrides(options, overrides); + // `/link` and all that follows must come after the filename + const linkIndex = userOptions.indexOf('/link'); + let linkUserOptions: string[] = []; + let compileUserOptions = userOptions; + if (linkIndex !== -1) { + linkUserOptions = userOptions.slice(linkIndex + 1); + compileUserOptions = userOptions.slice(0, linkIndex); + preLink = ['/link']; + } + return options.concat( libIncludes, libOptions, - userOptions, + compileUserOptions, [this.filename(inputFilename)], preLink, + linkUserOptions, libPaths, libLinks, staticlibLinks,