Skip to content

Fixes to get the plugin working again#5

Open
kristallizer wants to merge 3 commits into
fdaciuk:mainfrom
kristallizer:krishna.fixes
Open

Fixes to get the plugin working again#5
kristallizer wants to merge 3 commits into
fdaciuk:mainfrom
kristallizer:krishna.fixes

Conversation

@kristallizer
Copy link
Copy Markdown

Hello, I ran into deployment issues when I was trying to deploy a Rust function from my Macbook. I'd love to get your feedback on whether these changes make sense or I was using it wrong to being with.

Also, I don't have a Linux machine to test these changes on, so some testing on your side would be much appreciated.

First issue

Deploying your dev env to AWS
sls deploy --stage k1
Running "serverless" from node_modules

Deploying test-rust to stage k1 (us-east-1)
Building Rust my-project1.test-func func...

✖ Stack test-rust-k1 failed to deploy (8s)
Environment: darwin, node 18.16.0, framework 3.33.0 (local) 3.31.0v (global), plugin 6.2.3, SDK 4.3.2
Credentials: Local, "default" profile
Docs:        docs.serverless.com
Support:     forum.serverless.com
Bugs:        github.com/serverless/serverless/issues

Error:
Error: Error trying to zip artefact in test-func: Error: spawn rm ENOENT
    at SlsRust.runZipArtifact (/code/libs/sls-rust/sls-rust.js:84:13)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async SlsRust.build (/code/libs/sls-rust/sls-rust.js:94:5)
    at async Promise.all (index 0)
    at async SlsRust.buildPrepare (/code/libs/sls-rust/sls-rust.js:40:5)
    at async PluginManager.runHooks (/code/test-rust/node_modules/serverless/lib/classes/plugin-manager.js:530:9)
    at async PluginManager.invoke (/code/test-rust/node_modules/serverless/lib/classes/plugin-manager.js:563:9)
    at async PluginManager.spawn (/code/test-rust/node_modules/serverless/lib/classes/plugin-manager.js:585:5)
    at async before:deploy:deploy (/code/test-rust/node_modules/serverless/lib/plugins/deploy.js:40:11)
    at async PluginManager.runHooks (/code/test-rust/node_modules/serverless/lib/classes/plugin-manager.js:530:9)
    at async PluginManager.invoke (/code/test-rust/node_modules/serverless/lib/classes/plugin-manager.js:563:9)
    at async PluginManager.run (/code/test-rust/node_modules/serverless/lib/classes/plugin-manager.js:604:7)
    at async Serverless.run (/code/test-rust/node_modules/serverless/lib/serverless.js:179:5)
    at async /code/test-rust/node_modules/serverless/scripts/serverless.js:834:9
error: Recipe `deploy` failed on line 28 with exit code 1

I dug into the source code a bit and the main issue I found was that Cargo defaults to building the binary in the root target/, but this plugin tries to build in <project-dir>/target. I propose that we fix this by building everything in the root target/ directory.

Second issue

I also ran into an issue with the linker:

WARN rustc_codegen_ssa::back::link Linker does not support -static-pie command line option. Retrying with -static instead.
error: linking with `cc` failed: exit status: 1

I was able to fix this by switching to cargo-zigbuild as a linker.

Signed-off-by: Krishna Aradhi <karadhi@justworks.com>
Signed-off-by: Krishna Aradhi <karadhi@justworks.com>
Signed-off-by: Krishna Aradhi <karadhi@justworks.com>
@fdaciuk
Copy link
Copy Markdown
Owner

fdaciuk commented Aug 1, 2023

Hi @kristallizer! The first error is probably because you're putting the serverless.yml file inside the Rust project directory. It should be outside, as shown in README. That way you can create as many functions as you wish, and deploy them separately.

About the linker issue, I'll do some tests here. But thanks in advance for this PR, I really appreciate it ❤️

@kristallizer
Copy link
Copy Markdown
Author

Hey @fdaciuk, my serverless.yml is in the root dir alongside the README file.

I defined the function in serverless.yml like so:

functions:
  hello:
    # handler value syntax is `{cargo-package-name}.{bin-name}`
    # or `{cargo-package-name}` for short when you are building a
    # default bin for a given package.
    handler: my-project1.test-func
    events:
      - http:
          path: "/"
          method: GET
    tags:
      rust: true

Cargo.toml in the root dir:

[workspace]
members = ["my-project1"]

My project file structure is like so:

my-project1/
├── Cargo.toml
└── src
    └── main.rs

Cargo.toml in project dir:

[package]
name = "my-project1"
version = "0.1.0"
edition = "2018"

[dependencies]
tokio = { version = "^1.29.1", features = ["macros"] }
lambda_http = "^0.8.1"
serde_json = "^1.0"
clippy = "^0.0.302"
serde = "^1.0.174"
tracing-subscriber = "^0.3.17"
tracing = "^0.1.37"

[[bin]]
name = "test-func"
path = "src/main.rs"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants