-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Esbuild bundle the Python pool setup code
We want to execute a single standalone JavaScript file in the pool scope. It should work in a normal v8 isolate with no modifications. This adds the esbuild bundle step, but keeps everything else working the same.
- Loading branch information
Showing
11 changed files
with
224 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# WARNING: THIS FILE IS AUTOGENERATED BY update-deps.py DO NOT EDIT | ||
|
||
load("@//:build/http.bzl", "http_archive") | ||
|
||
TAG_NAME = "v0.21.0" | ||
URL = "https://api.github.com/repos/aspect-build/rules_esbuild/tarball/v0.21.0" | ||
STRIP_PREFIX = "aspect-build-rules_esbuild-798abd3" | ||
SHA256 = "695a967d5e327b239618adc421ae62120bf4d3096bbac7c3550a6a31731fb03c" | ||
TYPE = "tgz" | ||
|
||
def dep_aspect_rules_esbuild(): | ||
http_archive( | ||
name = "aspect_rules_esbuild", | ||
url = URL, | ||
strip_prefix = STRIP_PREFIX, | ||
type = TYPE, | ||
sha256 = SHA256, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
""" | ||
Give a collection of js files a JsInfo provider so it can be used as a dependency for aspect_rules. | ||
""" | ||
|
||
load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "COPY_FILE_TO_BIN_TOOLCHAINS", "copy_file_to_bin_action") | ||
load("@aspect_rules_js//js:providers.bzl", "JsInfo", "js_info") | ||
|
||
_ATTRS = { | ||
"srcs": attr.label_list( | ||
allow_files = True, | ||
), | ||
"deps": attr.label_list(), | ||
} | ||
|
||
def _gather_sources_and_types(ctx, targets, files): | ||
"""Gathers sources and types from a list of targets | ||
Args: | ||
ctx: the rule context | ||
targets: List of targets to gather sources and types from their JsInfo providers. | ||
These typically come from the `srcs` and/or `data` attributes of a rule | ||
files: List of files to gather as sources and types. | ||
These typically come from the `srcs` and/or `data` attributes of a rule | ||
Returns: | ||
Sources & declaration files depsets in the sequence (sources, types) | ||
""" | ||
sources = [] | ||
types = [] | ||
|
||
for file in files: | ||
if file.is_source: | ||
file = copy_file_to_bin_action(ctx, file) | ||
|
||
if file.is_directory: | ||
# assume a directory contains types since we can't know that it doesn't | ||
types.append(file) | ||
sources.append(file) | ||
elif ( | ||
file.path.endswith((".d.ts", ".d.ts.map", ".d.mts", ".d.mts.map", ".d.cts", ".d.cts.map")) | ||
): | ||
types.append(file) | ||
elif file.path.endswith(".json"): | ||
# Any .json can produce types: https://www.typescriptlang.org/tsconfig/#resolveJsonModule | ||
# package.json may be required to resolve types with the "typings" key | ||
types.append(file) | ||
sources.append(file) | ||
else: | ||
sources.append(file) | ||
|
||
# sources as depset | ||
sources = depset(sources, transitive = [ | ||
target[JsInfo].sources | ||
for target in targets | ||
if JsInfo in target | ||
]) | ||
|
||
# types as depset | ||
types = depset(types, transitive = [ | ||
target[JsInfo].types | ||
for target in targets | ||
if JsInfo in target | ||
]) | ||
|
||
return (sources, types) | ||
|
||
def _js_file_impl(ctx): | ||
sources, types = _gather_sources_and_types( | ||
ctx = ctx, | ||
targets = ctx.attr.srcs, | ||
files = ctx.files.srcs, | ||
) | ||
|
||
return [ | ||
js_info( | ||
target = ctx.label, | ||
sources = sources, | ||
types = types, | ||
), | ||
DefaultInfo( | ||
files = sources, | ||
), | ||
OutputGroupInfo( | ||
types = types, | ||
), | ||
] | ||
|
||
js_file_lib = struct( | ||
attrs = _ATTRS, | ||
implementation = _js_file_impl, | ||
provides = [DefaultInfo, JsInfo, OutputGroupInfo], | ||
) | ||
|
||
js_file = rule( | ||
implementation = js_file_lib.implementation, | ||
attrs = js_file_lib.attrs, | ||
provides = js_file_lib.provides, | ||
toolchains = COPY_FILE_TO_BIN_TOOLCHAINS, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { dirname, join } from 'node:path'; | ||
import { existsSync } from 'node:fs'; | ||
import { readFile } from 'node:fs/promises'; | ||
|
||
const pyodideRootDir = dirname( | ||
dirname(dirname(new URL(import.meta.url).pathname)) | ||
); | ||
|
||
let resolvePlugin = { | ||
name: 'example', | ||
setup(build) { | ||
// Redirect all paths starting with "images/" to "./public/images/" | ||
build.onResolve({ filter: /pyodide-internal:.*/ }, (args) => { | ||
let rest = args.path.split(':')[1]; | ||
let path; | ||
if (rest.startsWith('generated')) { | ||
path = join(pyodideRootDir, rest); | ||
if (!existsSync(path)) { | ||
path += '.js'; | ||
} | ||
} else { | ||
path = join(pyodideRootDir, 'internal', rest); | ||
if (!existsSync(path)) { | ||
path += '.ts'; | ||
} | ||
} | ||
return { path }; | ||
}); | ||
}, | ||
}; | ||
|
||
export default { | ||
plugins: [resolvePlugin], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters