go-libsql icon indicating copy to clipboard operation
go-libsql copied to clipboard

'libsql.h' file not found

Open risico opened this issue 1 year ago • 5 comments

Just signed up to try Turso as a huge fan of SQLite but sadly encountered a weird bug right off the bat.

I say weird because when I try the the sample code as a standalone, in a separate go project it works asp expected, but when I try to integrate it into my bigger project it crashes with the following error:

# github.com/tursodatabase/go-libsql
vendor/github.com/tursodatabase/go-libsql/libsql.go:16:10: fatal error: 'libsql.h' file not found
#include <libsql.h>
         ^~~~~~~~~~
1 error generated.

Sharing the code I used, although nothing fancy, just the example code take off the documentation.

func main() {
    dbName := "local.db"
    primaryUrl := "libsql://url.turso.io"
    authToken := "<token>"

    dir, err := os.MkdirTemp("", "libsql-*")
    if err != nil {
        fmt.Println("Error creating temporary directory:", err)
        os.Exit(1)
    }
    defer os.RemoveAll(dir)

    dbPath := filepath.Join(dir, dbName)
    connector, err := libsql.NewEmbeddedReplicaConnector(dbPath, primaryUrl,
        libsql.WithAuthToken(authToken),
    )
    if err != nil {
        fmt.Println("Error creating connector:", err)
        os.Exit(1)
    }
    defer connector.Close()

    db := sql.OpenDB(connector)
    defer db.Close()
}

It is pretty late around here and I am a bit spent, so there might be a chance I am doing something stupid. Currently my only hunch is that there might be some sort of conflict with the other sqlite packages, although not sure how that'd be possible.

risico avatar Mar 22 '24 21:03 risico

OK, I think I found the issue, there is a conflict with antlrv4.

go: github.com/antlr/antlr4/runtime/Go/antlr/[email protected]: parsing go.mod:
        module declares its path as: github.com/antlr4-go/antlr/v4
                but was required as: github.com/antlr/antlr4/runtime/Go/antlr/v4
        restoring github.com/antlr/antlr4/runtime/Go/antlr/[email protected]

Making a PR, gonna check if updating the path fixes my issue.

risico avatar Mar 22 '24 21:03 risico

Went even more into the rabbit whole and it seems that Antlr moved their Go runtime into its own dedicated repo as per their documentation: image

I tried to change the repo and the dependencies inside the go-libsql but it seems it the changes reach up to github.com/libsql/sqlite-antlr4-parser.

I'll try and open up an MR in github.com/libsql/sqlite-antlr4-parser so we can fix that, then once that's merged, pull it in go-libsql and get the fix done here as well.

risico avatar Mar 22 '24 21:03 risico

Here is the PR to change the path for libsql/sqlite-antlr4-parser: https://github.com/libsql/sqlite-antlr4-parser/pull/4

Once that gets merged I'll make the PR for this repo.

risico avatar Mar 23 '24 14:03 risico

I've just run into this same issue 😞 My project still uses vendoring, and I noticed that the libsql.h file is nowhere to be found within the vendored directory. Could that be caused by this same issue, or is it a different one? The library mentioned seems mostly unrelated to this issue.

ryanskidmore avatar Mar 29 '24 20:03 ryanskidmore

I've just run into this same issue. Our project is using vendoring. I resolved this issue with manual copy of folder"lib" into vendored folder of go-libsql The problem is that go mod -vendor pruned the "lib" folder, which contains the C code needed to build this package. https://github.com/golang/go/issues/26366

soky314 avatar Aug 13 '24 19:08 soky314