[M6] resolver: pkg-config probe + codegen for PkgConfig
This commit is contained in:
@@ -86,11 +86,33 @@ auto emit_find_packages(const std::vector<linkdb::Recipe>& recipes,
|
||||
return {};
|
||||
}
|
||||
std::string out = "\n# ----- dependencies -----\n";
|
||||
|
||||
bool pkgconfig_emitted = false;
|
||||
auto emit_one = [&](const linkdb::Recipe& r) {
|
||||
if (r.pkg_config_module && !r.pkg_config_module->empty()) {
|
||||
if (!pkgconfig_emitted) {
|
||||
out += "find_package(PkgConfig REQUIRED)\n";
|
||||
pkgconfig_emitted = true;
|
||||
}
|
||||
std::string upper;
|
||||
upper.reserve(r.pkg_config_module->size());
|
||||
for (char c : *r.pkg_config_module) {
|
||||
upper += std::isalnum(static_cast<unsigned char>(c))
|
||||
? static_cast<char>(std::toupper(
|
||||
static_cast<unsigned char>(c)))
|
||||
: '_';
|
||||
}
|
||||
out += std::format("pkg_check_modules({} REQUIRED IMPORTED_TARGET {})\n",
|
||||
upper, *r.pkg_config_module);
|
||||
} else {
|
||||
out += std::format("find_package({})\n", r.find_package);
|
||||
}
|
||||
};
|
||||
for (const auto& r : recipes) {
|
||||
out += std::format("find_package({})\n", r.find_package);
|
||||
emit_one(r);
|
||||
}
|
||||
for (const auto& r : dev_recipes) {
|
||||
out += std::format("find_package({})\n", r.find_package);
|
||||
emit_one(r);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -167,6 +167,18 @@ auto flake_nix(const GenerateInputs& in) -> std::string {
|
||||
|
||||
out += emit_inputs_block(pinned);
|
||||
|
||||
const bool any_pkg_config =
|
||||
std::ranges::any_of(in.recipes,
|
||||
[](const linkdb::Recipe& r) {
|
||||
return r.pkg_config_module &&
|
||||
!r.pkg_config_module->empty();
|
||||
}) ||
|
||||
std::ranges::any_of(in.dev_recipes,
|
||||
[](const linkdb::Recipe& r) {
|
||||
return r.pkg_config_module &&
|
||||
!r.pkg_config_module->empty();
|
||||
});
|
||||
|
||||
out += "\n";
|
||||
out += " outputs = ";
|
||||
out += emit_outputs_params(pinned);
|
||||
@@ -181,8 +193,11 @@ auto flake_nix(const GenerateInputs& in) -> std::string {
|
||||
" version = \"1.0\";\n"
|
||||
" nativeBuildInputs = [\n"
|
||||
" pkgs.ninja\n"
|
||||
" pkgs.cmake\n"
|
||||
" ];\n"
|
||||
" pkgs.cmake\n";
|
||||
if (any_pkg_config) {
|
||||
out += " pkgs.pkg-config\n";
|
||||
}
|
||||
out += " ];\n"
|
||||
" buildInputs = [\n";
|
||||
out += emit_build_inputs(bindings);
|
||||
out += " ];\n"
|
||||
|
||||
Reference in New Issue
Block a user