Skip to content

Commit 75b4c6e

Browse files
Add native build to CI
1 parent 0f9813c commit 75b4c6e

File tree

7 files changed

+166
-67
lines changed

7 files changed

+166
-67
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
name: Build native image
2+
defaults:
3+
run:
4+
shell: bash -euo pipefail -O nullglob {0}
5+
on:
6+
workflow_dispatch:
7+
inputs:
8+
ref:
9+
type: string
10+
description: "Git ref from which to release"
11+
required: true
12+
default: "master"
13+
workflow_call:
14+
inputs:
15+
ref:
16+
type: string
17+
description: "Git ref from which to release"
18+
required: true
19+
default: "master"
20+
env:
21+
INPUT_REF: ${{ github.event.inputs.ref }}
22+
23+
jobs:
24+
build_native_images:
25+
name: Build native test server
26+
strategy:
27+
fail-fast: false
28+
matrix:
29+
include:
30+
- runner: ubuntu-latest
31+
os_family: linux
32+
arch: amd64
33+
musl: true
34+
- runner: ubuntu-latest
35+
os_family: linux
36+
arch: amd64
37+
musl: false
38+
- runner: macos-13
39+
os_family: macOS
40+
arch: amd64
41+
- runner: macos-latest
42+
os_family: macOS
43+
arch: arm64
44+
- runner: ubuntu-24.04-arm
45+
os_family: linux
46+
arch: arm64
47+
- runner: windows-latest
48+
os_family: windows
49+
arch: amd64
50+
runs-on: ${{ matrix.runner }}
51+
steps:
52+
- name: Checkout repo
53+
uses: actions/checkout@v4
54+
with:
55+
fetch-depth: 0
56+
submodules: recursive
57+
ref: ${{ env.INPUT_REF }}
58+
59+
- name: Set up Java
60+
if: matrix.os_family != 'Linux'
61+
uses: actions/setup-java@v4
62+
with:
63+
java-version: "21"
64+
distribution: "graalvm"
65+
66+
- name: Set up Gradle
67+
if: matrix.os_family != 'Linux'
68+
uses: gradle/actions/setup-gradle@v4
69+
70+
- name: Build native test server (non-Docker)
71+
if: matrix.os_family != 'Linux'
72+
run: |
73+
./gradlew -PnativeBuild :temporal-test-server:nativeCompile
74+
75+
- name: Build native test server (Docker non-musl)
76+
if: matrix.os_family == 'Linux' && matrix.musl == false
77+
run: |
78+
docker run \
79+
--rm -w /github/workspace -v "$(pwd):/github/workspace" \
80+
$(docker build -q ./docker/native-image) \
81+
sh -c "./gradlew -PnativeBuild :temporal-test-server:nativeCompile"
82+
83+
- name: Build native test server (Docker musl)
84+
if: matrix.os_family == 'Linux' && matrix.musl == true
85+
run: |
86+
docker run \
87+
--rm -w /github/workspace -v "$(pwd):/github/workspace" \
88+
$(docker build -q ./docker/native-image-musl) \
89+
sh -c "./gradlew -PnativeBuild -PnativeBuildMusl :temporal-test-server:nativeCompile"
90+
# path ends in a wildcard because on windows the file ends in '.exe'
91+
- name: Upload executable to workflow
92+
uses: actions/upload-artifact@v4
93+
with:
94+
name: ${{ matrix.musl && format('{0}_{1}_musl', matrix.os_family, matrix.arch) || format('{0}_{1}', matrix.os_family, matrix.arch)}}
95+
path: |
96+
temporal-test-server/build/native/nativeCompile/temporal-test-server*
97+
if-no-files-found: error
98+
retention-days: 1
99+

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,9 @@ jobs:
188188

189189
- name: Run copyright and code format checks
190190
run: ./gradlew --no-daemon checkLicenseMain checkLicenses spotlessCheck
191+
192+
build_native_images:
193+
name: Build native test server
194+
uses: ./.github/workflows/build-native-image.yml
195+
with:
196+
ref: ${{ github.event.pull_request.head.sha }}

.github/workflows/prepare-release.yml

Lines changed: 3 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -124,70 +124,9 @@ jobs:
124124
name: Build native test server
125125
needs: create_draft_release
126126
if: github.event.inputs.do_build_native_images == 'true'
127-
strategy:
128-
fail-fast: false
129-
matrix:
130-
include:
131-
- runner: ubuntu-latest
132-
os_family: linux
133-
arch: amd64
134-
- runner: macos-13
135-
os_family: macOS
136-
arch: amd64
137-
- runner: macos-latest
138-
os_family: macOS
139-
arch: arm64
140-
- runner: ubuntu-24.04-arm
141-
os_family: linux
142-
arch: arm64
143-
- runner: windows-2019
144-
os_family: windows
145-
arch: amd64
146-
runs-on: ${{ matrix.runner }}
147-
steps:
148-
- name: Checkout repo
149-
uses: actions/checkout@v4
150-
with:
151-
submodules: recursive
152-
ref: ${{ env.INPUT_REF }}
153-
154-
# See comment on temporary tag above. tldr: this is a local tag; never
155-
# gets pushed
156-
- name: Temporary tag
157-
run: git tag "$INPUT_TAG"
158-
159-
- name: Set up Java
160-
if: matrix.os_family != 'Linux'
161-
uses: actions/setup-java@v4
162-
with:
163-
java-version: "21"
164-
distribution: "graalvm"
165-
166-
- name: Set up Gradle
167-
if: matrix.os_family != 'Linux'
168-
uses: gradle/actions/setup-gradle@v4
169-
170-
- name: Build native test server (non-Docker)
171-
if: matrix.os_family != 'Linux'
172-
run: |
173-
./gradlew -PnativeBuild :temporal-test-server:nativeBuild
174-
175-
- name: Build native test server (Docker)
176-
if: matrix.os_family == 'Linux'
177-
run: |
178-
docker run \
179-
--rm -w /github/workspace -v "$(pwd):/github/workspace" \
180-
$(docker build -q ./docker/native-image) \
181-
sh -c "./gradlew -PnativeBuild :temporal-test-server:nativeBuild"
182-
# path ends in a wildcard because on windows the file ends in '.exe'
183-
- name: Upload executable to workflow
184-
uses: actions/upload-artifact@v4
185-
with:
186-
name: ${{ matrix.os_family }}_${{ matrix.arch }}
187-
path: |
188-
temporal-test-server/build/native/nativeCompile/temporal-test-server*
189-
if-no-files-found: error
190-
retention-days: 1
127+
uses: ./.github/workflows/build-native-image.yml
128+
with:
129+
ref: ${{ github.event.inputs.ref }}
191130

192131
attach_to_release:
193132
name: Attach native executables to release

docker/native-image-musl/dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Use an old version of Ubuntu to build the test server to maintain compatibility with
2+
# older versions of glibc, specifically glib 2.17.
3+
FROM ubuntu:18.04
4+
ENV JAVA_HOME=/usr/lib64/graalvm/graalvm-community-java21
5+
COPY --from=ghcr.io/graalvm/native-image-community:21 $JAVA_HOME $JAVA_HOME
6+
ENV PATH="${JAVA_HOME}/bin:${PATH}"
7+
RUN apt-get update
8+
RUN apt-get install -y git build-essential curl
9+
COPY install-musl.sh /opt/install-musl.sh
10+
RUN chmod +x /opt/install-musl.sh
11+
WORKDIR /opt
12+
# We need to build musl and zlibc with musl to for a static build
13+
# See https://www.graalvm.org/21.3/reference-manual/native-image/StaticImages/index.html
14+
RUN ./install-musl.sh
15+
ENV MUSL_HOME=/opt/musl-toolchain
16+
ENV PATH="$MUSL_HOME/bin:$PATH"
17+
# Avoid errors like: "fatal: detected dubious ownership in repository"
18+
RUN git config --global --add safe.directory '*'
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Specify an installation directory for musl:
2+
export MUSL_HOME=$PWD/musl-toolchain
3+
4+
# Download musl and zlib sources:
5+
curl -O https://musl.libc.org/releases/musl-1.2.5.tar.gz
6+
curl -O https://zlib.net/fossils/zlib-1.2.13.tar.gz
7+
8+
# Build musl from source
9+
tar -xzvf musl-1.2.5.tar.gz
10+
cd musl-1.2.5
11+
./configure --prefix=$MUSL_HOME --static
12+
# The next operation may require privileged access to system resources, so use sudo
13+
make && make install
14+
cd ..
15+
16+
# Install a symlink for use by native-image
17+
ln -s $MUSL_HOME/bin/musl-gcc $MUSL_HOME/bin/x86_64-linux-musl-gcc
18+
19+
# Extend the system path and confirm that musl is available by printing its version
20+
export PATH="$MUSL_HOME/bin:$PATH"
21+
x86_64-linux-musl-gcc --version
22+
23+
# Build zlib with musl from source and install into the MUSL_HOME directory
24+
tar -xzvf zlib-1.2.13.tar.gz
25+
cd zlib-1.2.13
26+
CC=musl-gcc ./configure --prefix=$MUSL_HOME --static
27+
make && make install
28+
cd ..

docker/native-image/dockerfile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22
# older versions of glibc, specifically glib 2.17.
33
FROM ubuntu:18.04
44
ENV JAVA_HOME=/usr/lib64/graalvm/graalvm-community-java21
5-
COPY --from=ghcr.io/graalvm/jdk-community:21 $JAVA_HOME $JAVA_HOME
5+
COPY --from=ghcr.io/graalvm/native-image-community:21 $JAVA_HOME $JAVA_HOME
66
ENV PATH="${JAVA_HOME}/bin:${PATH}"
7+
RUN apt-get update && apt-get install -y software-properties-common
8+
RUN add-apt-repository ppa:ubuntu-toolchain-r/test
79
RUN apt-get update
8-
RUN apt-get install -y git build-essential zlib1g-dev
10+
# We need to update gcc and g++ to 10 for Graal to work on ARM64
11+
RUN apt-get install -y git build-essential zlib1g-dev gcc-10 g++-10
12+
RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 60 --slave /usr/bin/g++ g++ /usr/bin/g++-10
913
# Avoid errors like: "fatal: detected dubious ownership in repository"
1014
RUN git config --global --add safe.directory '*'

temporal-test-server/build.gradle

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,12 @@ if (project.hasProperty("nativeBuild")) {
120120
// If we're on linux, static link everything but libc. Otherwise link
121121
// everything dynamically (note the '-' rather than '+' in front of
122122
// StaticExecutable)
123-
buildArgs.add(isLinux() ? "-H:+StaticExecutableWithDynamicLibC": "-H:-StaticExecutable")
123+
if (isLinux() && !project.hasProperty("nativeBuildMusl")) {
124+
buildArgs.add("-H:+StaticExecutableWithDynamicLibC")
125+
} else if (isLinux() && project.hasProperty("nativeBuildMusl")) {
126+
buildArgs.add("--static")
127+
buildArgs.add("--libc=musl")
128+
}
124129
buildArgs.add("-H:+UnlockExperimentalVMOptions")
125130
buildArgs.add("-O4")
126131

0 commit comments

Comments
 (0)