fix: let a program find the shared libraries it is built on

The link of an executable built on a LibraryDynamic dependency took
lib<name>.so from the library's bin dir and recorded nowhere to find it
at run time: no run path pointed there and nothing copied it beside the
program, which mingw does for a DLL. The program failed at start with
"cannot open shared object file". A shared library now hands its bin dir
up as a run path, as a CMake external does with its build directory, and
a program linked against it records it. Run paths reach the linker
through -Xlinker, quoted for the shell (RunPathFlags), in a program's
link and in project.so's: unlike the external cache's directories, the
bin dir is the project's own, and clang splits a -Wl, value at every
comma its name may hold.
This commit is contained in:
Jorijn van der Graaf 2026-11-01 19:24:02 +01:00
commit bc98c87f01
Signed by: jorijnvdgraaf
GPG key ID: 2937E59CDCC1BCFB
4 changed files with 26 additions and 10 deletions

View file

@ -54,8 +54,10 @@ export namespace Crafter {
// when a consumer #includes them directly. Propagates transitively.
std::set<std::string> publicCompileFlags;
// Absolute directories the shared libraries this links against are
// loaded from at run time, its dependencies' included. An executable
// or shared library linked from them records each one as a run path.
// loaded from at run time, its dependencies' included, and, once a
// shared library is linked, its own bin dir, for its consumers. An
// executable or shared library linked from them records each one as
// a run path.
std::set<std::string> runPaths;
};

View file

@ -53,6 +53,11 @@ namespace Crafter {
// and not to crafter-build, which then sees it as exit code 130.
// Project scripts reach this through ScriptContext::Run.
std::int32_t RunCommandAttached(std::string_view command);
// The link flags that record `dir` as a run path, with -Xlinker rather
// than -Wl,: clang splits a -Wl, value at every comma, and `dir` may be a
// project's own directory, named whatever its owner chose. Quoted for
// the shell the link runs in.
std::string RunPathFlags(std::string_view dir);
// `s` as one single-quoted sh word, safe to splice into a command line
// whatever it contains: paths with spaces, arguments a user typed.
export std::string ShellQuote(std::string_view s);