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

configure: introduce --embedded #5918

Closed
wants to merge 1 commit into from
Closed

Conversation

indutny
Copy link
Member

@indutny indutny commented Mar 27, 2016

Pull Request check-list

Please make sure to review and check all of these items:

  • Does make -j8 test (UNIX) or vcbuild test nosign (Windows) pass with
    this change (including linting)?
  • Is the commit message formatted according to CONTRIBUTING.md?
  • If this change fixes a bug (or a performance problem), is a regression
    test (or a benchmark) included?
  • Is a documentation update included (if this change modifies
    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:

@indutny
Copy link
Member Author

indutny commented Mar 27, 2016

cc @zcbenz , I would appreciate if you would give it a try in electron to see if it helps. Thank you!

@indutny
Copy link
Member Author

indutny commented Mar 27, 2016

cc @nodejs/collaborators @nodejs/ctc

@indutny indutny added c++ Issues and PRs that require attention from people who are familiar with C++. build Issues and PRs related to build files or the CI. labels Mar 27, 2016
@jbergstroem
Copy link
Member

If this intends to build a shared library, can't we refer to it as shard instead? Autotools does --enable-shared for most libraries. Not exactly sure what the common procedure for a scenario like this would be.

@indutny
Copy link
Member Author

indutny commented Mar 27, 2016

@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?

@jbergstroem
Copy link
Member

@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);
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Member

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.

@mscdex
Copy link
Contributor

mscdex commented Mar 27, 2016

I think a better subsystem choice would be build?

@zcbenz
Copy link
Contributor

zcbenz commented Mar 27, 2016

@indutny It works great! 👍

@indutny
Copy link
Member Author

indutny commented Mar 27, 2016

@mscdex

I think a better subsystem choice would be build?

I agree, will change it before committing. Does it otherwise LGTY?

@bnoordhuis

May I ask you to take a look at this?

@indutny
Copy link
Member Author

indutny commented Mar 27, 2016

@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. ' +
Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack.

@mcollina
Copy link
Member

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 --enable-shared, or --as-shared if we want to state this is something different. Another option is --embeddable, which IMHO has no meaning from embedded software.

@mhdawson
Copy link
Member

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.

@indutny
Copy link
Member Author

indutny commented Mar 29, 2016

@mhdawson perhaps we may want a separate configure option to disable this then?

@mhdawson
Copy link
Member

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.

@indutny
Copy link
Member Author

indutny commented Apr 5, 2016

Sorry for delay, everyone. Force pushed an update with fixed subsystem, configure option, and separate --no-v8-platform configure option. PTAL

@indutny
Copy link
Member Author

indutny commented Apr 5, 2016

@bnoordhuis
Copy link
Member

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 v8_platform instead.

@Fishrock123
Copy link
Contributor

@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
@indutny
Copy link
Member Author

indutny commented Apr 16, 2016

@bnoordhuis updated, PTAL

@stefanmb
Copy link
Contributor

stefanmb commented May 6, 2016

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:

-I.../electron/vendor/brightray/vendor/download/libchromiumcontent/src/v8

The net effect is that it's not possible to actually build a standalone Node shared library, i.e.

Executing ./configure --shared && make with this PR results in errors about missing headers:

In file included from ../src/async-wrap.h:4:0,
                 from ../src/async-wrap.cc:1:
../src/base-object.h:4:16: fatal error: v8.h: No such file or directory
 #include "v8.h"

In its current state this PR and --shared are perfect for Electron (since it mirrors their patches), but not very consumable for other embedders who may want a standalone library that they can simply link against.

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.

@stefanmb
Copy link
Contributor

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:

  1. Make the --shared version of Node compile-able outside of the Electron build system.
  2. Link with the MS C Runtime dynamically.

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)?
b) Write a driver to initialize Node from the shared library and run all the tests against it.
c) Make sure that addons still work correctly.
d) Everything I'm forgetting. :)

I hope to make more progress on this in the coming days, time allowing.

@eljefedelrodeodeljefe
Copy link
Contributor

ping @indutny care for a rebase and moving to land this?

@mhdawson
Copy link
Member

I think we need address the issues Stefan is working on before landing.

@eljefedelrodeodeljefe
Copy link
Contributor

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.

@Fishrock123
Copy link
Contributor

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'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.

@mhdawson
Copy link
Member

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).

@stefanmb
Copy link
Contributor

@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:

  • Make --shared work out of the box (i.e. git checkout, ./configure --shared, make)
  • Separate --no-v8-platform from header (ex|in)clusion concerns, I added --no-bundled-v8, which, while terribly named, handles whether or not Node's bundled V8 will be used (in the case of Electron it's not).
  • Allow building the shared library on Windows, including linking dynamically with the C Runtime.

@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).

@indutny
Copy link
Member Author

indutny commented May 20, 2016

@stefanmb Thank you for this follow up! I certainly don't mind if you'll take this over from me.

The changes look fine.

@stefanmb
Copy link
Contributor

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.

@stefanmb stefanmb closed this May 26, 2016
@indutny indutny deleted the feature/atom-2 branch June 13, 2016 05:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Issues and PRs related to build files or the CI. c++ Issues and PRs that require attention from people who are familiar with C++.
Projects
None yet
Development

Successfully merging this pull request may close these issues.