Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation error : failed to run custom build command for 'ring v0.16.20' #78

Closed
albanducos87 opened this issue Jul 29, 2022 · 7 comments
Labels
bug Something isn't working
Milestone

Comments

@albanducos87
Copy link

Hello everyone
I hava an issue when I want to execute this command : serverless deploy

My terminal show me an error and after many and many attempts, I don't know what to do.

Here's the error :
image

@albanducos87 albanducos87 added the bug Something isn't working label Jul 29, 2022
@demeringo
Copy link
Collaborator

Hello @albanducos87, thank you for openning the issue.

I did not test (yet) the compilation or serverless deployment from Windows, as I do all the development from Linux.

But I suspect that the error is related to cross-compiling (from a windows machine to produce a binary suitable for lambda deployment). Something may be need to be installed for the cross compilation to work from Windows.

I really do not have much experience with such setup, but solution may be related to something like:

Posssible workaround:

If setting up a Rust + serverless environment on Windows is too much complication, a simpler workaroound could be either to

  • run the commands from WSL (The Windows Subsystem for Linux)
    or
  • use a temporary AWS or Azure Linux instance (Ubuntu or Debian) and use it to checkout / compile / deploy the lambdas.

Sadly, I may not be able to give you much support in the coming days, because I'm traveling and do not have a Windows laptop with me to do the tests.

@jfaixo
Copy link

jfaixo commented Jul 29, 2022

Hi,

I reproduced the problem. This is a problem related to cross compilation of the ring crate while targetting linux-musl (the target that is set in serverless) from windows.

I don't know serverless very well, but it might be more robust to compile the rust part inside a linux container with the proper toolchain (musl & co :) )

See for example: briansmith/ring/#1472

The workaround seems to be to use WSL when you want to cross-compile...

@demeringo
Copy link
Collaborator

demeringo commented Jul 29, 2022

Thanks @jfaixo, I realize that I used the dockerless=true setting in the serverless.yml file:

dockerless: true

According to serverless-rust plugin doc, it means that I had to add the x86_64-unknown-linux-musl target https://github.com/softprops/serverless-rust#-experimental-local-builds.

I probably did this initially with the following command: rustup target add x86_64-unknown-linux-musl

@jfaixo
Copy link

jfaixo commented Jul 30, 2022

Rust is usually very good at cross compilation, but the ring crate embeds C code I think, which require to have a fully blown toolchain for compiling C for the target platform, so it's becoming way more complex.. containerizing is the way !

@demeringo
Copy link
Collaborator

demeringo commented Sep 1, 2022

I finally tested building or deploying the serverless app from Windows using WSL2 + Ubuntu. It works ⚡,
You can use this way until we provide a simpler building container for windows....

Added procedure here: https://boavizta.github.io/cloud-scanner/how-to/building-cli.html and https://boavizta.github.io/cloud-scanner/how-to/deploy-sls.html.

@demeringo
Copy link
Collaborator

Long story short,:

  1. we need to install musl development packages in Linux.
  2. add x86_64-unknown-linux-musl as a target for the Rust compiler .

1. Check availability and install if needed musl

#  Warning: musl-gcc may be missing, wich results in error: 
#    error: failed to run custom build command for `ring v0.16.20`
# it can be verified by trying to call musl-gcc on command prompt
# $ musl-gcc
# Which results in:
#    Command 'musl-gcc' not found, but can be installed with:
# This musl-gcc is not available (preventing cross compilation)

# On linux  Need to install musl-gcc
sudo apt update && sudo apt install -y musl-tools musl-dev

2. Install x86_64-unknown-linux-musl as rustup target

# Add Linux musl target (needed for cross compilation for aws lambda)
rustup target add x86_64-unknown-linux-musl

@demeringo
Copy link
Collaborator

Not yet mentionned in the docs but I published a docker image to use Rust + Serverless in CI:
https://github.com/demeringo/rust-serverless-ci

# get image
docker pull ghcr.io/demeringo/rust-serverless-ci:latest

@demeringo demeringo added this to the Release 0.1.0 milestone Nov 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants