basho / erlang_js

A linked-in driver for Erlang to Mozilla's Spidermonkey Javascript runtime.
Apache License 2.0
238 stars 88 forks source link

Add BSD support to erlang_js #11

Closed Vagabond closed 12 years ago

Vagabond commented 13 years ago

This patch adds .mk files for FreeBSD, NetBSD, OpenBSD and DragonFlyBSD. It also patches some nspr files so that nspr builds correctly for the BSDs as well.

The only thing not solved by this commit is the make/gmake issue, which is also a problem on solaris. On BSD GNU make is called 'gmake' and BSD make is called 'make'. However rebar is blindly assuming that GNU make is called 'make', so this is problematic on any non-Linux UNIX flavor.

PiotrSikora commented 13 years ago

Hi, thanks for your hard work on bringing Riak to BSDs!

However, I kind of disagree with your approach (and Riak's packaging of nspr & spidermonkey in general). All BSDs have great porting/packaging systems and they make sure that everything actually works (and not just compiles)... But since most software vendors don't support BSDs, that usually involves some patching, which is also the case with ports of nspr & spidermonkey.

For example, let's take a look at patches in OpenBSD's port tree (similar situation is in the FreeBSD's and NetBSD's): http://www.openbsd.org/cgi-bin/cvsweb/ports/devel/nspr/patches/ http://www.openbsd.org/cgi-bin/cvsweb/ports/www/firefox36/patches/ (OpenBSD uses spidermonkey-1.9.2.16 from Firefox).

As you can imagine, we would be way better off using nspr & spidermonkey provided by the operating system's porting team that by compiling them ourselves without any additional patches.

This is actually very simple on NetBSD and DragonFly (since they have spidermonkey-1.8.0 in the ports). It just requires changing paths to libraries and disabling port_{pre,cleanup}_script hooks in the rebar.conf. The make call requires patching anyway, so this isn't a problem at all.

FreeBSD has spidermonkey-1.7.0, so bundled in version is the only option.

The situation complicates a bit on OpenBSD, which has spidermonkey-1.9.2.16 and as you may know, Mozilla removed JS_SetBranchCallback (which is used by erlang_js) in 1.8.5 and 1.9.x releases, so erlang_js simply cannot compile there.

Do you think it would be possible to add some #ifdefs in the code to make it work with spidermonkey-1.9.x (and OpenBSD)?

Vagabond commented 13 years ago

Well, I think we're planning to update erlang_js to 1.8.5 anyway, so those issues are ones we will have to address.

I agree that bundling spidermonkey like this isn't ideal, but as you've already noted; the spidermonkey version available across different OSes (and I'm sure different linux distributions) is not consistant and they've changed enough between 1.8.0 and 1.8.5 (or 1.9.x which doesn't really exist unless you extract it from the firefox tarball) that I don't know if we can ship a version of erlang_js that will build against such radically different versions of spidermonkey.

I guess we'll know better once we do the work porting erlang_js to 1.8.5. I just wanted to get the ball rolling on this.

PiotrSikora commented 13 years ago

Damn, I wrote so much in the last comment that I kind of missed my point :)

The issue I'm having isn't the fact that you're bundling-in nspr & spidermonkey in general (it isn't very elegant, but since there is bunch of systems that don't have recent enough versions, there is no other way around it). The problem isn't even the fact that there is no switch to choose between bundled-in version vs system provided one (but it would be definitely nice to have it!), since the "porting patch" is super small:

--- deps/erlang_js/rebar.config.orig
+++ deps/erlang_js/rebar.config
@@ -5,8 +5,8 @@
 %%

 {port_envs, [
-             {"DRV_CFLAGS", "$DRV_CFLAGS -I c_src/system/include/js -DXP_UNIX"},
-             {"DRV_LDFLAGS", "$DRV_LDFLAGS c_src/system/lib/libjs.a c_src/system/lib/libnspr4.a"},
+             {"DRV_CFLAGS", "$DRV_CFLAGS -I /usr/local/include/js -DXP_UNIX"},
+             {"DRV_LDFLAGS", "$DRV_LDFLAGS -L /usr/local/lib -lmozjs"},

              %% Define flags for enabling/disable 64 bit build of NSPR
              {"-32$", "NSPR_SIXTYFOUR", "--disable-64bit"},
@@ -26,5 +26,5 @@
              {"darwin10.*-32$", "LDFLAGS", "-arch i386"}
             ]}.

-{port_pre_script, {"make -C c_src", ""}}.
-{port_cleanup_script, "make -C c_src clean"}.
+%% {port_pre_script, {"make -C c_src", ""}}.
+%% {port_cleanup_script, "make -C c_src clean"}.

The real problem is that erlang_js works only with one specific version of spidermonkey. To be honest I even looked at what needs to be done (and the only problematic change is JS_SetBranchCallback which was replaced by similar JS_SetOperationCallback), but I don't know single thing about how spidermonkey operates, so I'm unable to provide quality patch for this.

Vagabond commented 12 years ago

Rebased on top of master with gmake/make compatibility fixes.