-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the nocgo build flag to enable a build without sqlite3
This involves adding some stub files that panic if they are ever used on a nocgo build - i.e. one excluding sqlite3 but the default build will build with sqlite3 support using CGO. CGO is great if you need it, but can cause various types of failures and complexities particularly on on-standard toolcahins. As a library user I if I do not use sqlite3 I would rather not pay the prices of using CGO. In particular at the time of writing static CGO builds with go 1.13 do not work for me on musl-gcc or Arch Linux. Signed-off-by: Silas Davis <[email protected]>
- Loading branch information
Silas Davis
committed
Sep 4, 2019
1 parent
824d57d
commit 3462d0f
Showing
6 changed files
with
79 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// +build !nocgo | ||
|
||
package sqlite3 | ||
|
||
import ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// +build nocgo | ||
|
||
// This stub package allows authn-server to be build without CGO, i.e. with CGO_ENABLED=0. This has numerous advantages | ||
// including on toolchains where static linking is impossible. In order to use it run with `go build -tags nocgo`. | ||
|
||
package sqlite3 | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/jmoiron/sqlx" | ||
"github.com/keratin/authn-server/ops" | ||
) | ||
|
||
var placeholder = "generating" | ||
|
||
type BlobStore struct { | ||
TTL time.Duration | ||
LockTime time.Duration | ||
DB sqlx.Ext | ||
} | ||
|
||
func (s *BlobStore) Clean(reporter ops.ErrorReporter) { | ||
panic("Cannot use sqlite3 BlobStore because building with nocgo build tag") | ||
} | ||
|
||
func (s *BlobStore) Read(name string) ([]byte, error) { | ||
panic("Cannot use sqlite3 BlobStore because building with nocgo build tag") | ||
} | ||
|
||
func (s *BlobStore) WriteNX(name string, blob []byte) (bool, error) { | ||
panic("Cannot use sqlite3 BlobStore because building with nocgo build tag") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// +build !nocgo | ||
|
||
package sqlite3_test | ||
|
||
import ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// +build nocgo | ||
|
||
// This stub package allows authn-server to be build without CGO, i.e. with CGO_ENABLED=0. This has numerous advantages | ||
// including on toolchains where static linking is impossible. In order to use it run with `go build -tags nocgo`. | ||
|
||
package sqlite3 | ||
|
||
import ( | ||
"github.com/jmoiron/sqlx" | ||
) | ||
|
||
type Error struct { | ||
ExtendedCode int | ||
} | ||
|
||
func (Error) Error() string { | ||
panic("Cannot use sqlite3 Error because building with nocgo build tag") | ||
} | ||
|
||
var ErrConstraintUnique int | ||
|
||
func NewDB(env string) (*sqlx.DB, error) { | ||
panic("Cannot use sqlite3 DB because building with nocgo build tag") | ||
} | ||
|
||
func TestDB() (*sqlx.DB, error) { | ||
panic("Cannot use sqlite3 DB because building with nocgo build tag") | ||
} |