Setting up CDT to work on SpiderMonkey

Eclipse’s CDT has some pretty decent features that make it an attractive environment to work in when you're interested in getting code hints, autocompletion, function and field usage information and general IDE goodness for C/C++.

There's a guide for setting up CDT to work with the Mozilla codebase, but it doesn’t cover setting things up for just SpiderMonkey instead of the whole Mozilla codebase. Hence, here’s a short-ish guide for doing just that:

Step 1 - Preparing a SpiderMonkey build

For CDT to index all code, SpiderMonkey has to be built with debug information. The full process of and requisites for doing so are described here. Please follow those instructions up until the point of invoking configure.

I prefer building with clang, so my modified build commands look like this:

mkdir _DBG.OBJ
cd _DBG.OBJ
CC='clang -Qunused-arguments -fcolor-diagnostics' CXX='clang++ -Qunused-arguments -fcolor-diagnostics' \
    ../configure --enable-debug --disable-optimize --enable-debug-symbols
Note: If you want to use ccache, you can enable it by adding --with-ccache to the arguments list. Due to a bug in CDT, you have to make a small change to CDT's build configuration as explained in Step 3 below for that to work, though.

Step 2 - Installing Eclipse and setting up the project

The following run-down is a condensed and updated version of what’s explained in much more detail for the entire Mozilla codebase. Luckily, improvements in CDT have reduced the basic process to a manageable 5 steps:

  1. Download and extract “Eclipse IDE for C/C++ Developers” from the Eclipse downloads page.
  2. Start Eclipse and create a workspace somewhere
  3. Select “New > Makefile Project with Existing Code” from the “File” menu
  4. Give the project a name you like (“SpiderMonkey” has a nice ring to it) and use the “Browser…” button to select your checkout’s js/src folder for the “Existing Code Location”
  5. Choose the correct toolchain for your platform (i.e. MacOS X GCC on Mac) and click “Finish”

At this point, the indexer starts running and already produces a pretty decent index of much of SpiderMonkey. Still, there are a quite a few things that CDT doesn’t pick up yet: For everything to be indexed, CDT has to be aware of the project’s build details.

Step 3 - Index all the code

To let CDT know about the build, it has to invoke make itself (or, as is done in the guide for the whole Mozilla codebase on MDN, read a log of the build). This can be setup in another set of decently simple steps:

  1. Open the project’s properties by selecting its root and clicking “Properties” in the “File” menu and select “C/C++ Build”
  2. Under “Builder Settings”, deactivate “Use default build command”
  3. Instead, change “Build command” to read make -w (this is required because CDT needs detailed information about which directories make operates on, which using -w causes make to provide)
  4. Change the “Build location” to the build directory configured in step 1. For me, that means changing “Build directory” to read ${workspace_loc:/SpiderMonkey/_DBG.OBJ}
  5. Under “Behavior”, make sure that “Enable parallel build” is deactivated, as CDT’s indexer will freak out otherwise
  6. Remove “all” from “Build (Incremental build)”
  7. Deactivate “Clean” so that your builds don’t take ages
  8. If you want to use ccache: Select "C/C++ General -> Preprocessor Include Patterns". Under "Providers", select "CDT GCC Build Output Parser" and add the string |(ccache) to the end of the "Compiler command pattern" text input
  9. Start the build by selecting “Build All” from the “Project” menu
  10. Start the indexer by selecting “Index > Rebuild” from the project’s context menu

And that’s pretty much it: Large parts of SpiderMonkey should now be indexed. Unfortunately, there are also large parts that aren’t properly indexed, leading to errors and warnings being shown for perfectly valid code, but I find that the parts that do work do so nicely enough to make it totally worth it.

See also

Document Tags and Contributors

Contributors to this page: Sheppy, tschneidereit
Last updated by: tschneidereit,