Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Port build to gyp + setup for binary distribution

node-gyp powers building now, for all operating systems. Only Windows,
Linux, and OS X were tested. arm support for Linux also was not tested.

Also included is a wrapper module which pulls in a binary specific to
your platform.
  • Loading branch information...
commit 9d9efdd272c49d93c044839e117908061c8c82f0 1 parent 5d04e85
@laverdet authored
View
9 .gitignore
@@ -1,6 +1,3 @@
-*.dylib
-*.dSYM
-*.o
-*.so
-*.node
-*.swp
+build/
+node_modules/
+bin/*.node
View
27 Makefile
@@ -1,27 +0,0 @@
-include src/platform.mk
-FIBERS_SO := $(shell echo `pwd`/src/fibers.node)
-
-all: fibers test
-
-native:
- FIBERS_NATIVE=1 $(MAKE) all || $(MAKE) fibers
-
-fibers: $(FIBERS_SO)
-
-dist: man
-
-$(FIBERS_SO):
- $(MAKE) -C src fibers.node
-
-man: README.md
- mkdir -p man
- ronn --roff $< > $@/fibers.1
-
-test: fibers
- ./test.sh
-
-clean:
- $(MAKE) -C src clean
- $(RM) -r man
-
-.PHONY: clean dist fibers test $(FIBERS_SO)
View
42 README.md
@@ -9,17 +9,39 @@ INSTALLING
* You're done!
### from source
-* git clone git://github.com/laverdet/node-fibers.git
-* cd node-fibers
-* make
-
-### notes
-Only Linux, SunOS and OS X environments are supported. Windows support is
-totally possible, but I'm not going to do it for you.
-
-node 0.6.x is required to run this release of `node-fibers`. Older versions of
+* `git clone git://github.com/laverdet/node-fibers.git`
+* `cd node-fibers`
+* `node-gyp rebuild`
+
+### important!
+While node-fibers is functional on node 0.6.x, it may be unstable during high
+load. This is caused by a bug in v8 which has since been fixed, but the fix will
+not be ported back to node 0.6.x. It is highly recommended that you use a more
+recent version of node if you are using node-fibers in production.
+
+You may also consider using the 32-bit version of node as it does seem the bug
+affects 32-bit systems dramatically less, though your mileage may vary.
+
+Please see
+[v8 issue #1763](http://code.google.com/p/v8/issues/detail?id=1763) for more
+information on the specific bug.
+
+### other notes
+Unlike most NodeJS projects, node-fibers is a C++ project. Some extra work is
+required to compile node-fibers, but pretty much every platform is supported
+in some way. Binary distributions in 32 and 64-bit forms are provided in npm for
+Linux, OS X, and Windows (special thanks to
+[Jeroen Janssen](https://github.com/japj) for his work on fibers in Windows).
+
+Support for Solaris, FreeBSD, and OpenBSD is provided by compiling the extension
+on your system during install time via
+[node-gyp](https://github.com/TooTallNate/node-gyp). If your operating system
+isn't listed here you may have luck copying the build process for one of the
+other OS's, assuming you are running a POSIX-like OS.
+
+node 0.6.x is required to run this release of node-fibers. Older versions of
node (0.4.x) are supported in older releases of node-fibers. See the 0.5.x
-branch of `node-fibers` for documentation.
+branch of node-fibers for documentation.
EXAMPLES
View
0  bin/.gitignore
No changes.
View
53 binding.gyp
@@ -1,30 +1,51 @@
{
+ 'variables': {
+ 'platform': '<(OS)',
+ },
+ 'conditions': [
+ # Replace gyp platform with node platform, blech
+ ['platform == "mac"', {'variables': {'platform': 'darwin'}}],
+ ['platform == "win"', {'variables': {'platform': 'win32'}}],
+ ],
'targets': [
{
- 'target_name': 'fibers',
+ 'target_name': 'fibers-<(platform)-<(target_arch)',
'sources': [
'src/fibers.cc',
'src/coroutine.cc',
'src/libcoro/coro.c',
- # to help IDE experience
+ # Rebuild on header changes
'src/coroutine.h',
'src/libcoro/coro.h',
],
-
+ 'cflags!': ['-ansi'],
'conditions': [
- ['OS=="linux"', {
- 'defines': [
- 'CORO_UCONTEXT',
- 'USE_CORO',
- ],
- }],
- ['OS=="win"', {
- 'defines': [
- 'USE_WINFIBER',
- ],
- }, { # OS != "win",
- }]
+ ['OS == "win"',
+ {'defines': ['USE_WINFIBER']},
+ # else
+ {
+ 'cflags': ['-Wno-deprecated-declarations'],
+ 'defines': ['USE_CORO'],
+ 'ldflags': ['-pthread'],
+ }
],
+ ['OS == "linux" or OS == "solaris" or OS == "freebsd"', {'defines': ['CORO_UCONTEXT']}],
+ ['OS == "mac"', {
+ 'defines': ['CORO_SJLJ'],
+ 'xcode_settings': {
+ 'GCC_OPTIMIZATION_LEVEL': '3',
+ 'GCC_GENERATE_DEBUGGING_SYMBOLS': 'NO',
+ },
+ }],
+ ['OS == "openbsd"', {'defines': ['CORO_ASM']}],
+ ['target_arch == "arm"',
+ {
+ # There's been problems getting real fibers working on arm
+ 'defines': ['CORO_PTHREAD'],
+ 'defines!': ['CORO_UCONTEXT', 'CORO_SJLJ', 'CORO_ASM'],
+ },
+ ],
+ ],
},
- ]
+ ],
}
View
54 build.js
@@ -0,0 +1,54 @@
+#!/usr/bin/env node
+var spawn = require('child_process').spawn,
+ fs = require('fs'),
+ path = require('path');
+
+// Parse args
+var force = false;
+var arch = process.arch;
+var args = process.argv.slice(2).filter(function(arg) {
+ if (arg === '-f') {
+ force = true;
+ return false;
+ } else if (arg.substring(0, 13) === '--target_arch') {
+ arch = arg.substring(14);
+ }
+ return true;
+});
+if (!{ia32: true, x64: true, arm: true}.hasOwnProperty(arch)) {
+ console.error('Unsupported (?) architecture: `'+ arch+ '`');
+ process.exit(1);
+}
+
+// Test for pre-built library
+var file = 'fibers-'+ process.platform+ '-'+ arch+ '.node';
+if (!force) {
+ try {
+ fs.statSync(path.join(__dirname, 'bin', file));
+ console.log('`'+ file+ '` exists; skipping build');
+ return process.exit();
+ } catch (ex) {}
+}
+
+// Build it
+spawn('./node_modules/node-gyp/bin/node-gyp.js', ['rebuild'].concat(args), {customFds: [0, 1, 2]}).on('exit', function(err) {
+ if (err) {
+ console.error('Build failed');
+ return process.exit(err);
+ }
+ afterBuild();
+});
+
+// Move it to expected location
+function afterBuild() {
+ var target = path.join(__dirname, 'build', 'Release', file);
+ var install = path.join(__dirname, 'bin', file);
+ try {
+ fs.statSync(target);
+ } catch (ex) {
+ console.error('Build succeeded but `'+ target+ '` not found');
+ process.exit(1);
+ }
+ fs.renameSync(target, install);
+ console.log('Installed in `'+ install+ '`');
+}
View
13 fibers.js
@@ -1,5 +1,14 @@
var fs = require('fs'), path = require('path');
-// Injects `Fiber` and `yield` in to global
-require('./src/fibers');
+// Look for binary for this platform
+var modPath = path.join(__dirname, 'bin', 'fibers-'+ process.platform+ '-'+ process.arch);
+try {
+ fs.statSync(modPath+ '.node');
+} catch (ex) {
+ // No binary!
+ throw new Error('`'+ modPath+ '.node` is missing. Try reinstalling `node-fibers`?');
+}
+
+// Injects `Fiber` and `yield` in to global scope (for now)
+require(modPath);
module.exports = Fiber;
View
11 package.json
@@ -1,22 +1,21 @@
{
"name": "fibers",
- "version": "0.6.6",
- "description": "Cooperative multi-tasking for Javascript; or, the closest thing to a thread you'll see in node",
+ "version": "0.6.7",
+ "description": "Cooperative multi-tasking for Javascript",
"keywords": [
"fiber", "fibers", "coroutine", "thread", "async", "parallel", "worker", "future", "promise"],
"homepage": "https://github.com/laverdet/node-fibers",
"author": "Marcel Laverdet <marcel@laverdet.com> (https://github.com/laverdet/)",
"main": "fibers",
"scripts": {
- "install": "$(which gmake || which make) clean native"
+ "install": "node ./build.js"
},
- "man": "./man/fibers.1",
"repository": {
"type": "git",
"url": "git://github.com/laverdet/node-fibers.git"
},
- "os": ["darwin", "linux", "sunos", "openbsd", "freebsd"],
"engines": {
"node": ">=0.5.2"
- }
+ },
+ "dependencies": ['node-gyp']
}
View
32 src/Makefile
@@ -1,32 +0,0 @@
-include platform.mk
-
-ifeq ($(NODE_PLATFORM), linux)
- CPP_NODEFLAGS = -fPIC -shared -Wl,-Bdynamic
-endif
-ifeq ($(NODE_PLATFORM), sunos)
- CPP_NODEFLAGS = -fPIC -shared -Wl,-Bdynamic
-endif
-ifeq ($(NODE_PLATFORM), darwin)
- CPP_NODEFLAGS = -bundle -undefined dynamic_lookup
-endif
-ifeq ($(NODE_PLATFORM), openbsd)
- CPP_NODEFLAGS = -fPIC -shared -Wl,-Bdynamic
-endif
-ifeq ($(NODE_PLATFORM), freebsd)
- CPP_NODEFLAGS = -fPIC -shared -Wl,-Bdynamic
-endif
-
-all: fibers.node
-
-libcoro.o: libcoro/coro.c
- $(CC) $(CFLAGS) $(CPPFLAGS) -fPIC -c -o $@ $^
-
-coroutine.o: coroutine.cc
- $(CXX) $(CXXFLAGS) $(CPPFLAGS) -fPIC -c -o $@ $^
-
-fibers.node: fibers.cc coroutine.o libcoro.o
- $(CXX) $(CPP_NODEFLAGS) $(CPPFLAGS) $^ -o $@ -lpthread
-
-clean:
- -$(RM) fibers.node libcoro.o coroutine.o
- -$(RM) -r *.dSYM
View
50 src/platform.mk
@@ -1,50 +0,0 @@
-# I know nothing about scons, waf, or autoconf. Sorry.
-NODE_PREFIX := $(shell node -e "console.log(require('path').dirname(require('path').dirname(process.execPath)))")
-NODE_PLATFORM := $(shell node -e "console.log(process.platform.replace('2', ''))")
-NODE_BITS := $(shell node -e "console.log(process.arch.replace(/^(?:ia|x)/, ''))")
-
-CPPFLAGS += -Wall -Wno-deprecated-declarations -I$(NODE_PREFIX)/include -I$(NODE_PREFIX)/include/node
-ifdef FIBERS_NATIVE
- CPPFLAGS += -march=native
-endif
-ifdef DEBUG
- CPPFLAGS += -ggdb -O0
-else
- CPPFLAGS += -g -O3
-endif
-
-ifneq ($(HOSTTYPE), arm)
- ifeq ($(NODE_BITS), )
- CPPFLAGS += -m32
- endif
- ifeq ($(NODE_BITS), 32)
- CPPFLAGS += -m32
- endif
- ifeq ($(NODE_BITS), 64)
- CPPFLAGS += -m64
- endif
-endif
-
-ifeq ($(NODE_PLATFORM), linux)
- ifeq ($(HOSTTYPE), arm)
- # SJLJ & UCONTEXT don't work on arm (?)
- CPPFLAGS += -DCORO_PTHREAD -DUSE_CORO
- else
- # SJLJ in linux = hangs & segfaults
- CPPFLAGS += -DCORO_UCONTEXT -DUSE_CORO
- endif
-endif
-ifeq ($(NODE_PLATFORM), sunos)
- # Same as Linux
- CPPFLAGS += -DCORO_UCONTEXT -DUSE_CORO
-endif
-ifeq ($(NODE_PLATFORM), darwin)
- # UCONTEXT in os x = hangs & segfaults :(
- CPPFLAGS += -DCORO_SJLJ -DUSE_CORO
-endif
-ifeq ($(NODE_PLATFORM), openbsd)
- CPPFLAGS += -DCORO_ASM -DUSE_CORO
-endif
-ifeq ($(NODE_PLATFORM), freebsd)
- CPPFLAGS += -DCORO_UCONTEXT -DUSE_CORO
-endif
Please sign in to comment.
Something went wrong with that request. Please try again.