Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/workerd/api/pyodide/pyodide.c++
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ kj::Maybe<const jsg::CompiledWasmModuleHolder&> PyodideBundleManager::getPyodide
}

void PyodideBundleManager::setPyodideBundleData(
kj::String version, kj::Array<unsigned char> data) const {
kj::String version, kj::Array<const kj::byte> data) const {
auto wordArray = kj::arrayPtr(
reinterpret_cast<const capnp::word*>(data.begin()), data.size() / sizeof(capnp::word));
// We're going to reuse this in the ModuleRegistry for every Python isolate, so set the traversal
Expand Down
4 changes: 3 additions & 1 deletion src/workerd/api/pyodide/pyodide.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ WD_STRONG_BOOL(SnapshotToDisk);

class PyodideBundleManager {
public:
void setPyodideBundleData(kj::String version, kj::Array<unsigned char> data) const;
// `data` is read in place for the manager's lifetime, including by V8, through external strings
// over the bundle's module sources.
void setPyodideBundleData(kj::String version, kj::Array<const kj::byte> data) const;
const kj::Maybe<jsg::Bundle::Reader> getPyodideBundle(kj::StringPtr version) const;

// Returns the holder for the compiled pyodide.asm.wasm of bundle `version`, or kj::none if that
Expand Down
8 changes: 6 additions & 2 deletions src/workerd/io/worker-modules.h
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,9 @@ jsg::Bundle::Reader retrievePyodideBundle(
// `pyodideWasmModuleHolder`, if given, must outlive the registry. Pyodide's pyodide.asm.wasm is
// then instantiated from it: once a Python isolate has stored a compilation there, later Python
// isolates with the same Wasm compile setting reuse it instead of compiling again.
//
// `moduleSource`, if given, provides the storage V8 reads the compiled-in PYODIDE_BUNDLE sources
// from; see jsg/module-source.h. The `pyodideBundle` sources are read where they are.
template <typename TracerApi, class Registry>
void registerPythonCommonModules(jsg::Lock& lock,
Registry& modules,
Expand All @@ -509,12 +512,13 @@ void registerPythonCommonModules(jsg::Lock& lock,
kj::Maybe<jsg::Ref<api::pyodide::DiskCache>> diskCache,
kj::Maybe<jsg::Ref<TracerApi>> internalJaeger,
kj::Maybe<jsg::ModuleRegistry::ModuleCallback> maybeLimiter,
kj::Maybe<const jsg::CompiledWasmModuleHolder&> pyodideWasmModuleHolder = kj::none) {
kj::Maybe<const jsg::CompiledWasmModuleHolder&> pyodideWasmModuleHolder = kj::none,
const jsg::ModuleSource* moduleSource = nullptr) {
KJ_REQUIRE(featureFlags.getPythonWorkers(),
"The python_workers compatibility flag is required to use Python.");

// We add `pyodide:` packages here including python-entrypoint-helper.js.
modules.addBuiltinBundle(PYODIDE_BUNDLE, kj::none);
modules.addBuiltinBundle(PYODIDE_BUNDLE, kj::none, moduleSource);

using namespace workerd::api::pyodide;
auto pythonRelease = KJ_REQUIRE_NONNULL(getPythonSnapshotRelease(featureFlags));
Expand Down
Loading