| 1 |
name: Cross compilers |
| 2 |
|
| 3 |
on: |
| 4 |
pull_request: |
| 5 |
types: [opened, synchronize, reopened, labeled, unlabeled] |
| 6 |
workflow_dispatch: |
| 7 |
|
| 8 |
# Restrict the GITHUB_TOKEN |
| 9 |
permissions: {} |
| 10 |
|
| 11 |
# See build.yml |
| 12 |
concurrency: |
| 13 |
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name == 'pull_request' || github.sha }} |
| 14 |
cancel-in-progress: true |
| 15 |
|
| 16 |
env: |
| 17 |
failed: 0 |
| 18 |
TESTDIR: >- |
| 19 |
C:\Бактріан🐫 |
| 20 |
STR_UTF8: >- |
| 21 |
"C:\\Бактріан🐫" |
| 22 |
STR_UTF16: >- |
| 23 |
L"C:\\\x0411\x0430\x043a\x0442\x0440\x0456\x0430\x043d\xd83d\xdc2b" |
| 24 |
EXAMPLE_PROGRAM: | |
| 25 |
let _ = |
| 26 |
Printf.printf "Version: %s\nOS: %s\nUnix: %b\nWin: %b\nCygwin: %b\n" |
| 27 |
Sys.ocaml_version Sys.os_type Sys.unix Sys.win32 Sys.cygwin |
| 28 |
COMPLIBS_PROG_X86_64: | |
| 29 |
let _ = |
| 30 |
Printf.printf "allow_unaligned_access = %b\n" Arch.allow_unaligned_access; |
| 31 |
Printf.printf "win64 = %b\n" Arch.win64 |
| 32 |
COMPLIBS_PROG_AARCH64: | |
| 33 |
let _ = |
| 34 |
Printf.printf "allow_unaligned_access = %b\n" Arch.allow_unaligned_access; |
| 35 |
Printf.printf "macosx = %b\n" Arch.macosx |
| 36 |
|
| 37 |
jobs: |
| 38 |
non-cross: |
| 39 |
if: contains(github.event.pull_request.labels.*.name, 'run-crosscompiler-tests') |
| 40 |
runs-on: ubuntu-latest |
| 41 |
steps: |
| 42 |
- name: Checkout OCaml |
| 43 |
uses: actions/checkout@v5 |
| 44 |
with: |
| 45 |
persist-credentials: false |
| 46 |
- name: Configure, build and install OCaml |
| 47 |
run: | |
| 48 |
PREFIX="$HOME/.local" |
| 49 |
echo "$PREFIX/bin" >> "$GITHUB_PATH" |
| 50 |
set -x |
| 51 |
./configure --disable-warn-error --disable-ocamldoc \ |
| 52 |
--disable-ocamltest --disable-stdlib-manpages \ |
| 53 |
--disable-dependency-generation --prefix="$PREFIX" || failed=$? |
| 54 |
if ((failed)) ; then set +x |
| 55 |
echo ; echo "::group::config.log content ($(wc -l config.log) lines)" |
| 56 |
cat config.log ; echo '::endgroup::' ; exit $failed |
| 57 |
fi |
| 58 |
make -j |
| 59 |
make install |
| 60 |
cd "$HOME" |
| 61 |
tar caf /tmp/ocaml.tar.zst .local |
| 62 |
- name: Upload Artifact |
| 63 |
uses: actions/upload-artifact@v4 |
| 64 |
with: |
| 65 |
name: non-cross-ocaml |
| 66 |
path: /tmp/ocaml.tar.zst |
| 67 |
retention-days: 1 |
| 68 |
|
| 69 |
cross-windows: |
| 70 |
runs-on: ubuntu-latest |
| 71 |
needs: non-cross |
| 72 |
steps: |
| 73 |
- name: Download Artifact |
| 74 |
uses: actions/download-artifact@v4 |
| 75 |
with: |
| 76 |
name: non-cross-ocaml |
| 77 |
- name: Install non-cross OCaml and set up environment |
| 78 |
run: | |
| 79 |
set -x |
| 80 |
tar xaf ocaml.tar.zst -C "$HOME" |
| 81 |
rm -f ocaml.tar.zst |
| 82 |
echo "$HOME/.local/bin" >> "$GITHUB_PATH" |
| 83 |
sudo apt-get update -y |
| 84 |
sudo apt-get install -y gcc-mingw-w64-x86-64 |
| 85 |
- name: Checkout OCaml |
| 86 |
uses: actions/checkout@v5 |
| 87 |
with: |
| 88 |
submodules: true |
| 89 |
persist-credentials: false |
| 90 |
- name: Configure, build and install Linux-to-Windows OCaml |
| 91 |
run: | |
| 92 |
set -x |
| 93 |
./configure --prefix="$HOME/cross" --target=x86_64-w64-mingw32 \ |
| 94 |
TARGET_LIBDIR="$TESTDIR" || failed=$? |
| 95 |
if ((failed)) ; then set +x |
| 96 |
echo ; echo "::group::config.log content ($(wc -l config.log) lines)" |
| 97 |
cat config.log ; echo '::endgroup::' ; exit $failed |
| 98 |
fi |
| 99 |
# The OOM-killer may be triggered if the number of parallel |
| 100 |
# jobs isn't limited. |
| 101 |
make crossopt -j$(nproc) |
| 102 |
make installcross |
| 103 |
ln -sr "$HOME/cross/bin/flexlink.opt.exe" "$HOME/.local/bin/flexlink" |
| 104 |
- name: Show opt.opt configuration |
| 105 |
run: | |
| 106 |
set -x |
| 107 |
$HOME/cross/bin/ocamlopt.opt.exe -config |
| 108 |
cat runtime/build_config.h |
| 109 |
- name: Cross compile a small program |
| 110 |
run: | |
| 111 |
printf %s "$EXAMPLE_PROGRAM$COMPLIBS_PROG_X86_64" > example.ml |
| 112 |
set -x |
| 113 |
cat example.ml |
| 114 |
$HOME/cross/bin/ocamlopt.opt.exe -I $HOME/cross/lib/ocaml/compiler-libs/ ocamlcommon.cmxa ocamloptcomp.cmxa example.ml -o example.exe -verbose |
| 115 |
- name: Upload Artifact |
| 116 |
uses: actions/upload-artifact@v4 |
| 117 |
with: |
| 118 |
name: windows-executable |
| 119 |
path: example.exe |
| 120 |
retention-days: 1 |
| 121 |
- name: Test cross sak |
| 122 |
run: | |
| 123 |
printf %s "$STR_UTF16" > utf16.ref |
| 124 |
printf %s "$STR_UTF8" > utf8.ref |
| 125 |
set -x |
| 126 |
runtime/sak encode-C-utf16-literal "$TESTDIR" > utf16 |
| 127 |
git diff --no-index utf16.ref utf16 |
| 128 |
runtime/sak encode-C-utf8-literal "$TESTDIR" > utf8 |
| 129 |
git diff --no-index utf8.ref utf8 |
| 130 |
|
| 131 |
run-windows: |
| 132 |
runs-on: windows-latest |
| 133 |
needs: cross-windows |
| 134 |
steps: |
| 135 |
- name: Download Artifact |
| 136 |
uses: actions/download-artifact@v4 |
| 137 |
with: |
| 138 |
name: windows-executable |
| 139 |
- name: Run example program |
| 140 |
run: | |
| 141 |
.\example.exe |
| 142 |
|
| 143 |
cross-arm-linux: |
| 144 |
runs-on: ubuntu-latest |
| 145 |
needs: non-cross |
| 146 |
steps: |
| 147 |
- name: Download Artifact |
| 148 |
uses: actions/download-artifact@v4 |
| 149 |
with: |
| 150 |
name: non-cross-ocaml |
| 151 |
- name: Install non-cross OCaml and set up environment |
| 152 |
run: | |
| 153 |
set -x |
| 154 |
tar xaf ocaml.tar.zst -C "$HOME" |
| 155 |
rm -f ocaml.tar.zst |
| 156 |
echo "$HOME/.local/bin" >> "$GITHUB_PATH" |
| 157 |
sudo apt-get update -y |
| 158 |
sudo apt-get install -y gcc-aarch64-linux-gnu qemu-user |
| 159 |
- name: Checkout OCaml |
| 160 |
uses: actions/checkout@v5 |
| 161 |
with: |
| 162 |
submodules: true |
| 163 |
persist-credentials: false |
| 164 |
- name: Configure, build and install Linux-to-Windows OCaml |
| 165 |
run: | |
| 166 |
set -x |
| 167 |
./configure --prefix="$HOME/cross" --target=aarch64-linux-gnu \ |
| 168 |
|| failed=$? |
| 169 |
if ((failed)) ; then set +x |
| 170 |
echo ; echo "::group::config.log content ($(wc -l config.log) lines)" |
| 171 |
cat config.log ; echo '::endgroup::' ; exit $failed |
| 172 |
fi |
| 173 |
make crossopt -j |
| 174 |
make installcross |
| 175 |
- name: Show opt.opt configuration |
| 176 |
run: | |
| 177 |
set -x |
| 178 |
$HOME/cross/bin/ocamlopt.opt -config |
| 179 |
cat runtime/build_config.h |
| 180 |
- name: Cross compile a small program |
| 181 |
run: | |
| 182 |
printf %s "$EXAMPLE_PROGRAM$COMPLIBS_PROG_AARCH64" > example.ml |
| 183 |
set -x |
| 184 |
cat example.ml |
| 185 |
$HOME/cross/bin/ocamlopt.opt -I $HOME/cross/lib/ocaml/compiler-libs/ ocamlcommon.cmxa ocamloptcomp.cmxa example.ml -o example -verbose |
| 186 |
- name: Run the small example program |
| 187 |
run: | |
| 188 |
set -x |
| 189 |
qemu-aarch64 -L /usr/aarch64-linux-gnu example |
| 190 |
- name: Test cross sak |
| 191 |
run: | |
| 192 |
printf %s "$STR_UTF16" > utf16.ref |
| 193 |
printf %s "$STR_UTF8" > utf8.ref |
| 194 |
set -x |
| 195 |
runtime/sak encode-C-utf16-literal "$TESTDIR" > utf16 |
| 196 |
git diff --no-index utf16.ref utf16 |
| 197 |
runtime/sak encode-C-utf8-literal "$TESTDIR" > utf8 |
| 198 |
git diff --no-index utf8.ref utf8 |
| 199 |
|
| 200 |
cross-android: |
| 201 |
runs-on: ubuntu-latest |
| 202 |
needs: non-cross |
| 203 |
env: |
| 204 |
# https://developer.android.com/ndk/downloads#lts-downloads |
| 205 |
NDK: r27d # Latest LTS Version |
| 206 |
API_LEVEL: 21 |
| 207 |
steps: |
| 208 |
- name: Download Artifact |
| 209 |
uses: actions/download-artifact@v4 |
| 210 |
with: |
| 211 |
name: non-cross-ocaml |
| 212 |
- name: Install non-cross OCaml |
| 213 |
run: | |
| 214 |
set -x |
| 215 |
tar xaf ocaml.tar.zst -C "$HOME" |
| 216 |
rm -f ocaml.tar.zst |
| 217 |
echo "$HOME/.local/bin" >> "$GITHUB_PATH" |
| 218 |
- name: Restore the Android NDK from cache |
| 219 |
uses: actions/cache/restore@v4 |
| 220 |
id: cache |
| 221 |
with: |
| 222 |
path: | |
| 223 |
/home/runner/android |
| 224 |
key: android-ndk-${{ env.NDK }} |
| 225 |
- name: Download the Android NDK |
| 226 |
run: | |
| 227 |
set -x |
| 228 |
mkdir -p "$HOME/android" |
| 229 |
cd "$HOME/android" |
| 230 |
wget --no-verbose "https://dl.google.com/android/repository/android-ndk-$NDK-linux.zip" |
| 231 |
unzip android-ndk-$NDK-linux.zip |
| 232 |
rm android-ndk-$NDK-linux.zip |
| 233 |
if: steps.cache.outputs.cache-hit != 'true' |
| 234 |
- name: Save the Android NDK to cache |
| 235 |
uses: actions/cache/save@v4 |
| 236 |
with: |
| 237 |
path: | |
| 238 |
/home/runner/android |
| 239 |
key: android-ndk-${{ env.NDK }} |
| 240 |
if: steps.cache.outputs.cache-hit != 'true' |
| 241 |
- name: Checkout OCaml |
| 242 |
uses: actions/checkout@v5 |
| 243 |
with: |
| 244 |
persist-credentials: false |
| 245 |
- name: Configure, build and install Linux-to-Android OCaml |
| 246 |
env: |
| 247 |
TARGET: x86_64-linux-android${{ env.API_LEVEL }} |
| 248 |
TOOLDIR: android-ndk-${{ env.NDK }}/toolchains/llvm/prebuilt/linux-x86_64/bin |
| 249 |
run: | |
| 250 |
DIR="$HOME/android/$TOOLDIR" |
| 251 |
set -x |
| 252 |
# Hack around the fact that pthread_cancel isn't available on Android |
| 253 |
# So the result program should _not_ be run with cleanup on exit |
| 254 |
# (so no `c=1` in `OCAMLRUNPARAM`) |
| 255 |
./configure --prefix="$HOME/cross" --target=$TARGET \ |
| 256 |
TARGET_LIBDIR="/dummy/directory" \ |
| 257 |
CC="$DIR/clang --target=$TARGET" \ |
| 258 |
CPPFLAGS='-Dpthread_cancel=assert' \ |
| 259 |
AR="$DIR/llvm-ar" \ |
| 260 |
PARTIALLD="$DIR/ld -r" \ |
| 261 |
RANLIB="$DIR/llvm-ranlib" \ |
| 262 |
STRIP="$DIR/llvm-strip" || failed=$? |
| 263 |
if ((failed)) ; then set +x |
| 264 |
echo ; echo "::group::config.log content ($(wc -l config.log) lines)" |
| 265 |
cat config.log ; echo '::endgroup::' ; exit $failed |
| 266 |
fi |
| 267 |
make crossopt -j |
| 268 |
make installcross |
| 269 |
- name: Show opt.opt configuration |
| 270 |
run: | |
| 271 |
set -x |
| 272 |
$HOME/cross/bin/ocamlopt.opt -config |
| 273 |
cat runtime/build_config.h |
| 274 |
- name: Cross compile a small program |
| 275 |
run: | |
| 276 |
printf %s "$EXAMPLE_PROGRAM" > example.ml |
| 277 |
set -x |
| 278 |
cat example.ml |
| 279 |
$HOME/cross/bin/ocamlopt.opt example.ml -o example -verbose |
| 280 |
file example |
| 281 |
- name: Run example |
| 282 |
uses: reactivecircus/android-emulator-runner@v2 |
| 283 |
with: |
| 284 |
api-level: ${{ env.API_LEVEL }} |
| 285 |
arch: x86_64 |
| 286 |
disable-animations: true |
| 287 |
script: | |
| 288 |
adb push example /data/local/tmp/example |
| 289 |
adb shell /data/local/tmp/example |