Skip to content

Commit 6aefa1d

Browse files
committed
use sqlite3.h from trunk when building with sqlite_trunk and report sqlite3 version
When building with tag `sqlite3_trunk`, we now use `sqlite3_trunk.h` instead of the `sqlite3.h` from the released version. We now also report the SQLite version and version number via `SQLiteVersion()` and `SQLiteVersionNumber()`. Updates tailscale/corp#37997 Signed-off-by: Percy Wegmann <percy@tailscale.com>
1 parent fa68443 commit 6aefa1d

6 files changed

Lines changed: 14172 additions & 11 deletions

File tree

cgosqlite/cgosqlite.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,3 +531,13 @@ func APIArmorEnabled() bool {
531531
func TimestampVFSEnabled() bool {
532532
return C.tmstmpvfs_enabled == 1
533533
}
534+
535+
// SQLiteVersion reports SQLITE_VERSION.
536+
func SQLiteVersion() string {
537+
return C.GoString(C.sqlite3_libversion())
538+
}
539+
540+
// SQLiteVersionNumber reports SQLITE_VERSION_NUMBER.
541+
func SQLiteVersionNumber() int {
542+
return int(C.sqlite3_libversion_number())
543+
}

cgosqlite/cgosqlite.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#include <math.h> // math.h is required on linux for FTS5.
2+
#ifdef SQLITE_TRUNK
3+
#include "sqlite3_trunk.h"
4+
#else
25
#include "sqlite3.h"
6+
#endif
37
#include <stdlib.h>
48
#include <stdint.h>
59
#include <string.h>

cgosqlite/release_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//go:build !sqlite_trunk
2+
3+
package cgosqlite
4+
5+
import "testing"
6+
7+
func TestSQLiteVersion(t *testing.T) {
8+
const want = "3.51.2"
9+
got := SQLiteVersion()
10+
if got != want {
11+
t.Fatalf("wrong version, want %s, got %s", want, got)
12+
}
13+
}
14+
15+
func TestSQLiteVersionNumber(t *testing.T) {
16+
const want = 3051002
17+
got := SQLiteVersionNumber()
18+
if got != want {
19+
t.Fatalf("wrong version, want %d, got %d", want, got)
20+
}
21+
}

cgosqlite/sqlite3_trunk.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -141394,7 +141394,7 @@ SQLITE_API int sqlite3_exec(
141394141394
*/
141395141395
#ifndef SQLITE3EXT_H
141396141396
#define SQLITE3EXT_H
141397-
/* #include "sqlite3.h" */
141397+
/* #include "sqlite3_trunk.h" */
141398141398

141399141399
/*
141400141400
** The following structure holds pointers to all of the SQLite API
@@ -186161,7 +186161,7 @@ SQLITE_API int sqlite3_complete16(const void *zSql){
186161186161
** This header file is used by programs that want to link against the
186162186162
** FTS3 library. All it does is declare the sqlite3Fts3Init() interface.
186163186163
*/
186164-
/* #include "sqlite3.h" */
186164+
/* #include "sqlite3_trunk.h" */
186165186165

186166186166
#if 0
186167186167
extern "C" {
@@ -186194,7 +186194,7 @@ SQLITE_PRIVATE int sqlite3Fts3Init(sqlite3 *db);
186194186194
** This header file is used by programs that want to link against the
186195186195
** RTREE library. All it does is declare the sqlite3RtreeInit() interface.
186196186196
*/
186197-
/* #include "sqlite3.h" */
186197+
/* #include "sqlite3_trunk.h" */
186198186198

186199186199
#ifdef SQLITE_OMIT_VIRTUALTABLE
186200186200
# undef SQLITE_ENABLE_RTREE
@@ -186231,7 +186231,7 @@ SQLITE_PRIVATE int sqlite3RtreeInit(sqlite3 *db);
186231186231
** This header file is used by programs that want to link against the
186232186232
** ICU extension. All it does is declare the sqlite3IcuInit() interface.
186233186233
*/
186234-
/* #include "sqlite3.h" */
186234+
/* #include "sqlite3_trunk.h" */
186235186235

186236186236
#if 0
186237186237
extern "C" {
@@ -192094,7 +192094,7 @@ SQLITE_PRIVATE void sqlite3ConnectionClosed(sqlite3 *db){
192094192094
SQLITE_EXTENSION_INIT3
192095192095
#endif
192096192096

192097-
/* #include "sqlite3.h" */
192097+
/* #include "sqlite3_trunk.h" */
192098192098
/************** Include fts3_tokenizer.h in the middle of fts3Int.h **********/
192099192099
/************** Begin file fts3_tokenizer.h **********************************/
192100192100
/*
@@ -192123,7 +192123,7 @@ SQLITE_EXTENSION_INIT3
192123192123
** If tokenizers are to be allowed to call sqlite3_*() functions, then
192124192124
** we will need a way to register the API consistently.
192125192125
*/
192126-
/* #include "sqlite3.h" */
192126+
/* #include "sqlite3_trunk.h" */
192127192127

192128192128
/*
192129192129
** Structures used by the tokenizer interface. When a new tokenizer
@@ -217202,7 +217202,7 @@ SQLITE_PRIVATE Module *sqlite3JsonVtabRegister(sqlite3 *db, const char *zName){
217202217202
/* #include "sqlite3ext.h" */
217203217203
SQLITE_EXTENSION_INIT1
217204217204
#else
217205-
/* #include "sqlite3.h" */
217205+
/* #include "sqlite3_trunk.h" */
217206217206
#endif
217207217207
SQLITE_PRIVATE sqlite3_int64 sqlite3GetToken(const unsigned char*,int*); /* In SQLite core */
217208217208

@@ -223517,7 +223517,7 @@ SQLITE_API int sqlite3_rtree_init(
223517223517
/* #include "sqlite3ext.h" */
223518223518
SQLITE_EXTENSION_INIT1
223519223519
#else
223520-
/* #include "sqlite3.h" */
223520+
/* #include "sqlite3_trunk.h" */
223521223521
#endif
223522223522

223523223523
/*
@@ -224413,7 +224413,7 @@ SQLITE_PRIVATE void sqlite3Fts3IcuTokenizerModule(
224413224413
/* #include <string.h> */
224414224414
/* #include <stdio.h> */
224415224415

224416-
/* #include "sqlite3.h" */
224416+
/* #include "sqlite3_trunk.h" */
224417224417

224418224418
#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_RBU)
224419224419
/************** Include sqlite3rbu.h in the middle of sqlite3rbu.c ***********/
@@ -224687,7 +224687,7 @@ SQLITE_PRIVATE void sqlite3Fts3IcuTokenizerModule(
224687224687
#ifndef _SQLITE3RBU_H
224688224688
#define _SQLITE3RBU_H
224689224689

224690-
/* #include "sqlite3.h" ** Required for error code definitions ** */
224690+
/* #include "sqlite3_trunk.h" ** Required for error code definitions ** */
224691224691

224692224692
#if 0
224693224693
extern "C" {
@@ -239242,7 +239242,7 @@ SQLITE_API int sqlite3session_config(int op, void *pArg){
239242239242
#ifndef _FTS5_H
239243239243
#define _FTS5_H
239244239244

239245-
/* #include "sqlite3.h" */
239245+
/* #include "sqlite3_trunk.h" */
239246239246

239247239247
#if 0
239248239248
extern "C" {

0 commit comments

Comments
 (0)