Skip to content
abergmeier edited this page Apr 13, 2013 · 25 revisions

This page should outline the idea of making (common) libraries available to Emscripten users.

Idea

Provide commonly used libraries at a centralized location, so additional external libraries might be build without having to patch their build system for Emscripten.

Prototype

Since Emscripten has not support for dynamic libraries and/or their file format a solution should not rely on the dynamic library infrastructure. Building for Unix systems it is common for packages to provide the means to link to them via pkg-config files. Similarly this mechanism could be adopted for Emscripten.

Introducing empkg-config

An example for building and linking with zlib in a Makefile:

CFLAGS := $(shell pkg-config --cflags zlib)
# Some build command
LDFLAGS := $(shell pkg-config --libs zlib)
# Some link command

Utilizing this way of retrieving necessary information for zlib we could provide zlib to the user. A new script empkg-config would do the following:

  1. Download the <package name>/versions file from https://github.com/abergmeier/emscripten-libs or fail if no package directory is available.
  2. Find the highest (latest) version in versions file.
  3. Check in EM_CACHE/build/<package name><latestversion> whether there is a valid build-timestamp file. If there is go to 5.
  4. Download the latest version from the src in versions.
  5. Attempt to execute the build command from the configuration.
  6. Return failure or success depending whether build did work.
Format of versions:

The versions file is a JSON version of the pkg-config format with additional source information.

{ "name"       : "zlib",
  "description": "zlib compression library",
  "src"        : { "git": { "repo": "git://github.com/madler/zlib.git" }
  },
  "build"      : "make EMSCRIPTEN=1",
  "versions"   : [ { "version": "1.2.7",
                     "libs"   : "somestring",
                     "cflags" : "somestring",
                     "src"    : { "git": { "tag": "1.2.7" }
                     }
                   },
                   { "version": "1.2.6.1",
                     "libs"   : "somestring",
                     "cflags" : "somestring",
                     "src"    : { "git": { "tag": "1.2.6.1" }
                     }
                   }
  ]
}

Pro

  • Less to no work for users
  • Higher chances for pushing patches upstream
  • Maintainance necessary

Contra

  • Might not fit every usage scenario
  • Library has to be available via sourcecode