The wrapper script no longer has any purpose on Unix.
Just do a plain symlink to the clang-scan-deps tool.
On Windows, the wrapper executable still is used to inject a
default -target option, if the executable name doesn't contain
a triple.
clang-scan-deps can pick it up automatically from the first argument
now.
For the windows wrapper, keep passing -target, to allow running with
a potentially foreign clang-scan-deps.exe.
Clang only picks up config files implicitly using the normalized
triple form, so use file names with "-windows-gnu" instead of
"-mingw32".
In theory, we could also want to pick up the config file implicitly
by having "<triple>-<mode>" be a symlink directly to the clang
executable. That works for regular mingw32 targets, but for the
mingw32uwp target, there's no distinction in the normalized
triple, so both would end up using the same "-windows-gnu" config
files. So as long as we want to support the mingw32uwp prefixed
tools, we need to use a wrapper.
The wrapper script no longer has any purpose on Unix.
Just do a plain symlink to the clang-scan-deps tool.
On Windows, the wrapper executable still is used to inject a
default -target option, if the executable name doesn't contain
a triple.
clang-scan-deps can pick it up automatically from the first argument
now.
For the windows wrapper, keep passing -target, to allow running with
a potentially foreign clang-scan-deps.exe.
Clang only picks up config files implicitly using the normalized
triple form, so use file names with "-windows-gnu" instead of
"-mingw32".
In theory, we could also want to pick up the config file implicitly
by having "<triple>-<mode>" be a symlink directly to the clang
executable. That works for regular mingw32 targets, but for the
mingw32uwp target, there's no distinction in the normalized
triple, so both would end up using the same "-windows-gnu" config
files. So as long as we want to support the mingw32uwp prefixed
tools, we need to use a wrapper.
If we never set $TARGET, we'd previously miss including $CMD_EXE
in the nested command. (This doesn't happen in actual uses of
the wrapper though, but is included for completeness.)
This matches how the corresponding variable is handled in the C
version of the wrapper.
This can happen if the input command line is barely under the limit,
but ends up exceeding it due to the extra arguments that the wrapper
adds.
One could hope that _tspawnvp would set errno to a helpful error code,
to identify the issue when printing the error with _tperror(), but in
practice, it doesn't.
This avoids inflating the total size of the command line too much.
If the input command line is near the max size of a command line
(32767 characters), it may grow past that limit when adding the
arguments injected by the wrapper. If we excessively quote all
arguments that don't need to be quoted, we can more easily run
into this situation.
Thus, by avoiding excessive quoting, we reduce the risk for this
issue to happen.
This avoids the issue reported at
https://github.com/mstorsjo/llvm-mingw/issues/296.
When setting up wrappers for Windows, rename clang-scan-deps.exe to
clang-scan-deps-real.exe, make clang-scan-deps.exe a wrapper, and
configure the wrapper to target executing clang-scan-deps-real.exe.
This makes sure that we always pass in crucial options like
-stdlib=libc++.
By default, our Clang executables are built with that option
hardcoded, configured with CLANG_DEFAULT_CXX_STDLIB=libc++
when built for Windows. However, we generally don't rely on this;
we assume the tools could be plain default executables, so we
try to provide wrappers on all common access paths.
This picks the architecture by looking for a triple prefix in the
nested command, and passes it as an explicit flag, to let
clang-scan-deps find it.
We also pass -stdlib=libc++, to let it find the libc++ headers
as expected.
Older macOS versions (macOS 12.2 at least) don't support this
option, while newer macOS versions do support it (macOS 12.6).
The solution is based on https://stackoverflow.com/a/1116890/3115956,
but simplified for this usecase.
This allows the wrappers to invoke the right tool with the right
options, even when the wrapper was invoked with an obfuscated
short form file name.
This happens e.g. when CMake/Ninja invokes the tools from a path
that contains spaces.
Normally, we'd split the string at the last dash. However if the
tool name is "llvm-<tool>", make sure to include "llvm-" in the
tool name part when splitting the executable name.
In llvm-wrapper, don't add a duplicate "llvm-" prefix for the tool
name in these cases.
This matches how the compiler driver normally includes default
linked libraries; the user provided -l flags are passed first,
followed by the compiler's default ones. That allows a user
specified library to override the default ones.
This makes sure that if a user provides -lwindowsappcompat, it
gets linked before -lwindowsapp, which makes a difference for
symbols that are provided in both (such as e.g. LoadLibraryW).
Clang's general default dwarf version was raised from 4 to 5 in
d3b26dea16108c427b19b5480c9edc76edf8f5b4 in llvm-project (Jan 23
2022) before the 14.0.0 branch, but dwarf 5 on Windows seems to not
work with either LLDB or GDB.
Thus force the default back to 4 here as a temporary workaround, and try
to set the default back to 4 for mingw targets in Clang for later
releases (https://reviews.llvm.org/D119326).
This makes warnings for other unused arguments visible to the user.
This requires a version of llvm-project past
50ec1306d060e46e0d53c9f5d8a052e1b0d10d3b (Jan 2022) which added these
new options.
Since df0ba47c36f6bd0865e3286853b76d37e037c2d7 in llvm-project
(November 5th 2021), clang built with mingw defaults to producing
paths with forward slashes - thus, this hack no longer is needed.
Since LLVM 13, llvm-dlltool can imply the target architecture from
a triple prefix on the tool name, so there's no more need for a
wrapper.
The *-dlltool tools are now symlinks to the main llvm-dlltool
executable. In the Windows distribution, the *-dlltool.exe used to be
copies of dlltool-wrapper.exe (which is small; 15 KB). Now they
will instead be copies of llvm-dlltool.exe. Luckily, thanks to
building with -DLLVM_LINK_LLVM_DYLIB=ON by default, llvm-dlltool.exe
is only a mere 65 KB, while it used to be much larger, e.g. around
11 MB in older releases.
LLVM's OpenMP implementation only supports Windows on x86, and it
requires a MASM-compatible assembler to build it. Build UASM
for this purpose, for now. (UASM isn't available packaged in
debian/ubuntu repos.) In the future, llvm-ml should be able
to handle it instead, but it's not currently mature enough.
Not including it in the regular build-all.sh for now, as UASM
isn't generally available.