rust.aws-cdk-lambda
rust.aws-cdk-lambda copied to clipboard
Add an option to compile code in a Docker container
The goal here is quite simple, but ideally we want to provide a way for users to compile rust code in a containerized manner, perhaps leveraging Docker and an Amazon Linux build image. If the host machine doesn't have rustup or cargo-zigbuild installed, we should by default use Docker to build and compile rust code.
The end goal would probably be to find a suitable Docker container, so if the container for example has zigbuild and zig already installed, that would be ideal; though of course if the architecture in the Docker container matches the target, then there's a chance we might not need zigbuild in such a case.
We could also take inspiration from other similar NPM libraries such as aws-lambda-go, which does also support building code in a Docker environment.
Docker Image
For the actual Docker image to use, I'm still open to suggestions as mentioned above, so ideally an image that comes with tools like cargo-zigbuild and cross already installed. I think an excellent starting point would be to look into the image that softprops/lambda-rust provides:
https://github.com/softprops/lambda-rust
I would say it's quite important that you do start from the Amazon Linux build image, and then perhaps use it as a base image that you install cargo into and then re-use for builds. But to be clear, it's no one's preference to use Docker. If I can get it to compile for the right glibc version using zig then that's ideal.
Yes, I certainly agree. I do think the Dockerfile that softprops/lambda-rust uses is a good starting point. I'll need to run some initial tests to confirm if the build environment works without the need to cross-compile with something like zig, but my initial impression is it won't be needed. I also likewise feel that using Docker is not ideal is general, and building code with zig should be preferrable in most cases.