I can use Bundle on macOS to load a framework at runtime, and that works reasonably well even with Swift (given the principal class is
@objc). Can I do something similar under Linux?
A similar question has been posted quite a while ago without any answer (
How do you dynamically load a module on Linux?)
Given that Swift has advanced quite a bit, is this possible now?
Can I load a framework/dylib under linux at runtime and use it?
Bundle seems to be mostly unimplemented in corelibs foundation.
It is definitely possible to load dylib in linux using swift, I made a little example app couple months ago to document a bug in SPM. You can see implementation here:
This file has been truncated.
// This is free and unencumbered software released into the public domain.
// Anyone is free to copy, modify, publish, use, compile, sell, or
// distribute this software, either in source code form or as a compiled
// binary, for any purpose, commercial or non-commercial, and by any
// In jurisdictions that recognize copyright laws, the author or authors
// of this software dedicate any and all copyright interest in the
// software to the public domain. We make this dedication for the benefit
// of the public at large and to the detriment of our heirs and
// successors. We intend this dedication to be an overt act of
// relinquishment in perpetuity of all present and future rights to this
// software under copyright law.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
there are two related projects, one that defines plugin's interface and other that show how actual plugin is implemented:
Not sure if this is exactly what you need, but it is possible to load your own dylib and interface with it
Ok the problem here is that only C functions can be called, and Swift libraries are not really supported.
I guess my question is if there is any kind of story or roadmap on how and when this is planned to be properly supported (not just on Linux). I mean even on macOS the requirement to only use Obj-C protocols leaves a lot to be desired.
I think we can start with a JIRA, for the Linux bit.
This may depend on ABI and module stability; otherwise loading some bit of Swift code that was not compiled with the rest of your code may result in some strange behavior.
Thank you Tony for your answer. Makes sense that it is tied to ABI stability. I can’t wait though when Swift on Linux is fully usable™
Should I file the issue on Jira? I guess you are a lot better at wording it though
@Aciid knows something about this ?
Please feel free to create one yourself, and put a link here. Thanks!
Please feel free to fix terminology mistakes. I have no CS ed after all.
Thank you for your kind support.