Cross-compiling C++ to serverless ARM

AWS Lambda is arguably the most popular serverless service. Lambda functions support natively several programming languages, such as Python, Node.js, Java or Golang. However, other languages can be supported through custom runtime, where we deploy a function with a bootstrap script to execute.

Lambda has a unique execution environment for C++. The runtime is based on Amazon Linux 2, which is a CentOS derivative. In languages like Python or Node.js, shipping the function code to serverless is easy Since there is no standardized packaging environment in C++, we

There are various methods of creating cross-compilation environments, such as crostool-ng. Alternatively, the entire compilation can be executed within a Docker container that contains the entire toolchain for a different platform.

no standardized build - so no way to tell if dependency A does not brin ganother one.

First, since we are on x64 Linux and we want to compile Lambda

First, we need to get the entire toolchain from. To simplify this process, we will use an existing, containerized cross-compilation toolchain and locate it under the arm-sysroot path on our local disk: We could obtain form the dockcross containers.

However, since we need to ship all system libraries as suggested by AWS, and we know the operating environment of Lambda on AWS, we can instead extract the corss-compilation toolchain from an AWS container. This will simplify the deployment process since we will be able to skip libc and its dependencies, as we know that this library will be available at the destination.

mkdir arm-sysroot && docker run --rm dockcross/linux-arm64  tar --dereference -czf - /usr/xcc | tar -xzf - -C arm-sysroot



Enjoy Reading This Article?

Here are some more articles you might like to read next:


giscus comments misconfigured

Please follow instructions at http://giscus.app and update your giscus configuration.

Missing required keys: repo_id, category_id.