Skip to content

Migrate to capnp-es #3927

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 28, 2025
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
6 changes: 3 additions & 3 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ load("@aspect_rules_js//npm:defs.bzl", "npm_link_package")
load("@bazel_skylib//lib:selects.bzl", "selects")
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
load("@capnp-cpp//src/capnp:cc_capnp_library.bzl", "cc_capnp_library")
load("@npm//:capnpc-ts/package_json.bzl", capnpc_ts_bin = "bin")
load("@npm//:capnp-es/package_json.bzl", capnp_es_binary = "bin")
load("@npm//:defs.bzl", "npm_link_all_packages")

cc_capnp_library(
Expand All @@ -23,8 +23,8 @@ npm_link_package(
package = "@workerd/jsg",
)

capnpc_ts_bin.capnpc_ts_binary(
name = "capnpc_ts",
capnp_es_binary.capnp_es_binary(
name = "capnpc_es",
visibility = ["//visibility:public"],
)

Expand Down
9 changes: 1 addition & 8 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ deps_gen()
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file")

NODE_VERSION = "22.11.0"
NODE_VERSION = "22.14.0"

load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

Expand Down Expand Up @@ -212,13 +212,6 @@ load("@aspect_rules_js//npm:repositories.bzl", "npm_translate_lock")
npm_translate_lock(
name = "npm",
npmrc = "//:.npmrc",
patch_args = {
"[email protected]": ["-p1"],
},
# Patches required for `capnp-ts` to type-check
patches = {
"[email protected]": ["//:patches/[email protected]"],
},
pnpm_lock = "//:pnpm-lock.yaml",
)

Expand Down
8 changes: 4 additions & 4 deletions build/deps/gen/dep_rules_nodejs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

load("@//:build/http.bzl", "http_archive")

TAG_NAME = "v6.3.4"
URL = "https://github.com/bazel-contrib/rules_nodejs/releases/download/v6.3.4/rules_nodejs-v6.3.4.tar.gz"
STRIP_PREFIX = "rules_nodejs-6.3.4"
SHA256 = "b361863788b15d9d0cebf6803c22e8d1afa689a0eefef96dec46bcce30527090"
TAG_NAME = "v6.3.5"
URL = "https://github.com/bazel-contrib/rules_nodejs/releases/download/v6.3.5/rules_nodejs-v6.3.5.tar.gz"
STRIP_PREFIX = "rules_nodejs-6.3.5"
SHA256 = "164f1bd7e2a67ab3f6caf5b49b53c7dd625d293513154fa720e30d39eaa8285f"
TYPE = "tgz"

def dep_rules_nodejs():
Expand Down
19 changes: 9 additions & 10 deletions build/js_capnp_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def _capnp_gen_impl(ctx):
if src_prefix != "":
out_dir = out_dir + "/" + src_prefix

js_out = "-o%s:%s" % (ctx.executable._capnpc_ts.path, out_dir)
js_out = "-o%s:%s" % (ctx.executable._capnpc_es.path, out_dir)
args = ctx.actions.args()
args.add_all(["compile", "--verbose", js_out])
args.add_all(["-I" + inc for inc in includes])
Expand All @@ -46,8 +46,8 @@ def _capnp_gen_impl(ctx):
args.add_all([s for s in ctx.files.srcs])

ctx.actions.run(
inputs = inputs + ctx.files._capnpc_ts + ctx.files._capnpc_capnp + ctx.files._capnp_system,
tools = [ctx.executable._capnpc_ts], # Include required js_binary runfiles
inputs = inputs + ctx.files._capnpc_es + ctx.files._capnpc_capnp + ctx.files._capnp_system,
tools = [ctx.executable._capnpc_es], # Include required js_binary runfiles
outputs = ctx.outputs.outs,
executable = ctx.executable._capnpc,
arguments = [args],
Expand All @@ -70,7 +70,7 @@ _capnp_gen = rule(
"outs": attr.output_list(),
"src_prefix": attr.string(),
"_capnpc": attr.label(executable = True, allow_single_file = True, cfg = "exec", default = "@capnp-cpp//src/capnp:capnp_tool"),
"_capnpc_ts": attr.label(executable = True, allow_single_file = True, cfg = "exec", default = "//:capnpc_ts"),
"_capnpc_es": attr.label(executable = True, allow_single_file = True, cfg = "exec", default = "//:capnpc_es"),
"_capnpc_capnp": attr.label(executable = True, allow_single_file = True, cfg = "exec", default = "@capnp-cpp//src/capnp:capnpc-capnp"),
"_capnp_system": attr.label(default = "@capnp-cpp//src/capnp:capnp_system_library"),
},
Expand All @@ -82,6 +82,7 @@ def js_capnp_library(
name,
srcs = [],
data = [],
outs = [],
deps = [],
src_prefix = "",
visibility = None,
Expand All @@ -94,30 +95,28 @@ def js_capnp_library(
srcs: list of files to compile
data: additional files to provide to the compiler - data files and includes that need not to
be compiled
outs: expected output files
deps: other js_capnp_library rules to depend on
src_prefix: src_prefix for capnp compiler to the source root
visibility: rule visibility
target_compatible_with: target compatibility
**kwargs: rest of the arguments to js_library rule
"""

js_files = [s + ".js" for s in srcs]
d_ts_files = [s + ".d.ts" for s in srcs]

_capnp_gen(
name = name + "_gen",
srcs = srcs,
deps = [s + "_gen" for s in deps],
data = data,
outs = js_files + d_ts_files,
outs = outs,
src_prefix = src_prefix,
visibility = visibility,
target_compatible_with = target_compatible_with,
)
js_library(
name = name,
srcs = js_files + d_ts_files,
deps = deps + ["//:node_modules/capnp-ts"],
srcs = outs,
deps = deps + ["//:node_modules/capnp-es"],
visibility = visibility,
target_compatible_with = target_compatible_with,
**kwargs
Expand Down
13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,25 @@
"format": "prettier"
},
"dependencies": {
"capnp-ts": "^0.7.0",
"prettier": "^3.5.1",
"typescript": "5.6.2"
},
"devDependencies": {
"@eslint/js": "^9.20.0",
"@types/debug": "^4.1.12",
"@types/node": "^22.7.5",
"capnpc-ts": "^0.7.0",
"@types/node": "^22.14.0",
"capnp-es": "^0.0.9",
"chrome-remote-interface": "^0.33.3",
"esbuild": "^0.25.0",
"eslint": "^9.20.1",
"expect-type": "^1.1.0",
"typescript-eslint": "^8.23.0"
},
"pnpm": {
"overrides": {
"capnpc-ts>typescript": "4.7.4"
},
"onlyBuiltDependencies": []
"onlyBuiltDependencies": [],
"patchedDependencies": {
"capnp-es": "patches/capnp-es.patch"
}
},
"packageManager": "[email protected]+sha512.faf344af2d6ca65c4c5c8c2224ea77a81a5e8859cbc4e06b1511ddce2f0151512431dd19e6aff31f2c6a8f5f2aced9bd2273e1fed7dd4de1868984059d2c4247"
}
26 changes: 26 additions & 0 deletions patches/capnp-es.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
diff --git a/dist/compiler/main.mjs b/dist/compiler/main.mjs
index 6999c0e0c50570efd51959661ffc611f561bd31b..c37f97d5d786e4fc316acd4f5780e8e3976b21dd 100755
--- a/dist/compiler/main.mjs
+++ b/dist/compiler/main.mjs
@@ -38,7 +38,7 @@ Options:
`;
const sources = [];
const options = [];
-let outFormats = ["js"];
+let outFormats = ["ts","js"];
let outDir;
for (const arg of process.argv.slice(2)) {
if (arg === "--help") {
diff --git a/dist/shared/capnp-es.C3d1NAZK.mjs b/dist/shared/capnp-es.C3d1NAZK.mjs
index 08c44dc210d976e80cac085de9443068b367b2ff..61d6af8c4917d09ed7157a5098504eb28f85d729 100644
--- a/dist/shared/capnp-es.C3d1NAZK.mjs
+++ b/dist/shared/capnp-es.C3d1NAZK.mjs
@@ -2128,7 +2128,7 @@ async function compileAll(buff, opts) {
}
if (!opts?.ts) {
for (const [fileName] of files) {
- if (fileName.endsWith(".ts")) {
+ if (fileName.endsWith(".ts") && !fileName.endsWith(".d.ts")) {
files.delete(fileName);
}
}
11 changes: 0 additions & 11 deletions patches/[email protected]

This file was deleted.

Loading
Loading