awslabs / aws-lambda-rust-runtime

A Rust runtime for AWS Lambda
Apache License 2.0
3.32k stars 338 forks source link

Build fails on Windows #927

Open sszabo11 opened 1 week ago

sszabo11 commented 1 week ago

I am trying to create a lambda function with rust but I am facing some very annoying issues.

Problem

The build process fails with a linking error when using `cargo lambda build --release``. I suspect this may be related to the cross-compilation toolchain, but I'm not sure how to resolve it.

What I have done

1. Created new function:

cargo lambda new banana

2. Tested function locally

cargo lambda watch

3. TRIED to build function

cargo lambda build --release

error: could not compile banana (bin "banana") due to 1 previous error


## Thoughts
So I think the underlying issue is something to do with cross compiling. As seen in the final error note:
It could also do to with the current toolchain I am on. I have tested it with
- `stable-x86_64-pc-windows-gnu`
- `stable-x86_64-pc-windows-msvc`
- `nightly-x86_64-pc-windows-msvc`

C:\Users\Rabbit Muncher\Desktop\rusty\kol>C:\Users\Rabbit Muncher\scoop\apps\cargo-lambda\current\cargo-lambda.exe zig cc -- -g -target x86_64-linux-gnu @C:\Users\RABBIT~1\AppData\Local\Temp\rustcIbw7hS\linker-arguments


This could have something to do with the `x86_64-linux-gnu` target.
@calavera has had this issue while in production, with the same error message
Issue: https://github.com/cargo-lambda/cargo-lambda/issues/77
Error: https://ci.appveyor.com/project/AWSSAMCLI/aws-lambda-builders/builds/43271090/job/3ovwam50va3735y2

## My current fix
I have tested this in Windows Subsystem for Linux and it built successfully.
And I want to try a docker container

## Frustrating
This has stopped me from being able to use AWS Lambda!!
At this point I'm converting to linux!!!!!
I just want Arc browser support!!
Really annoying.
Help would be great!!
Thanks in advance
calavera commented 1 week ago

Make sure you're using the latest version of Zig, 0.13. This sounds like the same problem reported in https://github.com/cargo-lambda/cargo-lambda/issues/698#issuecomment-2365031247

sszabo11 commented 1 week ago

I have reinstalled zig with the latest version 0.13. When I check where it is located with cargo lambda system, it prints out with:

Zig installation found at:
C:\Users\Rabbit Muncher\zig-windows-x86_64-0.13.0\zig.exe

That is where I installed it. But it still returns with the same error when I run cargo lambda build --release

calavera commented 6 days ago

I'm wondering if this a bug in cargo-zigbuild and the way it creates bat files on Windows.

'C:\Users\Rabbit' is not recognized as an internal or external command, operable program or batch file.

This error makes me think that something is splitting the command to run by whitespaces, and because your username is Rabbit Muncher, it's taking C:\Users\Rabbit as the command to run.

/cc @messense

sszabo11 commented 6 days ago

Yes, I suspected that might be the issue. I'll create a new user, install the necessary packages, and try and build it. I'll get back to you on the results.

sszabo11 commented 6 days ago

I built the function on another account on my machine, and yes it worked. Must be an issue with the space in my user. But still, is there a way to fix that? Thanks for your help.

calavera commented 6 days ago

I suspect the bug is here: https://github.com/rust-cross/cargo-zigbuild/blob/06d31bc66e793e3b4f33d68df7ead7bb329c1c98/src/zig.rs#L1040

We'll need to dive deeper and create a patch to fix it.