25
Introducing cvm Offirmo, 18/01/2013 The best way to manage your C++ applications dependencies Tribute to rvm

Introducing cvm

  • Upload
    offirmo

  • View
    1.587

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Introducing cvm

Introducing cvm

Offirmo, 18/01/2013

The best way to manage your C++ applications dependencies

Tribute to rvm

Page 2: Introducing cvm

cvm

C++ Version Manager

a tool

to automatically manage

your C++ application's dependencies

Page 3: Introducing cvm

Once upon a time…

…there was a programmer…

…who was developping an honest C++ application…

Page 4: Introducing cvm

His C++ app was not standalone…

His app was based on a C++ lib called :

He was using of course.

He was also unit-testing using : UnitTest++

…and using cmake to build. (and gcc of course)

Page 5: Introducing cvm

One day, the app got (somewhat) ready to go in production.

The programmer set up a clean linux box and began installing his app… (Note : it's a server app)

Then the troubles arrived...

Page 6: Introducing cvm

● Ubuntu 10.04 LTS (at that time, and make a better example ;)

● Clean, no packages installed● Current situation :

Page 7: Introducing cvm

● My app : git clone https://github.com/abcd/xyz● So I need git : sudo apt-get install git

● Need gcc & co. : sudo apt-get install build-essentials● Need wt : sudo apt-get install witty witty-dbg witty-dev

● Need Boost : sudo apt-get install libboost-dev● Nedd UnitTest++, which has no packet :

wget …

make (yes, it's a very simple lib)

● Need cmake : sudo apt-get install cmake● Let's compile :

cmake ../xyzmake

Fail !!!

Page 8: Introducing cvm

● First cmake can't find UnitTest++ that I installed manually in a custom dir, so :

export … (have fun with pathes)

● Then cmake of Ubuntu 10.04 is too old for my app, I need to install latest from source :

wget …./bootstrap --prefix="…"makemake install

● Default Wt is also too old :git clone …cmake ../… -PREFIX … -DCONFIGDIR …makemake install--> but FAIL because Boost is too old !

● So for Boost :...

Well, you get it…

Pain !!!Pain!!!

Fail !!!

Page 9: Introducing cvm

Pain ! Fail ! %$# !Completely value-less task !

Utter loss of time and energy !Unworthy of us programmers !

Page 10: Introducing cvm

proposed solution : the cvmcvm tool

sudo apt-get install gitgit clone git://github.com/Offirmo/cvmcvm.git(add cvmcvm/bin to the path)git clone git://github.com/abcd/myappmyapp.git

cvmcvm new myapp

cd myappcvmcvm set_compfilecvmcvm updatecvmcvm upgrade

mkdir ../buildcd ../buildcvm_execcvm_exec cmake ../myappcvm_execcvm_exec make

Done !Installation of dependencies

App build

Page 11: Introducing cvm

The magic…

● The app provides a «component file» listing its dependencies :

(simplified)

# As far as I know, no particular gcc version is required require compiler.gcc require lib.std

# need a recent version require lib.UnitTest++, version : 1.4+

# need a recent version require lib.Boost, version : 1.51+

# need a recent version require lib.Wt, version : 3.2.3

Page 12: Introducing cvm

The magic…

● Then cvm automatically setup the environment so that all dependencies are met !

cvmcvm set_compfile

cvmcvm update

cvmcvm upgrade

Set the « component file »

compute dependencies (who needs what, which version)

Install everything needed : - use apt-get if possible - download and build from source else

Page 13: Introducing cvm

The magic…

● Of course, cvm must know about the components :● corresponding apt packets● download url● how to build them● ...

● So cvm has a database of components

Page 14: Introducing cvm

Does it ring a bell ?

● Other languages have such a tool for a while● ex. ruby "bundler" http://gembundler.com/

● It's a shame that C++ still didn't have it !● Fixed ;)

Page 15: Introducing cvm

More awesomness...

● cvm installs everything in user-land● No need to be admin (except for apt-get install)

● cvm doesn't mess with the env vars● set them on demand, hence the cvm_exec wrapper

● cvm can ensure exact components versions● Perfect for production environment

● cvm can maintain separate sets of components● So you can have different versions of the

components for different apps/versions

Page 16: Introducing cvm

More awesomness...

● cvm has more nice features● Not listed here for brievity, see «bonuses»

● cvm is easy to install● Just bash scripts !

● cvm is totally free● Copyfree license, do whatever you want with it !

Page 17: Introducing cvm

Current status

● cvm works (at last for me on my machine ;)● It is still rough :

● compfile syntax still in progress● multi-users usage needs to be enhanced● only 16 components at this time (jan-2013)

● But easy to add some !● Code and architecture would benefit from a little cleanup to ease contributions

● Comments and suggestions are welcomed !● Fork me on github ! (doc on internals coming soon)

Page 18: Introducing cvm

One more thing...

● Why c.v.m. ?● Because of rvm (ruby version manager) https://rvm.io/

● Like rvm, cvm is meant to play with multiple compilers : gcc 4.7 (for C++11), clang...● This feature is not available yet (jan-2013)

Page 19: Introducing cvm

Thank you !

https://github.com/Offirmo/cvm

Page 20: Introducing cvm

Bonuses

Page 21: Introducing cvm

Dependencies handlingOf course, cvm computes dependencies recursively and resolves them.

Example 1 : My app --> Boost 1.49+ My app --> Wt 3.2.3 --> Boost 1.41+ --> Latest known Boost newer or equal to 1.49 will be installed

Example 2 : My app --> Boost 1.40 (exact version) My app --> Wt 3.2.3 --> Boost 1.41+ --> Error ! cvm can't resolve those conflicting requests

Page 22: Introducing cvm

The real dependency graph of my app is :

The orange parts are non-trivial to install on my target OS (no correct packet)

While developping, I installed everything by hand when needed. Then I forgot about it...

Page 23: Introducing cvm

The corresponding compfile is…## C++ VM component set definition## see https://github.com/Offirmo/cvm#### Thanks to this file and the C++VM tool,## all exact dependencies are installed.

cvm_minimum_required_version 1.0

# As far as I know, no particular gcc version is requiredrequire compiler.gccrequire lib.std

require lib.UnitTest++, version : 1.4+

# need a recent versionrequire lib.Boost, version : 1.51+

# sqlite is an optional dependency of Wt. We want a decent version for some bugfixesrequire lib.sqlite, version : 3.7+# exact version of Wt + ensure that sqlite is built beforerequire lib.Wt, version : 3.2.3, require : lib.sqlite

Page 24: Introducing cvm

Additional features● cvm automatically set env vars needed by autotools and cmake, so they correctly find the manually installed libs (over the system one)● cvm can automatically detect headers for libs that don't provide a «make install»● cvm automatically creates a folder with all headers so you can provide it to your IDE code indexer (ex. Eclipse)● cvm try to save resources by caching common resources : downloaded archives and source code (src not duplicated if out-of-src build is available)

Page 25: Introducing cvm

Links :● https://rvm.io/● http://gembundler.com/

S/O● http://stackoverflow.com/q/14263324/587407● http://stackoverflow.com/q/1827705/587407

Image credits :● http://tecfa.unige.ch/tecfa/teaching/UVLibre/0001/bin17/troubles.html● wikipedia