Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

build: add --enable-shared and --enable-static #7336

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@
},
'msvs_disabled_warnings': [4351, 4355, 4800],
'conditions': [
['OS == "win"', {
[ 'component=="shared_library"', {
'cflags': [ '-fPIC' ],
}],
[ 'OS == "win"', {
'msvs_cygwin_shell': 0, # prevent actions from trying to use cygwin
'defines': [
'WIN32',
Expand Down
25 changes: 25 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ parser.add_option('--dest-os',
help='operating system to build for. Valid values are: '
'win, mac, solaris, freebsd, openbsd, linux, android')

parser.add_option('--enable-shared',
action='store_true',
dest='enable_shared',
help='build libnode.so (conflicts with --enable-static)')

parser.add_option('--enable-static',
action='store_true',
dest='enable_static',
help='build libnode.a (conflicts with --enable-shared)')

parser.add_option('--gdb',
action='store_true',
dest='gdb',
Expand Down Expand Up @@ -466,6 +476,21 @@ def configure_node(o):
o['variables']['node_install_npm'] = b(not options.without_npm)
o['default_configuration'] = 'Debug' if options.debug else 'Release'

if options.enable_shared or options.enable_static:
# TODO(bnoordhuis) Should be possible to build them both at the same time
# (and the executable too) but that requires some build system overhaul.
if options.enable_shared and options.enable_static:
raise Exception('--enable-shared and --enable-static are '
'currently mutually exclusive.')
if options.enable_shared:
component = 'shared_library'
elif options.enable_static:
component = 'static_library'
else:
assert(False)
o['variables']['component'] = component
o['variables']['node_component'] = component

host_arch = host_arch_win() if os.name == 'nt' else host_arch_cc()
target_arch = options.dest_cpu or host_arch
o['variables']['host_arch'] = host_arch
Expand Down
10 changes: 6 additions & 4 deletions node.gyp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
'variables': {
'v8_use_snapshot%': 'true',
'node_component%': 'executable',
'node_use_dtrace%': 'false',
'node_use_etw%': 'false',
'node_use_perfctr%': 'false',
Expand Down Expand Up @@ -73,7 +74,7 @@
'targets': [
{
'target_name': 'node',
'type': 'executable',
'type': '<(node_component)',

'dependencies': [
'node_js2c#host',
Expand All @@ -97,7 +98,6 @@
'src/node_file.cc',
'src/node_http_parser.cc',
'src/node_javascript.cc',
'src/node_main.cc',
'src/node_os.cc',
'src/node_v8.cc',
'src/node_stat_watcher.cc',
Expand Down Expand Up @@ -126,8 +126,6 @@
'src/node.h',
'src/node_buffer.h',
'src/node_constants.h',
'src/node_file.h',
'src/node_http_parser.h',
'src/node_internals.h',
'src/node_javascript.h',
'src/node_root_certs.h',
Expand Down Expand Up @@ -164,6 +162,10 @@
],

'conditions': [
[ 'node_component=="executable"', {
'sources': [ 'src/node_main.cc' ],
}],

[ 'node_use_openssl=="true"', {
'defines': [ 'HAVE_OPENSSL=1' ],
'sources': [
Expand Down
9 changes: 2 additions & 7 deletions src/cares_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1197,11 +1197,8 @@ static void StrError(const FunctionCallbackInfo<Value>& args) {
}


static void Initialize(Handle<Object> target,
Handle<Value> unused,
Handle<Context> context) {
Environment* env = Environment::GetCurrent(context);

extern "C" void node_builtin_cares_wrap_init(Environment* env,
Local<Object> target) {
int r = ares_library_init(ARES_LIB_INIT_ALL);
assert(r == ARES_SUCCESS);

Expand Down Expand Up @@ -1250,5 +1247,3 @@ static void Initialize(Handle<Object> target,

} // namespace cares_wrap
} // namespace node

NODE_MODULE_CONTEXT_AWARE_BUILTIN(cares_wrap, node::cares_wrap::Initialize)
18 changes: 8 additions & 10 deletions src/fs_event_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ using v8::Value;

class FSEventWrap: public HandleWrap {
public:
static void Initialize(Handle<Object> target,
Handle<Value> unused,
Handle<Context> context);
static void Initialize(Environment* env, Local<Object> target);
static void New(const FunctionCallbackInfo<Value>& args);
static void Start(const FunctionCallbackInfo<Value>& args);
static void Close(const FunctionCallbackInfo<Value>& args);
Expand Down Expand Up @@ -78,11 +76,7 @@ FSEventWrap::~FSEventWrap() {
}


void FSEventWrap::Initialize(Handle<Object> target,
Handle<Value> unused,
Handle<Context> context) {
Environment* env = Environment::GetCurrent(context);

void FSEventWrap::Initialize(Environment* env, Local<Object> target) {
Local<FunctionTemplate> t = FunctionTemplate::New(env->isolate(), New);
t->InstanceTemplate()->SetInternalFieldCount(1);
t->SetClassName(env->fsevent_string());
Expand Down Expand Up @@ -198,6 +192,10 @@ void FSEventWrap::Close(const FunctionCallbackInfo<Value>& args) {
HandleWrap::Close(args);
}

} // namespace node

NODE_MODULE_CONTEXT_AWARE_BUILTIN(fs_event_wrap, node::FSEventWrap::Initialize)
extern "C" void node_builtin_fs_event_wrap_init(Environment* env,
Local<Object> target) {
FSEventWrap::Initialize(env, target);
}

} // namespace node
49 changes: 17 additions & 32 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
#include "node.h"
#include "node_buffer.h"
#include "node_constants.h"
#include "node_file.h"
#include "node_http_parser.h"
#include "node_javascript.h"
#include "node_version.h"

Expand Down Expand Up @@ -132,7 +130,6 @@ static bool debug_wait_connect = false;
static int debug_port = 5858;
static bool v8_is_profiling = false;
static node_module* modpending;
static node_module* modlist_builtin;
static node_module* modlist_addon;

// used by C++ modules as well
Expand Down Expand Up @@ -2023,28 +2020,25 @@ void Hrtime(const FunctionCallbackInfo<Value>& args) {

extern "C" void node_module_register(void* m) {
struct node_module* mp = reinterpret_cast<struct node_module*>(m);

if (mp->nm_flags & NM_F_BUILTIN) {
mp->nm_link = modlist_builtin;
modlist_builtin = mp;
} else {
assert(modpending == NULL);
modpending = mp;
}
assert(modpending == NULL);
modpending = mp;
}

struct node_module* get_builtin_module(const char* name) {
struct node_module* mp;

for (mp = modlist_builtin; mp != NULL; mp = mp->nm_link) {
if (strcmp(mp->nm_modname, name) == 0)
break;
}
typedef void (*BuiltinModuleInitializerFunction)(Environment*, Local<Object>);

assert(mp == NULL || (mp->nm_flags & NM_F_BUILTIN) != 0);
return (mp);
BuiltinModuleInitializerFunction GetBuiltinModule(const char* modname) {
#define V(name) \
do { \
if (0 == strcmp(#name, modname)) \
return node_builtin_ ## name ## _init; \
} while (0);
BUILTIN_MODULES_MAP(V)
#undef V
return NULL;
}


typedef void (UV_DYNAMIC* extInit)(Handle<Object> exports);

// DLOpen is process.dlopen(module, filename).
Expand Down Expand Up @@ -2101,10 +2095,6 @@ void DLOpen(const FunctionCallbackInfo<Value>& args) {
env->ThrowError(errmsg);
return;
}
if (mp->nm_flags & NM_F_BUILTIN) {
env->ThrowError("Built-in module self-registered.");
return;
}

mp->nm_dso_handle = lib.handle;
mp->nm_link = modlist_addon;
Expand Down Expand Up @@ -2221,15 +2211,10 @@ static void Binding(const FunctionCallbackInfo<Value>& args) {
uint32_t l = modules->Length();
modules->Set(l, OneByteString(env->isolate(), buf));

node_module* mod = get_builtin_module(*module_v);
if (mod != NULL) {
BuiltinModuleInitializerFunction initializer = GetBuiltinModule(*module_v);
if (initializer != NULL) {
exports = Object::New(env->isolate());
// Internal bindings don't have a "module" object, only exports.
assert(mod->nm_register_func == NULL);
assert(mod->nm_context_register_func != NULL);
Local<Value> unused = Undefined(env->isolate());
mod->nm_context_register_func(exports, unused,
env->context(), mod->nm_priv);
initializer(env, exports);
cache->Set(module, exports);
} else if (!strcmp(*module_v, "constants")) {
exports = Object::New(env->isolate());
Expand Down Expand Up @@ -2473,7 +2458,7 @@ static Handle<Object> GetFeatures(Environment* env) {
obj->Set(env->tls_ocsp_string(), tls_ocsp);

obj->Set(env->tls_string(),
Boolean::New(env->isolate(), get_builtin_module("crypto") != NULL));
Boolean::New(env->isolate(), GetBuiltinModule("crypto") != NULL));

return scope.Escape(obj);
}
Expand Down
7 changes: 0 additions & 7 deletions src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,6 @@ typedef void (*addon_context_register_func)(
v8::Handle<v8::Context> context,
void* priv);

#define NM_F_BUILTIN 0x01

struct node_module {
int nm_version;
unsigned int nm_flags;
Expand All @@ -341,8 +339,6 @@ struct node_module {
struct node_module* nm_link;
};

node_module* get_builtin_module(const char *name);

extern "C" NODE_EXTERN void node_module_register(void* mod);

#ifdef _WIN32
Expand Down Expand Up @@ -408,9 +404,6 @@ extern "C" NODE_EXTERN void node_module_register(void* mod);
#define NODE_MODULE_CONTEXT_AWARE(modname, regfunc) \
NODE_MODULE_CONTEXT_AWARE_X(modname, regfunc, NULL, 0)

#define NODE_MODULE_CONTEXT_AWARE_BUILTIN(modname, regfunc) \
NODE_MODULE_CONTEXT_AWARE_X(modname, regfunc, NULL, NM_F_BUILTIN) \

/*
* For backward compatibility in add-on modules.
*/
Expand Down
10 changes: 2 additions & 8 deletions src/node_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@
namespace node {
namespace Buffer {

using v8::ArrayBuffer;
using v8::Context;
using v8::EscapableHandleScope;
using v8::Function;
using v8::FunctionCallbackInfo;
Expand Down Expand Up @@ -680,10 +678,8 @@ void SetupBufferJS(const FunctionCallbackInfo<Value>& args) {
}


void Initialize(Handle<Object> target,
Handle<Value> unused,
Handle<Context> context) {
Environment* env = Environment::GetCurrent(context);
extern "C" void node_builtin_buffer_init(Environment* env,
Local<Object> target) {
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "setupBufferJS"),
FunctionTemplate::New(env->isolate(), SetupBufferJS)
->GetFunction());
Expand All @@ -692,5 +688,3 @@ void Initialize(Handle<Object> target,

} // namespace Buffer
} // namespace node

NODE_MODULE_CONTEXT_AWARE_BUILTIN(buffer, node::Buffer::Initialize)
8 changes: 2 additions & 6 deletions src/node_contextify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -685,14 +685,10 @@ class ContextifyScript : public BaseObject {
};


void InitContextify(Handle<Object> target,
Handle<Value> unused,
Handle<Context> context) {
Environment* env = Environment::GetCurrent(context);
extern "C" void node_builtin_contextify_init(Environment* env,
Local<Object> target) {
ContextifyContext::Init(env, target);
ContextifyScript::Init(env, target);
}

} // namespace node

NODE_MODULE_CONTEXT_AWARE_BUILTIN(contextify, node::InitContextify);
9 changes: 2 additions & 7 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4703,14 +4703,11 @@ void SetEngine(const FunctionCallbackInfo<Value>& args) {


// FIXME(bnoordhuis) Handle global init correctly.
void InitCrypto(Handle<Object> target,
Handle<Value> unused,
Handle<Context> context,
void* priv) {
extern "C" void node_builtin_crypto_init(Environment* env,
Local<Object> target) {
static uv_once_t init_once = UV_ONCE_INIT;
uv_once(&init_once, InitCryptoOnce);

Environment* env = Environment::GetCurrent(context);
SecureContext::Initialize(env, target);
Connection::Initialize(env, target);
CipherBase::Initialize(env, target);
Expand All @@ -4734,5 +4731,3 @@ void InitCrypto(Handle<Object> target,

} // namespace crypto
} // namespace node

NODE_MODULE_CONTEXT_AWARE_BUILTIN(crypto, node::crypto::InitCrypto)
1 change: 0 additions & 1 deletion src/node_crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,6 @@ bool EntropySource(unsigned char* buffer, size_t length);
#ifndef OPENSSL_NO_ENGINE
void SetEngine(const v8::FunctionCallbackInfo<v8::Value>& args);
#endif // !OPENSSL_NO_ENGINE
void InitCrypto(v8::Handle<v8::Object> target);

} // namespace crypto
} // namespace node
Expand Down
10 changes: 1 addition & 9 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.

#include "node.h"
#include "node_file.h"
#include "node_buffer.h"
#include "node_internals.h"
#include "node_stat_watcher.h"
Expand Down Expand Up @@ -1114,12 +1113,7 @@ void FSInitialize(const FunctionCallbackInfo<Value>& args) {
env->set_fs_stats_constructor_function(stats_constructor);
}

void InitFs(Handle<Object> target,
Handle<Value> unused,
Handle<Context> context,
void* priv) {
Environment* env = Environment::GetCurrent(context);

extern "C" void node_builtin_fs_init(Environment* env, Local<Object> target) {
// Function which creates a new Stats object.
target->Set(
FIXED_ONE_BYTE_STRING(env->isolate(), "FSInitialize"),
Expand Down Expand Up @@ -1160,5 +1154,3 @@ void InitFs(Handle<Object> target,
}

} // end namespace node

NODE_MODULE_CONTEXT_AWARE_BUILTIN(fs, node::InitFs)
Loading