#ifndef SRC_NODE_SEA_H_ #define SRC_NODE_SEA_H_ #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS #include #include #include #include #include #include #include #include "node.h" #include "node_exit_code.h" namespace node { class Environment; namespace sea { // A special number that will appear at the beginning of the single executable // preparation blobs ready to be injected into the binary. We use this to check // that the data given to us are intended for building single executable // applications. const uint32_t kMagic = 0x143da20; enum class SeaFlags : uint32_t { kDefault = 0, kDisableExperimentalSeaWarning = 1 << 0, kUseSnapshot = 1 << 1, kUseCodeCache = 1 << 2, kIncludeAssets = 1 << 3, kIncludeExecArgv = 1 << 4, }; enum class SeaExecArgvExtension : uint8_t { kNone = 0, kEnv = 1, kCli = 2, }; struct SeaConfig { std::string main_path; std::string output_path; std::string executable_path; SeaFlags flags = SeaFlags::kDefault; SeaExecArgvExtension exec_argv_extension = SeaExecArgvExtension::kEnv; ModuleFormat main_format = ModuleFormat::kCommonJS; std::unordered_map assets; std::vector exec_argv; }; struct SeaResource { SeaFlags flags = SeaFlags::kDefault; SeaExecArgvExtension exec_argv_extension = SeaExecArgvExtension::kEnv; std::string_view code_path; std::string_view main_code_or_snapshot; ModuleFormat main_code_format = ModuleFormat::kCommonJS; std::optional code_cache; std::unordered_map assets; std::vector exec_argv; bool use_snapshot() const; bool use_code_cache() const; static constexpr size_t kHeaderSize = sizeof(kMagic) + sizeof(SeaFlags) + sizeof(SeaExecArgvExtension) + sizeof(ModuleFormat); }; bool IsSingleExecutable(); std::string_view FindSingleExecutableBlob(); SeaResource FindSingleExecutableResource(); std::tuple FixupArgsForSEA(int argc, char** argv); node::ExitCode WriteSingleExecutableBlob( const std::string& config_path, const std::vector& args, const std::vector& exec_args); // Try loading the Environment as a single-executable application. // Returns true if it is loaded as a single-executable application. // Otherwise returns false and the caller is expected to call LoadEnvironment() // differently. bool MaybeLoadSingleExecutableApplication(Environment* env); std::optional ParseSingleExecutableConfig( const std::string& config_path); ExitCode BuildSingleExecutable(const std::string& sea_config_path, const std::vector& args, const std::vector& exec_args); ExitCode GenerateSingleExecutableBlob( std::vector* out, const SeaConfig& config, const std::vector& args, const std::vector& exec_args); } // namespace sea } // namespace node #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS #endif // SRC_NODE_SEA_H_