1 #
  2 # Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
  3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4 #
  5 # This code is free software; you can redistribute it and/or modify it
  6 # under the terms of the GNU General Public License version 2 only, as
  7 # published by the Free Software Foundation.  Oracle designates this
  8 # particular file as subject to the "Classpath" exception as provided
  9 # by Oracle in the LICENSE file that accompanied this code.
 10 #
 11 # This code is distributed in the hope that it will be useful, but WITHOUT
 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14 # version 2 for more details (a copy is included in the LICENSE file that
 15 # accompanied this code).
 16 #
 17 # You should have received a copy of the GNU General Public License version
 18 # 2 along with this work; if not, write to the Free Software Foundation,
 19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20 #
 21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22 # or visit www.oracle.com if you need additional information or have any
 23 # questions.
 24 #
 25 
 26 name: 'Build (cross-compile)'
 27 
 28 on:
 29   workflow_call:
 30     inputs:
 31       gcc-major-version:
 32         required: true
 33         type: string
 34       extra-conf-options:
 35         required: false
 36         type: string
 37       configure-arguments:
 38         required: false
 39         type: string
 40       make-arguments:
 41         required: false
 42         type: string
 43 
 44 jobs:
 45   build-cross-compile:
 46     name: build
 47     runs-on: ubuntu-22.04
 48 
 49     strategy:
 50       fail-fast: false
 51       matrix:
 52         target-cpu:
 53           - aarch64
 54           - arm
 55           - s390x
 56           - ppc64le
 57           - riscv64
 58         include:
 59           - target-cpu: aarch64
 60             gnu-arch: aarch64
 61             debian-arch: arm64
 62             debian-repository: https://httpredir.debian.org/debian/
 63             debian-version: bullseye
 64           - target-cpu: arm
 65             gnu-arch: arm
 66             debian-arch: armhf
 67             debian-repository: https://httpredir.debian.org/debian/
 68             debian-version: bullseye
 69             gnu-abi: eabihf
 70           - target-cpu: s390x
 71             gnu-arch: s390x
 72             debian-arch: s390x
 73             debian-repository: https://httpredir.debian.org/debian/
 74             debian-version: bullseye
 75           - target-cpu: ppc64le
 76             gnu-arch: powerpc64le
 77             debian-arch: ppc64el
 78             debian-repository: https://httpredir.debian.org/debian/
 79             debian-version: bullseye
 80           - target-cpu: riscv64
 81             gnu-arch: riscv64
 82             debian-arch: riscv64
 83             debian-repository: https://httpredir.debian.org/debian/
 84             debian-version: sid
 85 
 86     steps:
 87       - name: 'Checkout the JDK source'
 88         uses: actions/checkout@v4
 89 
 90       - name: 'Get the BootJDK'
 91         id: bootjdk
 92         uses: ./.github/actions/get-bootjdk
 93         with:
 94           platform: linux-x64
 95 
 96         # Use linux-x64 JDK bundle as build JDK
 97       - name: 'Get build JDK'
 98         id: buildjdk
 99         uses: ./.github/actions/get-bundles
100         with:
101           platform: linux-x64
102 
103       - name: 'Get GTest'
104         id: gtest
105         uses: ./.github/actions/get-gtest
106 
107         # Upgrading apt to solve libc6 installation bugs, see JDK-8260460.
108       - name: 'Install toolchain and dependencies'
109         run: |
110           # Install dependencies using apt-get
111           sudo apt-get update
112           sudo apt-get install --only-upgrade apt
113           sudo apt-get install \
114               gcc-${{ inputs.gcc-major-version }} \
115               g++-${{ inputs.gcc-major-version }} \
116               gcc-${{ inputs.gcc-major-version }}-${{ matrix.gnu-arch }}-linux-gnu${{ matrix.gnu-abi}} \
117               g++-${{ inputs.gcc-major-version }}-${{ matrix.gnu-arch }}-linux-gnu${{ matrix.gnu-abi}} \
118               libxrandr-dev libxtst-dev libcups2-dev libasound2-dev
119           sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-${{ inputs.gcc-major-version }} 100 --slave /usr/bin/g++ g++ /usr/bin/g++-${{ inputs.gcc-major-version }}
120 
121       - name: 'Check cache for sysroot'
122         id: get-cached-sysroot
123         uses: actions/cache@v3
124         with:
125           path: sysroot
126           key: sysroot-${{ matrix.debian-arch }}-${{ hashFiles('./.github/workflows/build-cross-compile.yml') }}
127 
128       - name: 'Install sysroot dependencies'
129         run: sudo apt-get install debootstrap qemu-user-static
130         if: steps.get-cached-sysroot.outputs.cache-hit != 'true'
131 
132       - name: 'Create sysroot'
133         run: >
134           sudo debootstrap
135           --arch=${{ matrix.debian-arch }}
136           --verbose
137           --include=fakeroot,symlinks,build-essential,libx11-dev,libxext-dev,libxrender-dev,libxrandr-dev,libxtst-dev,libxt-dev,libcups2-dev,libfontconfig1-dev,libasound2-dev,libfreetype-dev,libpng-dev
138           --resolve-deps
139           --variant=minbase
140           ${{ matrix.debian-version }}
141           sysroot
142           ${{ matrix.debian-repository }}
143         if: steps.get-cached-sysroot.outputs.cache-hit != 'true'
144 
145       - name: 'Prepare sysroot'
146         run: |
147           # Prepare sysroot and remove unused files to minimize cache
148           sudo chroot sysroot symlinks -cr .
149           sudo chown ${USER} -R sysroot
150           rm -rf sysroot/{dev,proc,run,sys,var}
151           rm -rf sysroot/usr/{sbin,bin,share}
152           rm -rf sysroot/usr/lib/{apt,gcc,udev,systemd}
153           rm -rf sysroot/usr/libexec/gcc
154         if: steps.get-cached-sysroot.outputs.cache-hit != 'true'
155 
156       - name: 'Configure'
157         run: >
158           bash configure
159           --with-conf-name=linux-${{ matrix.target-cpu }}
160           --with-version-opt=${GITHUB_ACTOR}-${GITHUB_SHA}
161           --with-boot-jdk=${{ steps.bootjdk.outputs.path }}
162           --with-gtest=${{ steps.gtest.outputs.path }}
163           --with-zlib=system
164           --enable-debug
165           --disable-precompiled-headers
166           --openjdk-target=${{ matrix.gnu-arch }}-linux-gnu${{ matrix.gnu-abi}}
167           --with-sysroot=sysroot
168           --with-build-jdk=${{ steps.buildjdk.outputs.jdk-path }}
169           --with-jmod-compress=zip-1
170           CC=${{ matrix.gnu-arch }}-linux-gnu${{ matrix.gnu-abi}}-gcc-${{ inputs.gcc-major-version }}
171           CXX=${{ matrix.gnu-arch }}-linux-gnu${{ matrix.gnu-abi}}-g++-${{ inputs.gcc-major-version }}
172           ${{ inputs.extra-conf-options }} ${{ inputs.configure-arguments }} || (
173           echo "Dumping config.log:" &&
174           cat config.log &&
175           exit 1)
176 
177       - name: 'Build'
178         id: build
179         uses: ./.github/actions/do-build
180         with:
181           make-target: 'hotspot ${{ inputs.make-arguments }}'
182           platform: linux-${{ matrix.target-cpu }}