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 ["jbuilder" "runtest" "-p" name "-j" jobs] {with-test} 19] 20depends: [ 21 "ocaml" {>= "4.03"} 22 "jbuilder" {>= "1.0+beta20"} 23 "base-unix" 24 "cmdliner" {>= "0.9.8" & < "1.1.0"} 25 "rresult" 26 "astring" 27 "fmt" {< "0.8.10"} 28 "ocamlgraph" 29 "logs" 30 "bos" 31 "fpath" 32 "alcotest" {with-test} 33] 34synopsis: "A DSL to organize functor applications" 35description: """ 36[![Build Status](https://travis-ci.org/mirage/functoria.svg?branch=master)](https://travis-ci.org/mirage/functoria) 37[![docs](https://img.shields.io/badge/doc-online-blue.svg)](https://mirage.github.io/functoria/index.html) 38 39## What is this for? 40 41Functoria 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. 42 43The main use case is mirage. See the [mirage][] repository for details. 44 45## How to write a configuration file? 46 47There 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. 48 49In 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. 50 51```ocaml 52let main = foreign "Unikernel.Main" (console @-> job) 53``` 54 55Here, 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. 56 57We can now use this declaration: 58 59```ocaml 60let () = register "console" [main $ default_console] 61``` 62 63Here, 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. 64 65Now that everything is ready, you can use the `configure` subcommand! 66 67### What is a job? 68 69A 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`. 70 71### Defining new keys 72 73A key is composed of: 74 75- _name_ : The name of the value in the program. 76- _description_ : How it should be displayed/serialized. 77- _stage_ : Is the key available only at runtime, at configure time or both? 78- _documentation_ : It is not optional so you should really write it. 79 80Consider 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: 81 82```ocaml 83let lang_key = 84 let doc = Key.Arg.info 85 ~doc:"The default language for the application." [ "l" ; "lang" ] 86 in 87 Key.create "language" @@ Key.Arg.(opt ~stage:`Both string "en" doc) 88``` 89 90Here, we defined both a long option `--lang` and a short one `-l` (the format is similar to the one used by [Cmdliner][cmdliner]). 91In the application code, the value is retrieved with `Key_gen.language ()`. 92 93The option is also documented in the `--help` option for both the `configure` subcommand (at configure time) and `./my_application` (at startup time). 94 95``` 96 -l VAL, --lang=VAL (absent=en) 97 The default language for the application. 98``` 99 100[cmdliner]: http://erratique.ch/software/cmdliner 101 102### Using switching keys 103 104We 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! 105 106First, we have to compute a boolean value from `lang`: 107 108```ocaml 109let is_fi = Key.(pure ((=) "fi") $ value lang_key) 110``` 111 112We can use the `if_impl` combinator to choose between two implementations depending on the value of the key: 113 114```ocaml 115let dynamic_storage = 116 if_impl is_fi 117 finnish_implementation 118 not_finnish_implementation 119``` 120 121This distinction will be visible using the `describe` subcommand and a dot diagram is available with the `--dot` option! 122 123## Internals 124 125### Phases 126 127Configuration is separated into phases: 128 1291. Specialized DSL keys 130 The specialized DSL's keys (along with functoria's keys) are resolved. 1312. Compilation and dynlink of the config file. 1323. Registering. 133 When the `register` function is called, the list of jobs is recorded and 134 immediately transformed into a graph. 1354. Switching keys and tree evaluation. 136 The switching keys are the keys inside the [If]. 137 Those keys are resolved and the graph is simplified. At this point, 138 the actual modules used are fully known. 139 Note: for the `describe` command, Only _partial_ evaluation is done, which 140 means decision nodes are resolved only if the value was given on the command 141 line, disregarding default values. 1425. Full Key resolution. 143 Once the actual modules are known, we can resolve all the keys and figure out 144 libraries and packages. 1456. Dependency handling, configuration and code emission. 146 147Phases 1. to 4. are also applied for the `clean` command. 148 149 150 151[mirage]: https://github.com/mirage/mirage 152[mirage-skeleton]: https://github.com/mirage/mirage-skeleton""" 153url { 154 src: 155 "https://github.com/mirage/functoria/releases/download/2.2.1/functoria-2.2.1.tbz" 156 checksum: [ 157 "sha256=e2c883d5a0a2c3cea59cffa9989c5ee78259aee9a199048cb730d19076e668c5" 158 "md5=ec768d65f4070dd76c369b4a32a1ac32" 159 ] 160} 161available: opam-version >= "2.2.0" 162flags: deprecated