Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Are Native modules supported. #25

Closed
mauron85 opened this issue May 5, 2017 · 15 comments
Closed

Are Native modules supported. #25

mauron85 opened this issue May 5, 2017 · 15 comments

Comments

@mauron85
Copy link

mauron85 commented May 5, 2017

Thank you for this amazing compiler.

I tried to compile one of my project which is using microtime native module. I compiled it succesfully, but when I run binary I get following error:

/__enclose_io_memfs__/node_modules/node-time-uuid/node_modules/microtime/node_modules/bindings/bindings.js:83
        throw e
        ^

Error: /__enclose_io_memfs__/node_modules/node-time-uuid/node_modules/microtime/build/Release/microtime.node: cannot open shared object file: No such file or directory
    at Object.Module._extensions..node (module.js:598:18)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at bindings (/__enclose_io_memfs__/node_modules/node-time-uuid/node_modules/microtime/node_modules/bindings/bindings.js:76:44)
    at Object.<anonymous> (/__enclose_io_memfs__/node_modules/node-time-uuid/node_modules/microtime/index.js:1:96)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.require (module.js:498:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/__enclose_io_memfs__/node_modules/node-time-uuid/lib/objectid.js:22:17)

So my question is. Are native modules supported?

@Dexus
Copy link

Dexus commented May 5, 2017

I dont know node-compiler but did you nodec run with --npm-package=node-time-uuid ?
Maybe you need compile native before you can use it?

@pmq20
Copy link
Owner

pmq20 commented May 5, 2017

I was planning to scan and statically link all native modules during compile time (theoretically it is feasible since we are building from the source and could make some change to how native modules are loaded), but failed to find time to do it. I'll implement it as soon as possible. Thanks for the feedback!

@pmq20
Copy link
Owner

pmq20 commented May 12, 2017

@mauron85 Native modules are starting to work on the master branch, if you are urgent you could clone the repo and run nodec from master to try it. I'll release it once I have tested it thoroughly.

image

@pmq20
Copy link
Owner

pmq20 commented Jun 5, 2017

Node.js Compiler v1.0.0 released! Native C++ modules are fully supported now.

https://github.com/pmq20/node-compiler/releases/tag/v1.0.0

@mauron85 Could you have a try and let me know if it works for you? Thanks!

@firrae
Copy link

firrae commented Jun 5, 2017

Hey @pmq20,

I just tried this out on an application I'm working on. It says it built but throws:

return process.dlopen(module, path._makeLong(filename));
                 ^
Error: dlopen(/__enclose_io_memfs__/node_modules/bcrypt/lib/binding/bcrypt_lib.node, 1): image not found

Seems like bcrypt wasn't built/included into the build? Is this an error or potentially something I did wrong? I have Node 8 installed on my Macbook and am using V1.0.0.

@firrae
Copy link

firrae commented Jun 5, 2017

To note I also get a number of ../deps/libsquash/sample/enclose_io_common.h:38:28: warning: variadic macros are a C99 feature [-Wvariadic-macros] in the build process. ex:

../deps/libsquash/sample/enclose_io_common.h:40:29: warning: variadic macros are a C99 feature [-Wvariadic-macros]

../deps/libsquash/sample/enclose_io_common.h:49:22: warning: variadic macros are a C99 feature [-Wvariadic-macros]

Could this be related?

@ptusch
Copy link

ptusch commented Jun 6, 2017

I tried this as well with sqlite3 with issues as well:

/Release/obj.target/openssl/deps/openssl/openssl/crypto/cpt_err.o ../deps/openssl/openssl/crypto/cpt_err.c
deps/libsquash/enclose_io_libsquash.target.mk:97: recipe for target '/tmp/nodec/node/out/Release/obj.target/enclose_io_libsquash/deps/libsquash/sample/enclose_io_memfs.o' failed
make[1]: *** [/tmp/nodec/node/out/Release/obj.target/enclose_io_libsquash/deps/libsquash/sample/enclose_io_memfs.o] Error 1
make[1]: *** Waiting for unfinished jobs....
rm c2142693082db8da77c35c9808dbcddd987ca620.intermediate
Makefile:76: recipe for target 'node' failed
make: *** [node] Error 2
Failed running ["make -j4"]

My index.js I'm trying to compile:

console.log(process.version)

var knex = require('knex')({
  dialect: 'sqlite3',
  connection: {
    filename: './data.db'
  }
});

// Create a table
knex.schema.createTableIfNotExists('users', function(table) {
  table.increments('id');
  table.string('user_name');
})

// ...and another
.createTableIfNotExists('accounts', function(table) {
  table.increments('id');
  table.string('account_name');
  table.integer('user_id').unsigned().references('users.id');
})

// Then query the table...
.then(function() {
  return knex.insert({user_name: 'Tim'}).into('users');
})

// ...and using the insert id, insert into the other table.
.then(function(rows) {
  return knex.table('accounts').insert({account_name: 'knex', user_id: rows[0]});
})

// Query both of the rows.
.then(function() {
  return knex('users')
    .join('accounts', 'users.id', 'accounts.user_id')
    .select('users.user_name as user', 'accounts.account_name as account');
})

// .map over the results
.map(function(row) {
  console.log(row);
})

// Finally, add a .catch handler for the promise chain
.catch(function(e) {
  console.error(e);
})
.finally(() => {
  return knex.destroy();
});

I'm using nvm with node8.
I used the fresh [email protected]

Compiling normal packages works nicely.

@pmq20
Copy link
Owner

pmq20 commented Jun 9, 2017

@firrae I failed to reproduce this on my local machine. See the screenshot. Could you check your build log to see if some error occurs when building bcrypt?

image

@pmq20
Copy link
Owner

pmq20 commented Jun 9, 2017

@ptusch Do you have more message regarding this particular failure:

deps/libsquash/enclose_io_libsquash.target.mk:97: recipe for target '/tmp/nodec/node/out/Release/obj.target/enclose_io_libsquash/deps/libsquash/sample/enclose_io_memfs.o' failed

The error message is too much truncated for a diagnosis.

@pmq20
Copy link
Owner

pmq20 commented Jun 9, 2017

Ping @ptusch

Ping @firrae

Also, have you cleaned your temporary directory that the compiler uses? If old directory generated by nodec 0.x is used then it would be problematic. It needs to be cleaned when a compiler of a new version is used. I should fix this in a precautionary way: #42

@ptusch
Copy link

ptusch commented Jun 9, 2017

@pmq20 Please forgive me, I think I forgot to add sqlite3 to the package.json.
I just reinstalled and everything went as expected.

Well done btw!

@firrae
Copy link

firrae commented Jun 9, 2017

@pmq20 where would the cache be? I had used nodec before the latest version so that may be it. I'm digging around to see if I can find it on my own. I am on a Mac.

@firrae
Copy link

firrae commented Jun 9, 2017

@pmq20 nevermind, I see it's a command line option. Rebuild seems to have worked well. Now I just need to figure out the sequence of flags needed to include our public folder and it looks like it'll work. This is awesome. Thanks!

@firrae
Copy link

firrae commented Jun 9, 2017

Looks like I just need to sit our Public folder beside the executable and it works :D

@lexor90
Copy link
Collaborator

lexor90 commented Jun 14, 2017

Closing this as native modules support has been added in v1.0.0.
Feel free to re-open it should you need it

@lexor90 lexor90 closed this as completed Jun 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants