{"owner":"bbatsov","repo":"ocaml","hasSkills":true,"totalSkillsCount":1,"totalTokensCount":2148,"categories":["anthropic-skill"],"hasMcp":false,"mcpConfig":null,"found":["tools/opam/Layout.md"],"skills":{"tools/opam/Layout.md":"# OCaml opam packaging\n\nUsers in opam primarily see the OCaml compiler through the `ocaml` package. For\nexample, installing the [ocaml.5.4.0](https://ocaml.org/p/ocaml/5.4.0) package\nin a switch succeeds if and only if OCaml 5.4.0 (or some variant of it) is\navailable in the opam switch.\n\nThere are various additional packages which assist in the process:\n- `ocaml-compiler` contains the actual build instructions and is responsible for\n  configuring and building a compiler from sources.\n- `ocaml-system` is available if the user has installed OCaml outside of opam\n  and made it available in PATH. For example, if `/usr/bin/ocaml` is an\n  installation of OCaml 5.4.0, then `ocaml-system.5.4.0` can be installed.\n- `arch-*` and `system-*` are meta-packages used to control exactly which\n  architecture and C compiler ecosystem are targetted by the compiler (at\n  present these are only used for Windows).\n- `ocaml-option-*` are meta-packages used to control features of the compiler,\n  for example whether frame pointers are used ([ocaml-option-fp](https://ocaml.org/p/ocaml-option-fp/latest))\n  or the flambda optimizer enabled ([ocaml-option-flambda](https://ocaml.org/p/ocaml-option-flambda/latest)).\n- `ocaml-options-vanilla` and `ocaml-options-only-*` are additional\n  meta-packages used to aid creation of switches with fixed specific options.\n  `ocaml-options-vanilla` is the \"default\" build of OCaml with no additional\n  options set. `ocaml-options-only-flambda`, for example, creates a switch with\n  the flambda optimizer enabled, but which prohibits the reconfiguration of the\n  compiler with different options. The idea behind these packages is that if\n  they are used when creating a switch, for example by running\n  `opam switch create release-builds ocaml-options-only-flambda ocaml.5.4.0`,\n  then packages which _conflict_ `ocaml-option-flambda` for some reason will be\n  rejected, rather than causing the compiler to be rebuilt with flambda support\n  disabled.\n- `ocaml-base-compiler` is a meta-package which builds OCaml sources and depends\n  on `ocaml-options-vanilla` - i.e. it installs an altered OCaml compiler.\n- `ocaml-variants` was used extensively prior to OCaml 4.12 when the\n  ocaml-option- packages were introduced for alternate configurations (for\n  example, `ocaml-variants.4.11.0+flambda` provided OCaml 4.11.0 with the\n  flambda optimizer enabled). It was also, and still is, used for experimental\n  branches of OCaml (e.g. MetaOCaml, Multicore OCaml, OxCaml, etc.)\n- `host-arch-*` and `host-system-*` are work-in-progress meta-packages which\n  _indicate_ which architecture and system the compiler targets. Their purpose\n  is to allow other packages in opam-repository to indicate a requirement or a\n  conflict with a given architecture or system.\n- `base-*` are similarly applied for some compiler features. For example,\n  [base-nnp](https://ocaml.org/p/base-nnp/latest) is installed with any compiler\n  which does not permit naked pointers in the heap (i.e. OCaml 5.x or 4.x when\n  [ocaml-option-nnp](https://ocaml.org/p/ocaml-option-nnp/latest) has been\n  installed).\n- `ocaml-beta` is a single package used to prevent accidental installation of\n  pre-release compilers when using opam 2.0.\n- `ocaml-config` packaged the tools/opam/gen\\_ocaml\\_config.ml script, but is no\n  longer required.\n- `flexdll` and `winpthreads` are source-installing packages which provide the\n  source code, when required, for the flexdll and winpthreads submodules when\n  compiling OCaml on Windows.\n\n## Scripts\n\n### `gen_ocaml_config.ml`\n\nPackages in opam are able to set variables as part of their build process; the\n`ocaml` package defines six:\n- `native` (boolean): indicates that `ocamlopt` is available\n- `native-tools` (boolean): indicates that the ocamlopt-compiled versions of\n  tools are available (`ocamlc.opt`, `ocamlopt.opt`, etc.)\n- `native-dynlink` (boolean): indicates that `dynlink.cmxa` is available\n- `stubsdir` (string): contains the lines of `ld.conf` presented in a format\n  suitable for `CAML_LD_LIBRARY_PATH`\n- `preinstalled` (boolean): is true if the `ocaml-system` package provided the\n  compiler (i.e. if OCaml is being used from an installation outside of opam)\n- `compiler` (string): OPAM 1.x derived value reflecting the name of the switch\n  based on the compiler's version. This is largely a legacy value, and is\n  essentially either \"system\" (if the ocaml-system package provided the\n  compiler) or the compiler version (e.g. \"5.4.0\"), otherwise.\n\nThis script is used by the `ocaml` package to generate the file `ocaml.config`\nwhen the `ocaml` package is installed.\n\nHistorically, this file lived in opam-repository itself, and was installed as a\nscript by the `ocaml-config` package and then used by each of the `ocaml`\npackages. opam-repository no longer stores files directly in its repo, but the\nscript is still downloaded from this repository by the `ocaml` package.\n\n### `gen_ocaml-system_config.ml`\n\nThis script is used by the `ocaml-system` package to generate the file\n`ocaml-system.config` when using a compiler which has been installed outside of\nopam. It works in a similar way to `gen_ocaml_config.ml`. `ocaml-system` defines\none variable `path` which contains the directory where the compiler's binaries\nare located. The script also sets up another mechanism in opam to\nensure that the package is recompiled by opam if the compiler is altered (for\nexample, by upgrading the compiler through the OS's package manager via\n`apt upgrade` or `brew upgrade`). This is done by recording the digest of\nthe `ocamlc` binary and the `graphics.cmi` file. The latter is a legacy check\nfrom when the Graphics library was part of OCaml, but not necessary installed,\nand could be added via a separate package.\n\nHistorically, this file lived in opam-repository itself, but opam-repository no\nlonger stores files directly in its repo. This script is referenced in this\nrepository by each of the `ocaml-system` packages.\n\n### `generate.ml`\n\nThe `install` target of the build system is meta-programmed to allow extraction\nof the directories, files and symlinks which are required for a given\ninstallation. This script is called automatically by the build system and takes\nthe files emitted during:\n\n```\nmake OPAM_PACKAGE_NAME=ocaml-compiler INSTALL_MODE=opam install\n```\n\nand produces `ocaml-compiler.install` and `ocaml-compiler-fixup.sh`. The\n.install file can be used by opam instead of running `make install`. At present,\nthere are two limitations in opam's installation mechanism. It is not possible\nto specify symlinks and it is not possible to install documentation files to\narbitrary package locations. These two limitations are dealt with by the\n`ocaml-compiler-fixup.sh` script - i.e. `ocaml-compiler.install` provides opam\nwith almost the entire installation manifest, and then the\n`ocaml-compiler-fixup.sh` script completes the missing parts (as it happens, the\n`-fixup` script runs first). Future versions of opam will hopefully deal with\nthese two limitations, at which point the `-fixup` script will become\nunnecessary.\n\n`generate.ml` is also used with `INSTALL_MODE=clone` and then produces\n`ocaml-compiler-clone.sh`. This script is used by `process.sh` as part of\nRelocatable OCaml to allow compilers to be duplicated by opam, instead of built\nfrom sources each time. The script is intended to be run from the prefix\ndirectory and receives as a single argument the directory to which the new\ncompiler should be written. The script's preference is to use copy-on-write (via\n`cp --reflink=always`) but falls back to hard-linking or normal copying\notherwise.\n\n### `process.sh`\n\nThis script is used by `ocaml-compiler` packages which support Relocatable OCaml\nand provides the ability to clone a compiler from an existing opam switch,\nrather than freshly building it from sources. It uses the `-clone.sh` scripts\nproduced by `generate.ml` in order to do this.\n\n`process.sh` is called in both the `build` and `install` sections of the\n`ocaml-compiler` package. In the `build` section, it is passed enough\ninformation to be able to build the compiler from sources if necessary, but also\nthe opam `build-id` of the compiler. The script searches for an existing\ncompiler. If one is found, the script records these details to be used when it\nis called again from the `install` section. Otherwise, it builds the compiler\nfrom the sources available. When invoked from the `install` section,\n`process.sh` then either clones the compiler which was found in the `build`\nstage, or installs the compiler which was built in the `build` stage, along with\nits cloning script, which allows subsuquent switches to clone it.\n"},"files":{"tools/opam/Layout.md":"# OCaml opam packaging\n\nUsers in opam primarily see the OCaml compiler through the `ocaml` package. For\nexample, installing the [ocaml.5.4.0](https://ocaml.org/p/ocaml/5.4.0) package\nin a switch succeeds if and only if OCaml 5.4.0 (or some variant of it) is\navailable in the opam switch.\n\nThere are various additional packages which assist in the process:\n- `ocaml-compiler` contains the actual build instructions and is responsible for\n  configuring and building a compiler from sources.\n- `ocaml-system` is available if the user has installed OCaml outside of opam\n  and made it available in PATH. For example, if `/usr/bin/ocaml` is an\n  installation of OCaml 5.4.0, then `ocaml-system.5.4.0` can be installed.\n- `arch-*` and `system-*` are meta-packages used to control exactly which\n  architecture and C compiler ecosystem are targetted by the compiler (at\n  present these are only used for Windows).\n- `ocaml-option-*` are meta-packages used to control features of the compiler,\n  for example whether frame pointers are used ([ocaml-option-fp](https://ocaml.org/p/ocaml-option-fp/latest))\n  or the flambda optimizer enabled ([ocaml-option-flambda](https://ocaml.org/p/ocaml-option-flambda/latest)).\n- `ocaml-options-vanilla` and `ocaml-options-only-*` are additional\n  meta-packages used to aid creation of switches with fixed specific options.\n  `ocaml-options-vanilla` is the \"default\" build of OCaml with no additional\n  options set. `ocaml-options-only-flambda`, for example, creates a switch with\n  the flambda optimizer enabled, but which prohibits the reconfiguration of the\n  compiler with different options. The idea behind these packages is that if\n  they are used when creating a switch, for example by running\n  `opam switch create release-builds ocaml-options-only-flambda ocaml.5.4.0`,\n  then packages which _conflict_ `ocaml-option-flambda` for some reason will be\n  rejected, rather than causing the compiler to be rebuilt with flambda support\n  disabled.\n- `ocaml-base-compiler` is a meta-package which builds OCaml sources and depends\n  on `ocaml-options-vanilla` - i.e. it installs an altered OCaml compiler.\n- `ocaml-variants` was used extensively prior to OCaml 4.12 when the\n  ocaml-option- packages were introduced for alternate configurations (for\n  example, `ocaml-variants.4.11.0+flambda` provided OCaml 4.11.0 with the\n  flambda optimizer enabled). It was also, and still is, used for experimental\n  branches of OCaml (e.g. MetaOCaml, Multicore OCaml, OxCaml, etc.)\n- `host-arch-*` and `host-system-*` are work-in-progress meta-packages which\n  _indicate_ which architecture and system the compiler targets. Their purpose\n  is to allow other packages in opam-repository to indicate a requirement or a\n  conflict with a given architecture or system.\n- `base-*` are similarly applied for some compiler features. For example,\n  [base-nnp](https://ocaml.org/p/base-nnp/latest) is installed with any compiler\n  which does not permit naked pointers in the heap (i.e. OCaml 5.x or 4.x when\n  [ocaml-option-nnp](https://ocaml.org/p/ocaml-option-nnp/latest) has been\n  installed).\n- `ocaml-beta` is a single package used to prevent accidental installation of\n  pre-release compilers when using opam 2.0.\n- `ocaml-config` packaged the tools/opam/gen\\_ocaml\\_config.ml script, but is no\n  longer required.\n- `flexdll` and `winpthreads` are source-installing packages which provide the\n  source code, when required, for the flexdll and winpthreads submodules when\n  compiling OCaml on Windows.\n\n## Scripts\n\n### `gen_ocaml_config.ml`\n\nPackages in opam are able to set variables as part of their build process; the\n`ocaml` package defines six:\n- `native` (boolean): indicates that `ocamlopt` is available\n- `native-tools` (boolean): indicates that the ocamlopt-compiled versions of\n  tools are available (`ocamlc.opt`, `ocamlopt.opt`, etc.)\n- `native-dynlink` (boolean): indicates that `dynlink.cmxa` is available\n- `stubsdir` (string): contains the lines of `ld.conf` presented in a format\n  suitable for `CAML_LD_LIBRARY_PATH`\n- `preinstalled` (boolean): is true if the `ocaml-system` package provided the\n  compiler (i.e. if OCaml is being used from an installation outside of opam)\n- `compiler` (string): OPAM 1.x derived value reflecting the name of the switch\n  based on the compiler's version. This is largely a legacy value, and is\n  essentially either \"system\" (if the ocaml-system package provided the\n  compiler) or the compiler version (e.g. \"5.4.0\"), otherwise.\n\nThis script is used by the `ocaml` package to generate the file `ocaml.config`\nwhen the `ocaml` package is installed.\n\nHistorically, this file lived in opam-repository itself, and was installed as a\nscript by the `ocaml-config` package and then used by each of the `ocaml`\npackages. opam-repository no longer stores files directly in its repo, but the\nscript is still downloaded from this repository by the `ocaml` package.\n\n### `gen_ocaml-system_config.ml`\n\nThis script is used by the `ocaml-system` package to generate the file\n`ocaml-system.config` when using a compiler which has been installed outside of\nopam. It works in a similar way to `gen_ocaml_config.ml`. `ocaml-system` defines\none variable `path` which contains the directory where the compiler's binaries\nare located. The script also sets up another mechanism in opam to\nensure that the package is recompiled by opam if the compiler is altered (for\nexample, by upgrading the compiler through the OS's package manager via\n`apt upgrade` or `brew upgrade`). This is done by recording the digest of\nthe `ocamlc` binary and the `graphics.cmi` file. The latter is a legacy check\nfrom when the Graphics library was part of OCaml, but not necessary installed,\nand could be added via a separate package.\n\nHistorically, this file lived in opam-repository itself, but opam-repository no\nlonger stores files directly in its repo. This script is referenced in this\nrepository by each of the `ocaml-system` packages.\n\n### `generate.ml`\n\nThe `install` target of the build system is meta-programmed to allow extraction\nof the directories, files and symlinks which are required for a given\ninstallation. This script is called automatically by the build system and takes\nthe files emitted during:\n\n```\nmake OPAM_PACKAGE_NAME=ocaml-compiler INSTALL_MODE=opam install\n```\n\nand produces `ocaml-compiler.install` and `ocaml-compiler-fixup.sh`. The\n.install file can be used by opam instead of running `make install`. At present,\nthere are two limitations in opam's installation mechanism. It is not possible\nto specify symlinks and it is not possible to install documentation files to\narbitrary package locations. These two limitations are dealt with by the\n`ocaml-compiler-fixup.sh` script - i.e. `ocaml-compiler.install` provides opam\nwith almost the entire installation manifest, and then the\n`ocaml-compiler-fixup.sh` script completes the missing parts (as it happens, the\n`-fixup` script runs first). Future versions of opam will hopefully deal with\nthese two limitations, at which point the `-fixup` script will become\nunnecessary.\n\n`generate.ml` is also used with `INSTALL_MODE=clone` and then produces\n`ocaml-compiler-clone.sh`. This script is used by `process.sh` as part of\nRelocatable OCaml to allow compilers to be duplicated by opam, instead of built\nfrom sources each time. The script is intended to be run from the prefix\ndirectory and receives as a single argument the directory to which the new\ncompiler should be written. The script's preference is to use copy-on-write (via\n`cp --reflink=always`) but falls back to hard-linking or normal copying\notherwise.\n\n### `process.sh`\n\nThis script is used by `ocaml-compiler` packages which support Relocatable OCaml\nand provides the ability to clone a compiler from an existing opam switch,\nrather than freshly building it from sources. It uses the `-clone.sh` scripts\nproduced by `generate.ml` in order to do this.\n\n`process.sh` is called in both the `build` and `install` sections of the\n`ocaml-compiler` package. In the `build` section, it is passed enough\ninformation to be able to build the compiler from sources if necessary, but also\nthe opam `build-id` of the compiler. The script searches for an existing\ncompiler. If one is found, the script records these details to be used when it\nis called again from the `install` section. Otherwise, it builds the compiler\nfrom the sources available. When invoked from the `install` section,\n`process.sh` then either clones the compiler which was found in the `build`\nstage, or installs the compiler which was built in the `build` stage, along with\nits cloning script, which allows subsuquent switches to clone it.\n"},"items":[{"name":"Layout.md","path":"tools/opam/Layout.md","rawUrl":"https://raw.githubusercontent.com/bbatsov/ocaml/HEAD/tools/opam/Layout.md","title":"Opam Skill","category":"anthropic-skill","format":"markdown","content":"# OCaml opam packaging\n\nUsers in opam primarily see the OCaml compiler through the `ocaml` package. For\nexample, installing the [ocaml.5.4.0](https://ocaml.org/p/ocaml/5.4.0) package\nin a switch succeeds if and only if OCaml 5.4.0 (or some variant of it) is\navailable in the opam switch.\n\nThere are various additional packages which assist in the process:\n- `ocaml-compiler` contains the actual build instructions and is responsible for\n  configuring and building a compiler from sources.\n- `ocaml-system` is available if the user has installed OCaml outside of opam\n  and made it available in PATH. For example, if `/usr/bin/ocaml` is an\n  installation of OCaml 5.4.0, then `ocaml-system.5.4.0` can be installed.\n- `arch-*` and `system-*` are meta-packages used to control exactly which\n  architecture and C compiler ecosystem are targetted by the compiler (at\n  present these are only used for Windows).\n- `ocaml-option-*` are meta-packages used to control features of the compiler,\n  for example whether frame pointers are used ([ocaml-option-fp](https://ocaml.org/p/ocaml-option-fp/latest))\n  or the flambda optimizer enabled ([ocaml-option-flambda](https://ocaml.org/p/ocaml-option-flambda/latest)).\n- `ocaml-options-vanilla` and `ocaml-options-only-*` are additional\n  meta-packages used to aid creation of switches with fixed specific options.\n  `ocaml-options-vanilla` is the \"default\" build of OCaml with no additional\n  options set. `ocaml-options-only-flambda`, for example, creates a switch with\n  the flambda optimizer enabled, but which prohibits the reconfiguration of the\n  compiler with different options. The idea behind these packages is that if\n  they are used when creating a switch, for example by running\n  `opam switch create release-builds ocaml-options-only-flambda ocaml.5.4.0`,\n  then packages which _conflict_ `ocaml-option-flambda` for some reason will be\n  rejected, rather than causing the compiler to be rebuilt with flambda support\n  disabled.\n- `ocaml-base-compiler` is a meta-package which builds OCaml sources and depends\n  on `ocaml-options-vanilla` - i.e. it installs an altered OCaml compiler.\n- `ocaml-variants` was used extensively prior to OCaml 4.12 when the\n  ocaml-option- packages were introduced for alternate configurations (for\n  example, `ocaml-variants.4.11.0+flambda` provided OCaml 4.11.0 with the\n  flambda optimizer enabled). It was also, and still is, used for experimental\n  branches of OCaml (e.g. MetaOCaml, Multicore OCaml, OxCaml, etc.)\n- `host-arch-*` and `host-system-*` are work-in-progress meta-packages which\n  _indicate_ which architecture and system the compiler targets. Their purpose\n  is to allow other packages in opam-repository to indicate a requirement or a\n  conflict with a given architecture or system.\n- `base-*` are similarly applied for some compiler features. For example,\n  [base-nnp](https://ocaml.org/p/base-nnp/latest) is installed with any compiler\n  which does not permit naked pointers in the heap (i.e. OCaml 5.x or 4.x when\n  [ocaml-option-nnp](https://ocaml.org/p/ocaml-option-nnp/latest) has been\n  installed).\n- `ocaml-beta` is a single package used to prevent accidental installation of\n  pre-release compilers when using opam 2.0.\n- `ocaml-config` packaged the tools/opam/gen\\_ocaml\\_config.ml script, but is no\n  longer required.\n- `flexdll` and `winpthreads` are source-installing packages which provide the\n  source code, when required, for the flexdll and winpthreads submodules when\n  compiling OCaml on Windows.\n\n## Scripts\n\n### `gen_ocaml_config.ml`\n\nPackages in opam are able to set variables as part of their build process; the\n`ocaml` package defines six:\n- `native` (boolean): indicates that `ocamlopt` is available\n- `native-tools` (boolean): indicates that the ocamlopt-compiled versions of\n  tools are available (`ocamlc.opt`, `ocamlopt.opt`, etc.)\n- `native-dynlink` (boolean): indicates that `dynlink.cmxa` is available\n- `stubsdir` (string): contains the lines of `ld.conf` presented in a format\n  suitable for `CAML_LD_LIBRARY_PATH`\n- `preinstalled` (boolean): is true if the `ocaml-system` package provided the\n  compiler (i.e. if OCaml is being used from an installation outside of opam)\n- `compiler` (string): OPAM 1.x derived value reflecting the name of the switch\n  based on the compiler's version. This is largely a legacy value, and is\n  essentially either \"system\" (if the ocaml-system package provided the\n  compiler) or the compiler version (e.g. \"5.4.0\"), otherwise.\n\nThis script is used by the `ocaml` package to generate the file `ocaml.config`\nwhen the `ocaml` package is installed.\n\nHistorically, this file lived in opam-repository itself, and was installed as a\nscript by the `ocaml-config` package and then used by each of the `ocaml`\npackages. opam-repository no longer stores files directly in its repo, but the\nscript is still downloaded from this repository by the `ocaml` package.\n\n### `gen_ocaml-system_config.ml`\n\nThis script is used by the `ocaml-system` package to generate the file\n`ocaml-system.config` when using a compiler which has been installed outside of\nopam. It works in a similar way to `gen_ocaml_config.ml`. `ocaml-system` defines\none variable `path` which contains the directory where the compiler's binaries\nare located. The script also sets up another mechanism in opam to\nensure that the package is recompiled by opam if the compiler is altered (for\nexample, by upgrading the compiler through the OS's package manager via\n`apt upgrade` or `brew upgrade`). This is done by recording the digest of\nthe `ocamlc` binary and the `graphics.cmi` file. The latter is a legacy check\nfrom when the Graphics library was part of OCaml, but not necessary installed,\nand could be added via a separate package.\n\nHistorically, this file lived in opam-repository itself, but opam-repository no\nlonger stores files directly in its repo. This script is referenced in this\nrepository by each of the `ocaml-system` packages.\n\n### `generate.ml`\n\nThe `install` target of the build system is meta-programmed to allow extraction\nof the directories, files and symlinks which are required for a given\ninstallation. This script is called automatically by the build system and takes\nthe files emitted during:\n\n```\nmake OPAM_PACKAGE_NAME=ocaml-compiler INSTALL_MODE=opam install\n```\n\nand produces `ocaml-compiler.install` and `ocaml-compiler-fixup.sh`. The\n.install file can be used by opam instead of running `make install`. At present,\nthere are two limitations in opam's installation mechanism. It is not possible\nto specify symlinks and it is not possible to install documentation files to\narbitrary package locations. These two limitations are dealt with by the\n`ocaml-compiler-fixup.sh` script - i.e. `ocaml-compiler.install` provides opam\nwith almost the entire installation manifest, and then the\n`ocaml-compiler-fixup.sh` script completes the missing parts (as it happens, the\n`-fixup` script runs first). Future versions of opam will hopefully deal with\nthese two limitations, at which point the `-fixup` script will become\nunnecessary.\n\n`generate.ml` is also used with `INSTALL_MODE=clone` and then produces\n`ocaml-compiler-clone.sh`. This script is used by `process.sh` as part of\nRelocatable OCaml to allow compilers to be duplicated by opam, instead of built\nfrom sources each time. The script is intended to be run from the prefix\ndirectory and receives as a single argument the directory to which the new\ncompiler should be written. The script's preference is to use copy-on-write (via\n`cp --reflink=always`) but falls back to hard-linking or normal copying\notherwise.\n\n### `process.sh`\n\nThis script is used by `ocaml-compiler` packages which support Relocatable OCaml\nand provides the ability to clone a compiler from an existing opam switch,\nrather than freshly building it from sources. It uses the `-clone.sh` scripts\nproduced by `generate.ml` in order to do this.\n\n`process.sh` is called in both the `build` and `install` sections of the\n`ocaml-compiler` package. In the `build` section, it is passed enough\ninformation to be able to build the compiler from sources if necessary, but also\nthe opam `build-id` of the compiler. The script searches for an existing\ncompiler. If one is found, the script records these details to be used when it\nis called again from the `install` section. Otherwise, it builds the compiler\nfrom the sources available. When invoked from the `install` section,\n`process.sh` then either clones the compiler which was found in the `build`\nstage, or installs the compiler which was built in the `build` stage, along with\nits cloning script, which allows subsuquent switches to clone it.\n","isInternal":false,"tokens":2148,"sizeBytes":8661}],"systemPromptSnippet":"<yakaai_skills repo=\"bbatsov/ocaml\">\n<!-- File: tools/opam/Layout.md (Tokens: ~2148 | Category: anthropic-skill) -->\n# OCaml opam packaging\n\nUsers in opam primarily see the OCaml compiler through the `ocaml` package. For\nexample, installing the [ocaml.5.4.0](https://ocaml.org/p/ocaml/5.4.0) package\nin a switch succeeds if and only if OCaml 5.4.0 (or some variant of it) is\navailable in the opam switch.\n\nThere are various additional packages which assist in the process:\n- `ocaml-compiler` contains the actual build instructions and is responsible for\n  configuring and building a compiler from sources.\n- `ocaml-system` is available if the user has installed OCaml outside of opam\n  and made it available in PATH. For example, if `/usr/bin/ocaml` is an\n  installation of OCaml 5.4.0, then `ocaml-system.5.4.0` can be installed.\n- `arch-*` and `system-*` are meta-packages used to control exactly which\n  architecture and C compiler ecosystem are targetted by the compiler (at\n  present these are only used for Windows).\n- `ocaml-option-*` are meta-packages used to control features of the compiler,\n  for example whether frame pointers are used ([ocaml-option-fp](https://ocaml.org/p/ocaml-option-fp/latest))\n  or the flambda optimizer enabled ([ocaml-option-flambda](https://ocaml.org/p/ocaml-option-flambda/latest)).\n- `ocaml-options-vanilla` and `ocaml-options-only-*` are additional\n  meta-packages used to aid creation of switches with fixed specific options.\n  `ocaml-options-vanilla` is the \"default\" build of OCaml with no additional\n  options set. `ocaml-options-only-flambda`, for example, creates a switch with\n  the flambda optimizer enabled, but which prohibits the reconfiguration of the\n  compiler with different options. The idea behind these packages is that if\n  they are used when creating a switch, for example by running\n  `opam switch create release-builds ocaml-options-only-flambda ocaml.5.4.0`,\n  then packages which _conflict_ `ocaml-option-flambda` for some reason will be\n  rejected, rather than causing the compiler to be rebuilt with flambda support\n  disabled.\n- `ocaml-base-compiler` is a meta-package which builds OCaml sources and depends\n  on `ocaml-options-vanilla` - i.e. it installs an altered OCaml compiler.\n- `ocaml-variants` was used extensively prior to OCaml 4.12 when the\n  ocaml-option- packages were introduced for alternate configurations (for\n  example, `ocaml-variants.4.11.0+flambda` provided OCaml 4.11.0 with the\n  flambda optimizer enabled). It was also, and still is, used for experimental\n  branches of OCaml (e.g. MetaOCaml, Multicore OCaml, OxCaml, etc.)\n- `host-arch-*` and `host-system-*` are work-in-progress meta-packages which\n  _indicate_ which architecture and system the compiler targets. Their purpose\n  is to allow other packages in opam-repository to indicate a requirement or a\n  conflict with a given architecture or system.\n- `base-*` are similarly applied for some compiler features. For example,\n  [base-nnp](https://ocaml.org/p/base-nnp/latest) is installed with any compiler\n  which does not permit naked pointers in the heap (i.e. OCaml 5.x or 4.x when\n  [ocaml-option-nnp](https://ocaml.org/p/ocaml-option-nnp/latest) has been\n  installed).\n- `ocaml-beta` is a single package used to prevent accidental installation of\n  pre-release compilers when using opam 2.0.\n- `ocaml-config` packaged the tools/opam/gen\\_ocaml\\_config.ml script, but is no\n  longer required.\n- `flexdll` and `winpthreads` are source-installing packages which provide the\n  source code, when required, for the flexdll and winpthreads submodules when\n  compiling OCaml on Windows.\n\n## Scripts\n\n### `gen_ocaml_config.ml`\n\nPackages in opam are able to set variables as part of their build process; the\n`ocaml` package defines six:\n- `native` (boolean): indicates that `ocamlopt` is available\n- `native-tools` (boolean): indicates that the ocamlopt-compiled versions of\n  tools are available (`ocamlc.opt`, `ocamlopt.opt`, etc.)\n- `native-dynlink` (boolean): indicates that `dynlink.cmxa` is available\n- `stubsdir` (string): contains the lines of `ld.conf` presented in a format\n  suitable for `CAML_LD_LIBRARY_PATH`\n- `preinstalled` (boolean): is true if the `ocaml-system` package provided the\n  compiler (i.e. if OCaml is being used from an installation outside of opam)\n- `compiler` (string): OPAM 1.x derived value reflecting the name of the switch\n  based on the compiler's version. This is largely a legacy value, and is\n  essentially either \"system\" (if the ocaml-system package provided the\n  compiler) or the compiler version (e.g. \"5.4.0\"), otherwise.\n\nThis script is used by the `ocaml` package to generate the file `ocaml.config`\nwhen the `ocaml` package is installed.\n\nHistorically, this file lived in opam-repository itself, and was installed as a\nscript by the `ocaml-config` package and then used by each of the `ocaml`\npackages. opam-repository no longer stores files directly in its repo, but the\nscript is still downloaded from this repository by the `ocaml` package.\n\n### `gen_ocaml-system_config.ml`\n\nThis script is used by the `ocaml-system` package to generate the file\n`ocaml-system.config` when using a compiler which has been installed outside of\nopam. It works in a similar way to `gen_ocaml_config.ml`. `ocaml-system` defines\none variable `path` which contains the directory where the compiler's binaries\nare located. The script also sets up another mechanism in opam to\nensure that the package is recompiled by opam if the compiler is altered (for\nexample, by upgrading the compiler through the OS's package manager via\n`apt upgrade` or `brew upgrade`). This is done by recording the digest of\nthe `ocamlc` binary and the `graphics.cmi` file. The latter is a legacy check\nfrom when the Graphics library was part of OCaml, but not necessary installed,\nand could be added via a separate package.\n\nHistorically, this file lived in opam-repository itself, but opam-repository no\nlonger stores files directly in its repo. This script is referenced in this\nrepository by each of the `ocaml-system` packages.\n\n### `generate.ml`\n\nThe `install` target of the build system is meta-programmed to allow extraction\nof the directories, files and symlinks which are required for a given\ninstallation. This script is called automatically by the build system and takes\nthe files emitted during:\n\n```\nmake OPAM_PACKAGE_NAME=ocaml-compiler INSTALL_MODE=opam install\n```\n\nand produces `ocaml-compiler.install` and `ocaml-compiler-fixup.sh`. The\n.install file can be used by opam instead of running `make install`. At present,\nthere are two limitations in opam's installation mechanism. It is not possible\nto specify symlinks and it is not possible to install documentation files to\narbitrary package locations. These two limitations are dealt with by the\n`ocaml-compiler-fixup.sh` script - i.e. `ocaml-compiler.install` provides opam\nwith almost the entire installation manifest, and then the\n`ocaml-compiler-fixup.sh` script completes the missing parts (as it happens, the\n`-fixup` script runs first). Future versions of opam will hopefully deal with\nthese two limitations, at which point the `-fixup` script will become\nunnecessary.\n\n`generate.ml` is also used with `INSTALL_MODE=clone` and then produces\n`ocaml-compiler-clone.sh`. This script is used by `process.sh` as part of\nRelocatable OCaml to allow compilers to be duplicated by opam, instead of built\nfrom sources each time. The script is intended to be run from the prefix\ndirectory and receives as a single argument the directory to which the new\ncompiler should be written. The script's preference is to use copy-on-write (via\n`cp --reflink=always`) but falls back to hard-linking or normal copying\notherwise.\n\n### `process.sh`\n\nThis script is used by `ocaml-compiler` packages which support Relocatable OCaml\nand provides the ability to clone a compiler from an existing opam switch,\nrather than freshly building it from sources. It uses the `-clone.sh` scripts\nproduced by `generate.ml` in order to do this.\n\n`process.sh` is called in both the `build` and `install` sections of the\n`ocaml-compiler` package. In the `build` section, it is passed enough\ninformation to be able to build the compiler from sources if necessary, but also\nthe opam `build-id` of the compiler. The script searches for an existing\ncompiler. If one is found, the script records these details to be used when it\nis called again from the `install` section. Otherwise, it builds the compiler\nfrom the sources available. When invoked from the `install` section,\n`process.sh` then either clones the compiler which was found in the `build`\nstage, or installs the compiler which was built in the `build` stage, along with\nits cloning script, which allows subsuquent switches to clone it.\n</yakaai_skills>"}