Git Product home page Git Product logo

ghc-hotswap's Introduction

GHC.Hotswap

Demonstrates how to build an application that can hot-swap parts of itself at runtime, using GHC. This is a standalone illustration of the technology used in production in the Sigma system at Facebook.

There are a handful of Haskell packages here:

ghc-hotswap

Shared object swapping goodness.

Demo

Quick Start

Build types

  1. cd ghc-hotswap-types
  2. cabal configure
  3. cabal install

Build hotswap

  1. cd ghc-hotswap
  2. cabal configure
  3. cabal install

Build so

  1. cd ghc-hotswap-so
  2. cabal configure --enable-library-for-ghci
  3. cabal build (Note the file path of dist/build/HSghc-hotswap-so(...).o)

Run demo

  1. cd ghc-hotswap-demo
  2. cabal configure
  3. cabal build
  4. cabal run <path of first .o file>

ghc-hotswap-types

Example library for common types between the main binary and shared object. The object code for this library will end up in the final binary, but the shared object needs to know what types to generate at the API boundary.

No special configuration for this library

  • cabal configure
  • cabal install

ghc-hotswap

General library for loading and consecutively updating shared objects in a concurrency-safe manner.

No special configuration for this library

  • cabal configure
  • cabal install

ghc-hotswap-so

Example shared object library. Constains:

  • Handles module defining a function that returns a StablePtr to our expected API object and exports a c-symbol for it.
  • MyCode module as an example of complex library code that can be updated quickly

The main purpose is to generate an object file that another binary will know how to dynamically open. The --enable-library-for-ghci cabal flag does this for us.

  • cabal configure --enable-library-for-ghci
  • cabal build

The file we care about gets placed in ghc-hotswap-so/dist/build/ with a filename prefix like HSghc-hotswap-so and extension .o. The path to this file is important (or copy it to a nicer location for yourself) as you'll need it later.

ghc-hotswap-demo

Demo executable for loading + unloading shared objects on the fly.

Note the configuration set in ghc-hotswap-demo.cabal. It does not depend on ghc-hotswap-so and adds -rdynamic and -fwhole-archive-hs-libs as GHC flags.

  • cabal configure
  • cabal run <path-of-first-.o>

The program loads in the first shared object and periodically prints some information. It's waiting for input on stdin for the path of the next shared object to use.

  • Go back to ghc-hotswap-so
  • Edit SO/Handles.hs or SO/MyCode.hs to do as you want
  • Rebuild the object file (cabal build)
  • Copy the desired .o file somewhere friendlier
  • Send the full path of the .o to stdin of the demo program
  • See the output of the program change live
  • ???
  • Profit!

ghc-hotswap's People

Contributors

joncoens avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.