serverless-aws-rust-multi icon indicating copy to clipboard operation
serverless-aws-rust-multi copied to clipboard

How to include a shared code crate?

Open hassox opened this issue 6 years ago • 3 comments

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.

hassox avatar Dec 16 '19 07:12 hassox

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

softprops avatar Dec 23 '19 18:12 softprops

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 :/

hassox avatar Dec 23 '19 18:12 hassox

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"}

swilcox3 avatar Jan 20 '20 14:01 swilcox3