Skip to content

Commit

Permalink
src: fix --disable-single-executable-application
Browse files Browse the repository at this point in the history
Previously it would not compile if the build is configured with
--disable-single-executable-application because we use directives
to exclude the definition of SEA-related code completely. This patch
changes them so that the SEA code are still compiled and internals
still check whether the executable is an SEA. If future modifications
to the C++ code attempt to load the SEA blob when SEA is disabled,
UNREACHABLE() would be raised. If user attempt to generate the
SEA blob with --experimental-sea-config with an executable that
disables SEA, they would get an error.
  • Loading branch information
joyeecheung committed Feb 19, 2024
1 parent fe22990 commit f60d6d3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
7 changes: 5 additions & 2 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1403,13 +1403,16 @@ static ExitCode StartInternal(int argc, char** argv) {
});

uv_loop_configure(uv_default_loop(), UV_METRICS_IDLE_TIME);

std::string sea_config = per_process::cli_options->experimental_sea_config;
if (!sea_config.empty()) {
#if !defined(DISABLE_SINGLE_EXECUTABLE_APPLICATION)
return sea::BuildSingleExecutableBlob(
sea_config, result->args(), result->exec_args());
#else
fprintf(stderr, "Single executable application is disabled.\n");
return ExitCode::kGenericUserError;
#endif // !defined(DISABLE_SINGLE_EXECUTABLE_APPLICATION)
}

// --build-snapshot indicates that we are in snapshot building mode.
if (per_process::cli_options->per_isolate->build_snapshot) {
if (per_process::cli_options->per_isolate->build_snapshot_config.empty() &&
Expand Down
8 changes: 4 additions & 4 deletions src/node_sea.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
#include <tuple>
#include <vector>

#if !defined(DISABLE_SINGLE_EXECUTABLE_APPLICATION)

using node::ExitCode;
using v8::ArrayBuffer;
using v8::BackingStore;
Expand Down Expand Up @@ -189,6 +187,7 @@ SeaResource SeaDeserializer::Read() {
}

std::string_view FindSingleExecutableBlob() {
#if !defined(DISABLE_SINGLE_EXECUTABLE_APPLICATION)
CHECK(IsSingleExecutable());
static const std::string_view result = []() -> std::string_view {
size_t size;
Expand All @@ -209,6 +208,9 @@ std::string_view FindSingleExecutableBlob() {
result.data(),
result.size());
return result;
#else
UNREACHABLE();
#endif // !defined(DISABLE_SINGLE_EXECUTABLE_APPLICATION)
}

} // anonymous namespace
Expand Down Expand Up @@ -668,5 +670,3 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {

NODE_BINDING_CONTEXT_AWARE_INTERNAL(sea, node::sea::Initialize)
NODE_BINDING_EXTERNAL_REFERENCE(sea, node::sea::RegisterExternalReferences)

#endif // !defined(DISABLE_SINGLE_EXECUTABLE_APPLICATION)
4 changes: 0 additions & 4 deletions src/node_sea.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

#if !defined(DISABLE_SINGLE_EXECUTABLE_APPLICATION)

#include <cinttypes>
#include <optional>
#include <string>
Expand Down Expand Up @@ -52,8 +50,6 @@ node::ExitCode BuildSingleExecutableBlob(
} // namespace sea
} // namespace node

#endif // !defined(DISABLE_SINGLE_EXECUTABLE_APPLICATION)

#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

#endif // SRC_NODE_SEA_H_

0 comments on commit f60d6d3

Please sign in to comment.