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