-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Replace worker-build with it's individual steps (#2)
This allows me to modify the JS side and gives more control of what and how things get built.
- Loading branch information
1 parent
f5441b4
commit 4677335
Showing
6 changed files
with
76 additions
and
23 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,46 @@ | ||
// Entrypoint for the cloudflare worker runtime. | ||
|
||
import * as imports from "./pyoci.js"; | ||
import wasmModule from "./pyoci_bg.wasm"; | ||
import { WorkerEntrypoint } from "cloudflare:workers"; | ||
|
||
// Run the worker's initialization function. | ||
imports.start?.(); | ||
|
||
export { wasmModule }; | ||
|
||
class Entrypoint extends WorkerEntrypoint { | ||
async fetch(request) { | ||
return await imports.fetch(request, this.env, this.ctx) | ||
} | ||
|
||
// async queue(batch) { | ||
// return await imports.queue(batch, this.env, this.ctx) | ||
// } | ||
// | ||
// async scheduled(event) { | ||
// return await imports.scheduled(event, this.env, this.ctx) | ||
// } | ||
} | ||
|
||
const EXCLUDE_EXPORT = [ | ||
"IntoUnderlyingByteSource", | ||
"IntoUnderlyingSink", | ||
"IntoUnderlyingSource", | ||
"MinifyConfig", | ||
"PolishConfig", | ||
"R2Range", | ||
"RequestRedirect", | ||
"fetch", | ||
"queue", | ||
"scheduled", | ||
"getMemory" | ||
]; | ||
|
||
Object.keys(imports).map(k => { | ||
if (!(EXCLUDE_EXPORT.includes(k) | k.startsWith("__"))) { | ||
Entrypoint.prototype[k] = imports[k]; | ||
} | ||
}) | ||
|
||
export default Entrypoint; |
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,7 @@ | ||
import * as imports from "./pyoci_bg.js"; | ||
|
||
import wkmod from "./pyoci_bg.wasm"; | ||
const instance = new WebAssembly.Instance(wkmod, {"./pyoci_bg.js": imports}); | ||
imports.__wbg_set_wasm(instance.exports); | ||
|
||
export * from "./pyoci_bg.js"; |
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 |
---|---|---|
@@ -1,29 +1,15 @@ | ||
name = "pyoci" | ||
main = "build/worker/shim.mjs" | ||
main = "build/cf_worker.mjs" | ||
compatibility_date = "2023-12-01" | ||
|
||
# disable *.workers.dev | ||
workers_dev = false | ||
route = { pattern = "pyoci.allexveldman.nl", custom_domain = true } | ||
|
||
# what worker-build does: | ||
# - install wasm-pack | ||
# - `wasm-pack build --no-typescript --target bundler --out-dir "build" --out-name "index" {args}` | ||
# - install esbuild | ||
# - create ./build/worker | ||
# - move build/index_bg.js to ./build/worker/index_bg.js | ||
# - move build/index_bg.wasm to ./build/worker/index.wasm | ||
# - move build/snippets/ to ./build/worker/snippets/ | ||
# https://rustwasm.github.io/wasm-bindgen/reference/js-snippets.html | ||
# - patch index_bg.js instantiate WASM module instead of importing it | ||
# https://developers.cloudflare.com/workers/languages/rust/#javascript-plumbing-wasm-bindgen | ||
# - include glue.js and shim.js (hard-coded in worker-build) | ||
# - `esbuild --external:./index.wasm --externale:cloudflare:sockets --external:cloudflare:workers --format=esm --bundle ./shim.js --outfile=shim.mjs` --minify | ||
# - remove ./build/worker/snippets/, ./build/worker/index_bg.js, shim.js, and glue.js | ||
# these are part of the esbuild bundle | ||
# Use env NO_MINIFY=1 to disable minification | ||
[build] | ||
command = "cargo install -q worker-build && worker-build --release" | ||
# command = "cargo install -q worker-build && worker-build --release" | ||
command = "just build --release" | ||
|
||
[env.dev] | ||
build = { command = "cargo install -q worker-build && worker-build --dev" } | ||
# build = { command = "cargo install -q worker-build && worker-build --dev" } | ||
build = { command = "just build --dev" } |