summaryrefslogtreecommitdiffhomepage
path: root/dev/src
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-09-18 13:00:28 +0200
committerAmlal El Mahrouss <amlal@nekernel.org>2025-09-18 13:00:28 +0200
commit3b849a5a02d060504e9e7d2150618999b395b351 (patch)
treeaa8c0ef88c99aa9e4cfcb6ea182d0a317fbd9e43 /dev/src
parentb4be375da454686eb1268358dc5a41a65c6ac8e5 (diff)
feat: `shared_runner` for `run_after_build` in nebuild.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'dev/src')
-rw-r--r--dev/src/JSONManifestBuilder.cc34
1 files changed, 19 insertions, 15 deletions
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 <BuildKit/JSONManifestBuilder.h>
+#include <dlfcn.h>
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<bool>()) {
- 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)