RabsRincon | 2ab39a0 | 2017-11-18 01:03:31 +0100 | [diff] [blame] | 1 | # Adding a new library |
| 2 | |
| 3 | This document explains how to add a new library to Compiler Explorer ("CE" from here on), first for a local instance, and |
| 4 | then how to submit PRs to get it into the main CE site. |
| 5 | |
| 6 | ## Configuration |
| 7 | |
richardthe3rd | 72e333f | 2017-11-27 21:16:54 +0000 | [diff] [blame] | 8 | Library configurations are part of the compiler's properties, which is done through the `etc/config/c++.*.properties` files |
RabsRincon | 2ab39a0 | 2017-11-18 01:03:31 +0100 | [diff] [blame] | 9 | (for C++, other languages follow the obvious pattern). The various named configuration files are used in different contexts: |
| 10 | for example `etc/config/c++.local.properties` take priority over `etc/config/c++.defaults.properties`. |
| 11 | The `local` version is ignored by git, so you can make your own personalised changes there. |
| 12 | The live site uses the `etc/config/c++.amazon.properties` file. |
| 13 | |
| 14 | Within the file, configuration is a set of key and value pairs, separated by an `=`. Whitespace is _not_ trimmed. |
| 15 | Lines starting with `#` are considered comments and not parsed. |
| 16 | The list of libraries is set by the `libs` key and is a list of library identifiers, separated by colons. |
| 17 | The identifier itself is not important, but must be unique to that library. |
| 18 | |
| 19 | An example configuration: |
| 20 | |
| 21 | ``` |
| 22 | libs=kvasir:boost:rangesv3 |
| 23 | ``` |
| 24 | |
RabsRincon | 3b8fb3b | 2017-11-18 01:06:59 +0100 | [diff] [blame] | 25 | This says there are three libraries with identifiers `kvasir`, `boost` and `rangesv3`. CE will look for the key named |
RabsRincon | e5ef041 | 2018-03-04 05:59:40 +0100 | [diff] [blame] | 26 | `libs.ID.versions`, `libs.ID.name` and the optionals `libs.ID.url` & `libs.ID.description`. The `ID` is the identifier (The one we just set) of the library being looked up. |
RabsRincon | 2ab39a0 | 2017-11-18 01:03:31 +0100 | [diff] [blame] | 27 | The `name` key expects the human readable name of the library (Note that you can use spaces here!) |
| 28 | The `versions` key expects another list, akin to the libs key itself. This time, you have to define the available versions |
| 29 | for each library. |
RabsRincon | 7bd30b4 | 2018-01-18 17:40:10 +0100 | [diff] [blame] | 30 | The `url` key expects an unescaped url, where users can go to learn more about the library (This is usually the project's homepage, or in its |
| 31 | absence, the GitHub repo) |
RabsRincon | 5f7756d | 2018-03-04 06:01:44 +0100 | [diff] [blame] | 32 | The `description` key should be use as an extremely short description of the library. Usually used to spell the library's full name in cases where the `name` key is an acronym. |
RabsRincon | 2ab39a0 | 2017-11-18 01:03:31 +0100 | [diff] [blame] | 33 | |
| 34 | For example: |
| 35 | |
| 36 | ``` |
RabsRincon | e5ef041 | 2018-03-04 05:59:40 +0100 | [diff] [blame] | 37 | libs.kvasir.name=Kvasir::mpl |
RabsRincon | 2ab39a0 | 2017-11-18 01:03:31 +0100 | [diff] [blame] | 38 | libs.kvasir.versions=trunk |
RabsRincon | 7bd30b4 | 2018-01-18 17:40:10 +0100 | [diff] [blame] | 39 | libs.kvasir.url=https://github.com/kvasir-io/Kvasir |
RabsRincon | 2ab39a0 | 2017-11-18 01:03:31 +0100 | [diff] [blame] | 40 | libs.boost.name=Boost |
| 41 | libs.boost.versions=164:165 |
RabsRincon | 7bd30b4 | 2018-01-18 17:40:10 +0100 | [diff] [blame] | 42 | libs.boost.url=http://www.boost.org/ |
RabsRincon | e5ef041 | 2018-03-04 05:59:40 +0100 | [diff] [blame] | 43 | libs.rangesv3.name=range-v3 |
| 44 | libs.rangesv3.description=Range library for C++11/14/17 |
RabsRincon | 2ab39a0 | 2017-11-18 01:03:31 +0100 | [diff] [blame] | 45 | libs.rangesv3.versions=trunk:030 |
RabsRincon | 7bd30b4 | 2018-01-18 17:40:10 +0100 | [diff] [blame] | 46 | libs.rangesv3.url=https://github.com/ericniebler/range-v3 |
RabsRincon | 2ab39a0 | 2017-11-18 01:03:31 +0100 | [diff] [blame] | 47 | ``` |
| 48 | |
RabsRincon | 7bd30b4 | 2018-01-18 17:40:10 +0100 | [diff] [blame] | 49 | Now, for each declared version, CE will look for a `version` key, an human readable string representing the corresponding version, |
RabsRincon | 3b8fb3b | 2017-11-18 01:06:59 +0100 | [diff] [blame] | 50 | and `path`, a list consisting of the paths to add to the inclusion path of the library. |
RabsRincon | 2ab39a0 | 2017-11-18 01:03:31 +0100 | [diff] [blame] | 51 | |
| 52 | This would leave us with: (Empty lines added for clarity. Please refrain from using them if you plan to PR us :D) |
| 53 | |
| 54 | ``` |
| 55 | libs.kvasir.name=Kvasir::mpl |
| 56 | libs.kvasir.versions=trunk |
RabsRincon | 7bd30b4 | 2018-01-18 17:40:10 +0100 | [diff] [blame] | 57 | libs.kvasir.url=https://github.com/kvasir-io/Kvasir |
RabsRincon | 2ab39a0 | 2017-11-18 01:03:31 +0100 | [diff] [blame] | 58 | |
RabsRincon | 928c7a1 | 2018-06-28 22:13:50 +0200 | [diff] [blame] | 59 | libs.kvasir.versions.trunk.version=trunk |
RabsRincon | 2ab39a0 | 2017-11-18 01:03:31 +0100 | [diff] [blame] | 60 | # Note how there are 2 paths defined for Kvasir in our case (Example usage!) |
| 61 | libs.kvasir.versions.trunk.path=/opt/compiler-explorer/libs/kvasir/mpl/trunk/src/kvasir:/opt/compiler-explorer/libs/kvasir/mpl/trunk/src |
| 62 | |
| 63 | |
| 64 | libs.boost.name=Boost |
| 65 | libs.boost.versions=164:165 |
RabsRincon | 7bd30b4 | 2018-01-18 17:40:10 +0100 | [diff] [blame] | 66 | libs.boost.url=http://www.boost.org/ |
RabsRincon | 2ab39a0 | 2017-11-18 01:03:31 +0100 | [diff] [blame] | 67 | |
RabsRincon | 928c7a1 | 2018-06-28 22:13:50 +0200 | [diff] [blame] | 68 | libs.boost.versions.164.version=1.64 |
| 69 | libs.boost.versions.165.version=1.65 |
RabsRincon | 2ab39a0 | 2017-11-18 01:03:31 +0100 | [diff] [blame] | 70 | |
| 71 | libs.boost.versions.164.path=/opt/compiler-explorer/libs/boost_1_64_0 |
| 72 | libs.boost.versions.165.path=/opt/compiler-explorer/libs/boost_1_65_0 |
| 73 | |
| 74 | |
RabsRincon | e5ef041 | 2018-03-04 05:59:40 +0100 | [diff] [blame] | 75 | libs.rangesv3.name=range-v3 |
RabsRincon | 2ab39a0 | 2017-11-18 01:03:31 +0100 | [diff] [blame] | 76 | libs.rangesv3.versions=trunk:030 |
RabsRincon | 7bd30b4 | 2018-01-18 17:40:10 +0100 | [diff] [blame] | 77 | libs.rangesv3.url=https://github.com/ericniebler/range-v3 |
RabsRincon | 2ab39a0 | 2017-11-18 01:03:31 +0100 | [diff] [blame] | 78 | |
RabsRincon | 928c7a1 | 2018-06-28 22:13:50 +0200 | [diff] [blame] | 79 | libs.rangesv3.versions.trunk.version=trunk |
| 80 | libs.rangesv3.versions.030.version=0.3.0 |
RabsRincon | 2ab39a0 | 2017-11-18 01:03:31 +0100 | [diff] [blame] | 81 | |
| 82 | libs.rangesv3.versions.trunk.path=/opt/compiler-explorer/libs/rangesv3/trunk/include |
| 83 | libs.rangesv3.versions.030.path=/opt/compiler-explorer/libs/rangesv3/0.3.0/include |
| 84 | ``` |
| 85 | |
RabsRincon | 1c46f8f | 2018-05-08 15:17:47 +0200 | [diff] [blame] | 86 | ## Setting default libraries |
| 87 | |
| 88 | The `defaultLibs` key specifies an array of libs/versions which will be enabled by default when the user visits the site. |
| 89 | The expected format is: |
| 90 | ``` |
| 91 | defaultLibs=libKeyA.version:libKeyB.version:libKeyC.version |
| 92 | ``` |
| 93 | Where `libKey` is the key of the library to be enabled by default, and `version` is the version key to load. |
| 94 | Note that the site won't complain if invalid key/version pairs are set. Repeating a lib key more than once is supported. |
| 95 | |
RabsRincon | 2ab39a0 | 2017-11-18 01:03:31 +0100 | [diff] [blame] | 96 | ## Adding a new library locally |
| 97 | |
| 98 | It should be pretty straightforward to add a library of your own. Create a `etc/config/c++.local.properties` file and override the |
| 99 | `libs` list to include your own library, and its configuration. |
| 100 | |
| 101 | Once you've done that, running `make` should pick up the configuration and you should be able to use them from the library dropdown |
| 102 | on the compiler view (The book icon) |
| 103 | |
| 104 | If you're looking to add libraries for another language, obviously create the `etc/config/LANG.local.properties` in |
| 105 | the above steps, and run with `make EXTRA_ARGS='--language LANG` (e.g. `etc/config/rust.local.properties` and |
| 106 | `make EXTRA_ARGS='--language Rust'`). |
| 107 | |
| 108 | Test locally, and for many compilers that's probably all you need to do. Some compilers might need a few options tweaks (like |
| 109 | the intel asm setting, or the version flag). For a completely new compiler, you might need to define a whole new `compilerType`. |
| 110 | Doing so is beyond this document's scope at present, but take a look inside `lib/compilers/` to get some idea what might need |
| 111 | to be done. |
| 112 | |
| 113 | ## Adding a new library to the live site |
| 114 | |
| 115 | On the main CE website, libraries are installed into a `/opt/compiler-explorer/` directory by a set of scripts in the sister |
| 116 | GitHub repo: https://github.com/mattgodbolt/compiler-explorer-image |
| 117 | |
| 118 | In the `update_compilers` directory in that repository are a set of scripts that download and install the libraries. |
| 119 | If you wish to test locally, and can create a `/opt/compiler-explorer` directory on your machine which is readable and writable by your |
| 120 | current user, then you can run the scripts directly. |
| 121 | |
| 122 | If your library fits nicely into the harness then it should be straightforward to add it there. Anything more complex: contact the CE |
| 123 | authors for more help. |
| 124 | |
RabsRincon | e5ef041 | 2018-03-04 05:59:40 +0100 | [diff] [blame] | 125 | Remember to also add the library dependencies following the same steps. It's on you if those should also appear in the UI. |
RabsRincon | 8ac96fa | 2018-02-23 07:20:39 +0100 | [diff] [blame] | 126 | |
RabsRincon | 2ab39a0 | 2017-11-18 01:03:31 +0100 | [diff] [blame] | 127 | ## Putting it all together |
| 128 | |
| 129 | Hopefully that's enough to get an idea. The ideal case should be a pull request to add a couple of |
| 130 | lines to the `compiler-explorer-image` to install the library, and a pull request to add a few lines to the `LANG.amazon.properties` |
| 131 | file in this repository. |
RabsRincon | e5ef041 | 2018-03-04 05:59:40 +0100 | [diff] [blame] | 132 | Once that's done, remember to update [the wiki](https://github.com/mattgodbolt/compiler-explorer/wiki/Installed-libraries) with the new library, adding the library in alphabetical order, with newer versions on top. |
| 133 | |
| 134 | If you feel like we could improve this document in any way, please contact us. We'd love to hear from you! |