softprops / serverless-rust

⚡ 🦀 a serverless framework plugin for rustlang applications
https://www.npmjs.com/package/serverless-rust
MIT License
548 stars 82 forks source link

Binary dependencies? #23

Closed triptec closed 5 years ago

triptec commented 5 years ago

Hello, I’ve been playing around with this plugin and I wonder if you got any idea for how to handle dependencies on dynamic libs? Just add the lib folder if it exist to every binary zip or perhaps something else? I’d like to hear your thoughts on the matter. Thanks

softprops commented 5 years ago

Hi @triptec thanks for reaching out. Do you have a concrete example of what you're blocked on. I can think of a few ideas. Atm this plugin only bundles your rust binary into a deployment. I could add a hook to also include other binaries. Alternatively there's a newer feature of lambda that serverless exposes called layers which may be of interest

triptec commented 5 years ago

Well, I've been playing around with crates that depend on sys crates and those sys crates depend on c headers and dynamic libraries. So my work flow right now is

  1. Create a aws linux docker image where I install/build the dependencies.
  2. Copy those .so files that I depend on to a lib dir
  3. Point out previous docker image in my serverless.yml so that my project builds
  4. Then include the lib folder together with the binary in the zip stage
softprops commented 5 years ago

Thanks posting back.

I think I have some idea for how to make this happen. I'll try to turn those ideas into code next weekend.

I think this the fact that this plugin leverages the actual lambda runtime makes binaries will be deployed into actually enables some predicability useful approaches.

I can get a list of provided libs in the runtime using

 $ ldconfig -c -new -p

then in the lambda rust docker image I can get a list of link dependencies using

$ ldd {bin-name}

what I'd have to bundle into the zip is just whats missing from the runtime.

triptec commented 5 years ago

Yes that’s what I was playing with in my head as well. Though I think there would need to be a option like “include” or something that also would be added to the final zip. Like in my case there’s .gir files because of gobject-introspection though now that I think of it that might not be a dependency on those. I’ll have to look that up. Anyhow, thanks for taking the time making this, serverless and rust is neat on their own and even more together.

softprops commented 5 years ago

no doubt. thanks for reaching out. I'm always interested in seeing how people are using this