Skip to content

Commit 85a15a7

Browse files
SpaiderDenis Dmitriev
and
Denis Dmitriev
authored
Add build tags to support both x86 and ARM compilation on macOS (#1069)
* Add build tags to support both x86 and ARM compilation on macOS * Documentation fix: command line for build under macOS * Global replace 'macOS X' -> 'macOS'. Fix typo in -tags cmd line param * `README.md`: fix all `--tags` -> `-tags` --------- Co-authored-by: Denis Dmitriev <dmitriev@itspartner.net>
1 parent 819cc0d commit 85a15a7

File tree

3 files changed

+31
-18
lines changed

3 files changed

+31
-18
lines changed

README.md

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ This package follows the official [Golang Release Policy](https://golang.org/doc
4040
- [Alpine](#alpine)
4141
- [Fedora](#fedora)
4242
- [Ubuntu](#ubuntu)
43-
- [Mac OSX](#mac-osx)
43+
- [macOS](#mac-osx)
4444
- [Windows](#windows)
4545
- [Errors](#errors)
4646
- [User Authentication](#user-authentication)
@@ -145,7 +145,7 @@ Click [here](https://golang.org/pkg/go/build/#hdr-Build_Constraints) for more in
145145
If you wish to build this library with additional extensions / features, use the following command:
146146

147147
```bash
148-
go build --tags "<FEATURE>"
148+
go build -tags "<FEATURE>"
149149
```
150150

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

156156
```bash
157-
go build --tags "icu json1 fts5 secure_delete"
157+
go build -tags "icu json1 fts5 secure_delete"
158158
```
159159

160160
### Feature / Extension List
@@ -194,7 +194,7 @@ This package can be compiled for android.
194194
Compile with:
195195

196196
```bash
197-
go build --tags "android"
197+
go build -tags "android"
198198
```
199199

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

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

222-
## Cross Compiling from MAC OSX
223-
The simplest way to cross compile from OSX is to use [musl-cross](https://github.com/FiloSottile/homebrew-musl-cross).
222+
## Cross Compiling from macOS
223+
The simplest way to cross compile from macOS is to use [xgo](https://github.com/karalabe/xgo).
224224

225225
Steps:
226226
- Install [musl-cross](https://github.com/FiloSottile/homebrew-musl-cross) (`brew install FiloSottile/musl-cross/musl-cross`).
@@ -241,13 +241,13 @@ To compile this package on Linux, you must install the development tools for you
241241
To compile under linux use the build tag `linux`.
242242

243243
```bash
244-
go build --tags "linux"
244+
go build -tags "linux"
245245
```
246246

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

249249
```
250-
go build --tags "libsqlite3 linux"
250+
go build -tags "libsqlite3 linux"
251251
```
252252

253253
### Alpine
@@ -270,34 +270,43 @@ sudo yum groupinstall "Development Tools" "Development Libraries"
270270
sudo apt-get install build-essential
271271
```
272272

273-
## Mac OSX
273+
## macOS
274274

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

277277
Required dependency:
278278

279279
```bash
280280
brew install sqlite3
281281
```
282282

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

285285
This additional package can be installed with `homebrew`:
286286

287287
```bash
288288
brew upgrade icu4c
289289
```
290290

291-
To compile for Mac OSX:
291+
To compile for macOS on x86:
292292

293293
```bash
294-
go build --tags "darwin"
294+
go build -tags "darwin amd64"
295+
```
296+
297+
To compile for macOS on ARM chips:
298+
299+
```bash
300+
go build -tags "darwin arm64"
295301
```
296302

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

299305
```
300-
go build --tags "libsqlite3 darwin"
306+
# x86
307+
go build -tags "libsqlite3 darwin amd64"
308+
# ARM
309+
go build -tags "libsqlite3 darwin arm64"
301310
```
302311

303312
Additional information:

sqlite3_libsqlite3.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ package sqlite3
1010
/*
1111
#cgo CFLAGS: -DUSE_LIBSQLITE3
1212
#cgo linux LDFLAGS: -lsqlite3
13-
#cgo darwin LDFLAGS: -L/usr/local/opt/sqlite/lib -lsqlite3
14-
#cgo darwin CFLAGS: -I/usr/local/opt/sqlite/include
13+
#cgo darwin,amd64 LDFLAGS: -L/usr/local/opt/sqlite/lib -lsqlite3
14+
#cgo darwin,amd64 CFLAGS: -I/usr/local/opt/sqlite/include
15+
#cgo darwin,arm64 LDFLAGS: -L/opt/homebrew/opt/sqlite/lib -lsqlite3
16+
#cgo darwin,arm64 CFLAGS: -I/opt/homebrew/opt/sqlite/include
1517
#cgo openbsd LDFLAGS: -lsqlite3
1618
#cgo solaris LDFLAGS: -lsqlite3
1719
#cgo windows LDFLAGS: -lsqlite3

sqlite3_opt_icu.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ package sqlite3
1010
/*
1111
#cgo LDFLAGS: -licuuc -licui18n
1212
#cgo CFLAGS: -DSQLITE_ENABLE_ICU
13-
#cgo darwin CFLAGS: -I/usr/local/opt/icu4c/include
14-
#cgo darwin LDFLAGS: -L/usr/local/opt/icu4c/lib
13+
#cgo darwin,amd64 CFLAGS: -I/usr/local/opt/icu4c/include
14+
#cgo darwin,amd64 LDFLAGS: -L/usr/local/opt/icu4c/lib
15+
#cgo darwin,arm64 CFLAGS: -I/opt/homebrew/opt/icu4c/include
16+
#cgo darwin,arm64 LDFLAGS: -L/opt/homebrew/opt/icu4c/lib
1517
#cgo openbsd LDFLAGS: -lsqlite3
1618
*/
1719
import "C"

0 commit comments

Comments
 (0)