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
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
--with-ccacheto 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:
- Download and extract “Eclipse IDE for C/C++ Developers” from the Eclipse downloads page.
- Start Eclipse and create a workspace somewhere
- Select “New > Makefile Project with Existing Code” from the “File” menu
- 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/srcfolder for the “Existing Code Location”
- 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:
- Open the project’s properties by selecting its root and clicking “Properties” in the “File” menu and select “C/C++ Build”
- Under “Builder Settings”, deactivate “Use default build command”
- Instead, change “Build command” to read
make -w(this is required because CDT needs detailed information about which directories
makeoperates on, which using
- Change the “Build location” to the build directory configured in step 1. For me, that means changing “Build directory” to read
- Under “Behavior”, make sure that “Enable parallel build” is deactivated, as CDT’s indexer will freak out otherwise
- Remove “all” from “Build (Incremental build)”
- Deactivate “Clean” so that your builds don’t take ages
- 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
- Start the build by selecting “Build All” from the “Project” menu
- 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.