this repo has no description
1opam-version: "2.0" 2maintainer: "Gabriel Radanne <drupyog@zoho.com>" 3authors: [ "Thomas Gazagnaire" 4 "Anil Madhavapeddy" 5 "Dave Scott" 6 "Thomas Leonard" 7 "Gabriel Radanne" ] 8homepage: "https://github.com/mirage/functoria" 9bug-reports: "https://github.com/mirage/functoria/issues" 10dev-repo: "git+https://github.com/mirage/functoria.git" 11doc: "https://mirage.github.io/functoria/" 12license: "ISC" 13tags: ["org:mirage"] 14 15build: [ 16 ["jbuilder" "subst" "-p" name] {dev} 17 ["jbuilder" "build" "-p" name "-j" jobs] 18] 19depends: [ 20 "ocaml" {>= "4.02" & < "4.12"} 21 "jbuilder" {>= "1.0+beta10"} 22 "cmdliner" {>= "0.9.8"} 23 "fmt" 24] 25conflicts: [ 26 "functoria" {< "2.0.0"} 27] 28synopsis: "A DSL to organize functor applications" 29description: """ 30[![Build Status](https://travis-ci.org/mirage/functoria.svg)](https://travis-ci.org/mirage/functoria) 31[![docs](https://img.shields.io/badge/doc-online-blue.svg)](https://mirage.github.io/functoria/index.html) 32 33## What is this for? 34 35Functoria is a DSL to describe a set of modules and functors, their types and how to apply them in order to produce a complete application. 36 37The main use case is mirage. See the [mirage][] repository for details. 38 39## How to write a configuration file? 40 41There are numerous examples of configuration files in [mirage-skeleton][]. Most of them should be fairly general and understandable, even outside the context of mirage. We can distinguish two parts in a `config.ml`: Defining new modules and using them. 42 43In order to define a new module, we use the `foreign` function. Among its various arguments, it takes a module name and a type. The type is assembled with the DSL's combinators and the `@->` operator, which symbols a functor arrow. 44 45```ocaml 46let main = foreign "Unikernel.Main" (console @-> job) 47``` 48 49Here, we declare the functor `Unikernel.Main` that takes a module that should be a `console` and returns a module that is a `job`. It is up to the user to ensure that the declaration matches the implementation (or be punished by a compiler error later on). If the declaration is correct, everything that follows will be. 50 51We can now use this declaration: 52 53```ocaml 54let () = register "console" [main $ default_console] 55``` 56 57Here, we register a new application with the `register` function. This function should only be called once and takes as argument the name of the application and a list of jobs. We use the `$` operator to apply the functor `main` (aka `Unikernel.Main`) to the default console. 58 59Now that everything is ready, you can use the `configure` subcommand! 60 61### What is a job? 62 63A job is a module containing a function `start`. This function will receive one argument per functor argument and one per dependency, in this order. `foreign` assumes the function `start` returns `unit`. 64 65### Defining new keys 66 67A key is composed of: 68 69- _name_ : The name of the value in the program. 70- _description_ : How it should be displayed/serialized. 71- _stage_ : Is the key available only at runtime, at configure time or both? 72- _documentation_ : It is not optional so you should really write it. 73 74Consider a multilingual application: we want to pass the default language as a parameter. We will use a simple string, so we can use the predefined description `Key.Desc.string`. We want to be able to define it both at configure and run time, so we use the stage `` `Both``. This gives us the following code: 75 76```ocaml 77let lang_key = 78 let doc = Key.Doc.create 79 ~doc:"The default language for the application." [ "l" ; "lang" ] 80 in 81 Key.create ~doc ~stage:`Both ~default:"en" "language" Key.Desc.string 82``` 83 84Here, we defined both a long option `--lang` and a short one `-l` (the format is similar to the one used by [Cmdliner][cmdliner]). 85In the application code, the value is retrieved with `Key_gen.language ()`. 86 87The option is also documented in the `--help` option for both the `configure` subcommand (at configure time) and `./my_application` (at startup time). 88 89``` 90 -l VAL, --lang=VAL (absent=en) 91 The default language for the application. 92``` 93 94[cmdliner]: http://erratique.ch/software/cmdliner 95 96### Using switching keys 97 98We can do much more with keys: we can use them to switch implementation at configure time. Imagine we want to completely change some implementation based on the language. Finns are special snowflakes, they deserve their special application! 99 100First, we have to compute a boolean value from `lang`: 101 102```ocaml 103let is_fi = Key.(pure ((=) "fi") $ value lang_key) 104``` 105 106We can use the `if_impl` combinator to choose between two implementations depending on the value of the key: 107 108```ocaml 109let dynamic_storage = 110 if_impl is_fi 111 finnish_implementation 112 not_finnish_implementation 113``` 114 115This distinction will be visible using the `describe` subcommand and a dot diagram is available with the `--dot` option! 116 117## Internals 118 119### Phases 120 121Configuration is separated into phases: 122 1231. Specialized DSL keys 124 The specialized DSL's keys (along with functoria's keys) are resolved. 1252. Compilation and dynlink of the config file. 1263. Registering. 127 When the `register` function is called, the list of jobs is recorded and 128 immediately transformed into a graph. 1294. Switching keys and tree evaluation. 130 The switching keys are the keys inside the [If]. 131 Those keys are resolved and the graph is simplified. At this point, 132 the actual modules used are fully known. 133 Note: for the `describe` command, Only _partial_ evaluation is done, which 134 means decision nodes are resolved only if the value was given on the command 135 line, disregarding default values. 1365. Full Key resolution. 137 Once the actual modules are known, we can resolve all the keys and figure out 138 libraries and packages. 1396. Dependency handling, configuration and code emission. 140 141Phases 1. to 4. are also applied for the `clean` command. 142 143 144 145[mirage]: https://github.com/mirage/mirage 146[mirage-skeleton]: https://github.com/mirage/mirage-skeleton""" 147url { 148 src: 149 "https://github.com/mirage/functoria/releases/download/2.1.0/functoria-2.1.0.tbz" 150 checksum: [ 151 "sha256=83fa056e52fe1fdc996d68ad2ce50f490d44e4b9cdd67e8c88a05753d99e70ec" 152 "md5=4541047f19a2842df17b9ffb5badbb3e" 153 ] 154} 155available: opam-version >= "2.2.0" 156flags: deprecated