1 #
  2 # Copyright (c) 2022, 2024, 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       dry-run:
 44         required: false
 45         type: boolean
 46         default: false
 47 
 48 jobs:
 49   build-cross-compile:
 50     name: build
 51     runs-on: ubuntu-22.04
 52 
 53     strategy:
 54       fail-fast: false
 55       matrix:
 56         target-cpu:
 57           - aarch64
 58           - arm
 59           - s390x
 60           - ppc64le
 61           - riscv64
 62         include:
 63           - target-cpu: aarch64
 64             gnu-arch: aarch64
 65             debian-arch: arm64
 66             debian-repository: https://httpredir.debian.org/debian/
 67             debian-version: trixie
 68             tolerate-sysroot-errors: false
 69           - target-cpu: arm
 70             gnu-arch: arm
 71             debian-arch: armhf
 72             debian-repository: https://httpredir.debian.org/debian/
 73             debian-version: trixie
 74             tolerate-sysroot-errors: false
 75             gnu-abi: eabihf
 76           - target-cpu: s390x
 77             gnu-arch: s390x
 78             debian-arch: s390x
 79             debian-repository: https://httpredir.debian.org/debian/
 80             debian-version: trixie
 81             tolerate-sysroot-errors: false
 82           - target-cpu: ppc64le
 83             gnu-arch: powerpc64le
 84             debian-arch: ppc64el
 85             debian-repository: https://httpredir.debian.org/debian/
 86             debian-version: trixie
 87             tolerate-sysroot-errors: false
 88           - target-cpu: riscv64
 89             gnu-arch: riscv64
 90             debian-arch: riscv64
 91             debian-repository: https://httpredir.debian.org/debian/
 92             debian-version: trixie
 93             tolerate-sysroot-errors: false
 94 
 95     steps:
 96       - name: 'Checkout the JDK source'
 97         uses: actions/checkout@v4
 98 
 99       - name: 'Get the BootJDK'
100         id: bootjdk
101         uses: ./.github/actions/get-bootjdk
102         with:
103           platform: linux-x64
104 
105       - name: 'Get GTest'
106         id: gtest
107         uses: ./.github/actions/get-gtest
108 
109         # Upgrading apt to solve libc6 installation bugs, see JDK-8260460.
110       - name: 'Install toolchain and dependencies'
111         run: |
112           # Install dependencies using apt-get
113           sudo apt-get update
114           sudo apt-get install --only-upgrade apt
115           sudo apt-get install \
116               gcc-${{ inputs.gcc-major-version }} \
117               g++-${{ inputs.gcc-major-version }} \
118               gcc-${{ inputs.gcc-major-version }}-${{ matrix.gnu-arch }}-linux-gnu${{ matrix.gnu-abi}} \
119               g++-${{ inputs.gcc-major-version }}-${{ matrix.gnu-arch }}-linux-gnu${{ matrix.gnu-abi}} \
120               libxrandr-dev libxtst-dev libcups2-dev libasound2-dev
121           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 }}
122 
123       - name: 'Check cache for sysroot'
124         id: get-cached-sysroot
125         uses: actions/cache@v4
126         with:
127           path: sysroot
128           key: sysroot-${{ matrix.debian-arch }}-${{ hashFiles('./.github/workflows/build-cross-compile.yml') }}
129 
130       - name: 'Install sysroot dependencies'
131         run: sudo apt-get install debootstrap qemu-user-static
132         if: steps.get-cached-sysroot.outputs.cache-hit != 'true'
133 
134       - name: 'Create sysroot'
135         id: create-sysroot
136         run: >
137           sudo debootstrap
138           --no-merged-usr
139           --arch=${{ matrix.debian-arch }}
140           --verbose
141           --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
142           --resolve-deps
143           --variant=minbase
144           ${{ matrix.debian-version }}
145           sysroot
146           ${{ matrix.debian-repository }}
147         continue-on-error: ${{ matrix.tolerate-sysroot-errors }}
148         if: steps.get-cached-sysroot.outputs.cache-hit != 'true'
149 
150       - name: 'Prepare sysroot'
151         run: |
152           # Prepare sysroot and remove unused files to minimize cache
153           sudo chroot sysroot symlinks -cr .
154           sudo chown ${USER} -R sysroot
155           rm -rf sysroot/{dev,proc,run,sys,var}
156           rm -rf sysroot/usr/{sbin,bin,share}
157           rm -rf sysroot/usr/lib/{apt,gcc,udev,systemd}
158           rm -rf sysroot/usr/libexec/gcc
159           # /{bin,sbin,lib}/ are not symbolic links to /usr/{bin,sbin,lib}/ when debootstrap with --no-merged-usr
160           rm -rf sysroot/{sbin,bin}
161           rm -rf sysroot/lib/{udev,systemd}
162         if: steps.create-sysroot.outcome == 'success' && steps.get-cached-sysroot.outputs.cache-hit != 'true'
163 
164       - name: 'Remove broken sysroot'
165         run: |
166           sudo rm -rf sysroot/
167         if: steps.create-sysroot.outcome != 'success' && steps.get-cached-sysroot.outputs.cache-hit != 'true'
168 
169       - name: 'Configure'
170         run: >
171           bash configure
172           --with-conf-name=linux-${{ matrix.target-cpu }}
173           --with-version-opt=${GITHUB_ACTOR}-${GITHUB_SHA}
174           --with-boot-jdk=${{ steps.bootjdk.outputs.path }}
175           --with-gtest=${{ steps.gtest.outputs.path }}
176           --with-zlib=system
177           --enable-debug
178           --disable-precompiled-headers
179           --openjdk-target=${{ matrix.gnu-arch }}-linux-gnu${{ matrix.gnu-abi}}
180           --with-sysroot=sysroot
181           --with-jmod-compress=zip-1
182           CC=${{ matrix.gnu-arch }}-linux-gnu${{ matrix.gnu-abi}}-gcc-${{ inputs.gcc-major-version }}
183           CXX=${{ matrix.gnu-arch }}-linux-gnu${{ matrix.gnu-abi}}-g++-${{ inputs.gcc-major-version }}
184           ${{ inputs.extra-conf-options }} ${{ inputs.configure-arguments }} || (
185           echo "Dumping config.log:" &&
186           cat config.log &&
187           exit 1)
188         if: steps.create-sysroot.outcome == 'success' || steps.get-cached-sysroot.outputs.cache-hit == 'true'
189 
190       - name: 'Build'
191         id: build
192         uses: ./.github/actions/do-build
193         with:
194           make-target: 'hotspot ${{ inputs.make-arguments }}'
195           platform: linux-${{ matrix.target-cpu }}
196         if: ((steps.create-sysroot.outcome == 'success' || steps.get-cached-sysroot.outputs.cache-hit == 'true') && inputs.dry-run == false)