diff --git a/.cargo/config.toml b/.cargo/config.toml index 94dd605be..f0e43da95 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -3,3 +3,13 @@ incremental = true [target.x86_64-pc-windows-msvc] rustflags = ["-Ctarget-feature=+crt-static"] + +# Use lld linker on Linux — significantly less memory than default ld, +# critical for arm64 builds on 16GB Graviton runners. +[target.x86_64-unknown-linux-gnu] +linker = "clang" +rustflags = ["-Clink-arg=-fuse-ld=lld"] + +[target.aarch64-unknown-linux-gnu] +linker = "clang" +rustflags = ["-Clink-arg=-fuse-ld=lld"] diff --git a/.github/Dockerfile b/.github/Dockerfile index 0fb558e4d..b7d5afe49 100644 --- a/.github/Dockerfile +++ b/.github/Dockerfile @@ -1,7 +1,7 @@ # Use a Rust base image FROM rust:bookworm AS builder ARG BUILD_TYPE -RUN apt-get update && apt-get install -y libclang-dev cmake libssl-dev libc++-dev libc++abi-dev lld +RUN apt-get update && apt-get install -y clang libclang-dev cmake libssl-dev libc++-dev libc++abi-dev lld # Install nvm, npm and node RUN rm /bin/sh && ln -s /bin/bash /bin/sh @@ -36,6 +36,10 @@ COPY . . RUN rustup default 1.88 RUN rustup component add rustfmt +# Limit parallel jobs to prevent OOM on arm64 (16GB Graviton). +# lld linker configured in .cargo/config.toml (uses ~3x less RAM than ld). +ENV CARGO_BUILD_JOBS=4 + # Build main code, pre-compile tests, and cleanup in SINGLE layer # This is critical - separate RUN commands create Docker layers that preserve old data # Even if we delete files in a later layer, the image size includes all layers diff --git a/docker/Dockerfile b/docker/Dockerfile index bdd18f849..73b9e7bb5 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -25,6 +25,7 @@ ARG VCS_REF # Install build dependencies RUN apt-get update && apt-get install -y \ + clang \ libclang-dev \ cmake \ libssl-dev \ @@ -43,6 +44,10 @@ COPY . . # Add rustfmt for build RUN rustup component add rustfmt +# Limit parallel codegen/linker jobs to prevent OOM on arm64 (16GB Graviton). +# lld is configured as the linker via .cargo/config.toml (uses ~3x less RAM than ld). +ENV CARGO_BUILD_JOBS=4 + # Build the project # Build the entire workspace to properly resolve all dependencies # Then extract just the hanzo_node binary we need