-
Notifications
You must be signed in to change notification settings - Fork 548
Make MCPL a Runtime Optional Dependency #3429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Make MCPL a Runtime Optional Dependency #3429
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tkittel Does this PR look sensible to you? From a quick scan, it looks very similar to what we did with the NCrystal interface.
This PR would be useful for getting the sci kit build core working again. Any objections to merging |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Ahnaf another nice build system improvement.
LGTM
I will merge this in on Friday if there are no objections
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just putting a placeholder review as I'd like to take a look before we merge this. I was also hoping to get @tkittel's vote of confidence on this. I'm assuming he's been in the loop on this?
I've not seen any conversations on this PR outside of this PR thread. |
Hi guys. Sorry, I am on vacation so I didnt have a chance to look at this. I like the aim of this PR though :-) Not 100% sure when I might have a chance to have a look at the details, but perhaps I can find a quiet moment within the next few days. |
Hi guys, So I had a very quick skim through, and I have a few comments. Do keep in mind though, that the OpenMC-MCPL bindings were initially contributed by @ebknudsen not me. In general, big thumbs up to the work here. And yes, the intention is to have the MCPL C ABI stable enough to do these kinds of things. I have a few minor issues though:
Anyway, apart from the points above and the fact that it was just a quick skim-through, it all looks great to me :-) |
Description
This pull request refactors the MCPL interface in OpenMC to make MCPL a runtime optional dependency rather than a build-time one. This version enhances the previous effort by implementing cross-platform dynamic library loading and discovery mechanisms, including support for Windows.
Benefits
Key Changes
CMake Modifications:
OPENMC_USE_MCPL
CMake option.Cross-Platform Runtime Library Loading (
mcpl_interface.cpp
):dlopen()
on POSIX-like systems (Linux, macOS).LoadLibraryA()
on Windows.dlsym()
on POSIX.GetProcAddress()
on Windows.void*
orHMODULE
) and cleanup functions (dlclose
orFreeLibrary
) are used.McplApi
struct holds these function pointers.initialize_mcpl_interface_if_needed
) handles the loading and symbol resolution.Library Discovery Mechanisms:
The
initialize_mcpl_interface_impl
function attempts to locate the MCPL library in the following order:mcpl-config --show libpath
Command:popen()
on POSIX systems._popen()
on Windows systems (requiresmcpl-config.bat
or.exe
to be in the systemPATH
).libmcpl.so
,libmcpl.dylib
on POSIX.mcpl.dll
,libmcpl.dll
on Windows. These are searched in standard system library locations (e.g., those covered byPATH
on Windows orLD_LIBRARY_PATH
on Linux).Avoidance of
mcpl.h
at Compile Time:mcpl.h
is not included to ensure MCPL is not a compile-time dependency.Necessary MCPL data structures (e.g.,
mcpl_particle_t
) and function signatures are manually re-declared withinmcpl_interface.cpp
asmcpl_particle_repr_t
, etc.Error Handling and User Guidance:
fatal_error
s with an informative message, suggesting installation (e.g.,pip install mcpl
) and how to make the library findable.is_mcpl_interface_available()
function can be used to programmatically check MCPL availability.Code Updates:
mcpl_interface.cpp
use the dynamically resolved function pointers.MCPL_ENABLED
preprocessor logic has been removed.