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

@ -38,6 +38,11 @@ export namespace Crafter {
struct ExternalBuildResult {
std::vector<std::string> compileFlags;
std::vector<std::string> linkFlags;
// Absolute directories the dependency's shared libraries are loaded
// from at run time: what a consumer's link records as its run path.
// Kept apart from linkFlags because what becomes of them depends on
// how the consumer is packaged (see BuildResult::runPaths).
std::vector<std::string> runPaths;
fs::file_time_type latestArtifact = fs::file_time_type::min();
};
@ -66,8 +71,8 @@ export namespace Crafter {
// short would leave them a clone nobody fetched.
std::string BuildExternal(const ExternalDependency& dep, std::string_view target);
// What a configuration that declares `dep` compiles and links with once
// BuildExternal has run: the -I flags and, for CMake, the -L, -rpath and -l
// flags and the newest library. Per declaration, because two that share a
// BuildExternal has run: the -I flags and, for CMake, the -L and -l flags,
// the run path directories and the newest library. Per declaration, because two that share a
// clone can still differ in includeDirs, libDirs and libs.
ExternalBuildResult ExternalOutputs(const ExternalDependency& dep, std::string_view target);