mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
This patch: 1. Refactor the routines used to compile and run an embedder entrypoint. In JS land special handling for SEA is done directly in main/embedding.js instead of clobbering the CJS loader. Add warnings to remind users that currently the require() in SEA bundled scripts only supports loading builtins. 2. Don't use the bundled SEA code cache when compiling CJS loaded from disk, since in that case we are certainly not compiling the code bundled into the SEA. Use a is_sea_main flag in CompileFunctionForCJSLoader() (which replaces an unused argument) to pass this into the C++ land - the code cache is still read directly from C++ to avoid the overhead of ArrayBuffer creation. 3. Move SEA loading code into MaybeLoadSingleExecutableApplication() which calls LoadEnvironment() with its own StartExecutionCallback(). This avoids more hidden switches in StartExecution() and make them explicit. Also add some TODOs about how to support ESM in embedded applications. 4. Add more comments PR-URL: https://github.com/nodejs/node/pull/53573 Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
65 lines
1.9 KiB
C++
65 lines
1.9 KiB
C++
#ifndef SRC_NODE_SEA_H_
|
|
#define SRC_NODE_SEA_H_
|
|
|
|
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
|
|
#include <cinttypes>
|
|
#include <optional>
|
|
#include <string>
|
|
#include <string_view>
|
|
#include <tuple>
|
|
#include <unordered_map>
|
|
#include <vector>
|
|
|
|
#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,
|
|
};
|
|
|
|
struct SeaResource {
|
|
SeaFlags flags = SeaFlags::kDefault;
|
|
std::string_view code_path;
|
|
std::string_view main_code_or_snapshot;
|
|
std::optional<std::string_view> code_cache;
|
|
std::unordered_map<std::string_view, std::string_view> assets;
|
|
|
|
bool use_snapshot() const;
|
|
bool use_code_cache() const;
|
|
|
|
static constexpr size_t kHeaderSize = sizeof(kMagic) + sizeof(SeaFlags);
|
|
};
|
|
|
|
bool IsSingleExecutable();
|
|
SeaResource FindSingleExecutableResource();
|
|
std::tuple<int, char**> FixupArgsForSEA(int argc, char** argv);
|
|
node::ExitCode BuildSingleExecutableBlob(
|
|
const std::string& config_path,
|
|
const std::vector<std::string>& args,
|
|
const std::vector<std::string>& 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);
|
|
} // namespace sea
|
|
} // namespace node
|
|
|
|
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
|
|
|
|
#endif // SRC_NODE_SEA_H_
|