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

GLIBC not found while building against Amazon Linux 2 - x86_64 #467

Closed
fancywriter opened this issue Apr 22, 2022 · 7 comments
Closed

GLIBC not found while building against Amazon Linux 2 - x86_64 #467

fancywriter opened this issue Apr 22, 2022 · 7 comments

Comments

@fancywriter
Copy link

fancywriter commented Apr 22, 2022

Hello!

I am trying to build example from README. It is said it's recommended to use Amazon Linux 2 runtime because it's "easier to build", that's what I am trying to do.

My Cargo.toml:

[package]
name = "rust-lambda-hello"
version = "0.1.0"
edition = "2018"

[dependencies]
lambda_runtime = "0.5.1"
serde_json = "1.0.79"
tokio = { version = "1.17.0", features = [ "macros" ] }

src/main.rs is the same as in README.

Building with command (from the Linux laptop with the same x86_64 architecture, uname -m gives me x86_64)

cargo lambda build --release --target x86_64-unknown-linux-gnu --output-format zip

Success. Than deploying with command

aws lambda create-function --function-name rust-lambda-hello --handler bootstrap --zip-file fileb://./target/lambda/rust-lambda-hello/bootstrap.zip --role <MY_LAMBDA_ROLE_ID> --runtime provided.al2  --environment Variables={RUST_BACKTRACE=1}   --tracing-config Mode=Active

Also success.

But later when I am trying to invoke this function

aws lambda invoke  --function-name rust-lambda-hello --payload '{"hello": "world"}'  --cli-binary-format raw-in-base64-out   output.txt

, it doesn't work, it gives

{
  "errorMessage": "RequestId: <???> Error: Runtime exited with error: exit status 1",
  "errorType": "Runtime.ExitError"
}

When trying to search some logs, I found three lines

/var/task/bootstrap: /lib64/libc.so.6: version `GLIBC_2.28' not found (required by /var/task/bootstrap)
/var/task/bootstrap: /lib64/libc.so.6: version `GLIBC_2.33' not found (required by /var/task/bootstrap)
/var/task/bootstrap: /lib64/libc.so.6: version `GLIBC_2.32' not found (required by /var/task/bootstrap)

I am using rust-1.59.0.

What did I do wrong?

@calavera
Copy link
Contributor

I think you've bumped into this issue: ziglang/zig#9485

I'm trying to find a way to mitigate that. @messense documented that as one of the caveats of using Zig: https://github.com/messense/cargo-zigbuild#caveats

@messense
Copy link

@calavera I think the problem is that cargo-lambda disables zig linker when compiling from x86_64 to x86_64: https://github.com/cargo-lambda/cargo-lambda/blob/b9b6a1993ad7ae5563d8c1a82b023396bfaf2a31/crates/cargo-lambda-build/src/lib.rs#L72

@calavera
Copy link
Contributor

oh yeah, you might be right. And the problem is that if we don't disable it, you need to use a nightly build, is that still the case @messense?

If the --target argument is the same as the host target, for example when compiling from Linux x86_64 to Linux x86_64, Cargo by default also uses zig as linker for build dependencies like build scripts and proc-macros which might not work (See rust-cross/cargo-zigbuild#4). You need to use the nightly Rust compiler then cargo-zigbuild will enable the unstable target-applies-to-host option automatically to make it work out of the box.

@messense
Copy link

@calavera I'm working on a hack to enable that feature on stable Rust: rust-cross/cargo-zigbuild#32

@messense
Copy link

@calavera I'm working on a hack to enable that feature on stable Rust: messense/cargo-zigbuild#32

Released in v0.8.5.

@calavera
Copy link
Contributor

Thanks @messense I'll test it today.

@fancywriter, as a "workaround" until I release a new version of cargo-lambda, you can also build and deploy using ARM as the architecture if your code is not dependent on X86_64 in any way.

  1. Change the target when you build the function:
cargo lambda build --release --target aarch64-unknown-linux-gnu --output-format zip
  1. Add the --architectures flag in the aws cli:
aws lambda create-function --function-name rust-lambda-hello \
  --handler bootstrap --zip-file fileb://./target/lambda/rust-lambda-hello/bootstrap.zip \
  --role <MY_LAMBDA_ROLE_ID> --runtime provided.al2  \
  --environment Variables={RUST_BACKTRACE=1} \
  --tracing-config Mode=Active \
  --architectures arm64

@calavera
Copy link
Contributor

I just published cargo-lambda 0.7 that mitigates this problem.

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

No branches or pull requests

3 participants