refactor: carry run paths as directories, not -Wl,-rpath flags

ExternalOutputs put an -Wl,-rpath,<dir> per library directory of a CMake
external into its link flags, and the flags travelled up the dependency
graph in BuildResult::libs to every link that consumed them: an
executable's or a shared library's, and that of the project.so
LoadProject links against a project file's pragma dependencies. Whether
a program should record those directories depends on how it is packaged:
a Flatpak has to load its libraries from its own files/lib instead, and
has to know the directories to copy them from. ExternalBuildResult and
BuildResult now carry them as runPaths, merged up the graph beside libs,
and all three links turn each into an -Wl,-rpath as before, so the link
commands differ only in the order of their flags. PragmaSharedExternal
holds project.so's link to them.
This commit is contained in:
Jorijn van der Graaf 2026-11-01 18:56:41 +01:00
commit aa6b555395
Signed by: jorijnvdgraaf
GPG key ID: 2937E59CDCC1BCFB
5 changed files with 37 additions and 11 deletions

View file

@ -506,7 +506,11 @@ namespace {
struct ProjectFileDependencies {
std::vector<Configuration*> configs;
std::string compileFlags; // " -fprebuilt-module-path=…" for each dependency and its transitive deps
std::string linkFlags; // every dependency's BuildResult.libs, verbatim
// Every dependency's BuildResult.libs, verbatim, then an -Wl,-rpath
// per directory of its runPaths, as Build() links a program: the
// shared libraries a pragma dependency is built on are found there
// when LoadProject dlopens project.so.
std::string linkFlags;
fs::file_time_type newestArtifact = fs::file_time_type::min();
};
@ -524,6 +528,7 @@ namespace {
std::unordered_set<Configuration*> forced;
std::unordered_set<Configuration*> walked;
std::set<std::string> libs;
std::set<std::string> runPaths;
for (const PragmaDependency& pragma : pragmas) {
// Neither spec sets args, and the tool still gets none of the
@ -568,6 +573,7 @@ namespace {
if (!built.result.empty()) PragmaError(absProject, pragma.line, std::format("project dependency '{}' failed to build: {}", cfg->name, built.result));
out.configs.push_back(cfg);
libs.insert(built.libs.begin(), built.libs.end());
runPaths.insert(built.runPaths.begin(), built.runPaths.end());
// The module path needs the dependency and everything it depends
// on, same as GetCompileCommand does for a consumer; the newest
@ -583,6 +589,7 @@ namespace {
walk(cfg);
}
for (const std::string& lib : libs) out.linkFlags += std::format(" {}", lib);
for (const std::string& dir : runPaths) out.linkFlags += std::format(" -Wl,-rpath,{}", dir);
return out;
}