Code Monkey home page Code Monkey logo

Comments (3)

silvioprog avatar silvioprog commented on June 24, 2024

Running deno_bindgen --release in my laptop, it generated the following binding (using the library locally, from ../target/release):

// 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)
}

function decode(v: Uint8Array): string {
  return new TextDecoder().decode(v)
}

function readPointer(v: any): Uint8Array {
  const ptr = new Deno.UnsafePointerView(v as bigint)
  const lengthBe = new Uint8Array(4)
  const view = new DataView(lengthBe.buffer)
  ptr.copyInto(lengthBe, 0)
  const buf = new Uint8Array(view.getUint32(0))
  ptr.copyInto(buf, 4)
  return buf
}

const url = new URL("../target/release", import.meta.url)
let uri = url.toString()
if (!uri.endsWith("/")) uri += "/"

let darwin: string | { aarch64: string; x86_64: string } = uri
  + "libdeno_audio.dylib"

if (url.protocol !== "file:") {
  // Assume that remote assets follow naming scheme
  // for each macOS artifact.
  darwin = {
    aarch64: uri + "libdeno_audio_arm64.dylib",
    x86_64: uri + "libdeno_audio.dylib",
  }
}

const opts = {
  name: "deno_audio",
  urls: {
    darwin,
    windows: uri + "deno_audio.dll",
    linux: uri + "libdeno_audio.so",
  },
  policy: undefined,
}
const _lib = await prepare(opts, {
  play: { parameters: ["pointer", "usize"], result: "void", nonblocking: true },
})

export function play(a0: string) {
  const a0_buf = encode(a0)
  const a0_ptr = Deno.UnsafePointer.of(a0_buf)
  let rawResult = _lib.symbols.play(a0_ptr, a0_buf.byteLength)
  const result = rawResult
  return result
}

...and this library below:

libdeno_audio.dylib.zip

...that worked like a charm.

Anyway, it would be nice to provide arm64 binary at littledivy/deno_audio/releases too.

from deno_audio.

silvioprog avatar silvioprog commented on June 24, 2024

Good news from GitHub blog:

GitHub Actions: Self-hosted runners now support Apple M1 hardware

from deno_audio.

Alixxx-please avatar Alixxx-please commented on June 24, 2024

Running deno_bindgen --release in my laptop, it generated the following binding (using the library locally, from ../target/release):

// 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)
}

function decode(v: Uint8Array): string {
  return new TextDecoder().decode(v)
}

function readPointer(v: any): Uint8Array {
  const ptr = new Deno.UnsafePointerView(v as bigint)
  const lengthBe = new Uint8Array(4)
  const view = new DataView(lengthBe.buffer)
  ptr.copyInto(lengthBe, 0)
  const buf = new Uint8Array(view.getUint32(0))
  ptr.copyInto(buf, 4)
  return buf
}

const url = new URL("../target/release", import.meta.url)
let uri = url.toString()
if (!uri.endsWith("/")) uri += "/"

let darwin: string | { aarch64: string; x86_64: string } = uri
  + "libdeno_audio.dylib"

if (url.protocol !== "file:") {
  // Assume that remote assets follow naming scheme
  // for each macOS artifact.
  darwin = {
    aarch64: uri + "libdeno_audio_arm64.dylib",
    x86_64: uri + "libdeno_audio.dylib",
  }
}

const opts = {
  name: "deno_audio",
  urls: {
    darwin,
    windows: uri + "deno_audio.dll",
    linux: uri + "libdeno_audio.so",
  },
  policy: undefined,
}
const _lib = await prepare(opts, {
  play: { parameters: ["pointer", "usize"], result: "void", nonblocking: true },
})

export function play(a0: string) {
  const a0_buf = encode(a0)
  const a0_ptr = Deno.UnsafePointer.of(a0_buf)
  let rawResult = _lib.symbols.play(a0_ptr, a0_buf.byteLength)
  const result = rawResult
  return result
}

...and this library below:

libdeno_audio.dylib.zip

...that worked like a charm.

Anyway, it would be nice to provide arm64 binary at littledivy/deno_audio/releases too.

How would I use your .dylib to use the play function in my code?

from deno_audio.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.