Skip to content

Commit

Permalink
Merge pull request #3328 from cloudflare/dominik/remove-python-lock
Browse files Browse the repository at this point in the history
Removes usage of embedded PYODIDE_LOCK in C++ code.
  • Loading branch information
dom96 authored Jan 14, 2025
2 parents 8cb7ffd + 29612f9 commit f15ac0f
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 6 deletions.
1 change: 0 additions & 1 deletion src/workerd/api/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ wd_cc_library(
hdrs = [
"pyodide/pyodide.h",
"pyodide/setup-emscripten.h",
"//src/pyodide:generated/pyodide_extra.capnp.h",
],
implementation_deps = ["//src/workerd/util:string-buffer"],
visibility = ["//visibility:public"],
Expand Down
2 changes: 0 additions & 2 deletions src/workerd/api/pyodide/pyodide.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
#include <workerd/server/workerd.capnp.h>
#include <workerd/util/autogate.h>

#include <pyodide/generated/pyodide_extra.capnp.h>

#include <capnp/serialize.h>
#include <kj/array.h>
#include <kj/common.h>
Expand Down
1 change: 1 addition & 0 deletions src/workerd/server/tests/python/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ py_wd_test("subdirectory")

py_wd_test(
"sdk",
# TODO(EW-8976): Disabled in dev due to test getting stuck
python_flags = ["0.26.0a2"],
tags = [
# TODO(someday): Fix asan failure for this, see https://github.com/cloudflare/workerd/pull/3140#discussion_r1858273318
Expand Down
4 changes: 3 additions & 1 deletion src/workerd/server/workerd-api.c++
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
#include <workerd/util/thread-scopes.h>
#include <workerd/util/use-perfetto-categories.h>

#include <pyodide/generated/pyodide_extra.capnp.h>

#include <kj/compat/http.h>
#include <kj/compat/tls.h>
#include <kj/compat/url.h>
Expand Down Expand Up @@ -157,6 +159,7 @@ void writePyodideBundleFileToDisk(const kj::Maybe<kj::Own<const kj::Directory>>&
replacer->commit();
}
}
} // namespace

kj::Maybe<jsg::Bundle::Reader> fetchPyodideBundle(
const api::pyodide::PythonConfig& pyConfig, kj::StringPtr version) {
Expand Down Expand Up @@ -213,7 +216,6 @@ kj::Maybe<jsg::Bundle::Reader> fetchPyodideBundle(
KJ_LOG(INFO, "Loaded Pyodide package from internet");
return pyConfig.pyodideBundleManager.getPyodideBundle(version);
}
} // namespace

struct WorkerdApi::Impl final {
kj::Own<CompatibilityFlags::Reader> features;
Expand Down
3 changes: 3 additions & 0 deletions src/workerd/server/workerd-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,7 @@ class WorkerdApi final: public Worker::Api {
capnp::List<config::Extension>::Reader extensions) const;
};

kj::Maybe<jsg::Bundle::Reader> fetchPyodideBundle(
const api::pyodide::PythonConfig& pyConfig, kj::StringPtr version);

} // namespace workerd::server
22 changes: 20 additions & 2 deletions src/workerd/server/workerd.c++
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
// https://opensource.org/licenses/Apache-2.0

#include "server.h"
#include "workerd-api.h"

#include <workerd/io/compatibility-date.capnp.h>
#include <workerd/io/compatibility-date.h>
#include <workerd/io/supported-compatibility-date.capnp.h>
#include <workerd/jsg/setup.h>
#include <workerd/rust/cxx-integration/lib.rs.h>
Expand All @@ -15,7 +17,6 @@

#include <fcntl.h>
#include <openssl/rand.h>
#include <pyodide/generated/pyodide_extra.capnp.h>
#include <sys/stat.h>

#include <capnp/dynamic.h>
Expand Down Expand Up @@ -807,7 +808,24 @@ class CliMain final: public SchemaFileImpl::ErrorReporter {
context, getVersionString(), "Outputs the package lock file used by Pyodide.");
return builder
.callAfterParsing([]() -> kj::MainBuilder::Validity {
printf("%s\n", PYODIDE_LOCK->cStr());
static const PythonConfig config{
.packageDiskCacheRoot = kj::none,
.pyodideDiskCacheRoot = kj::none,
.createSnapshot = false,
.createBaselineSnapshot = false,
};

capnp::MallocMessageBuilder message;
// TODO(EW-8977): Implement option to specify python worker flags.
auto features = message.getRoot<CompatibilityFlags>();
features.setPythonWorkers(true);
auto pythonRelease = KJ_ASSERT_NONNULL(getPythonSnapshotRelease(features));
auto version = getPythonBundleName(pythonRelease);
KJ_ASSERT_NONNULL(fetchPyodideBundle(config, version), "Failed to get Pyodide bundle");

auto lock = KJ_ASSERT_NONNULL(config.pyodideBundleManager.getPyodideLock(pythonRelease));

printf("%s\n", lock.cStr());
fflush(stdout);
return true;
}).build();
Expand Down

0 comments on commit f15ac0f

Please sign in to comment.