I am developing a package that is designed to be used either by standard Julia or by Julia library embedded in a third party application. Most of the code is the same in either mode, but a few functions are currently defined conditionally like this
const embedded = isembedded() # true when embedded, false otherwise if embedded f() = "one implementation" else f() = "another implementation" end
Unfortunately, this approach does not work if I want to have my package precompiled. Since pre-compilation is always done by a standard julia instance, the precompiled code will always have
embedded set to
I could probably redefine
Base.LOAD_CACHE_PATH in the embedded case, but this will result in a duplicate cache for all packages, not only mine.
What is the recommended approach in a situation like this? I thought this problem would be resolved in pyjulia, but it looks like it is not.
One solution that comes to mind is to move the variable code to the
function __init__() if isembedded() global f() = "one implementation" else global f() = "another implementation" end end