Skip to content

feat: support building GraalVM with zig instead of llvm - #13714

Draft
izaakschroeder wants to merge 1 commit into
oracle:masterfrom
izaakschroeder:zig
Draft

feat: support building GraalVM with zig instead of llvm#13714
izaakschroeder wants to merge 1 commit into
oracle:masterfrom
izaakschroeder:zig

Conversation

@izaakschroeder

Copy link
Copy Markdown

Summary

  • Turn off requiring glibc.
  • Use zig instead of gcc-musl/llvm for GraalVM itself. This also requires a corresponding mx patch: feat: add zig toolchain聽graalvm/mx#306
  • Ship zig with GraalVM to be used when building native images instead of gcc. Also ship zlib source to be able to compile statically without installing any other dependencies.

Related Issues

  • Link the relevant issue, design discussion, or other prior context if applicable.

Testing

ARG ALPINE_VERSION=3.23.4
# =====================================================================
# JDK
# https://github.com/graalvm/labs-openjdk
# =====================================================================
FROM alpine:${ALPINE_VERSION} AS jdk

RUN apk update
RUN apk add curl

ARG JDK_VERSION=jvmci-25.1-b18
ARG JDK_PKG=https://github.com/graalvm/labs-openjdk/archive/refs/tags/${JDK_VERSION}.tar.gz

ENV LANG=en_US.UTF-8

RUN mkdir /src
RUN set -eux \
    && curl --fail --silent --location --retry 3 ${JDK_PKG} \
    | tar -xzf- -C /src \
    && mv /src/labs-openjdk-* /src/jdk

RUN apk add bash gcc alpine-sdk autoconf file make zip\
    alsa-lib-dev cups-dev fontconfig-dev \
    libxtst-dev libxt-dev libxrender-dev libxrandr-dev \
    zlib-dev libffi-dev elfutils-dev libjpeg-turbo-dev

# JDK25 can compile JDK25 and JDK26
RUN apk add openjdk25-jdk

ENV PREFIX=/usr/lib/java
RUN cd /src/jdk \
    && bash configure \
    --prefix=${PREFIX} \
    --sysconfdir=/etc \
    --mandir=/usr/share/man \
    --infodir=/usr/share/info \
    --localstatedir=/var \
    --with-extra-cflags="-D_LARGEFILE64_SOURCE" \
    --with-extra-cxxflags="-D_LARGEFILE64_SOURCE" \
    --with-native-debug-symbols=none \
    --disable-warnings-as-errors \
    --disable-precompiled-headers \
    --enable-dtrace=no \
    --with-jvm-variants=server \
    --with-debug-level=release \
    --with-jmod-compress=zip-1 \
    && make product-bundles static-libs-bundles

RUN mkdir -p /dist${PREFIX}
RUN tar -xzf /src/jdk/build/linux-*/bundles/jdk-*-internal_linux-*-musl_bin.tar.gz --strip-components=1 -C /dist${PREFIX}
RUN tar -xzf /src/jdk/build/linux-*/bundles/jdk-*-internal_linux-*-musl_bin-static-libs.tar.gz --strip-components=1 -C /dist${PREFIX}

# =====================================================================
# Ninja
# https://github.com/ninja-build/ninja
#
# Used to build GraalVM
# =====================================================================
FROM alpine:${ALPINE_VERSION} AS ninja

RUN apk add bash gcc g++ make zip curl python3

RUN mkdir -p /src/ninja
RUN curl --fail --silent --location --retry 3 https://github.com/ninja-build/ninja/archive/refs/tags/v1.10.2.tar.gz | tar --strip-components=1 -xzf- -C /src/ninja
RUN cd /src/ninja && ./configure.py --bootstrap
RUN mkdir -p /dist/usr/bin && mv /src/ninja/ninja /dist/usr/bin/ninja

# =====================================================================
# GraalVM
# https://github.com/graalvm/mx
# https://github.com/oracle/graal
#
# Used to build native binaries. The version of this is linked closely
# to the JVM version and both must often be updated in tandem.
#
# =====================================================================
FROM alpine:${ALPINE_VERSION} AS graalvm

COPY --from=jdk /dist /
COPY --from=ninja /dist /

# Note that zlib-static and zlib-dev are _NOT_ added here because they
# are now compiled on-demand.
RUN apk add \
    bash gcc patch linux-headers make git zip \
    musl-dev curl python3

RUN mkdir -p /src/mx
RUN mkdir -p /src/graal

RUN curl --fail --silent --location --retry 3 https://github.com/izaakschroeder/mx/archive/refs/heads/zig.tar.gz \
    | tar --strip-components=1 -xzf- -C /src/mx
RUN curl --fail --silent --location --retry 3 https://github.com/oracle/graal/archive/refs/heads/master.tar.gz \
    | tar --strip-components=1 -xzf- -C /src/graal

ENV JAVA_HOME=/usr/lib/java
ENV LANG=en_US.UTF-8

# See: https://github.com/oracle/graal/blob/e4bd1eae508dec3e2020797714e92c7c8fd46b86/.github/actions/build-graalvm/action.yml#L51
ENV MX_NATIVE_IMAGES="native-image"
ENV MX_COMPONENTS="Native Image"

RUN cd /src/graal/substratevm && /src/mx/mx --native-images="${MX_NATIVE_IMAGES}" --components="${MX_COMPONENTS}" --extra-image-builder-argument='--libc=musl' --extra-image-builder-argument='--static' build

RUN mkdir -p /dist/usr/lib/graalvm
RUN GRAALVM_HOME=$(cd /src/graal/substratevm && /src/mx/mx --native-images="${MX_NATIVE_IMAGES}" --components="${MX_COMPONENTS}" graalvm-home) && mv "${GRAALVM_HOME}"/* /dist/usr/lib/graalvm

Documentation

TBD

  • Describe any documentation updates included in this pull request.
  • If no documentation updates are needed, state that explicitly.

Contributor Checklist

TBD

  • I have read the contribution guide.
  • I have the right to contribute the submitted material under the project terms.
  • I have updated tests and documentation where appropriate.
  • If I used a coding assistant, I remain responsible for the entire contribution and have reviewed it accordingly.

@oracle-contributor-agreement

Copy link
Copy Markdown

Thank you for your pull request and welcome to our community! To contribute, please sign the Oracle Contributor Agreement (OCA).
The following contributors of this PR have not signed the OCA:

To sign the OCA, please create an Oracle account and sign the OCA in Oracle's Contributor Agreement Application.

When signing the OCA, please provide your GitHub username. After signing the OCA and getting an OCA approval from Oracle, this PR will be automatically updated.

If you are an Oracle employee, please make sure that you are a member of the main Oracle GitHub organization, and your membership in this organization is public.

@oracle-contributor-agreement oracle-contributor-agreement Bot added the OCA Required At least one contributor does not have an approved Oracle Contributor Agreement. label Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OCA Required At least one contributor does not have an approved Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant