Crafter.Build/implementations
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Jorijn van der Graaf 8019f9d44f
fix(lint): look for libc++ where the compiler does
In crafter-build's Flatpak, whose compiler keeps libc++ in /app and
whose /usr has none, a file that includes a header of the C++ standard
library could not be parsed for the lint rules that read its AST in a
build like that of #46: the file built, and `crafter-build lint` then
ran none of those rules on it, printed "'algorithm' file not found"
and exited 1.

libclang parses through a clang driver of its own. In a build for the
host whose compile command names no libc++ directory, as #46's names
none, where a sysroot or CRAFTER_BUILD_LIBCXX_DIR would name one, that
driver looks for libc++'s headers under ../include from the directory
of its argv[0], then under /usr/local/include and /usr/include.
ParseAst gave libclang the compile command without its compiler, and
clang_parseTranslationUnit names argv[0] plain "clang", in no
directory. So the parse of such a build, natively as in the Flatpak,
took the first libc++ it found under ../include from the working
directory, /usr/local/include and /usr/include, whichever compiler the
build used. The -resource-dir ParseAst passes is for clang's own
headers and changes nothing for libc++.

The compile command's argv[0] would not do on its own: a clang++ from
PATH is the bare name clang++, in no directory either, and a clang++
reached through a link into another directory takes itself to be where
the link leads, as clang finds its installation from the file it runs
as. The compiler says where that is, on the InstalledDir line of
`clang++ --version`, which GetToolchain() already runs for clangVersion.
Toolchain::installedDir keeps it, InstalledClangxx(command) names the
compiler in it, and ParseAst passes that as argv[0], through
clang_parseTranslationUnit2FullArgv, which takes argv[0] from its
caller. With argv[0] there, the parse finds libc++ where the compile
does, whatever the working directory.

A compile command can have the compiler look from elsewhere: with
-no-canonical-prefixes, where the last of it and -canonical-prefixes is
that one, clang takes itself to be at clangxx as written, or, where no
file is there, as is usual for a bare name, at the one PATH gives, a
link not followed, and `clang++ -no-canonical-prefixes --version` names
that directory. GetToolchain() runs that too,
Toolchain::installedDirAsWritten keeps what it names, and
InstalledClangxx(command) names the compiler there for a command whose
last prefix flag is -no-canonical-prefixes, as clang's own driver reads
them.

argv[0] also gives libclang's driver its mode, by its file name, and
the configuration files it reads by default, from its directory. The
parse now runs in the g++ mode the compile runs in, where it ran in
clang's gcc mode, and reads the default configuration files beside the
compiler that the compile reads, clang++.cfg among them; before, it read
none from there, as the driver skips the directory of an argv[0] that
has none.

-resource-dir stays, for a libclang of another release than the
compiler, whose driver would derive the directory from argv[0] for its
own release. The comment on it said libclang found clang's own headers
relative to its own install path; its driver derived them from argv[0],
as it does libc++'s.

Fixes #46
2026-11-27 16:16:38 +01:00
..
Crafter.Build-Agents.cpp feat: let a project file return several configurations 2026-11-15 02:16:06 +01:00
Crafter.Build-Asset.cpp linting 2026-07-23 01:24:42 +02:00
Crafter.Build-Clang.cpp fix(build): read what a source declares and imports with clang-scan-deps 2026-11-27 09:25:53 +01:00
Crafter.Build-External.cpp feat: let a project file return several configurations 2026-11-15 02:16:06 +01:00
Crafter.Build-Flatpak.cpp feat: install a Flatpak's data under /app/share 2026-11-09 01:55:31 +01:00
Crafter.Build-Implementation.cpp fix(build): read what a source declares and imports with clang-scan-deps 2026-11-27 09:25:53 +01:00
Crafter.Build-Interface.cpp fix(build): read what a source declares and imports with clang-scan-deps 2026-11-27 09:25:53 +01:00
Crafter.Build-Jobs.cpp feat(build): run a build's steps on one worker per hardware thread 2026-11-13 17:59:55 +01:00
Crafter.Build-Lint.cpp fix(lint): look for libc++ where the compiler does 2026-11-27 16:16:38 +01:00
Crafter.Build-Platform.cpp feat: let a project file return several configurations 2026-11-15 02:16:06 +01:00
Crafter.Build-Progress.cpp refactor: drop Windows host support 2026-10-02 22:03:34 +02:00
Crafter.Build-Script.cpp feat: let a project file return several configurations 2026-11-15 02:16:06 +01:00
Crafter.Build-Shader.cpp fix: rebuild and relink on what changed, submodules at their revisions, and mingw found where it is 2026-10-20 20:20:29 +02:00
Crafter.Build-Test.cpp fix(build): read what a source declares and imports with clang-scan-deps 2026-11-27 09:25:53 +01:00
Crafter.Build-Toolchain.cpp fix(lint): look for libc++ where the compiler does 2026-11-27 16:16:38 +01:00
main.cpp refactor: drop Windows host support 2026-10-02 22:03:34 +02:00