ReluctantProgrammer
ReluctantProgrammer

Reputation: 77

Embedding Mozilla's JavaScript Engine in C++

I want to embed Mozilla's SpiderMonkey in my standalone C++ program (in Visual Studio 2019). I went over all the documentation and whatnot but the problem is (or what I need is):

And that's it. The thing is, in the documentation it says I need to build the entirety of Mozilla's Firefox browser (which is not less than a Gigabyte) and download Mercurial and open the command prompt and create directories etc. and all that disgusting stuff. I just need to be able to:

#include <jsapi.h>

And perform all the necessary C++-to-JS (and vice-versa) operations.

I do not think I need to download and build the entire FireFox browser to do this (I maybe wrong?).

Upvotes: 2

Views: 1285

Answers (2)

Mr. Shroom
Mr. Shroom

Reputation: 11

If anyone is still interested the spider monkey on Windows, you would follow the build instructions here:

https://firefox-source-docs.mozilla.org/js/build.html

using the build tools here:

https://firefox-source-docs.mozilla.org/setup/windows_build.html

If you are very meticulous you don't need to download the entire FireFox code base but your life will be easier if you do. In order to only build spidermonkey only (plus js command line), be sure to activate a particular MOZCONFIG with ac_add_options --enable-application=js in it before calling any of the mach commands.

Note: if you plan to use the Visual C++ compiler and not clang-cl, you are limited to version 78 or you will have to figure out how to modify the header yourself.

for reference this is the config I used to successfully build spidermonkey 81.0.2 on Windows 10:

# Build only the JS shell
ac_add_options --enable-application=js

# Enable optimization for speed
ac_add_options --enable-optimize
# Enable the debugging tools: Assertions, debug only code etc.
# For performance testing you would probably want to change this
# to --disable-debug.
ac_add_options --disable-debug
ac_add_options --disable-jemalloc
ac_add_options --prefix=$MY_PREFIX
mk_add_options MOZ_MAKE_FLAGS="-j4"
# Use a separate objdir for optimized builds to allow easy
# switching between optimized and debug builds while developing.
mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/obj-opt-@CONFIG_GUESS@

If you use this config, after you successfully build, then navigate to @TOPSRCDIR@/obj-opt-@CONFIG_GUESS@ and do mozmake install, it "install" all the files you need into $MY_PREFIX

Upvotes: 1

Tom
Tom

Reputation: 6709

UPDATE - This answer is wrong. sparse checkout actually downloads all the history. One would have to use the narrowhg ext, which isn't supported on the hg.mozilla.org repo.

the following answer is wrong.

You could use mercurial sparse checkout to just get the js/src folder. (but with all the history of the js/src folder it will still likely be quite big) This will just the history for js/src folder.

you need a version of mercurial which is newer then 3 years old (4.3 or newer)

 mkdir spidermonkey
 cd spirdermonkey
 hg init
 hg debugsparse --include js/src
 hg pull https://hg.mozilla.org/releases/mozilla-release -u

Upvotes: 0

Related Questions