Skip to content

Commit

Permalink
Merge pull request #43 from skanehira/support-deno-v1.32.5
Browse files Browse the repository at this point in the history
chore: support deno v1.32.4
  • Loading branch information
skanehira authored May 3, 2023
2 parents f99a251 + 0e813e1 commit 74571a1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 28 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
47 changes: 19 additions & 28 deletions bindings/bindings.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// Auto-generated with deno_bindgen
import { CachePolicy, prepare } from "https://deno.land/x/[email protected]/plug.ts"

function encode(v: string | Uint8Array): Uint8Array {
if (typeof v !== "string") return v
return new TextEncoder().encode(v)
Expand All @@ -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)
Expand All @@ -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/[email protected]/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
Expand Down Expand Up @@ -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
}

0 comments on commit 74571a1

Please sign in to comment.