sls-rust icon indicating copy to clipboard operation
sls-rust copied to clipboard

Fixes to get the plugin working again

Open kristallizer opened this issue 1 year ago • 2 comments

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.

kristallizer avatar Jul 28 '23 21:07 kristallizer