You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[clang] Support --sysroot= for ${arch}-windows-msvc targets
I think it is possible to use the same rule for msvc targets with
--target= and --sysroot=
See Repository:
https://github.com/trcrsired/windows-msvc-sysroot
Add sysroot support for msvc
MSVC.cpp needs getDriver before using D
add stl in parser for -stdlib=
Add Vcruntime to runtime list and unwind list
MSVC add default runtime lib type and default unwind lib type
add a msvc sysroot test
use %S instead of /foo
Fix test for msvc-sysroot
Also add a pesudo implementation for WebAssembly and
maybe Microsoft STL could be ported to more targets in the future
Fix the toggle of wasm that prevents -stdlib=stl passed into
Avoid clang-formatting in MSVC.cpp
Add some comments to ToolChain
avoid indent the if block
Add back space before winsysroot line
use instead of arch in the comment
remove FIXME for libc++ since we have added the logic here
Remove MSVC.h formatting
Remove default cases in WebAssembly
add back the empty line before the Sysroot line
fix msvc-sysroot typo for libc++ loongarch
Fix : missing in CST_Stl case
Support --sysroot= for ${arch}-windows-msvc targets
I think it is possible to use the same rule for msvc targets with
--target= and --sysroot=
See Repository:
https://github.com/trcrsired/windows-msvc-sysroot
Add sysroot support for msvc
MSVC.cpp needs getDriver before using D
add stl in parser for -stdlib=
Add Vcruntime to runtime list and unwind list
MSVC add default runtime lib type and default unwind lib type
add a msvc sysroot test
use %S instead of /foo
Fix test for msvc-sysroot
Also add a pesudo implementation for WebAssembly and
maybe Microsoft STL could be ported to more targets in the future
Fix the toggle of wasm that prevents -stdlib=stl passed into
Avoid clang-formatting in MSVC.cpp
Add some comments to ToolChain
avoid indent the if block
Add back space before winsysroot line
use instead of arch in the comment
remove FIXME for libc++ since we have added the logic here
Remove MSVC.h formatting
Remove default cases in WebAssembly
add back the empty line before the Sysroot line
fix msvc-sysroot typo for libc++ loongarch
Fix : missing in CST_Stl case
[clang] update msvc-sysroot.cpp tep to test arm64ec and arm64x
[clang] Add arm64ec -windows-msvc support for msvc sysroot by finding libs in the aarch64-unknown-windows-msvc subdir
MSVC target needs to include Gnu.h to support libstdc++
[clang] fix formatting issues for MSVC sysroot PR
[clang] Support --sysroot= for ${arch}-windows-msvc targets
I think it is possible to use the same rule for msvc targets with
--target= and --sysroot=
See Repository:
https://github.com/trcrsired/windows-msvc-sysroot
Add sysroot support for msvc
MSVC.cpp needs getDriver before using D
add stl in parser for -stdlib=
Add Vcruntime to runtime list and unwind list
MSVC add default runtime lib type and default unwind lib type
add a msvc sysroot test
use %S instead of /foo
Fix test for msvc-sysroot
Also add a pesudo implementation for WebAssembly and
maybe Microsoft STL could be ported to more targets in the future
Fix the toggle of wasm that prevents -stdlib=stl passed into
Avoid clang-formatting in MSVC.cpp
Add some comments to ToolChain
avoid indent the if block
Add back space before winsysroot line
use instead of arch in the comment
remove FIXME for libc++ since we have added the logic here
Remove MSVC.h formatting
Remove default cases in WebAssembly
add back the empty line before the Sysroot line
fix msvc-sysroot typo for libc++ loongarch
Fix : missing in CST_Stl case
Support --sysroot= for ${arch}-windows-msvc targets
I think it is possible to use the same rule for msvc targets with
--target= and --sysroot=
See Repository:
https://github.com/trcrsired/windows-msvc-sysroot
Add sysroot support for msvc
MSVC.cpp needs getDriver before using D
add stl in parser for -stdlib=
Add Vcruntime to runtime list and unwind list
MSVC add default runtime lib type and default unwind lib type
add a msvc sysroot test
use %S instead of /foo
Fix test for msvc-sysroot
Also add a pesudo implementation for WebAssembly and
maybe Microsoft STL could be ported to more targets in the future
Fix the toggle of wasm that prevents -stdlib=stl passed into
Avoid clang-formatting in MSVC.cpp
Add some comments to ToolChain
avoid indent the if block
Add back space before winsysroot line
use instead of arch in the comment
remove FIXME for libc++ since we have added the logic here
Remove MSVC.h formatting
Remove default cases in WebAssembly
add back the empty line before the Sysroot line
fix msvc-sysroot typo for libc++ loongarch
Fix : missing in CST_Stl case
[clang] update msvc-sysroot.cpp tep to test arm64ec and arm64x
[clang] Add arm64ec -windows-msvc support for msvc sysroot by finding libs in the aarch64-unknown-windows-msvc subdir
MSVC target needs to include Gnu.h to support libstdc++
[clang] fix formatting issues for MSVC sysroot PR
Copy file name to clipboardExpand all lines: clang/docs/UsersManual.rst
+73Lines changed: 73 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5457,3 +5457,76 @@ Restrictions and Limitations compared to Clang
5457
5457
Strict aliasing (TBAA) is always off by default in clang-cl whereas in clang,
5458
5458
strict aliasing is turned on by default for all optimization levels. For more
5459
5459
details, see :ref:`Strict aliasing <strict_aliasing>`.
5460
+
5461
+
Using clang/clang++ with MSVC Targets
5462
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5463
+
5464
+
While ``clang-cl`` emulates the MSVC compiler interface, users may prefer to invoke ``clang`` or ``clang++`` directly for greater control and platform consistency. When targeting MSVC environments, Clang supports the use of ``--target=`` and ``--sysroot=`` following the same conventions as Unix-style cross-compilation.
5465
+
5466
+
This approach avoids reliance on a Windows environment, Wine, or environmental variables, instead using a predictable and portable sysroot layout:
5467
+
5468
+
Headers
5469
+
-------
5470
+
5471
+
- Windows + CRT headers: ``include/``
5472
+
5473
+
- C++ standard library headers (selected via ``-stdlib=``):
5474
+
5475
+
- ``-stdlib=msstl`` → ``include/c++/msstl``
5476
+
Microsoft STL (MSVC's standard library implementation)
5477
+
5478
+
- ``-stdlib=libc++`` → ``include/c++/v1``
5479
+
LLVM libc++ (Clang's standard library implementation)
GNU libstdc++ (GCC's standard library implementation)
5483
+
5484
+
Library Naming Conventions
5485
+
--------------------------
5486
+
5487
+
When targeting ``${cpu}-unknown-windows-msvc``, the naming of runtime libraries differs from GNU-style targets:
5488
+
5489
+
- **LLVM libc++**:
5490
+
- MSVC target: ``c++.dll``, ``c++.lib``
5491
+
- GNU target: ``libc++.dll``, ``libc++.a``
5492
+
5493
+
- **GNU libstdc++**:
5494
+
- MSVC target: ``stdc++-6.dll``, ``stdc++.lib``
5495
+
- GNU target: ``libstdc++-6.dll``, ``libstdc++.a``
5496
+
5497
+
These naming conventions reflect platform-specific linker and runtime expectations. The MSVC target omits the ``lib`` prefix and uses `.lib` import libraries, while GNU targets retain the traditional Unix-style naming.
5498
+
5499
+
Libraries
5500
+
---------
5501
+
5502
+
The sysroot must contain libraries in the following fallback order:
5503
+
5504
+
1. ``lib/${cpu}-unknown-windows-msvc``
5505
+
2. ``lib/``
5506
+
5507
+
Example for ``x86_64-unknown-windows-msvc``:
5508
+
``lib/x86_64-unknown-windows-msvc`` → ``lib/``
5509
+
5510
+
This structure allows toolchains to support both target-specific and shared libraries, enabling clean fallback behavior and simplifying multi-target packaging.
5511
+
5512
+
Binaries
5513
+
--------
5514
+
5515
+
The sysroot must also contain binaries in the following fallback order:
5516
+
5517
+
1. ``bin/${cpu}-unknown-windows-msvc``
5518
+
2. ``bin/``
5519
+
5520
+
Example for ``x86_64-unknown-windows-msvc``:
5521
+
``bin/x86_64-unknown-windows-msvc`` → ``bin/``
5522
+
5523
+
This layout supports future scenarios such as universal binaries and ensures consistent tool resolution across architectures.
5524
+
5525
+
Case Sensitivity
5526
+
----------------
5527
+
5528
+
All header and library paths must use lowercase file names. This ensures compatibility across case-sensitive filesystems such as Linux and macOS, and matches the behavior of ``mingw-w64-crt``. Windows itself is case-insensitive, but relying on mixed-case paths can lead to portability issues.
5529
+
5530
+
This layout is fully compatible with Clang’s standard sysroot resolution logic and requires no MSVC-specific flags. It enables clean cross-compilation workflows and portable toolchain packaging.
5531
+
5532
+
For a reference implementation, see `windows-msvc-sysroot <https://github.com/trcrsired/windows-msvc-sysroot>`_.
0 commit comments