Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 23 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ This package follows the official [Golang Release Policy](https://golang.org/doc
- [Alpine](#alpine)
- [Fedora](#fedora)
- [Ubuntu](#ubuntu)
- [Mac OSX](#mac-osx)
- [macOS](#mac-osx)
- [Windows](#windows)
- [Errors](#errors)
- [User Authentication](#user-authentication)
Expand Down Expand Up @@ -145,7 +145,7 @@ Click [here](https://golang.org/pkg/go/build/#hdr-Build_Constraints) for more in
If you wish to build this library with additional extensions / features, use the following command:

```bash
go build --tags "<FEATURE>"
go build -tags "<FEATURE>"
```

For available features, see the extension list.
Expand All @@ -154,7 +154,7 @@ When using multiple build tags, all the different tags should be space delimited
Example:

```bash
go build --tags "icu json1 fts5 secure_delete"
go build -tags "icu json1 fts5 secure_delete"
```

### Feature / Extension List
Expand Down Expand Up @@ -190,7 +190,7 @@ This package can be compiled for android.
Compile with:

```bash
go build --tags "android"
go build -tags "android"
```

For more information see [#201](https://github.com/mattn/go-sqlite3/issues/201)
Expand All @@ -215,8 +215,8 @@ This library can be cross-compiled.

In some cases you are required to the `CC` environment variable with the cross compiler.

## Cross Compiling from MAC OSX
The simplest way to cross compile from OSX is to use [xgo](https://github.com/karalabe/xgo).
## Cross Compiling from macOS
The simplest way to cross compile from macOS is to use [xgo](https://github.com/karalabe/xgo).

Steps:
- Install [xgo](https://github.com/karalabe/xgo) (`go get github.com/karalabe/xgo`).
Expand All @@ -238,13 +238,13 @@ To compile this package on Linux, you must install the development tools for you
To compile under linux use the build tag `linux`.

```bash
go build --tags "linux"
go build -tags "linux"
```

If you wish to link directly to libsqlite3 then you can use the `libsqlite3` build tag.

```
go build --tags "libsqlite3 linux"
go build -tags "libsqlite3 linux"
```

### Alpine
Expand All @@ -267,34 +267,43 @@ sudo yum groupinstall "Development Tools" "Development Libraries"
sudo apt-get install build-essential
```

## Mac OSX
## macOS

OSX should have all the tools present to compile this package. If not, install XCode to add all the developers tools.
macOS should have all the tools present to compile this package. If not, install XCode to add all the developers tools.

Required dependency:

```bash
brew install sqlite3
```

For OSX, there is an additional package to install which is required if you wish to build the `icu` extension.
For macOS, there is an additional package to install which is required if you wish to build the `icu` extension.

This additional package can be installed with `homebrew`:

```bash
brew upgrade icu4c
```

To compile for Mac OSX:
To compile for macOS on x86:

```bash
go build --tags "darwin"
go build -tags "darwin amd64"
```

To compile for macOS on ARM chips:

```bash
go build -tags "darwin arm64"
```

If you wish to link directly to libsqlite3, use the `libsqlite3` build tag:

```
go build --tags "libsqlite3 darwin"
# x86
go build -tags "libsqlite3 darwin amd64"
# ARM
go build -tags "libsqlite3 darwin arm64"
```

Additional information:
Expand Down
6 changes: 4 additions & 2 deletions sqlite3_libsqlite3.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ package sqlite3
/*
#cgo CFLAGS: -DUSE_LIBSQLITE3
#cgo linux LDFLAGS: -lsqlite3
#cgo darwin LDFLAGS: -L/usr/local/opt/sqlite/lib -lsqlite3
#cgo darwin CFLAGS: -I/usr/local/opt/sqlite/include
#cgo darwin,amd64 LDFLAGS: -L/usr/local/opt/sqlite/lib -lsqlite3
#cgo darwin,amd64 CFLAGS: -I/usr/local/opt/sqlite/include
#cgo darwin,arm64 LDFLAGS: -L/opt/homebrew/opt/sqlite/lib -lsqlite3
#cgo darwin,arm64 CFLAGS: -I/opt/homebrew/opt/sqlite/include
#cgo openbsd LDFLAGS: -lsqlite3
#cgo solaris LDFLAGS: -lsqlite3
#cgo windows LDFLAGS: -lsqlite3
Expand Down
6 changes: 4 additions & 2 deletions sqlite3_opt_icu.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ package sqlite3
/*
#cgo LDFLAGS: -licuuc -licui18n
#cgo CFLAGS: -DSQLITE_ENABLE_ICU
#cgo darwin CFLAGS: -I/usr/local/opt/icu4c/include
#cgo darwin LDFLAGS: -L/usr/local/opt/icu4c/lib
#cgo darwin,amd64 CFLAGS: -I/usr/local/opt/icu4c/include
#cgo darwin,amd64 LDFLAGS: -L/usr/local/opt/icu4c/lib
#cgo darwin,arm64 CFLAGS: -I/opt/homebrew/opt/icu4c/include
#cgo darwin,arm64 LDFLAGS: -L/opt/homebrew/opt/icu4c/lib

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering why this is different for them.

-I/usr/local/opt/icu4c/include -I/opt/homebrew/opt/icu4c/include
-L/usr/local/opt/icu4c/lib -L/opt/homebrew/opt/icu4c/lib

This is not good?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattn Not sure I understand your question, but Homebrew installs to a different location on arm64 (i.e, M1/M2) than on amd64 (i.e., Intel), as mentioned in the docs. https://docs.brew.sh/Installation

We could also choose to include both directories for macOS regardless of GOARCH, and I suppose that would also work. (Although I think we should put /opt/homebrew first in that case.)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just hit this issue on a M1 Mac and these locations are correct. This PR along with the build tags go build -tags "libsqlite3 darwin arm64" allowed me to build against the sqlite version installed via homebrew.

#cgo openbsd LDFLAGS: -lsqlite3
*/
import "C"