分享

SpiderMonkey Build Documentation - MDC

 jijo 2009-07-08

SpiderMonkey Build Documentation

Building SpiderMonkey 1.8 or earlier

Use these instructions to build SpiderMonkey from an official source release or from the old CVS repository. To build the latest SpiderMonkey sources from Mercurial, see Building SpiderMonkey tip below.

SpiderMonkey is easy to build from source if you have the usual Mozilla build prerequisites installed. Before you begin, make sure you have right build tools for your computer: Linux, Windows, Mac, others.

First, download a SpiderMonkey source distribution, such as SpiderMonkey 1.8 Release Candidate 1.

To build, use these commands:

tar xvzf js-1.8.0-rc1.tar.gz
cd js/src
make -f Makefile.ref

This builds a debug version of SpiderMonkey. All build files are created in a subdirectory named depending on your system (for example, Linux_All_DBG.OBJ if you are on Linux). To install this build on your system, see manual SpiderMonkey installation instructions.

To build an optimized (non-debug) version of SpiderMonkey:

make BUILD_OPT=1 -f Makefile.ref

To build a thread-safe version of SpiderMonkey:

make JS_DIST=/full/path/to/directory/containing/nspr JS_THREADSAFE=1 -f Makefile.ref

Building SpiderMonkey tip

This article covers features introduced in SpiderMonkey 1.8.1 (not yet released).

 

Use these instructions to build the latest SpiderMonkey sources.

Note for experienced JSAPI users: Read this carefully! Several important things have changed since 1.8. Where to get SpiderMonkey, how to build it, and how to compile and link your application have all changed (for the better, we think).

 

Before you begin, make sure you have right build tools for your computer: LinuxWindowsMacothers.

And of course you'll need to get the SpiderMonkey source code.

Easy build

Once you have the source code and build prerequisites, you can build current versions of SpiderMonkey like so:

cd js/src
autoconf-2.13
./configure
make

Note that autoconf version 2.13 is required. No later version will work.

This builds an executable named js in the current directory. At this point, you're ready to run and try out the shell.

On Mac, Linux, or UNIX, you can install SpiderMonkey on your system with the additional command make install. This installs the js executable, the shared library, and C header files to /usr/local/{bin,lib,include}.

Advanced build

For developing and debugging SpiderMonkey itself, it is best to have both a debug build (for everyday debugging) and an optimized build (for performance testing), in separate build directories.

cd js/src
autoconf-2.13
mkdir build-release
cd build-release
../configure
make
cd ..
mkdir build-debug
cd build-debug
../configure --enable-debug --disable-optimize
make

(Note:  If you previously did the easy build, you must first delete all the files and directories it created. If you don't, the advanced build will fail with error messages about not being able to open dependency files.)

For a list of other available build options, type:

./configure --help

Multithreaded applications require a special, thread-safe build of SpiderMonkey. See the additional build instructions at JS_THREADSAFE.

You may also build debug builds of SpiderMonkey with the JS_GC_ZEAL option, which adds a new built-in function to SpiderMonkey that lets you configure zealous garbage collection.  This can help debug memory leaks and other memory-related problems. See JS_SetGCZeal() for details.

Specifying installation directories

make install puts files in the following directories by default. You can override this by passing options to the configure script:

What it is Where it gets put configure option
executables, shell scripts /usr/local/bin --bindir
libraries, data /usr/local/lib --libdir
architecture-independent data /usr/local/share --sharedir
C header files /usr/local/include --includedir

For convenience, you can pass the configure script an option of the form --prefix=PREFIXDIR, which substitutes PREFIXDIR for /usr/local in all the settings above, in one step. This is usually the least troublesome thing to do, as it preserves the typical arrangement of lib, bin, and the rest.

Note that whatever directories you pass to configure are recorded in the generated Makefile, so you don't need to specify them again until you re-run configure.

Specifying compilers and compiler flags

If you'd like to use a compiler other than the one the configure script chooses for you by default, you can set the CXX variable in the environment when you run configure. This will save the values you specify in the generated Makefile, so once you've set it, you don't need to do so again until you re-run configure.

If you'd like to pass certain flags to the compiler, you can set the CXXFLAGS environment variable when you run configure. For example, if you're using the GNU toolchain, the following will pass the -g3 flag to the compiler, causing it to emit debug information about macros; then you can use those macros in gdb commands:

    $ CXXFLAGS=-g3 $SRC/configure
...
checking whether the C++ compiler (c++ -g3 ) works... yes
...
$

Whatever compiler and flags you pass to configure are recorded in the generated Makefile, so you don't need to specify them again until you re-run configure.

Building your application

While "How to build your complete application" is clearly out of scope for this document, here are some tips which will help get you on your way:

  • Versions of SpiderMonkey built with Makefile.ref require your application to define preprocessor macros visible to jsapi.h when you are building your own object files. These macros might have included XP_UNIX, JS_THREADSAFE, and so forth. With the new configure-based build, these are no longer needed, and you should remove them from your build system. The jsapi.h header now includes js-config.h, which is created at configure time. This header #defines all necessary preprocessor macros so that your objects build with an ABI that is compatible with the library built with the same invocation of configure.
  • The SpiderMonkey developers frequently and deliberately change the JSAPI ABI. You may not use headers built for one version/configuration of JSAPI to create object files which will be linked against another.
  • The ABI for SpiderMonkey with and without thread support is different. Be sure that your js-config.h header matches your library in this regard. There is currently no runtime test to determine if the ABIs match ( bug 477637).
  • The js-config script, described below, is the recommended way to determine correct include paths, required libraries, etc. for your embedding to use during compilation. We highly recommend calling the js-config script from your embedding's Makefile to set your CFLAGS, LDFLAGS, and so forth.
  • To install SpiderMonkey someplace other than the default, you must use configure's --prefix option, as described above. Failure to do so may break your js-config.h header or js-config script.
  • Some features detected by the configure script do not work for cross-compilation.

Using the js-config script

In addition to the SpiderMonkey libraries, header files, and shell, the SpiderMonkey build also produces a shell script named js-config which other build systems can use to find out how to compile code using the SpiderMonkey APIs, and how to link with the SpiderMonkey libraries.

When invoked with the --cflags option, js-config prints the flags that you should pass to the C compiler when compiling files that use the SpiderMonkey API; these flags ensure the compiler will find the SpiderMonkey header files.

    $ ./js-config --cflags
-I/usr/local/include/js
$ 

When invoked with the --libs option, js-config prints the flags that you should pass to the C compiler when linking an executable or shared library that uses SpiderMonkey. These flags ensure the compiler will find the SpiderMonkey libraries, along with any libraries that SpiderMonkey itself depends upon (like NSPR, in some circumstances).

    $ ./js-config --libs
-L/usr/local/lib -lmozjs  -ldl -lm  -lm -ldl
$ 

Test

The commands below assume you're using the advanced build.

  • Run ./js ../perfect.js and check if appropriate output is printed.

  • Run the following commands to start the test suite.

    cd ../../tests
        perl jsDriver.pl -L lc2 -L lc3 -L slow-n.tests     -L spidermonkey-n.tests -L spidermonkey-n-1.9.1.tests     -k -e smopt -s ../src/build-release/js
    • Warning: The test suite could run up to 30-40 minutes and eats up a lot of CPU cycles.
    • The tests run noticeably faster against an optimized build, but a debug build is more likely to catch regressions (because assertions are enabled).
  • If there are any failures, they will be recorded in a file, something like results-2007-08-23-010815-smopt-failures.txt. Rename this file to spidermonkey-known-failures-n.tests.

    (As of 2007-08-23, there are around 175-200 failing tests. Tests fail for various reasons. Some are testing obsolete features that have been deleted from SpiderMonkey. Some tests are a bit bogus in various ways, so innocent changes to SpiderMonkey break them. Decompiler tests in particular tend to be overly strict.)

  • In subsequent test runs, you can add the option -L spidermonkey-known-failures-n.tests to the above test suite run command to ignore these failing tests. This way, you can make sure your code changes haven't broken anything which was previously working.

(public-failures.txt should be documented here.)

Page last modified 22:18, 11 May 2009 by Tglek

Files (0)

 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多