Develop LLVM on Windows Dev Kit 2023
If you read the article Building LLVM in 90 seconds using Amazon Lambda in 2021, you might wonder whether you can do the same without the author's AMD Ryzen desktop. This blog will show you how I reproduce the results on a $600 ARM64 machine -- Windows Dev Kit 2023.
The software that offloads the compilation tasks to AWS Lambda is called "llama." I forked it to support ARM64. Everything to be discussed here will be using ARM64 -- Windows 11 ARM64, WSL that runs openSUSE Tumbleweed AArch64, Docker image that contains AArch64 binaries, LLVM that generates AArch64 codes, etc.
If you happen to use openSUSE Tumbleweed as well, you can check out the images I uploaded to Docker Hub: lichray/llama-gcc12 for GCC + gold linker and lichray/llama-clang15 for Clang + lld linker; the latter offers only libstdc++. As a jump start, let's give the GCC option a try.
First, clone https://github.com/zhihaoy/llama and switch to the aarch64 branch. Set the GOBIN environment variable to some PATH, go install ./... under the project root. Follow the Getting started guide carefully and bootstrap AWS resources for llama.
Next, make my Docker tag available on your local system with docker pull lichray/llama-gcc12:latest. Then you can create an AWS Lambda in your own account with llama update-function -create -tag lichray/llama-gcc12:latest gcc. The function name "gcc" is a llama default; we will change that when trying out Clang.
Everything is ready. I configure my llvm-project with the following:
env LLAMACC_LOCAL=1 \ cmake -G Ninja \ -DCMAKE_BUILD_TYPE=MinSizeRel \ -DLLVM_ENABLE_PROJECTS="clang" \ -DLLVM_USE_LINKER=gold \ -DCMAKE_C_COMPILER=llamacc \ -DCMAKE_CXX_COMPILER=llamac++ \ -DBUILD_SHARED_LIBS=YES \ -DLLVM_TARGETS_TO_BUILD=AArch64 \ -DCLANG_ENABLE_STATIC_ANALYZER=NO \ -DCLANG_ENABLE_ARCMT=NO \ -B build llvm
To simplify this small example, I didn't set up libc++. The full clang build finishes within 6 minutes with ninja -j 40 -C build/ clang
As you can see, there're warnings. For obvious reasons, the LLVM project guarantees warning-free only when building with Clang, so I'll set up a frustration-free LLVM dev environment next with Clang.
Create an AWS Lambda with my Clang image:
docker pull lichray/llama-clang15:latest llama update-function -create -tag lichray/llama-clang15:latest clang
Export an environment variable to change the Lambda function used by llama (you may want to save that in your shell profile):
# csh setenv LLAMACC_FUNCTION clang
Change cc and c++ commands to match what llamacc and llamac++ use from the image:
update-alternatives --install /usr/bin/cc cc /usr/bin/clang 30 update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++ 30
Now I can configure:
env LLAMACC_LOCAL=1 \ cmake -G Ninja \ -DCMAKE_BUILD_TYPE=MinSizeRel \ -DLLVM_ENABLE_PROJECTS="clang" \ -DLLVM_USE_LINKER=lld \ -DCMAKE_C_COMPILER=llamacc \ -DCMAKE_CXX_COMPILER=llamac++ \ -DBUILD_SHARED_LIBS=YES \ -DLLVM_TARGETS_TO_BUILD=AArch64 \ -DCLANG_ENABLE_STATIC_ANALYZER=NO \ -DCLANG_ENABLE_ARCMT=NO \ -B build llvm
200 seconds! It's totally not bad, as the original "90 seconds" article used the -O0 flag, which renders the resulting clang executable impractical to use in building clang checks or libc++ later.
And the build costs only 30¢. That is why I moved my dev environment to ARM64. ARM chips are inexpensive, even in the cloud (-20% cost overall). To take full advantage of that, all I did is to make my dev machine consume native artifacts from the cloud.
Caveats
WSL datetime can drift when the host sleeps, disrupting your cached AWS token. Read the comments in this issue to find a solution: #8204
AWS accounts that are new to Lambda have very low concurrency quota. Read this guide before requesting a quota increase: Lambda function scaling












