denodrivers / sqlite3

The fastest and correct SQLite3 module for Deno runtime
https://jsr.io/@db/sqlite
Apache License 2.0
265 stars 22 forks source link

Compiled binary throws zlib dependency error #117

Closed 7flash closed 9 months ago

7flash commented 11 months ago

Version: Deno 1.39.1

Jan05-2100.ts

import { Database } from "https://deno.land/x/sqlite3@0.10.0/mod.ts";

const db = new Database("test.db");

const [version] = db.prepare("select sqlite_version()").value<[string]>()!;
console.log(version);

db.close();

Compile it

deno compile Jan05-2100.ts

Then run

./Jan05-2100
error: Uncaught (in promise) Error: Failed to load SQLite3 Dynamic Library
  throw new Error("Failed to load SQLite3 Dynamic Library", {
        ^
    at https://deno.land/x/sqlite3@0.10.0/src/ffi.ts:543:9
    at eventLoopTick (ext:core/01_core.js:181:11)
Caused by: Error: Could not open library: Could not open library: dlopen(/Users/gur/Library/Caches/deno/plug/https/github.com/104011a9e1238b1ae4e9c5bd462569d5bdcb9ae2d6b36d982871dbce44f79c44.dylib, 0x0005): Library not loaded: /opt/homebrew/opt/zlib/lib/libz.1.dylib
  Referenced from: <61850E31-E458-361A-ADCC-2CD22831D197> /Users/gur/Library/Caches/deno/plug/https/github.com/104011a9e1238b1ae4e9c5bd462569d5bdcb9ae2d6b36d982871dbce44f79c44.dylib (built for macOS 14.0 which is newer than running OS)
  Reason: tried: '/opt/homebrew/opt/zlib/lib/libz.1.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/opt/zlib/lib/libz.1.dylib' (no such file), '/opt/homebrew/opt/zlib/lib/libz.1.dylib' (no such file)
    at new DynamicLibrary (ext:deno_ffi/00_ffi.js:454:46)
    at Object.dlopen (ext:deno_ffi/00_ffi.js:591:10)
    at dlopen (https://deno.land/x/plug@1.0.1/mod.ts:125:15)
    at eventLoopTick (ext:core/01_core.js:181:11)
    at async https://deno.land/x/sqlite3@0.10.0/src/ffi.ts:531:12

This error solved by installing zlib

brew install zlib

Then works

./Jan05-2100
3.44.0

It's expected to work regardless user machine has zlib installed

https://github.com/denoland/deno/issues/21809#issuecomment-1879057507

DjDeveloperr commented 11 months ago

Seems like we need to statically link to zlib for that. SQLite3 build doesn't seem to do it by default..

stereosteve commented 10 months ago

I encountered this too running the readme example on osx.

Built it works if I pull down the source and do:

git submodule update --init --recursive
deno task build
DENO_SQLITE_LOCAL=1 deno task test

Also I don't get the error if I use sqlite3@0.9.1... so seems specific to the current version dylib release artifact?

DjDeveloperr commented 10 months ago

Are you on ARM Mac? ARM binaries are built locally and uploaded manually when making a release. Maybe there was some configuration issue earlier. We can try cutting a new release

7flash commented 10 months ago

Yes macbook air m2

So what should I do?

DjDeveloperr commented 10 months ago

@7flash you should try building SQLite3 locally and run the tests in this repo to see if it works without installing zlib dependency. There are instructions to do so above my comment.

stereosteve commented 10 months ago

Yes on a M1.

Downloaded from github release:

otool -L ~/Downloads/libsqlite3_aarch64.dylib
/Users/steve/Downloads/libsqlite3_aarch64.dylib:
    /usr/local/lib/libsqlite3-3.44.0.0.dylib (compatibility version 9.0.0, current version 9.6.0)
    /opt/homebrew/opt/zlib/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.13)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1336.0.0)

If I build locally:

otool -L build/libsqlite3_aarch64.dylib
build/libsqlite3_aarch64.dylib:
    /usr/local/lib/libsqlite3-3.44.0.0.dylib (compatibility version 9.0.0, current version 9.6.0)
    /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.12)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1336.61.1)

Local build looks correct even if I do brew install zlib

mxcl commented 10 months ago

would probs just work if you uninstall brew’s zlib before building since darwin comes with its own zlib

DjDeveloperr commented 10 months ago

That would kinda explain why the build on CI (without installing brew zlib) doesn't have this issue compared to the build on my mac, where it is installed

ianawilson commented 9 months ago

I have the same issue, and I would prefer that the bundled builds do not require homebrew zlib.

DjDeveloperr commented 9 months ago

This issue should be resolved in release 0.11.0