From 0006752f536bfaa3927b1685a62580123d52cbc2 Mon Sep 17 00:00:00 2001 From: skanehira Date: Wed, 3 May 2023 15:56:34 +0900 Subject: [PATCH 1/2] chore: support deno v1.32.5 --- bindings/bindings.ts | 47 ++++++++++++++++++-------------------------- 1 file changed, 19 insertions(+), 28 deletions(-) diff --git a/bindings/bindings.ts b/bindings/bindings.ts index 05f7aa4..a13ebd2 100644 --- a/bindings/bindings.ts +++ b/bindings/bindings.ts @@ -1,6 +1,4 @@ // Auto-generated with deno_bindgen -import { CachePolicy, prepare } from "https://deno.land/x/plug@0.5.2/plug.ts" - function encode(v: string | Uint8Array): Uint8Array { if (typeof v !== "string") return v return new TextEncoder().encode(v) @@ -10,8 +8,9 @@ function decode(v: Uint8Array): string { return new TextDecoder().decode(v) } +// deno-lint-ignore no-explicit-any function readPointer(v: any): Uint8Array { - const ptr = new Deno.UnsafePointerView(v as bigint) + const ptr = new Deno.UnsafePointerView(v) const lengthBe = new Uint8Array(4) const view = new DataView(lengthBe.buffer) ptr.copyInto(lengthBe, 0) @@ -21,41 +20,33 @@ function readPointer(v: any): Uint8Array { } const url = new URL( - "https://github.com/skanehira/deno-silicon/releases/download/v0.0.4/", + "https://github.com/skanehira/deno-silicon/releases/download/v0.0.5/", import.meta.url, ) + +import { dlopen, FetchOptions } from "https://deno.land/x/plug@1.0.1/mod.ts" let uri = url.toString() if (!uri.endsWith("/")) uri += "/" let darwin: string | { aarch64: string; x86_64: string } = uri - + "libdeno_silicon.dylib" - -if (url.protocol !== "file:") { - // Assume that remote assets follow naming scheme - // for each macOS artifact. - darwin = { - aarch64: uri + "libdeno_silicon_arm64.dylib", - x86_64: uri + "libdeno_silicon.dylib", - } -} -const opts = { +const opts: FetchOptions = { name: "deno_silicon", - urls: { + url: { darwin, - windows: uri + "deno_silicon.dll", - linux: uri + "libdeno_silicon.so", + windows: uri, + linux: uri, }, - policy: undefined, + cache: "use", } -const _lib = await prepare(opts, { - font_list: { parameters: [], result: "pointer", nonblocking: false }, +const { symbols } = await dlopen(opts, { + font_list: { parameters: [], result: "buffer", nonblocking: false }, generate: { - parameters: ["pointer", "usize"], - result: "pointer", + parameters: ["buffer", "usize"], + result: "buffer", nonblocking: false, }, - theme_list: { parameters: [], result: "pointer", nonblocking: false }, + theme_list: { parameters: [], result: "buffer", nonblocking: false }, }) export type Options = { code: string @@ -99,19 +90,19 @@ export type SiliconResult = } } export function font_list() { - let rawResult = _lib.symbols.font_list() + const rawResult = symbols.font_list() const result = readPointer(rawResult) return JSON.parse(decode(result)) as SiliconResult } export function generate(a0: Options) { const a0_buf = encode(JSON.stringify(a0)) - const a0_ptr = Deno.UnsafePointer.of(a0_buf) - let rawResult = _lib.symbols.generate(a0_ptr, a0_buf.byteLength) + + const rawResult = symbols.generate(a0_buf, a0_buf.byteLength) const result = readPointer(rawResult) return JSON.parse(decode(result)) as SiliconResult } export function theme_list() { - let rawResult = _lib.symbols.theme_list() + const rawResult = symbols.theme_list() const result = readPointer(rawResult) return JSON.parse(decode(result)) as SiliconResult } From 0e813e18e2dce0176d9b52b19a3ba6e4ff0de0e1 Mon Sep 17 00:00:00 2001 From: skanehira Date: Wed, 3 May 2023 16:03:56 +0900 Subject: [PATCH 2/2] docs: update README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 865c07c..2f250dd 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ Please refer silicon's [dependencies](https://github.com/Aloxaf/silicon#dependen |----------------|----------------------| | v0.0.2 | `v1.24.3` or earlier | | v0.0.3 ~ | `v1.25.0` or later | +| v0.0.5 ~ | `v1.32.4` or later | ## Usage You can call `generateImage(code, language, options)` to generates image from source code.