Browse Source

First attempt at node.dlopen

Compiled first working 'hello world' module with this config
v0.7.4-release
Ryan 16 years ago
parent
commit
2b6d72431b
  1. 1
      deps/libeio/wscript
  2. 1
      deps/libev/wscript
  3. 7
      src/main.cc
  4. 34
      src/node.cc
  5. 1
      src/node.h
  6. 35
      wscript

1
deps/libeio/wscript

@ -113,4 +113,5 @@ def build(bld):
libeio.install_path = None libeio.install_path = None
if bld.env["USE_DEBUG"]: if bld.env["USE_DEBUG"]:
libeio.clone("debug"); libeio.clone("debug");
bld.install_files('${PREFIX}/include/node/', 'eio.h');

1
deps/libev/wscript

@ -56,4 +56,5 @@ def build(bld):
libev.install_path = None libev.install_path = None
if bld.env["USE_DEBUG"]: if bld.env["USE_DEBUG"]:
libev.clone("debug"); libev.clone("debug");
bld.install_files('${PREFIX}/include/node/', 'ev.h');

7
src/main.cc

@ -0,0 +1,7 @@
#include "node.h"
int
main (int argc, char *argv[])
{
return node::start(argc, argv);
}

34
src/node.cc

@ -16,6 +16,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <strings.h> #include <strings.h>
#include <assert.h> #include <assert.h>
#include <dlfcn.h> /* dlopen(), dlsym() */
#include <string> #include <string>
#include <list> #include <list>
@ -100,6 +101,36 @@ node_exit (const v8::Arguments& args)
return Undefined(); return Undefined();
} }
typedef void (*extInit)(Handle<Object> exports);
Handle<Value>
node_dlopen (const v8::Arguments& args)
{
if (args.Length() < 2) return Undefined();
HandleScope scope;
String::Utf8Value filename(args[0]->ToString());
Local<Object> target = args[1]->ToObject();
void *handle = dlopen(*filename, RTLD_LAZY);
if (handle == NULL) {
ThrowException(String::New("dlopen() failed."));
return Undefined();
}
void *init_handle = dlsym(handle, "init");
if (init_handle == NULL) {
ThrowException(String::New("No 'init' symbol found in module."));
return Undefined();
}
extInit init = reinterpret_cast<extInit>(init_handle);
init(target);
return Undefined();
}
v8::Handle<v8::Value> v8::Handle<v8::Value>
compile (const v8::Arguments& args) compile (const v8::Arguments& args)
{ {
@ -206,6 +237,7 @@ Load (int argc, char *argv[])
NODE_SET_METHOD(node_obj, "compile", compile); NODE_SET_METHOD(node_obj, "compile", compile);
NODE_SET_METHOD(node_obj, "reallyExit", node_exit); NODE_SET_METHOD(node_obj, "reallyExit", node_exit);
NODE_SET_METHOD(node_obj, "dlopen", node_dlopen);
node_obj->Set(String::NewSymbol("EventEmitter"), node_obj->Set(String::NewSymbol("EventEmitter"),
EventEmitter::constructor_template->GetFunction()); EventEmitter::constructor_template->GetFunction());
@ -283,7 +315,7 @@ ParseArgs (int *argc, char **argv)
} }
int int
main (int argc, char *argv[]) node::start (int argc, char *argv[])
{ {
evcom_ignore_sigpipe(); evcom_ignore_sigpipe();
ev_default_loop(EVFLAG_AUTO); // initialize the default ev loop. ev_default_loop(EVFLAG_AUTO); // initialize the default ev loop.

1
src/node.h

@ -32,6 +32,7 @@ do { \
enum encoding {ASCII, UTF8, RAW}; enum encoding {ASCII, UTF8, RAW};
enum encoding ParseEncoding (v8::Handle<v8::Value> encoding_v); enum encoding ParseEncoding (v8::Handle<v8::Value> encoding_v);
void FatalException (v8::TryCatch &try_catch); void FatalException (v8::TryCatch &try_catch);
int start (int argc, char *argv[]);
} // namespace node } // namespace node
#endif // node_h #endif // node_h

35
wscript

@ -56,6 +56,7 @@ def configure(conf):
conf.env["USE_DEBUG"] = Options.options.debug conf.env["USE_DEBUG"] = Options.options.debug
conf.check(lib='dl', uselib_store='DL')
if Options.options.debug: if Options.options.debug:
conf.check(lib='profiler', uselib_store='PROFILER') conf.check(lib='profiler', uselib_store='PROFILER')
@ -127,6 +128,7 @@ def build_udns(bld):
#debug.target = join(debug_dir, static_lib) #debug.target = join(debug_dir, static_lib)
bld.env_of_name('debug')["STATICLIB_UDNS"] = "udns" bld.env_of_name('debug')["STATICLIB_UDNS"] = "udns"
bld.env_of_name('debug')["LIBPATH_UDNS"] = debug_dir bld.env_of_name('debug')["LIBPATH_UDNS"] = debug_dir
bld.install_files('${PREFIX}/include/node/', 'deps/udns/udns.h');
def build_v8(bld): def build_v8(bld):
@ -162,6 +164,8 @@ def build_v8(bld):
v8_debug.rule = v8rule % (v8dir_tgt, scons, "debug") v8_debug.rule = v8rule % (v8dir_tgt, scons, "debug")
v8_debug.target = join("deps/v8", bld.env["staticlib_PATTERN"] % "v8_g") v8_debug.target = join("deps/v8", bld.env["staticlib_PATTERN"] % "v8_g")
bld.install_files('${PREFIX}/include/node/', 'deps/v8/include/v8*');
def build(bld): def build(bld):
bld.add_subdirs('deps/libeio deps/libev') bld.add_subdirs('deps/libeio deps/libev')
@ -178,6 +182,7 @@ def build(bld):
evcom.install_path = None evcom.install_path = None
if bld.env["USE_DEBUG"]: if bld.env["USE_DEBUG"]:
evcom.clone("debug") evcom.clone("debug")
bld.install_files('${PREFIX}/include/node/', 'deps/evcom/evcom.h');
### http_parser ### http_parser
http_parser = bld.new_task_gen("cc", "staticlib") http_parser = bld.new_task_gen("cc", "staticlib")
@ -222,10 +227,11 @@ def build(bld):
if bld.env["USE_DEBUG"]: if bld.env["USE_DEBUG"]:
native_cc.clone("debug") native_cc.clone("debug")
### node ### node lib
node = bld.new_task_gen("cxx", "program") libnode = bld.new_task_gen("cxx", "shlib")
node.target = 'node' libnode.name = "node"
node.source = """ libnode.target = "node"
libnode.source = """
src/node.cc src/node.cc
src/events.cc src/events.cc
src/http.cc src/http.cc
@ -237,7 +243,7 @@ def build(bld):
src/child_process.cc src/child_process.cc
src/constants.cc src/constants.cc
""" """
node.includes = """ libnode.includes = """
src/ src/
deps/v8/include deps/v8/include
deps/libev deps/libev
@ -247,11 +253,24 @@ def build(bld):
deps/http_parser deps/http_parser
deps/coupling deps/coupling
""" """
node.uselib_local = "evcom ev eio http_parser coupling" libnode.uselib_local = "evcom ev eio http_parser coupling"
node.uselib = "UDNS V8 EXECINFO PROFILER EFENCE" libnode.uselib = "UDNS V8 EXECINFO PROFILER EFENCE DL"
libnode.install_path = '${PREFIX}/lib'
bld.install_files('${PREFIX}/include/node/', 'config.h src/node.h src/object_wrap.h');
### node
node = bld.new_task_gen("cxx", "program")
node.target = 'node'
node.source = "src/main.cc"
node.includes = libnode.includes
node.uselib_local = "node"
node.install_path = '${PREFIX}/bin' node.install_path = '${PREFIX}/bin'
node.chmod = 0755 node.chmod = 0755
if bld.env["USE_DEBUG"]: if bld.env["USE_DEBUG"]:
node.clone("debug") node_g = node.clone("debug")
node_g.target = "node_g"
libnode_g = libnode.clone("debug")
libnode_g.target = "node_g"

Loading…
Cancel
Save