tursodatabase / go-libsql

libSQL API for Go
MIT License
79 stars 11 forks source link

'libsql.h' file not found #21

Open risico opened 5 months ago

risico commented 5 months ago

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 commented 5 months ago

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

go: github.com/antlr/antlr4/runtime/Go/antlr/v4@v4.0.0-20240322200237-990fbc2225a9: 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/v4@v4.0.0-20230512164433-5d1fd1a340c9

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

risico commented 5 months ago

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 commented 5 months ago

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.

ryanskidmore commented 5 months ago

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.

soky314 commented 4 weeks ago

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