blob: 3ced84970923c42075a58ef213ea7ebf90a9c543 [file] [log] [blame] [view] [raw]
RabsRincon2ab39a02017-11-18 01:03:31 +01001# Adding a new library
2
3This document explains how to add a new library to Compiler Explorer ("CE" from here on), first for a local instance, and
4then how to submit PRs to get it into the main CE site.
5
6## Configuration
7
richardthe3rd72e333f2017-11-27 21:16:54 +00008Library configurations are part of the compiler's properties, which is done through the `etc/config/c++.*.properties` files
RabsRincon2ab39a02017-11-18 01:03:31 +01009(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`.
11The `local` version is ignored by git, so you can make your own personalised changes there.
12The live site uses the `etc/config/c++.amazon.properties` file.
13
14Within the file, configuration is a set of key and value pairs, separated by an `=`. Whitespace is _not_ trimmed.
15Lines starting with `#` are considered comments and not parsed.
16The list of libraries is set by the `libs` key and is a list of library identifiers, separated by colons.
17The identifier itself is not important, but must be unique to that library.
18
19An example configuration:
20
21```
22libs=kvasir:boost:rangesv3
23```
24
RabsRincon3b8fb3b2017-11-18 01:06:59 +010025This says there are three libraries with identifiers `kvasir`, `boost` and `rangesv3`. CE will look for the key named
RabsRincone5ef0412018-03-04 05:59:40 +010026`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.
RabsRincon2ab39a02017-11-18 01:03:31 +010027The `name` key expects the human readable name of the library (Note that you can use spaces here!)
28The `versions` key expects another list, akin to the libs key itself. This time, you have to define the available versions
29for each library.
RabsRincon7bd30b42018-01-18 17:40:10 +010030The `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
31absence, the GitHub repo)
RabsRincon5f7756d2018-03-04 06:01:44 +010032The `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.
RabsRincon2ab39a02017-11-18 01:03:31 +010033
34For example:
35
36```
RabsRincone5ef0412018-03-04 05:59:40 +010037libs.kvasir.name=Kvasir::mpl
RabsRincon2ab39a02017-11-18 01:03:31 +010038libs.kvasir.versions=trunk
RabsRincon7bd30b42018-01-18 17:40:10 +010039libs.kvasir.url=https://github.com/kvasir-io/Kvasir
RabsRincon2ab39a02017-11-18 01:03:31 +010040libs.boost.name=Boost
41libs.boost.versions=164:165
RabsRincon7bd30b42018-01-18 17:40:10 +010042libs.boost.url=http://www.boost.org/
RabsRincone5ef0412018-03-04 05:59:40 +010043libs.rangesv3.name=range-v3
44libs.rangesv3.description=Range library for C++11/14/17
RabsRincon2ab39a02017-11-18 01:03:31 +010045libs.rangesv3.versions=trunk:030
RabsRincon7bd30b42018-01-18 17:40:10 +010046libs.rangesv3.url=https://github.com/ericniebler/range-v3
RabsRincon2ab39a02017-11-18 01:03:31 +010047```
48
RabsRincon7bd30b42018-01-18 17:40:10 +010049Now, for each declared version, CE will look for a `version` key, an human readable string representing the corresponding version,
RabsRincon3b8fb3b2017-11-18 01:06:59 +010050and `path`, a list consisting of the paths to add to the inclusion path of the library.
RabsRincon2ab39a02017-11-18 01:03:31 +010051
52This would leave us with: (Empty lines added for clarity. Please refrain from using them if you plan to PR us :D)
53
54```
55libs.kvasir.name=Kvasir::mpl
56libs.kvasir.versions=trunk
RabsRincon7bd30b42018-01-18 17:40:10 +010057libs.kvasir.url=https://github.com/kvasir-io/Kvasir
RabsRincon2ab39a02017-11-18 01:03:31 +010058
RabsRincon928c7a12018-06-28 22:13:50 +020059libs.kvasir.versions.trunk.version=trunk
RabsRincon2ab39a02017-11-18 01:03:31 +010060# Note how there are 2 paths defined for Kvasir in our case (Example usage!)
61libs.kvasir.versions.trunk.path=/opt/compiler-explorer/libs/kvasir/mpl/trunk/src/kvasir:/opt/compiler-explorer/libs/kvasir/mpl/trunk/src
62
63
64libs.boost.name=Boost
65libs.boost.versions=164:165
RabsRincon7bd30b42018-01-18 17:40:10 +010066libs.boost.url=http://www.boost.org/
RabsRincon2ab39a02017-11-18 01:03:31 +010067
RabsRincon928c7a12018-06-28 22:13:50 +020068libs.boost.versions.164.version=1.64
69libs.boost.versions.165.version=1.65
RabsRincon2ab39a02017-11-18 01:03:31 +010070
71libs.boost.versions.164.path=/opt/compiler-explorer/libs/boost_1_64_0
72libs.boost.versions.165.path=/opt/compiler-explorer/libs/boost_1_65_0
73
74
RabsRincone5ef0412018-03-04 05:59:40 +010075libs.rangesv3.name=range-v3
RabsRincon2ab39a02017-11-18 01:03:31 +010076libs.rangesv3.versions=trunk:030
RabsRincon7bd30b42018-01-18 17:40:10 +010077libs.rangesv3.url=https://github.com/ericniebler/range-v3
RabsRincon2ab39a02017-11-18 01:03:31 +010078
RabsRincon928c7a12018-06-28 22:13:50 +020079libs.rangesv3.versions.trunk.version=trunk
80libs.rangesv3.versions.030.version=0.3.0
RabsRincon2ab39a02017-11-18 01:03:31 +010081
82libs.rangesv3.versions.trunk.path=/opt/compiler-explorer/libs/rangesv3/trunk/include
83libs.rangesv3.versions.030.path=/opt/compiler-explorer/libs/rangesv3/0.3.0/include
84```
85
RabsRincon1c46f8f2018-05-08 15:17:47 +020086## Setting default libraries
87
88The `defaultLibs` key specifies an array of libs/versions which will be enabled by default when the user visits the site.
89The expected format is:
90```
91defaultLibs=libKeyA.version:libKeyB.version:libKeyC.version
92```
93Where `libKey` is the key of the library to be enabled by default, and `version` is the version key to load.
94Note that the site won't complain if invalid key/version pairs are set. Repeating a lib key more than once is supported.
95
RabsRincon2ab39a02017-11-18 01:03:31 +010096## Adding a new library locally
97
98It 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
101Once you've done that, running `make` should pick up the configuration and you should be able to use them from the library dropdown
102on the compiler view (The book icon)
103
104If you're looking to add libraries for another language, obviously create the `etc/config/LANG.local.properties` in
105the 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
108Test locally, and for many compilers that's probably all you need to do. Some compilers might need a few options tweaks (like
109the intel asm setting, or the version flag). For a completely new compiler, you might need to define a whole new `compilerType`.
110Doing so is beyond this document's scope at present, but take a look inside `lib/compilers/` to get some idea what might need
111to be done.
112
113## Adding a new library to the live site
114
115On the main CE website, libraries are installed into a `/opt/compiler-explorer/` directory by a set of scripts in the sister
116GitHub repo: https://github.com/mattgodbolt/compiler-explorer-image
117
118In the `update_compilers` directory in that repository are a set of scripts that download and install the libraries.
119If you wish to test locally, and can create a `/opt/compiler-explorer` directory on your machine which is readable and writable by your
120current user, then you can run the scripts directly.
121
122If your library fits nicely into the harness then it should be straightforward to add it there. Anything more complex: contact the CE
123authors for more help.
124
RabsRincone5ef0412018-03-04 05:59:40 +0100125Remember to also add the library dependencies following the same steps. It's on you if those should also appear in the UI.
RabsRincon8ac96fa2018-02-23 07:20:39 +0100126
RabsRincon2ab39a02017-11-18 01:03:31 +0100127## Putting it all together
128
129Hopefully that's enough to get an idea. The ideal case should be a pull request to add a couple of
130lines to the `compiler-explorer-image` to install the library, and a pull request to add a few lines to the `LANG.amazon.properties`
131file in this repository.
RabsRincone5ef0412018-03-04 05:59:40 +0100132Once 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
134If you feel like we could improve this document in any way, please contact us. We'd love to hear from you!