-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
configure: introduce --embedded #5918
Conversation
cc @zcbenz , I would appreciate if you would give it a try in electron to see if it helps. Thank you! |
cc @nodejs/collaborators @nodejs/ctc |
If this intends to build a shared library, can't we refer to it as shard instead? Autotools does |
@jbergstroem perhaps, though it is a bit more than just shared. It also turns off v8 platform setup. Is it still ok to name it shared then? |
@indutny I'm a bit conflicted as well. Lets keep it as you've suggested until someone has a better argument than mine :) |
more = uv_run(env->event_loop(), UV_RUN_ONCE); | ||
|
||
if (more == false) { | ||
#ifndef NODE_EMBEDDED_MODE | ||
v8::platform::PumpMessageLoop(default_platform, isolate); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity, how are embedders supposed to be able to perform these same tasks with node's main event loop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Electron, the message loop is managed by Electron itself, so the embedder would be responsible for performing the tasks. In practice StartNodeInstance
is never used by embedders. This line is commented out because for embedders v8_libplatform
is not compiled by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If embedders don't use it, would it make sense to break it out into a separate compilation unit that's skipped for embedded builds? I'm okay in principle with supporting embedded builds but this #ifdef soup isn't very pleasant.
I think a better subsystem choice would be |
@indutny It works great! 👍 |
I agree, will change it before committing. Does it otherwise LGTY? May I ask you to take a look at this? |
@zcbenz Thank you for verifying it! |
parser.add_option('--embedded', | ||
action='store_true', | ||
dest='embedded', | ||
help='compile shared library for embedding node in other project. ' + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in other
-> in another
or in other projects
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack.
I would prefer a different name rather than embedded: node is also used in IoT projects, and "embedded" there has a completely different meaning. I'm ok with |
I'd be bit worried about the "--enabled-shared" or "--as-shared" if it does more. ie " It also turns off v8 platform setup" as we have internal teams interested in Node as a shared library but not sure if disabling of v8 platform setup would be right for them. |
@mhdawson perhaps we may want a separate configure option to disable this then? |
That would make sense to me. If we have one option to build as a shared library and then one to disable the v8 platform setup that would make sense to me. My goal is to get to the point where we can build a shared library across platforms, we have testing in the CI, and we can move towards something that could be supported. Depending on how much work that turns out to be @stefanmb will help to push that forward. |
Sorry for delay, everyone. Force pushed an update with fixed subsystem, configure option, and separate |
I still think this #ifdef jungle is inelegant in the extreme, not to mention prone to bit-rot. Suggested alternative: something like this: static struct {
#ifdef NODE_NO_V8_PLATFORM
void Initialize(int thread_pool_size) {}
void PumpMessageLoop() {}
void Dispose() {}
#else
void Initialize(int thread_pool_size) { /* ... */ }
void PumpMessageLoop() { /* ... */ }
void Dispose() { /* ... */ }
v8::Platform* platform_;
#endif
} v8_platform; And update the v8::platform call sites to go through |
@indutny ping |
Add configure flag for building shared library that could be used to embed node.js in some application (like Electron). This commit is esentially a merged and refined version of: * atom/node@289649a * atom/node@f76669f * atom/node@0828dfa
@bnoordhuis updated, PTAL |
7da4fd4
to
c7066fb
Compare
Thanks @indutny for reviving this work. I'm also very interested in having a Node.js library officially supported. We already have a product that embeds 0.12 using some custom patches to the build system, but I'd like to move it up to a newer version and have official community support for the library builds. One concern I have with this PR is that the patches are, as you pointed out, based directly on the Electron fork of Node. In particular, electron/node@289649a causes the V8 headers to be omitted from the default node.gyp include path. I think they do this because they provide their own version of V8 (Chromium) instead of using Node's, i.e. their compiler invocations have this:
The net effect is that it's not possible to actually build a standalone Node shared library, i.e. Executing
In its current state this PR and I'd like to provide a more generic shared library option, I'll have a more in-depth look and get back with some suggestions. |
I haven't had a chance to fully address all the issues but here is my work in progress: stefanmb/node@stefanmb:cc0985b...stefanmb:v4.x-shared Note that I'm doing this against LTS first, but the changes for master are similar. The highlights are:
There are still many leftover issues: a) Add some options to make it easier for Electron to embed (however, this is a political question as well - should we officially support a build process that replaces upstream dependencies)? I hope to make more progress on this in the coming days, time allowing. |
ping @indutny care for a rebase and moving to land this? |
I think we need address the issues Stefan is working on before landing. |
I read it in full only now, sorry. Valid points. Looking forward to your progress @stefanmb. Was just wondering whether we would need to address all those issues in context of this single PR. Probably having subsequent work in other PRs will let us move easier on this and this can be edited by just dividing the option into two. |
I'm not sure this constitutes as "officially" supporting it, but the user-base is large enough that we should support it in some form regardless if we think it is "correct". For example, we don't officially support android either, but we do accept patches for it. |
My perspective is thats its not a matter of not accepting the patch, just tweaking so that it can be used for both electron and non-electron use cases which is what @stefanmb is working on. I also don't expect this to stretch out too long either as @stefanmb has already made progress on those tweaks and we just need to let @indutny comment/assimilate/refine/reject as appropriate. I think it is a reasonable question to ask if helping people replace dependencies is something we want to do, but agree that in the context of "not supported" its probably the right thing to do in this case. For me it is important though that we make sure we have a separation between the ability to build as a shared library which I would like to move more towards "supported" versus replacing the v8 level which would likely remain as unsupported (all of which is being covered by the discussion so far). |
@mhdawson @Fishrock123 @eljefedelrodeodeljefe I agree that we need not resolve every possible issue before landing this PR. In the interest of expediting things I've taken the liberty to rebase and add some changes to Fedor's patch here: master...stefanmb:sharedlib-proposal Highlights:
@indutny Would you be okay with these changes? If you are busy I can take over this PR, I'm interested in getting the basic functionality landed as well. Future issues to address include adding testing for the shared library and adding support for other platforms (e.g. AIX). |
@stefanmb Thank you for this follow up! I certainly don't mind if you'll take this over from me. The changes look fine. |
I've made #6994 to continue the work in this PR, I am closing this one to direct all new comments to the new PR. |
Pull Request check-list
Please make sure to review and check all of these items:
make -j8 test
(UNIX) orvcbuild test nosign
(Windows) pass withthis change (including linting)?
test (or a benchmark) included?
existing APIs, or introduces new ones)?
NOTE: these things are not required to open a PR and can be done
afterwards / while the PR is open.
Affected core subsystem(s)
node
Description of change
Add configure flag for building shared library that could be used to
embed node.js in some application (like Electron). This commit is
esentially a merged and refined version of: