Skip to content

Commit 807821f

Browse files
committed
Use dkml-target-abi-android_* to turn on Android cross-compilation
1 parent 6bf1e95 commit 807821f

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

dkml-base-compiler.opam

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,31 @@ synopsis: "OCaml cross-compiler and libraries from the DkML distribution"
1212
description:
1313
"""The DkML distribution of the OCaml bytecode and native compiler, Stdlib and the other OCaml libraries (str, unix, bigarray, etc.).
1414

15-
A cross-compiler for macOS x86_64 to macOS arm64 is included; for build consistency the regular OCaml compiler will be for
16-
x86_64 regardless of whether the build machine is Apple Silicon.
15+
The following cross-compilers have been included:
16+
- from macOS x86_64 and macOS arm64, and vice versa
17+
- from Linux x86 to the android armeabi-v7a ABI
18+
- from Linux x86_64 to either the android arm64-v8a or x86_64 ABI
1719

1820
To support cross-compilation, environment variables for compilers like CC and LDFLAGS have no effect on the 'host' ABI.
1921
The compiler for the 'host' ABI will be detected from conventional locations on the system and (for Visual Studio)
2022
from configuration stored in the DkML home directory.
2123

24+
If you use cross-compilation, you should also install the conf-dkml-cross-toolchain package
25+
so that your findlib installation recognizes the cross-compilers.
26+
27+
For Android compilation, the following opam global or switch variables are needed:
28+
- (required) ANDROID_NDK. This is the directory containing the Android NDK installation.
29+
Examples: /opt/downloaded/ndk-23.1.7779620
30+
- (optional) ANDROID_PLATFORM. The minimum API level for the Android app or library. The default varies based on the version
31+
of dkml-base-compiler, so it is best to set this. This version the default is 23.
32+
Confer: https://developer.android.com/ndk/guides/cmake#android_platform.
33+
Examples: android-23, 23, android-N, android-O_MR1
34+
2235
Advanced: Set environment variables like DKML_TARGET_ABI and DKML_COMPILE_* to do cross-compilation from the 'host' ABI
2336
to a 'target' ABI. Those variables are documented in dkml-runtime-common's crossplatform-functions.sh script.
24-
Search for: autodetect_compiler() {
37+
Search for: autodetect_compiler()
2538

26-
Install with something like:
39+
You can install dkml-base-compiler with something like:
2740
opam switch create dkml-4.14.2 '--formula="dkml-base-compiler" {>= "4.14.2~" & < "4.15.0~"}'"""
2841
maintainer: ["[email protected]"]
2942
authors: ["Diskuv, Inc. <[email protected]>"]
@@ -200,15 +213,12 @@ install: [
200213
"--disable-debug-runtime --disable-instrumented-runtime" { !dkml-option-debuginfo:installed }
201214
# Host architectures
202215
"-e%{dkml-host-abi:abi}%"
203-
# Target architectures (if cross-compiling; similar to dkml-component-staging-ocamlrun.opam)
204-
"-adarwin_x86_64=vendor/dkml-compiler/env/standard-compiler-env-to-ocaml-configure-env.sh" { dkml-host-abi:abi != "darwin_x86_64" & dkml-target-abi-darwin_x86_64:installed }
205-
"-adarwin_arm64=vendor/dkml-compiler/env/standard-compiler-env-to-ocaml-configure-env.sh" { dkml-host-abi:abi != "darwin_arm64" & dkml-target-abi-darwin_arm64:installed }
206-
# TODO: Would be nice to bundle the 3 Android cross-compilers here since they are already supported
207-
# by DkML, but I (jonahbeckford@) doubt there is an Android NDK available on the Opam hosts.
208-
# Confer: https://github.com/diskuv/diskuv-ocaml-ghmirror/runs/4831077050
209-
# Perhaps the Android NDK should just be downloaded via an 'android-option-ndk23' package? That would give control of the NDK version.
210-
# "-aandroid_arm64v8a=vendor/dkml-compiler/env/android-ndk-env-to-ocaml-configure-env.sh;android_arm64v8a=vendor/dkml-compiler/env/android-ndk-env-to-ocaml-configure-env.sh"] { dkml-target-abi-android_arm64v8a:installed }
211-
# "-aandroid_arm32v7a=vendor/dkml-compiler/env/android-ndk-env-to-ocaml-configure-env.sh" { dkml-target-abi-android_arm32v7a:installed }
216+
# Target architectures
217+
"-adarwin_x86_64=vendor/dkml-compiler/env/standard-compiler-env-to-ocaml-configure-env.sh" { dkml-host-abi:abi != "darwin_x86_64" & dkml-target-abi-darwin_x86_64:installed }
218+
"-adarwin_arm64=vendor/dkml-compiler/env/standard-compiler-env-to-ocaml-configure-env.sh" { dkml-host-abi:abi != "darwin_arm64" & dkml-target-abi-darwin_arm64:installed }
219+
"-aandroid_arm32v7a=vendor/dkml-compiler/env/android-ndk-env-to-ocaml-configure-env.sh" { dkml-target-abi-android_arm32v7a:installed }
220+
"-aandroid_arm64v8a=vendor/dkml-compiler/env/android-ndk-env-to-ocaml-configure-env.sh" { dkml-target-abi-android_arm64v8a:installed }
221+
"-aandroid_x86_64=vendor/dkml-compiler/env/android-ndk-env-to-ocaml-configure-env.sh" { dkml-target-abi-android_x86_64:installed }
212222
"-k" "vendor/dkml-compiler/env/standard-compiler-env-to-ocaml-configure-env.sh"
213223
]
214224

env/android-ndk-env-to-ocaml-configure-env.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ disambiguate_filesystem_paths
8787
# Documentation: https://developer.android.com/ndk/guides/other_build_systems
8888

8989
if [ -z "${ANDROID_NDK:-}" ]; then
90-
printf "FATAL: The ANDROID_NDK environment variable has not been defined. It is ordinarily set on macOS and Linux GitHub Actions hosts.\n" >&2
90+
printf "FATAL: The ANDROID_NDK environment variable has not been defined. If you are installing dkml-base-compiler, set the opam global or switch var 'ANDROID_NDK' so the dkml-base-compiler can set the ANDROID_NDK environment variable.\n" >&2
9191
exit 107
9292
fi
9393

0 commit comments

Comments
 (0)