{"id":18841926,"url":"https://github.com/diskuv/dkml-compiler","last_synced_at":"2026-01-30T15:30:17.968Z","repository":{"id":43778584,"uuid":"466587948","full_name":"diskuv/dkml-compiler","owner":"diskuv","description":"OCaml compiler from the DKML distribution","archived":false,"fork":false,"pushed_at":"2024-03-16T17:43:45.000Z","size":674,"stargazers_count":0,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-03-17T09:57:27.407Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/diskuv.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2022-03-05T23:09:07.000Z","updated_at":"2024-04-15T07:00:11.203Z","dependencies_parsed_at":"2023-02-12T08:15:18.225Z","dependency_job_id":"d38bd449-8e64-45ea-b0c7-f90d9b834574","html_url":"https://github.com/diskuv/dkml-compiler","commit_stats":null,"previous_names":[],"tags_count":126,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diskuv%2Fdkml-compiler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diskuv%2Fdkml-compiler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diskuv%2Fdkml-compiler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diskuv%2Fdkml-compiler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/diskuv","download_url":"https://codeload.github.com/diskuv/dkml-compiler/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239780120,"owners_count":19695734,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T02:53:03.365Z","updated_at":"2025-02-20T04:42:55.663Z","avatar_url":"https://github.com/diskuv.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dkml-compiler\n\nPOSIX Bourne shell scripts to compile the DkML distribution of OCaml.\n\nThe OCaml patches in [src/p](src/p) are dual-licensed under the [OCaml flavor of the LGPL 2.1 license](./LICENSE-LGPL21-ocaml)\nand the permissive [Apache 2.0 license](./LICENSE-Apache2).\nAll other source code including the shell scripts are released solely under the permissive [Apache 2.0 license](./LICENSE-Apache2).\n\nThere is also a `dkml-base-compiler.opam` that always compiles the latest\nDkML supported compiler. However you can choose an older version by\nadding an older version of [diskuv-opam-repository](https://github.com/diskuv/diskuv-opam-repository#readme)\nto your Opam switch.\n\nThe `diskuv-opam-repository` is also necessary if you want to use a DkML\nversion of the OCaml 4.x compiler on a non-Windows machine. The central Opam\nrepository only introduced the DkML distribution in OCaml 5.x generally and\nOCaml 4.14 for Windows specifically.\n\n## Quick Start\n\n### Android Cross-Compiler\n\nNOTE 1: There are a couple major patches done by DkML to the OCaml compiler to support Android 32-bit. And the cross-compiler support is not standard (or supported) in the official OCaml compiler. Do not expect to replicate these instructions using the generic OCaml compiler.\n\nNOTE 2: We'll use a Docker container for convenience with Windows and macOS users, and also because it is easy to get the Android NDK from CircleCI, but you can do this directly on a Linux machine.\n\nNOTE 3: Since Apple Silicon does not support 32-bit, and since cross-compiling OCaml requires the same bitness\nfor the build machine and the target machine, Apple Silicon users cannot compile [Android `armeabi-v7a`](https://developer.android.com/ndk/guides/abis)\n(aka. DkML `android_arm32v7a`).\n\n```console\n$ docker run -it --rm cimg/android:2024.10.1-ndk\n\n# Install opam if you don't have it\ncircleci:~/project$ sudo apt-get update \u0026\u0026 sudo apt-get install build-essential curl git patch rsync unzip -y\ncircleci:~/project$ echo /usr/local/bin | sudo bash -c \"sh \u003c(curl -fsSL https://opam.ocaml.org/install.sh) --version 2.2.1\"\n\n# Initialize opam if you haven't already. No sandboxing is needed in containers.\ncircleci:~/project$ opam init --cli=2.1 --no-setup --bare --disable-sandboxing\n\n# Two Android options to set. ANDROID_PLATFORM is the minimum API level (\"targetSdkVersion\" in the Android manifest)\ncircleci:~/project$ opam var --cli=2.1 --global ANDROID_NDK=/home/circleci/android-sdk/ndk/27.1.12297006\ncircleci:~/project$ opam var --cli=2.1 --global ANDROID_PLATFORM=android-34\n\n# PICK ONE: Android arm64-v8a switch\ncircleci:~/project$ opam switch create android34-ndk27-arm64-v8a --cli=2.1 \\\n  --packages dkml-base-compiler,dkml-host-abi-linux_x86_64,dkml-target-abi-android_arm64v8a,ocamlfind,conf-dkml-cross-toolchain \\\n  --repos default,diskuv-4d79e732=git+https://github.com/diskuv/diskuv-opam-repository.git#4d79e732\n\n# PICK ONE: Android armeabi-v7a switch. You will need a 32-bit C/C++ compiler.\ncircleci:~/project$ sudo apt-get install gcc-multilib g++-multilib -y\ncircleci:~/project$ opam switch create android34-ndk27-armeabi-v7a --cli=2.1 \\\n  --packages dkml-base-compiler,dkml-host-abi-linux_x86,dkml-target-abi-android_arm32v7a,ocamlfind,conf-dkml-cross-toolchain \\\n  --repos default,diskuv-4d79e732=git+https://github.com/diskuv/diskuv-opam-repository.git#4d79e732\n\n# PICK ONE: Android x86_64 switch\ncircleci:~/project$ opam switch create android34-ndk27-x86_64 --cli=2.1 \\\n  --packages dkml-base-compiler,dkml-host-abi-linux_x86_64,dkml-target-abi-android_x86_64,ocamlfind,conf-dkml-cross-toolchain \\\n  --repos default,diskuv-4d79e732=git+https://github.com/diskuv/diskuv-opam-repository.git#4d79e732\n\n# THEN: Get and cross-compile your source code. Here we use Dune and assume 'android34-ndk27-arm64-v8a'\ncircleci:~/project$ opam install --cli=2.1 --switch android34-ndk27-arm64-v8a dune\ncircleci:~/project$ git clone https://github.com/avsm/hello-world-action-ocaml hello\ncircleci:~/project$ cd hello\ncircleci:~/project/hello$ opam exec --cli=2.1 --switch android34-ndk27-arm64-v8a -- dune build -x android_arm64v8a world.exe\ncircleci:~/project/hello$ file _build/default*/world.exe\n_build/default.android_arm64v8a/world.exe: ELF 64-bit LSB pie executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /system/bin/linker64, with debug_info, not stripped\n_build/default/world.exe:                  ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=1731ad9ce0fdeff69df28af0b1217e843eabe26e, for GNU/Linux 3.2.0, with debug_info, not stripped\n\n# You can also directly use the ocamlfind -toolchain\ncircleci:~/project$ opam exec --cli=2.1 --switch android34-ndk27-arm64-v8a -- ocamlfind ocamlc -config-var native_c_compiler\ngcc -O2 -fno-strict-aliasing -fwrapv -pthread -fPIC  -D_FILE_OFFSET_BITS=64\ncircleci:~/project$ opam exec --cli=2.1 --switch android34-ndk27-arm64-v8a -- ocamlfind -toolchain android_arm64v8a ocamlc -config-var native_c_compiler\n/home/circleci/android-sdk/ndk/27.1.12297006/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android34-clang -O2 -fno-strict-aliasing -fwrapv -pthread -fPIC  -D_FILE_OFFSET_BITS=64\n```\n\nDkML supports three out of the four supported Android ABIs.\nThe three ABIs (all but `x86`) were chosen based on [statistics for a large game on Aug 29, 2023](https://github.com/android/ndk/issues/1772#issuecomment-1697831518):\n\n| Arch        | Percent |\n| ----------- | ------- |\n| arm64-v8a   | 68.66   |\n| armeabi-v7a | 30.38   |\n| x86_64      | 0.71    |\n| x86         | 0.26    |\n\nand also [Google's recommendation](https://android-developers.googleblog.com/2022/10/64-bit-only-devices.html):\n\n\u003e **Note**: While 64-bit-only devices will grow in popularity with phones joining Android Auto in this group, 32-bit-only devices will continue to be important for Android Go, Android TV, and Android Wear. Please continue supporting 32-bit ABIs; Google Play will continue serving 32-bit apps to 32-bit-only devices.\n\n---\n\nFinally, a word of **CAUTION**. The Android cross-compiler **can never** use OCaml 5+ because [OCaml 5 will never bring back the 32-bit instruction set](https://discuss.ocaml.org/t/32-bit-native-code-support-for-ocaml-5/12583/13?u=jbeckford). That means if you don't want to drop a large percent of your users or drop new Android categories over the next five (?) years, you will have a critical dependency on DkML.\n\n## Directory Structure\n\n### Build Directories\n\n| Path                               | Description                                                        |\n| ---------------------------------- | ------------------------------------------------------------------ |\n| `dl/*.tar.gz`                      | Opam extra-source downloads                                        |\n| `dl/ocaml`                         | Unpatched OCaml source from `dl/ocaml.tar.gz`                      |\n| `dl/ocaml/flexdll`                 | Unpatched flexdll source from `dl/flexdll.tar.gz`                  |\n| `dkmldir/.dkmlroot`                | Properties file with the version of DkML based on the Opam version |\n| `dkmldir/vendor/dkml-compiler/src` | A copy of the toplevel `src/`                                      |\n| `dkmldir/vendor/drc`               | Source from `dl/dkml-runtime-common.tar.gz`                        |\n\n### Opam Directories\n\n| Path                                                                  | Description                                 |\n| --------------------------------------------------------------------- | ------------------------------------------- |\n| `$(opam var prefix)/src-ocaml`                                        | OCaml source patched for the host ABI       |\n| `$(opam var prefix)/bin`                                              | OCaml host ABI binaries. Ex. `ocamlopt`     |\n| `$(opam var prefix)/lib/ocaml`                                        | OCaml host ABI libraries. Ex. `unix.cmxa`   |\n| `$(opam var prefix)/share/dkml-base-compiler/mlcross/\u003cABI\u003e/src-ocaml` | OCaml source patched for the target ABI     |\n| `$(opam var prefix)/share/dkml-base-compiler/mlcross/\u003cABI\u003e/bin`       | OCaml target ABI binaries. Ex. `ocamlopt`   |\n| `$(opam var prefix)/share/dkml-base-compiler/mlcross/\u003cABI\u003e/lib/ocaml` | OCaml target ABI libraries. Ex. `unix.cmxa` |\n\nAll ABI names are compatible with [dkml-c-probe](https://github.com/diskuv/dkml-c-probe#readme).\nThe target ABI folders will not be present if DkML does not support cross-compiling\non the host ABI. Currently only macOS has a target ABI.\n\nThere is another Opam package [conf-dkml-cross-toolchain](https://github.com/diskuv/conf-dkml-cross-toolchain)\nthat can take the \"mlcross\" Opam directory structure and add it to\n`findlib` so that `ocamlfind -toolchain \u003cABI\u003e` and `dune build -x \u003cABI\u003e` work.\n\n## Developing\n\nFirst run `with-dkml make local-install` on DkML on Windows, or\n`make local-install` on other platforms, to install the compiler in\na local opam switch using an in-place build.\n\nAs a useful side-effect, the in-place build recreates the\n[build directories](#build-directories) that `dkml-base-compiler.opam`\nassembles. Even if the `make local-install` fails to build a working OCaml\ncompiler, you still have all the directories ready for local development.\n\nMore developer documentation is in [DEVELOPING.md](./DEVELOPING.md).\n\n### Patching\n\nIn what follows, `VER` is a placeholder for the OCaml major version (ex. `4`)\n*and* for the OCaml major+minor version in underscore formatting (ex. `4_12`).\nThe major version patches are applied first, and then the major+minor version\npatches are applied.\n\nThe patches are all available in `src/p/`.\n\n* The OCaml source patched for the host ABI uses `ocaml-common-VER-*.patch` in lexographical order\n  and `ocaml-host-VER-*.patch` in lexographical order.\n* The OCaml source patched for the target ABI uses `ocaml-common-VER-*.patch` in lexographical order\n  and `ocaml-target-VER-*.patch` in lexographical order.\n\nIt is important to realize that patches are applied in a particular order, and\nto structure the patches so they are more or less independent of each other.\n\n**When you make a patch**, you should consult the [Opam directory structure table](#opam-directories)\nand do a `git log` in the `OCaml source patched ...` directories. You must also run\n`./dk user.reindex` in a Unix shell or PowerShell.\n\n## Optimization\n\nIf we have a prebuilt `ocamlc.opt` for an architecture ... possibly and likely for an old version of\nOCaml, it is used to save some initial bootstrapping time during `ocaml install dkml-base-compiler`.\n\nNote that the prebuilt `ocamlc.opt` is optional. If it doesn't exist, then some extra time is spent\nduring `opam install`. This optionality allows for:\n\n1. Let's `dkml-base-compiler` build in CI.\n2. Then `ocamlc.opt` can be saved forever as a CI release artifact.\n3. Then `ocamlc.opt` can be used for all new compiler builds by modifying the download links in\n   `dkml-base-compiler.opam`.\n\n## Status\n\n[![Syntax check](https://github.com/diskuv/dkml-compiler/actions/workflows/syntax.yml/badge.svg)](https://github.com/diskuv/dkml-compiler/actions/workflows/syntax.yml)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiskuv%2Fdkml-compiler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdiskuv%2Fdkml-compiler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiskuv%2Fdkml-compiler/lists"}