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

mattn/go-sqlite3 does not work when cross compiling from linux to windows #202

Open
gmbuell opened this issue Nov 17, 2024 · 0 comments
Open

Comments

@gmbuell
Copy link

gmbuell commented Nov 17, 2024

Minimal sqlite.go

package main

import (
        "database/sql"
        "fmt"

        _ "github.com/mattn/go-sqlite3"
)

func main() {
        fmt.Println("Started")
        db, err := sql.Open("sqlite3", ":memory:")
        if err != nil {
                fmt.Printf("Error: %v\n", err)
        }
        fmt.Println("Database opened successfully")
        err = db.Ping()
        if err != nil {
                fmt.Printf("Error: %v\n", err)
        }
        fmt.Println("Database ping successful")
        if _, err := db.Exec(`CREATE TABLE test (
  id INTEGER PRIMARY KEY
);
`); err != nil {
                fmt.Printf("Error: %v\n", err)
        }
        fmt.Println("Table created")
        fmt.Println("Done")
}

BUILD.bazel

load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")

go_library(
    name = "sqlite_lib",
    srcs = ["sqlite.go"],
    importpath = "gmbuell/project/sqlite",
    visibility = ["//visibility:private"],
    deps = ["@com_github_mattn_go_sqlite3//:go-sqlite3"],
)

go_binary(
    name = "sqlite",
    embed = [":sqlite_lib"],
    visibility = ["//visibility:public"],
)

Testing on linux:

bazel run :sqlite

gives the expected output:

Started
Database opened successfully
Database ping successful
Table created
Done

Building for windows:

BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1 bazel build :sqlite --platforms=@zig_sdk//platform:windows_amd64 --extra_toolchains @zig_sdk//toolchain:windows_amd64

If I run the exe with wine, I get the expected output:

Started
Database opened successfully
Database ping successful
Table created
Done

But actually running the exe on WIndows gives

PS Z:\> .\sqlite.exe
Started
Database opened successfully

With the program then exiting silently (presumably crashing somewhere?)

Any ideas? I would assume cross compiling sqlite3 would be a fairly common use case for this toolchain.

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

No branches or pull requests

1 participant