Skip to content

Commit

Permalink
Change versioning scheme, enable load-external autogate on samples
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettgu10 committed Aug 8, 2024
1 parent 826743f commit c3d0a86
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 4 deletions.
4 changes: 4 additions & 0 deletions samples/pyodide-fastapi/config.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ const config :Workerd.Config = (
service = "main"
),
],

autogates = [
"workerd-autogate-pyodide-load-external",
]
);

const mainWorker :Workerd.Worker = (
Expand Down
4 changes: 4 additions & 0 deletions samples/pyodide-langchain/config.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ const config :Workerd.Config = (
service = "main"
),
],

autogates = [
"workerd-autogate-pyodide-load-external",
]
);

const mainWorker :Workerd.Worker = (
Expand Down
1 change: 1 addition & 0 deletions samples/pyodide-secret/config.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const config :Workerd.Config = (
# Pyodide is included as a builtin wasm module so it requires the
# corresponding autogate flag.
"workerd-autogate-builtin-wasm-modules",
"workerd-autogate-pyodide-load-external",
]
);

Expand Down
4 changes: 4 additions & 0 deletions samples/pyodide/config.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ const config :Workerd.Config = (
service = "main"
),
],

autogates = [
"workerd-autogate-pyodide-load-external",
]
);

const mainWorker :Workerd.Worker = (
Expand Down
4 changes: 4 additions & 0 deletions samples/repl-server-python/config.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ const config :Workerd.Config = (
service = "main"
),
],

autogates = [
"workerd-autogate-pyodide-load-external",
]
);

const mainWorker :Workerd.Worker = (
Expand Down
17 changes: 13 additions & 4 deletions src/workerd/server/workerd-api.c++
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,8 @@ kj::Path getPyodideBundleFileName(kj::StringPtr version) {
return kj::Path(kj::str("pyodide-", version, ".capnp.bin"));
}

kj::Maybe<kj::Own<const kj::ReadableFile>> getPyodideBundleFile(const kj::Maybe<kj::Own<const kj::Directory>> &maybeDir, kj::StringPtr version) {
kj::Maybe<kj::Own<const kj::ReadableFile>> getPyodideBundleFile(
const kj::Maybe<kj::Own<const kj::Directory>> &maybeDir, kj::StringPtr version) {
KJ_IF_SOME(dir, maybeDir) {
kj::Path filename = getPyodideBundleFileName(version);
auto file = dir->tryOpenFile(filename);
Expand All @@ -451,7 +452,10 @@ kj::Maybe<kj::Own<const kj::ReadableFile>> getPyodideBundleFile(const kj::Maybe<
return kj::none;
}

void writePyodideBundleFileToDisk(const kj::Maybe<kj::Own<const kj::Directory>> &maybeDir, kj::StringPtr version, kj::ArrayPtr<byte> bytes) {
void writePyodideBundleFileToDisk(
const kj::Maybe<kj::Own<const kj::Directory>> &maybeDir,
kj::StringPtr version,
kj::ArrayPtr<byte> bytes) {
KJ_IF_SOME(dir, maybeDir) {
kj::Path filename = getPyodideBundleFileName(version);
auto replacer = dir->replaceFile(filename, kj::WriteMode::CREATE | kj::WriteMode::MODIFY);
Expand All @@ -462,7 +466,7 @@ void writePyodideBundleFileToDisk(const kj::Maybe<kj::Own<const kj::Directory>>
}

bool fetchPyodideBundle(const api::pyodide::PythonConfig& pyConfig, kj::StringPtr version) {
if(api::pyodide::hasPyodideBundle(version)) {
if (api::pyodide::hasPyodideBundle(version)) {
KJ_LOG(WARNING, "Pyodide version ", version, " already exists in pyodide bundle table");
return true;
}
Expand Down Expand Up @@ -538,7 +542,12 @@ void WorkerdApi::compileModules(
if (fetchPyodideBundle(impl->pythonConfig, "dev"_kj)) {
modules->addBuiltinBundle(getPyodideBundle("dev"_kj), kj::none);
} else {
auto version = KJ_ASSERT_NONNULL(getPythonSnapshotRelease(featureFlags)).getPyodide();
auto pythonRelease = KJ_ASSERT_NONNULL(getPythonSnapshotRelease(featureFlags));
auto pyodide = pythonRelease.getPyodide();
auto pyodideRevision = pythonRelease.getPyodideRevision();
auto backport = pythonRelease.getBackport();

auto version = kj::str(pyodide, "_", pyodideRevision, "_", backport);

KJ_REQUIRE(fetchPyodideBundle(impl->pythonConfig, version), "Failed to get Pyodide bundle");
modules->addBuiltinBundle(getPyodideBundle(version), kj::none);
Expand Down

0 comments on commit c3d0a86

Please sign in to comment.