Hey everyone,
I am successfully statically linking NIFs to my OTP build using ./otp_build configure —enable-static-nifs=/path/to/mynif.a
. Is it possible to link without rebuilding OTP? I’m looking into deploying to iOS where we need a static binary, we cannot load .so files. I was wondering if it’s possible for me to create ready made OTP binary builds for iOS that I take as is and add my custom NIFs on top.
Not really. Grafting an object file (whether a single .o
or an .a
containing one or more .o
s) onto an executable (e.g. beam.smp
) requires repeating the linking step with those new .o
or .a
files added.
Presumably BEAM also needs to know about the static NIFs in some table, and that too needs to be updated, which implies a rebuild of that .o
file.
In principle the linker could built the table of static NIFs via special sections, but I don’t know if that would work on mach-o object files. Nor do I think OTP would want that complication.
I think your options are to either:
- Rebuild OTP from scratch with your special NIFs added.
- Cache a vanilla build and just to an incremental rebuild + link to get your NIF in.
Why not just do 1?
As @mikpe said not really, but if you can stash the previously-compiled OTP build files, an incremental build will be quick. Does that help solve your problem at all – is it about getting faster builds / dev iteration?
Hey everyone, thanks for the replies. Yes, that definitely works. I was thinking about onboarding, someone trying out or contributing to a project ideally wouldn’t have to build OTP from scratch but yeah, it’s OK, with proper caching they’d have to do it only once (or possible whenever they change NIFs).