GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — src,doc: Experimental support for SEA by mhdawson · Pull Request #42334 · nodejs/node

Conversation

@mhdawson

@mhdawson mhdawson commented Mar 14, 2022

Copy link
Copy Markdown
Member
  • add strategy as discussed in next-10 mini-summit
    • https://github.com/nodejs/next-10/blob/main/meetings/summit-nov-2021.md#single-executable-applications
  • add initial support single executable application support for linux

Signed-off-by: Michael Dawson [email protected]

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

styfle, guest271314, and fengmk2 reacted with thumbs up emoji peterp and mxschmitt reacted with heart emoji
All reactions
  • 👍 3 reactions
  • ❤️ 2 reactions
@nodejs-github-bot

nodejs-github-bot commented Mar 14, 2022

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/gyp
  • @nodejs/startup
  • @nodejs/tsc
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run. labels Mar 14, 2022
@mhdawson
mhdawson force-pushed the single-binary branch from 052c468 to fe4688e Compare March 14, 2022 22:35
@mhdawson

mhdawson commented Mar 14, 2022

Copy link
Copy Markdown
Member Author

@igorklopov, @jesec, @styfle could you look at what is documented/the proof of concept to confirm this is what we talked about in the next-10 mini-summit and that it's what is needed. If so would be great if you could help fill in the windows/osx versions.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mhdawson
mhdawson commented Mar 14, 2022
View reviewed changes
Comment thread doc/contributing/maintaining-single-executable-application-support.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

styfle
styfle reviewed Mar 14, 2022
View reviewed changes
Comment thread doc/contributing/maintaining-single-executable-application-support.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

styfle
styfle reviewed Mar 14, 2022
View reviewed changes
Comment thread doc/contributing/maintaining-single-executable-application-support.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

styfle
styfle reviewed Mar 14, 2022
View reviewed changes
Comment thread doc/contributing/maintaining-single-executable-application-support.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

mcollina
mcollina approved these changes Mar 15, 2022
View reviewed changes

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

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.

lgtm

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
mscdex
mscdex reviewed Mar 15, 2022
View reviewed changes
Comment thread doc/contributing/maintaining-single-executable-application-support.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

mscdex
mscdex reviewed Mar 15, 2022
View reviewed changes
Comment thread doc/contributing/maintaining-single-executable-application-support.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

mscdex
mscdex reviewed Mar 15, 2022
View reviewed changes
Comment thread doc/contributing/maintaining-single-executable-application-support.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

mscdex
mscdex reviewed Mar 15, 2022
View reviewed changes
Comment thread doc/contributing/maintaining-single-executable-application-support.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

mscdex
mscdex reviewed Mar 15, 2022
View reviewed changes
Comment thread doc/contributing/maintaining-single-executable-application-support.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

mscdex
mscdex reviewed Mar 15, 2022
View reviewed changes
Comment thread doc/contributing/maintaining-single-executable-application-support.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

mscdex
mscdex reviewed Mar 15, 2022
View reviewed changes
Comment thread doc/contributing/maintaining-single-executable-application-support.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

mscdex
mscdex reviewed Mar 15, 2022
View reviewed changes
Comment thread doc/contributing/maintaining-single-executable-application-support.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

mscdex
mscdex reviewed Mar 15, 2022
View reviewed changes
Comment thread doc/contributing/maintaining-single-executable-application-support.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

mscdex
mscdex reviewed Mar 15, 2022
View reviewed changes
Comment thread doc/contributing/maintaining-single-executable-application-support.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

mscdex
mscdex reviewed Mar 15, 2022
View reviewed changes
Comment thread doc/contributing/maintaining-single-executable-application-support.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

mscdex
mscdex reviewed Mar 15, 2022
View reviewed changes
Comment thread doc/contributing/maintaining-single-executable-application-support.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

mscdex
mscdex reviewed Mar 15, 2022
View reviewed changes
Comment thread doc/contributing/maintaining-single-executable-application-support.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

mscdex
mscdex reviewed Mar 15, 2022
View reviewed changes
Comment thread doc/contributing/maintaining-single-executable-application-support.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

mscdex
mscdex reviewed Mar 15, 2022
View reviewed changes
Comment thread doc/contributing/maintaining-single-executable-application-support.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

mscdex
mscdex reviewed Mar 15, 2022
View reviewed changes
Comment thread doc/contributing/maintaining-single-executable-application-support.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

mscdex
mscdex reviewed Mar 15, 2022
View reviewed changes
Comment thread doc/contributing/maintaining-single-executable-application-support.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

mscdex
mscdex reviewed Mar 15, 2022
View reviewed changes
Comment thread doc/contributing/maintaining-single-executable-application-support.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

mscdex
mscdex reviewed Mar 15, 2022
View reviewed changes
Comment thread doc/contributing/maintaining-single-executable-application-support.md Resolved

Uh oh!

There was an error while loading. Please reload this page.

mhdawson added 3 commits July 13, 2022 09:47
@mhdawson
squash: add support for append as well
3ecb114
Signed-off-by: Michael Dawson <[email protected]>
@mhdawson
squash: cleanup
2c7a434
Signed-off-by: Michael Dawson <[email protected]>
@mhdawson
squash: add support for binary data
bef9dfc
Signed-off-by: Michael Dawson <[email protected]>
@mhdawson

mhdawson commented Jul 13, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

Pushed some additional commits to

  1. search the binary if there is no added segment. This is based on the code in @jesec's branch. It will let us experiment with both approaches at the same time. It would also let us add some tests more easily.
  2. add exposing the pointer to the binary data. Not really sure if this is how we'd want to do it since although @jesec indicates it's used by the virtual file system I'm thinking something in the C++ layer will need to wrap the pointer. I'm thinking it might make more sense to expose is as buffer?
  3. Change the eye catcher to a GUID in order to reduce the change of an accidental collision to as close as possible to 0.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@RaisinTen

RaisinTen commented Jul 14, 2022

Copy link
Copy Markdown
Member

Btw, I have a working implementation of SEA in my branch that uses postject main...RaisinTen:node:sea. It also implements the VFS (asar in this case)!

The major problem I can think of is that the bootstrap script assumes that I'm using asar as the vfs, so we should probably find a way to allow users to configure it - perhaps by exposing an interface that folks can implement to hook in their custom vfs implementations? Or maybe some other approach that I couldn't think of?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@RaisinTen

RaisinTen commented Jul 14, 2022

Copy link
Copy Markdown
Member

add exposing the pointer to the binary data. Not really sure if this is how we'd want to do it since although @jesec indicates it's used by the virtual file system I'm thinking something in the C++ layer will need to wrap the pointer. I'm thinking it might make more sense to expose is as buffer?

I tried to expose the embedded data as a buffer on process._singleExecutableApplicationCode in main...RaisinTen:node:sea#diff-6c1386cbc6e4a11941649af31a0257d5c3e40b5f41223cdddf87ab2e984b705aR549 but I think we should find a way to expose this in a way without adding new fields on process.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jesec

jesec commented Jul 14, 2022

Copy link
Copy Markdown
Member

Btw, I have a working implementation of SEA in my branch that uses postject main...RaisinTen:node:sea. It also implements the VFS (asar in this case)!

The major problem I can think of is that the bootstrap script assumes that I'm using asar as the vfs, so we should probably find a way to allow users to configure it - perhaps by exposing an interface that folks can implement to hook in their custom vfs implementations? Or maybe some other approach that I couldn't think of?

Or simply treat VFS as out-of-scope and let the packager utility / embedded script do it.

Implementing VFS inside Node.js does not help on its own, since a packager utility is still necessary after all. It is complicated to override Node.js APIs. Plus, there are many edge cases to handle and changes could easily become semver-major. It would significantly increase the maintenance burden for Node.js without tangible benefits (unless something like "node compile" is implemented along with it).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jesec

jesec commented Jul 14, 2022

Copy link
Copy Markdown
Member

Pushed some additional commits to

  1. search the binary if there is no added segment. This is based on the code in @jesec's branch. It will let us experiment with both approaches at the same time. It would also let us add some tests more easily.
  2. add exposing the pointer to the binary data. Not really sure if this is how we'd want to do it since although @jesec indicates it's used by the virtual file system I'm thinking something in the C++ layer will need to wrap the pointer. I'm thinking it might make more sense to expose is as buffer?
  3. Change the eye catcher to a GUID in order to reduce the change of an accidental collision to as close as possible to 0.

I am a bit concerned about the case that the payload could be huge. It is not efficient to prematurely store the payload in memory.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mhdawson

mhdawson commented Jul 14, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

I am a bit concerned about the case that the payload could be huge. It is not efficient to prematurely store the payload in memory.

I had wondered about your comment about 4096 being big enough. In the case of using an additional segment it will already be in memory so perhaps less of a concern.

Was the offset you were exposing an offset into the file instead of memory?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mhdawson

mhdawson commented Jul 14, 2022

Copy link
Copy Markdown
Member Author

Or simply treat VFS as out-of-scope and let the packager utility / embedded script do it.

I believe we should keep it as out-of-scope at least to start. Having the SEA support be minimal I think is best and we can then possibly adjust that based on feedback later on.

krk reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@RaisinTen

RaisinTen commented Jul 15, 2022

Copy link
Copy Markdown
Member

Or simply treat VFS as out-of-scope and let the packager utility / embedded script do it.

But wouldn't that promote monkey-patching in Node.js? I'm not sure if that's necessarily a good thing that we want to promote.

Implementing VFS inside Node.js does not help on its own, since a packager utility is still necessary after all. It is complicated to override Node.js APIs. Plus, there are many edge cases to handle and changes could easily become semver-major. It would significantly increase the maintenance burden for Node.js without tangible benefits (unless something like "node compile" is implemented along with it).

I totally agree with your points but if we support SEA in node, it would mean that we should at least support a way to implement a VFS, even if we don't provide a complete VFS implementation out of the box. The reason is that SEA won't be usable if node can't make sense of the data that was embedded in it. I can think of 2 solutions here:

  • officially support monkey patching fs and other components that get transitively monkey patched, like require() in this case
  • provide an interface that users can override to hook in their own VFS implementations
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@RaisinTen

RaisinTen commented Jul 15, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

In the case of using an additional segment it will already be in memory so perhaps less of a concern.

The current approach allocates a v8::BackingStore in main...RaisinTen:node:sea#diff-6c1386cbc6e4a11941649af31a0257d5c3e40b5f41223cdddf87ab2e984b705aR537-R538 that has the same size as the embedded data and then copying the embedded data to it before passing it to the JS layer, so I think this could be problematic.

I wonder if there's a way to prevent this extra allocation. 🤔

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@RaisinTen RaisinTen mentioned this pull request Jul 15, 2022
Provide a way to fetch the file offset of the embedded data nodejs/postject#2
Closed
@mhdawson

mhdawson commented Jul 19, 2022

Copy link
Copy Markdown
Member Author

@RaisinTen If you look at what is in this PR, if isntead of providing the address we provided a buffer created on the native side by passing in the pointer to the binary data it would avoid the copy in a similar manner to now it avoids copying any of the parameters/scripts passed. ie when its in a segement it just uses the memory already loaded when the binary was run.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mhdawson

mhdawson commented Jul 19, 2022

Copy link
Copy Markdown
Member Author

@RaisinTen in particular if you look at the Node-api code here:

napi_status NAPI_CDECL napi_create_external_buffer(napi_env env,

API docs
https://nodejs.org/api/n-api.html#napi_create_external_buffer

That should be creating a buffer without allocating/copying.

It does still mean that if the addition is large it will be loaded into memory. Having the binary data come from a read to the exe on disk might still have an advantage if that is done as needed as opposed to pre-loaded.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mhdawson

mhdawson commented Jul 19, 2022

Copy link
Copy Markdown
Member Author

provide an interface that users can override to hook in their own VFS implementations

This may be being discussed as part of the loaders effort. -> #41076

RaisinTen reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

targos pushed a commit that referenced this pull request Jul 20, 2022
@mhdawson @targos
doc: add single executable application initiative
a7dd71b
Refs: https://github.com/nodejs/node/issues/43432
Refs: #42334
Refs: https://github.com/nodejs/node/blob/main/doc/contributing/technical-priorities.md#single-executable-applications

Signed-off-by: Michael Dawson <[email protected]>

PR-URL: #43611
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Darshan Sen <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
@RaisinTen

RaisinTen commented Jul 22, 2022

Copy link
Copy Markdown
Member

thanks @mhdawson, removed the extra allocation here by passing a no-op FreeCallback :)

Local<Value> buffer =
    Buffer::New(
        isolate,
        const_cast<char*>(single_executable_application_code),
        single_executable_application_size,
        [](char* data, void* hint) {},
        nullptr)
        .ToLocalChecked();
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mhdawson

mhdawson commented Jul 22, 2022

Copy link
Copy Markdown
Member Author

@RaisinTen it would be good to work towards a PR that we might land.

Any chance you could PR changes you think are needed to this PR? I think at very least your changes to provide access to a buffer instead of the address would make sense. It would also be a good way to discuss any others and start heading towards 1 shared patch versus us each working on possibly different ones.

mhdawson reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@RaisinTen

RaisinTen commented Jul 26, 2022

Copy link
Copy Markdown
Member

I would be happy to send a PR for this but last week I had arranged a meeting between the Postject team and @jesec where we found out that there are some areas that need some more research, like these ones:

VFS:

  • all of the VFS implementations we were aware of depends on monkey-patching the fs module. Not shipping a full-blown VFS implementation or at least a way to implement it using hooks as you have already mentioned might promote more monkey-patching which might not be a good idea. Another good reason to revamp the way a VFS is implemented in userland is that, it's hard for the userland implementations to stay in sync with the API changes in node. For example, the asar implementation in electron is outdated - https://github.com/electron/electron/blob/06a00b74e817a61f20e2734d50d8eb7bc9b099f6/lib/asar/fs-wrapper.ts.
  • what factors should be considered while choosing a VFS?
  • do we even need to have different VFS implementations or do all use cases point towards a single kind of VFS?

Postject:

  • Since it currently depends on lief which has a significant amount of native code, how should we approach the problem of making it more portable? Do we have to manually rewrite it in JS? Compile it into WASM? Build it from scratch? Something else?
  • Should Postject also support deleting some segments from a binary? That might solve the problem of stripping large portions of the binary that aren't needed for a particular use case. Might be relevant for Node.js needs to lose weight #43811.

... etc.

I believe, having a team in node where we can discuss everything about SEA would be the right thing to do here. I've DM'ed you to learn about the process for creating a team and I'll follow that.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@joyeecheung joyeecheung mentioned this pull request Jul 28, 2022
Tracking issue: support of builtins and V8 issues in run-time user-land snapshots #44014
Closed
4 of 10 tasks
@RaisinTen RaisinTen mentioned this pull request Jul 28, 2022
Create @nodejs/single-executable team nodejs/admin#708
Closed
targos pushed a commit that referenced this pull request Jul 31, 2022
@mhdawson @targos
doc: add single executable application initiative
407beb2
Refs: https://github.com/nodejs/node/issues/43432
Refs: #42334
Refs: https://github.com/nodejs/node/blob/main/doc/contributing/technical-priorities.md#single-executable-applications

Signed-off-by: Michael Dawson <[email protected]>

PR-URL: #43611
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Darshan Sen <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
guangwong pushed a commit to noslate-project/node that referenced this pull request Oct 10, 2022
@mhdawson @guangwong
doc: add single executable application initiative
a0de01b
Refs: https://github.com/nodejs/node/issues/43432
Refs: nodejs/node#42334
Refs: https://github.com/nodejs/node/blob/main/doc/contributing/technical-priorities.md#single-executable-applications

Signed-off-by: Michael Dawson <[email protected]>

PR-URL: nodejs/node#43611
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Darshan Sen <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
@RaisinTen

RaisinTen commented Oct 17, 2022

Copy link
Copy Markdown
Member

Any chance you could PR changes you think are needed to this PR?

@mhdawson done - #45038 :)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Trott
Trott force-pushed the main branch from 2d76238 to ca3ed36 Compare November 12, 2022 01:49
@EricMCornelius EricMCornelius mentioned this pull request Nov 23, 2022
nexe with NodeJS 18.12.0 producing binaries that exit without running nexe/nexe#1019
Closed
@mhdawson

mhdawson commented Feb 8, 2023

Copy link
Copy Markdown
Member Author

Closing in favor of #45038

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mhdawson mhdawson closed this Feb 8, 2023
@RaisinTen RaisinTen mentioned this pull request Apr 28, 2023
Flaky test-single-executable-application #47741
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@Trott Trott Trott left review comments
@addaleax addaleax addaleax requested changes
@RaisinTen RaisinTen RaisinTen requested changes
@mcollina mcollina mcollina approved these changes
+4 more reviewers
@mscdex mscdex mscdex left review comments
@styfle styfle styfle left review comments
@devsnek devsnek devsnek left review comments
@jesec jesec jesec left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

14 participants

@mhdawson @nodejs-github-bot @addaleax @jesec @mscdex @guest271314 @RaisinTen @bnoordhuis @richardlau @Hypfer @mcollina @styfle @Trott @devsnek
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.