Building node.js as shared library

561 views
Skip to first unread message

Kp

unread,
Oct 15, 2011, 4:50:42 PM10/15/11
to nodejs, kobalic...@gmail.com
Hello,

Is it possible to build node.js as a shared library? I mean that the
result of build will be "nodejs.so" and "nodejs" (app) which will be
linked to the "nodejs.so".

I tried this (using 0.5.9):

cd ${NODEJS_DIR}

./tools/waf-light configure --dest-cpu=x64 --shared-zlib --shared-
cares --shared-v8 --shared-v8-includes=${REPOSITORY_INCLUDE} --shared-
v8 --libpath=${REPOSITORY_LIB} --prefix=${REPOSITORY_ROOT}
./tools/waf-light build --product-type=cshlib
./tools/waf-light install

But this won't install 'nodejs.so', but builds 'nodejs' application
and install it instead.

Another things (bugs?):

1. ./configure --product-type doesn't work, I needed to call to waf-
light manually.

2. waf-light install doesn't accept --product-type argument.

3. I needed to fix -fPIC issues under x64 platform, manually like
this:
export CCFLAGS="${CCFLAGS} -fPIC"
export CXXFLAGS="${CXXFLAGS} -fPIC"
export CPPFLAGS="${CPPFLAGS} -fPIC"
although this is already reported, I think.

==================================================

To be complete. This is my script for building node.js as a shared
library, v8 is included too.

#!/bin/sh

export JOBS=4

# Fix amd64 link error (no -fPIC flag set).
export CCFLAGS="${CCFLAGS} -fPIC"
export CXXFLAGS="${CXXFLAGS} -fPIC"
export CPPFLAGS="${CPPFLAGS} -fPIC"

# This is where I want to place NodeJS and all related, for now $
{HOME}/NodeJS.
REPOSITORY_ROOT=`pwd`
REPOSITORY_BIN="${REPOSITORY_ROOT}/bin"
REPOSITORY_LIB="${REPOSITORY_ROOT}/lib"
REPOSITORY_INCLUDE="${REPOSITORY_ROOT}/include"

# NodeJS.
NODEJS_VER="0.5.9"
NODEJS_DIR="${REPOSITORY_ROOT}/src/node-v${NODEJS_VER}"

# V8 - The V8 from NodeJS distribution is used, but built separately.
V8_DIR="${NODEJS_DIR}/deps/v8"

#
------------------------------------------------------------------------------
# [Repository]
#
------------------------------------------------------------------------------

mkdir ${REPOSITORY_BIN}
mkdir ${REPOSITORY_LIB}
mkdir ${REPOSITORY_INCLUDE}

#
------------------------------------------------------------------------------
# [NodeJS + V8]
#
------------------------------------------------------------------------------

# Extract NodeJS
tar -zxvf src/node-v${NODEJS_VER}.tar.gz -C src

# Build and install V8.
cd ${V8_DIR}
scons -Q -j 4 arch=x64 mode=release library=shared prefix=$
{NODEJS_DIR}
cd ${REPOSITORY_ROOT}

# There is no install script inside V8 build configuration.
# We need to install important files manually.
cp ${V8_DIR}/libv8.so ${REPOSITORY_LIB}/libv8.so
cp ${V8_DIR}/include/* ${REPOSITORY_INCLUDE}
strip ${PACKAGE_LIB}/libv8.so --strip-unneeded

# Build and install NodeJS.
cd ${NODEJS_DIR}
./tools/waf-light configure --dest-cpu=x64 --shared-zlib --shared-
cares --shared-v8 --shared-v8-includes=${REPOSITORY_INCLUDE} --shared-
v8-libpath=${REPOSITORY_LIB} --prefix=${REPOSITORY_ROOT}
./tools/waf-light build --product-type=cshlib
# Doesn't install nodejs.so
./tools/waf-light install
cd ${REPOSITORY_ROOT}

Thanks
Petr
Reply all
Reply to author
Forward
0 new messages