Skip to content

feat(pj_base): add getSharedLibDir() to platform.hpp#64

Merged
pabloinigoblasco merged 1 commit into
developmentfrom
feat/platform-get-shared-lib-dir
Apr 21, 2026
Merged

feat(pj_base): add getSharedLibDir() to platform.hpp#64
pabloinigoblasco merged 1 commit into
developmentfrom
feat/platform-get-shared-lib-dir

Conversation

@pabloinigoblasco
Copy link
Copy Markdown
Collaborator

@pabloinigoblasco pabloinigoblasco commented Apr 21, 2026

Summary

  • Adds PJ::sdk::getSharedLibDir(const void* fn_addr) to pj_base/include/pj_base/sdk/platform.hpp alongside the existing userDataDir() and getEnv() helpers
  • Returns the directory of the .so/.dll that contains fn_addr at runtime, without requiring a known install prefix at build time
  • Uses dladdr() on Linux/macOS and GetModuleHandleExW() + GetModuleFileNameW() on Windows
  • WIN32_LEAN_AND_MEAN / NOMINMAX guards prevent namespace pollution from <windows.h>

Use case

Plugins that bundle resources (e.g. a Python stdlib directory) alongside their binary need to locate those resources at runtime. Without a core helper they must each reimplement dladdr/GetModuleHandleExW with their own #ifdef blocks. This PR provides one canonical, tested implementation.

The first consumer is the toolbox_reactive_scripts_editor plugin (pj-official-plugins PR #64), which bundles CPython stdlib and needs to tell the interpreter where to find it.

Test plan

  • Builds on Linux (gcc, clang)
  • Builds on Windows (MSVC)
  • Builds on macOS
  • getSharedLibDir() called from a plugin .so returns the correct directory (validated via the plugins PR build)

Adds PJ::sdk::getSharedLibDir(const void* fn_addr) alongside the
existing userDataDir() and getEnv() helpers.

The function returns the directory of the .so / .dll that contains
fn_addr at runtime — useful for plugins that bundle resources (e.g. a
Python stdlib) next to their binary and need to locate them without
knowing the install prefix at build time.

Platform implementation:
- Linux / macOS: dladdr() — callers must link ${CMAKE_DL_LIBS}
- Windows:       GetModuleHandleExW() + GetModuleFileNameW()

WIN32_LEAN_AND_MEAN / NOMINMAX guards prevent namespace pollution from
<windows.h>.
@pabloinigoblasco pabloinigoblasco merged commit ccb7574 into development Apr 21, 2026
2 checks passed
@pabloinigoblasco pabloinigoblasco deleted the feat/platform-get-shared-lib-dir branch May 4, 2026 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant