Skip to content

Commit

Permalink
build: add --node-snapshot-main configure option
Browse files Browse the repository at this point in the history
  • Loading branch information
joyeecheung committed Jun 21, 2021
1 parent 1318178 commit 2f67449
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 27 deletions.
19 changes: 19 additions & 0 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,13 @@
default=False,
help='node will load builtin modules from disk instead of from binary')

parser.add_argument('--node-snapshot-main',
action='store',
dest='node_snapshot_main',
default=None,
help='Run a file when building the embedded snapshot. Currently ' +
'experimental.')

# Create compile_commands.json in out/Debug and out/Release.
parser.add_argument('-C',
action='store_true',
Expand Down Expand Up @@ -1181,6 +1188,18 @@ def configure_node(o):

o['variables']['want_separate_host_toolset'] = int(cross_compiling)

if options.node_snapshot_main is not None:
if options.shared:
# This should be possible to fix, but we will need to refactor the
# libnode target to avoid building it twice.
error('--node-snapshot-main is incompatible with --shared')
if options.without_node_snapshot:
error('--node-snapshot-main is incompatible with ' +
'--without-node-snapshot')
if cross_compiling:
error('--node-snapshot-main is incompatible with cross compilation')
o['variables']['node_snapshot_main'] = options.node_snapshot_main

if options.without_node_snapshot or options.node_builtin_modules_path:
o['variables']['node_use_node_snapshot'] = 'false'
else:
Expand Down
53 changes: 39 additions & 14 deletions node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
'node_use_dtrace%': 'false',
'node_use_etw%': 'false',
'node_no_browser_globals%': 'false',
'node_snapshot_main%': '',
'node_use_node_snapshot%': 'false',
'node_use_v8_platform%': 'true',
'node_use_bundled_v8%': 'true',
Expand Down Expand Up @@ -305,23 +306,47 @@
'dependencies': [
'node_mksnapshot',
],
'actions': [
{
'action_name': 'node_mksnapshot',
'process_outputs_as_sources': 1,
'inputs': [
'<(node_mksnapshot_exec)',
],
'outputs': [
'<(SHARED_INTERMEDIATE_DIR)/node_snapshot.cc',
'conditions': [
['node_snapshot_main!=""', {
'actions': [
{
'action_name': 'node_mksnapshot',
'process_outputs_as_sources': 1,
'inputs': [
'<(node_mksnapshot_exec)',
'<(node_snapshot_main)',
],
'outputs': [
'<(SHARED_INTERMEDIATE_DIR)/node_snapshot.cc',
],
'action': [
'<(node_mksnapshot_exec)',
'--snapshot-main',
'<(node_snapshot_main)',
'<@(_outputs)',
],
},
],
'action': [
'<@(_inputs)',
'<@(_outputs)',
}, {
'actions': [
{
'action_name': 'node_mksnapshot',
'process_outputs_as_sources': 1,
'inputs': [
'<(node_mksnapshot_exec)',
],
'outputs': [
'<(SHARED_INTERMEDIATE_DIR)/node_snapshot.cc',
],
'action': [
'<@(_inputs)',
'<@(_outputs)',
],
},
],
},
}],
],
}, {
}, {
'sources': [
'src/node_snapshot_stub.cc'
],
Expand Down
9 changes: 2 additions & 7 deletions src/node_snapshotable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -647,17 +647,12 @@ void SnapshotBuilder::Generate(SnapshotData* out,
per_process::v8_platform.Platform()->UnregisterIsolate(isolate);
}

void SnapshotBuilder::Generate(SnapshotData* out,
const std::vector<std::string> args,
const std::vector<std::string> exec_args) {
Generate(out, "", args, exec_args);
}

std::string SnapshotBuilder::Generate(
const std::string& entry_file,
const std::vector<std::string> args,
const std::vector<std::string> exec_args) {
SnapshotData data;
Generate(&data, args, exec_args);
Generate(&data, entry_file, args, exec_args);
std::string result = FormatBlob(&data);
delete[] data.blob.data;
return result;
Expand Down
6 changes: 2 additions & 4 deletions src/node_snapshotable.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,15 @@ bool IsSnapshotableType(FastStringKey key);

class SnapshotBuilder {
public:
static std::string Generate(const std::vector<std::string> args,
static std::string Generate(const std::string& entry_file,
const std::vector<std::string> args,
const std::vector<std::string> exec_args);
// Generate the snapshot into out.
// entry_file should be the content of the UTF-8 encoded entry files.
static void Generate(SnapshotData* out,
const std::string& entry_file,
const std::vector<std::string> args,
const std::vector<std::string> exec_args);
static void Generate(SnapshotData* out,
const std::vector<std::string> args,
const std::vector<std::string> exec_args);
};
} // namespace node

Expand Down
6 changes: 4 additions & 2 deletions tools/snapshot/node_mksnapshot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ int main(int argc, char* argv[]) {
CHECK_EQ(result.exit_code, 0);

{
std::string snapshot =
node::SnapshotBuilder::Generate(result.args, result.exec_args);
std::string snapshot = node::SnapshotBuilder::Generate(
node::per_process::cli_options->snapshot_main,
result.args,
result.exec_args);
out << snapshot;
out.close();
}
Expand Down

0 comments on commit 2f67449

Please sign in to comment.