jsish
Build
Not logged in

Building Jsi

We build Jsi on Linux.

Building Jsi on Ubuntu requires a few packages:

sudo apt-get install build-essential bison libreadline-dev libsqlite3-dev libwebsockets-dev libncurses-dev cmake libmysqlclient-dev

Some of these (eg. cmake) are only required for specific configurations.

Linux

To build the Linux target there are are two steps:

./configure

Do not be surprised to see comiler output from ./configure: it compiles the stripped down shell jsimin.

Next, run make to build the actual jsish executable.

make

If you want, you can see other available options using:

./configure --help

Note the directory Configs/, which contains a number of predefined configurations which can be copied to make.conf

Lastly, if you want you can run the test suite with:

make test

Windows

Jsi can be cross compiled from Linux to Windows using the Mingw32 package:

sudo apt-get install gcc-mingw32

The sqlite and libwebsockets source needs to be downloaded and unpacked in ../sqlite and ../websockets.

Then configure using:

./configure --config=win

Note that certain features (eg. signals) are disabled in the Windows build. There are also differences in some of the file-system access functions.

Standalone

The standalone build produces a static binary that contains no external library references. This is useful when you need a standalone executable with no external dependancies.

To create a static image, Jsi uses the Musl library.

The first step is to download Musl and unpack it. Then change to the musl dir and run configure/make, eg:

 ./configure --prefix=$HOME/usr && make install

Ensure that ~/usr/bin is in your path with export PATH=$PATH:$HOME/usr/bin. Then back in the jsi dir do the following:

echo '#define __P(x) x' > ~/usr/include/sys/cdefs.h
echo '#include <miniz/zlib.h>' >  ~/usr/include/zlib.h
cp -pr miniz ~/usr/include/

The sqlite and libwebsockets source needs to be downloaded and unpacked in ../sqlite and ../websockets.

The static jsish can then be built with:

./configure --config=musl
make

Amalgamation

Amalgamated source is the easiest way to incorporate Jsi into an existing application: Here is a simple example:

#include "jsi.c"

int main(int argc, char *argv[])
{
    Jsi_Interp *interp = Jsi_InterpNew(NULL);
    Jsi_EvalString(interp, "for (var i=1; i<=3; i++)  puts('TEST: '+i);", 0);
    Jsi_EvalFile(interp, argv[1], 0);
    //...
}

which we compile with:

gcc  myfile.c -lm -lz -ldl -lpthreads

Another alternative that simplifies debugging Jsi is using ../jsiOne.c (then linking against jsiOne.a).

For more details, see Using Jsi, Jsi-Lite or DBQuery.


Extensions

A Basic Extension

The source for a basic extension is shown in ../c-demos/demo1.c, which creates a new javascript method demo() that simply echo's its arguments.

We can build this into a jsish shell with:

gcc -o demo1 -g -I.. -DJSI_USER_EXTENSION=Jsi_Initdemo1 demo1.c ../jsish.c ../main.c -lm -lz -ldl -lpthreads

and run with:

./demo1
LOADED DEMO
# demo(1,2,3)
demo called with 3 args
Arg 0 = '1'
Arg 1 = '2'
Arg 2 = '3'
undefined

Alternatively, we can just call Jsi_Initdemo1(interp) from our own amalgamation.

Multi-method Extension

It is often more useful to create multiple related commands within a single object.

The source in ../c-demos/demo2.c does exactly this, which again we build it with:

gcc -o demo2 -g -I.. -DJSI_USER_EXTENSION=Jsi_Initdemo2 demo2.c ../jsish.c ../main.c -lm -lz -ldl -lpthreads

Now we have several new javascript methods


C++ Support

The Jsi source code is both valid C and valid C++. This means it will build with: "make CC=g++"


Getting Help

Having problems?