Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE REQUEST] Support for Apple Silicon (M1) #9

Open
silvioprog opened this issue Dec 9, 2022 · 3 comments · May be fixed by #14
Open

[FEATURE REQUEST] Support for Apple Silicon (M1) #9

silvioprog opened this issue Dec 9, 2022 · 3 comments · May be fixed by #14

Comments

@silvioprog
Copy link

When we try to run the module in a macOS running in arm64 architecture:

deno run --allow-all --unstable index.ts
error: Uncaught (in promise) Error: Could not open library: Could not open library: dlopen(~/Library/Caches/deno/plug/https/github.com/f53f000ac09e54195c49f3ca7d32b3dcff62ed2a62e213f36a5a4e02875d7d7c.dylib, 0x0005): tried: '~/Library/Caches/deno/plug/https/github.com/f53f000ac09e54195c49f3ca7d32b3dcff62ed2a62e213f36a5a4e02875d7d7c.dylib'
(mach-o file, but is an incompatible architecture (have (x86_64), need (arm64e)))
  return Deno.dlopen(file, symbols);
              ^
    at new DynamicLibrary (deno:ext/ffi/00_ffi.js:274:39)
    at Object.dlopen (deno:ext/ffi/00_ffi.js:368:12)
    at prepare (https://deno.land/x/plug@0.5.1/plug.ts:106:15)
    at async https://deno.land/x/audio@0.2.0/bindings/bindings.ts:28:14

Notice the error part: mach-o file, but is an incompatible architecture (have (x86_64), need (arm64e))

@silvioprog
Copy link
Author

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/plug@0.5.2/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.

@silvioprog
Copy link
Author

silvioprog commented Dec 9, 2022

@Alixxx-please
Copy link

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/plug@0.5.2/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?

@tehpsalmist tehpsalmist linked a pull request Sep 5, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants