How to include a shared code crate?
Hi there..
I'm new to rust and serverless. I've been trying to create a collection of functions using this template. One of the things that I would like to be able to do is have a common crate that's shared across all my functions. I'm unsure how to structure the code so that I can include this shared crate so that it builds..
My current setup is
mycommon
- src
myapp
- serverless.yml
- hello
- Cargo.toml
- src
- main.rs
- Cargo.toml
- world
-src
- main.rs
- Cargo.toml
When the build tries to run the docker container can't find the files.
How do other folks deal with this? Any help here would be really appreciated.
sorry I missed this message. I'll try to follow up with an example soon but it should really be no different than how you'd do this in any other multi package cargo project
typically this is updating the base Cargo.toml file to include members which map to paths of your shared crates.
Ill try to update the example soon
Thanks I'd appreciate it. I can manually build it locally, its only when I try to get serverless to build it that it can't find the files :/
The reason why the docker container can't find the files is because only the directory with your serverless.yml is copied over to the docker environment. I have a setup with a common crate as well, but I included it in my app directory. It looks like this:
serverless-project
-common
-src
-Cargo.toml
-lock
-src
-Cargo.toml
-disconnect
-src
-Cargo.toml
Cargo.toml
serverless.yml
My workspace Cargo.toml looks like this:
[workspace]
members = ["disconnect", "lock"]
And my lock and disconnect Cargo.toml files include common like this:
[dependencies]
common = {version = "0.1.0", path = "../common"}