From 18b92201be7e654ac9997b947d38aaf46adee06d Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Tue, 20 Dec 2011 22:03:32 -0800 Subject: [PATCH] Support addons with gyp Initial pass. --- test/addons/hello-world/binding.cc | 17 +++++++++++++++++ test/addons/hello-world/binding.gyp | 8 ++++++++ test/addons/hello-world/test.js | 4 ++++ tools/addon.gypi | 17 +++++++++++++++++ tools/gyp_addon | 26 ++++++++++++++++++++++++++ 5 files changed, 72 insertions(+) create mode 100644 test/addons/hello-world/binding.cc create mode 100644 test/addons/hello-world/binding.gyp create mode 100644 test/addons/hello-world/test.js create mode 100644 tools/addon.gypi create mode 100755 tools/gyp_addon diff --git a/test/addons/hello-world/binding.cc b/test/addons/hello-world/binding.cc new file mode 100644 index 0000000..82e8c55 --- /dev/null +++ b/test/addons/hello-world/binding.cc @@ -0,0 +1,17 @@ +#include +#include + +using namespace v8; + +extern "C" { + void init(Handle target); +} + +Handle Method(const Arguments& args) { + HandleScope scope; + return scope.Close(String::New("world")); +} + +void init(Handle target) { + NODE_SET_METHOD(target, "hello", Method); +} diff --git a/test/addons/hello-world/binding.gyp b/test/addons/hello-world/binding.gyp new file mode 100644 index 0000000..3bfb844 --- /dev/null +++ b/test/addons/hello-world/binding.gyp @@ -0,0 +1,8 @@ +{ + 'targets': [ + { + 'target_name': 'binding', + 'sources': [ 'binding.cc' ] + } + ] +} diff --git a/test/addons/hello-world/test.js b/test/addons/hello-world/test.js new file mode 100644 index 0000000..27550a3 --- /dev/null +++ b/test/addons/hello-world/test.js @@ -0,0 +1,4 @@ +var assert = require('assert'); +var binding = require('./out/Release/binding'); +assert.equal('world', binding.hello()); +console.log('binding.hello() =', binding.hello()); diff --git a/tools/addon.gypi b/tools/addon.gypi new file mode 100644 index 0000000..ad2237e --- /dev/null +++ b/tools/addon.gypi @@ -0,0 +1,17 @@ +{ + 'target_defaults': { + 'type': 'loadable_module', + 'product_extension': 'node', + 'include_dirs': [ + '../src', + '../deps/uv/include', + '../deps/v8/include' + ], + + 'conditions': [ + [ 'OS=="mac"', { + 'libraries': [ '-undefined dynamic_lookup' ], + }] + ] + } +} diff --git a/tools/gyp_addon b/tools/gyp_addon new file mode 100755 index 0000000..a93f7b2 --- /dev/null +++ b/tools/gyp_addon @@ -0,0 +1,26 @@ +#!/usr/bin/env python +import os +import sys + +script_dir = os.path.dirname(__file__) +node_root = os.path.normpath(os.path.join(script_dir, os.pardir)) + +sys.path.insert(0, os.path.join(node_root, 'tools', 'gyp', 'pylib')) +import gyp + +if __name__ == '__main__': + args = sys.argv[1:] + addon_gypi = os.path.join(node_root, 'tools', 'addon.gypi') + common_gypi = os.path.join(node_root, 'common.gypi') + args.extend(['-I', addon_gypi]) + args.extend(['-I', common_gypi]) + args.extend(['-Dlibrary=shared_library']) + args.extend(['-Dvisibility=default']) + args.extend(['--depth=.']); + + gyp_args = list(args) + rc = gyp.main(gyp_args) + if rc != 0: + print 'Error running GYP' + sys.exit(rc) + -- 2.7.4