From 3b849a5a02d060504e9e7d2150618999b395b351 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 18 Sep 2025 13:00:28 +0200 Subject: feat: `shared_runner` for `run_after_build` in nebuild. Signed-off-by: Amlal El Mahrouss --- dev/src/JSONManifestBuilder.cc | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'dev/src') diff --git a/dev/src/JSONManifestBuilder.cc b/dev/src/JSONManifestBuilder.cc index 33d7f62..f64dba4 100644 --- a/dev/src/JSONManifestBuilder.cc +++ b/dev/src/JSONManifestBuilder.cc @@ -4,6 +4,7 @@ // ============================================================= // #include +#include using JSON = nlohmann::json; @@ -99,12 +100,24 @@ bool JSONManifestBuilder::BuildTarget(const std::string& argv_val, const bool dr try { if (json_obj["run_after_build"].get()) { - if (target.ends_with(".so")) { - NeBuild::Logger::info() - << "error: can't open dynamic library, it mayn't have an entrypoint" << std::endl; + if (target.ends_with(".so") || target.ends_with(".dylib")) { +#if defined(NEBUILD_POSIX) + auto dll = dlopen(target.c_str(), RTLD_LAZY); - return true; - } else if (target.ends_with(".dylib") || target.ends_with(".dll")) { + if (dll) { + int (*entrypoint)(void) = nullptr; + entrypoint = (decltype(entrypoint))dlsym(dll, "shared_runner"); + + if (entrypoint) entrypoint(); + + dlclose(dll); + + return true; + } +#endif + + return false; + } else { std::ifstream file = std::ifstream(target); std::stringstream ss; @@ -119,17 +132,8 @@ bool JSONManifestBuilder::BuildTarget(const std::string& argv_val, const bool dr NeBuild::Logger::info() << "error: can't open FEP dynamic library, it mayn't contain an entrypoint" << std::endl; - else if (ss.str()[0] == 'M' && ss.str()[1] == 'Z') - NeBuild::Logger::info() - << "error: can't open MZ dynamic library, it mayn't contain an entrypoint" - << std::endl; - else if (ss.str()[0] == 0x7F && ss.str()[1] == 'E') { - NeBuild::Logger::info() - << "error: can't open ELF dynamic library, it mayn't contain an entrypoint" - << std::endl; - } - return true; + return false; } #if defined(NEBUILD_WINDOWS) -- cgit v1.2.3 From ff9afeee748fba7bd023f7decafa8fb99298b146 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 18 Sep 2025 13:11:16 +0200 Subject: feat: run-after-build: better portability of JSON builder. Signed-off-by: Amlal El Mahrouss --- dev/src/JSONManifestBuilder.cc | 3 +++ 1 file changed, 3 insertions(+) (limited to 'dev/src') diff --git a/dev/src/JSONManifestBuilder.cc b/dev/src/JSONManifestBuilder.cc index f64dba4..0b010fe 100644 --- a/dev/src/JSONManifestBuilder.cc +++ b/dev/src/JSONManifestBuilder.cc @@ -4,7 +4,10 @@ // ============================================================= // #include + +#if defined(NEBUILD_POSIX) #include +#endif using JSON = nlohmann::json; -- cgit v1.2.3