Closed bitsauce closed 2 years ago
Definitely doable, but I'll have to dig into this one. It would probably have to be a new preset (vs-llvm
or something), since the VS environment has to be created with vcvars before the toolchain is generated.
@bitsauce Decided to add this in the latest patch release since it was pretty straightforward. You can try it out in v0.5.9.
Use the llvm-vs-2022
and llvm-vs-2019
presets. They can use the same target architctures as MSVC -- x86_64 / x64, i686 / x86, arm, arm64 assuming you have the build tools installed. The Profile
configuration doesn't work with it currently -- same with the regular llvm
preset on Windows. Your mileage will vary with any CMake targets, but let me know if you notice anything that I can change/add!
Thanks @rewrking! I tested it on my computer, and chalet was able to find the clang installation with no issue.
Didn't manage to get the SDL example running yet (produces linker errors). Not sure why yet, although one thing I noticed is that chalet compiles with the -MD -MT
flags, which seems a little bit suspicious to me. Might try some more this weekend.
Hmmm, that's odd actually. The SDL example builds fine on my machine. This is the link command that generates for me (I'm using ninja during the build):
"C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/Llvm/x64/bin/clang++.exe" -target x86_64-pc-windows-msvc -Wl,/subsystem:windows -Wl,/entry:mainCRTStartup -L"build/x86_64-pc-windows-msvc_Release/chalet_external/sdl2" -L"C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/llvm/x64/lib" -L"build/x86_64-pc-windows-msvc_Release" -o "build/x86_64-pc-windows-msvc_Release/sdl2-app.exe" build/x86_64-pc-windows-msvc_Release/obj.sdl2-app/src/Main.cpp.obj build/x86_64-pc-windows-msvc_Release/obj.sdl2-app/build/int.sdl2-app/manifest.rc.res -lSDL2 -ldbghelp -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32
-MT
specifies the output dependency file to generate in compile commands
-MD
just tells the compiler to write the dep file.
They're the same in GCC & all versions of clang as far as I know. What are the linker errors you're getting? And is this the current version of chalet-example-sdl2
or an older version?
Did some further testing just now. Seems that it does, in fact, build successfully in Release mode (most recent commit in chalet-example-sdl2
).
However, in Debug, I get the following:
Aaah gotcha. I should have tested this more closely. I'll get that fixed - It has to do with clang using lld-link.exe under the hood, which probably requires the specific windows runtime library to be defined. /MT
/MTd
/MD
/MDd
- probably what you were thinking of before.
This is the workaround for now (place in sdl2-app > settings:Cxx):
"linkerOptions[:debug+toolchain:llvm-vs-2022]": [
"-Wl,/nodefaultlib:libcmt"
],
"links[:debug+toolchain:llvm-vs-2022]": [
"msvcrtd"
"vcruntimed",
"ucrtd"
]
I guess I just have to manually specify these instead of using /MD /MDd etc...
Release DLLs (/MD ): msvcrt.lib vcruntime.lib ucrt.lib
Debug DLLs (/MDd): msvcrtd.lib vcruntimed.lib ucrtd.lib
Release Static (/MT ): libcmt.lib libvcruntime.lib libucrt.lib
Debug Static (/MTd): libcmtd.lib libvcruntimed.lib libucrtd.lib
I'll have an update out...
Try this version: v0.5.10
Fixed the runtime library issues, and made sure the linker uses the same options that are passed to LINK.exe in the normal MSVC builds. Was able to make the Debug builds and debug them (in VSCode w/ C++ extension debugger and CodeLLDB)
As for things that definitely don't work
DebugSanitizeAddress
fails due to the mismatch in the clang library it requires.Just tested the new version, and it works great! For me personally having clang-cl
working is not particularly important. I haven't tried using profiling with Chalet yet, but it does sound interesting. I also haven't gotten the address sanitizers to work in my current Windows/Clang/CMake setup, so I'm not really using it (but it would be a great feature to have some point!)
Awesome! I'll close this out. Feel free to open a new issue if something unexpected comes up.
This is a quality-of-life thing, but I think it would be nice if Chalet could pick up on both or either of
clang.exe
andclang-cl.exe
from the Visual Studio install folder if Clang has been installed through theVisual Studio Installer
. When using the VSCode CMake extension, these are detected as:Without any manual work required by the developer.
What do you think? Is this something that Chalet can support?