In a nutshell, the problem is this: I am forced to compile a shared library for interoperability with Python to use the shared library as a Rust AWS Lambda function. I am building my shared library in the same environment as much as possible as the Amazon Linux execution environment used by AWS Lambda. Attempting to install openssl-devel in this environment, however, results in upgrading OpenSSL from the default version of 1.0.1 to 1.0.2. Since my build environment links against 1.0.2 and the runtime environment is the older 1.0.1, my library crashes on startup with an invalid/unexpected OpenSSL version. I must make a shared library for Python/Lambda integration, but I'd like to statically compile OpenSSL in so I don't run into this issue. Redoing everything in musl doesn't give me anything as I think a shared library in musl would still want to link against OpenSSL.
Please see the GitHub above as it demonstrates the exact subtle nature of the issue.
How can I tell Cargo/rustc that I would like to statically compile OpenSSL into my shared library?
One approach is to have Cargo produce a static library, then manually link that into a shared library. (This works because a static library is mostly just a collection of object files.)
The cargo build command should've output a list of libraries that you need to link, like so:
note: link against the following native artifacts when linking against this static library
note: the order and any duplication can be significant on some platforms, and so may need to be preserved
note: library: dl
note: library: rt
note: library: pthread
note: library: gcc_s
note: library: c
note: library: m
note: library: rt
note: library: pthread
note: library: util
/usr/bin/ld: /home/vagrant/.cache/cargo/target/debug/liblambda.so: version node not found for symbol SSLeay_version@OPENSSL_1.0.1
/usr/bin/ld: failed to set dynamic section sizes: Bad value
= note: /usr/bin/ld: /home/circleci/project/target/release/deps/liblambda.so: version node not found for symbol SSLeay_version@OPENSSL_1.0.1
/usr/bin/ld: failed to set dynamic section sizes: Bad value
collect2: error: ld returned 1 exit status
I'm kind of at the end of my rope here. Haven't yet spent this much time in linker hell.
I suppose musl might be a requirement at this point. This gets back to my original inquiry: is there a way to statically compile a shared library so that Python can still use it, yet bake in all dependencies in statically? I don't want to keep fussing around with linker flags.