Skip to content

Commit 63ec23e

Browse files
mhdawsonaduh95
authored andcommitted
sqlite: add build option to build without sqlite
Signed-off-by: Michael Dawson <[email protected]> PR-URL: #58122 Reviewed-By: Edy Silva <[email protected]> Reviewed-By: Rafael Gonzaga <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 0f6a262 commit 63ec23e

33 files changed

+142
-32
lines changed

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,16 +509,24 @@ SQLITE_BINDING_SOURCES := \
509509
$(wildcard test/sqlite/*/*.c)
510510

511511
# Implicitly depends on $(NODE_EXE), see the build-sqlite-tests rule for rationale.
512+
ifndef NOSQLITE
512513
test/sqlite/.buildstamp: $(ADDONS_PREREQS) \
513514
$(SQLITE_BINDING_GYPS) $(SQLITE_BINDING_SOURCES)
514515
@$(call run_build_addons,"$$PWD/test/sqlite",$@)
516+
else
517+
test/sqlite/.buildstamp:
518+
endif
515519

516520
.PHONY: build-sqlite-tests
521+
ifndef NOSQLITE
517522
# .buildstamp needs $(NODE_EXE) but cannot depend on it
518523
# directly because it calls make recursively. The parent make cannot know
519524
# if the subprocess touched anything so it pessimistically assumes that
520525
# .buildstamp is out of date and need a rebuild.
521526
build-sqlite-tests: | $(NODE_EXE) test/sqlite/.buildstamp ## Build SQLite tests.
527+
else
528+
build-sqlite-tests:
529+
endif
522530

523531
.PHONY: clear-stalled
524532
clear-stalled: ## Clear any stalled processes.

configure.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,12 @@
864864
default=None,
865865
help='build without NODE_OPTIONS support')
866866

867+
parser.add_argument('--without-sqlite',
868+
action='store_true',
869+
dest='without_sqlite',
870+
default=None,
871+
help='build without SQLite (disables SQLite and Web Stoage API)')
872+
867873
parser.add_argument('--ninja',
868874
action='store_true',
869875
dest='use_ninja',
@@ -1827,6 +1833,16 @@ def without_ssl_error(option):
18271833

18281834
configure_library('openssl', o)
18291835

1836+
def configure_sqlite(o):
1837+
o['variables']['node_use_sqlite'] = b(not options.without_sqlite)
1838+
if options.without_sqlite:
1839+
def without_sqlite_error(option):
1840+
error(f'--without-sqlite is incompatible with {option}')
1841+
if options.shared_sqlite:
1842+
without_sqlite_error('--shared-sqlite')
1843+
return
1844+
1845+
configure_library('sqlite', o, pkgname='sqlite3')
18301846

18311847
def configure_static(o):
18321848
if options.fully_static or options.partly_static:
@@ -2270,7 +2286,7 @@ def make_bin_override():
22702286
configure_library('nghttp2', output, pkgname='libnghttp2')
22712287
configure_library('nghttp3', output, pkgname='libnghttp3')
22722288
configure_library('ngtcp2', output, pkgname='libngtcp2')
2273-
configure_library('sqlite', output, pkgname='sqlite3')
2289+
configure_sqlite(output);
22742290
configure_library('uvwasi', output, pkgname='libuvwasi')
22752291
configure_library('zstd', output, pkgname='libzstd')
22762292
configure_v8(output, configurations)

node.gyp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
'node_shared_uvwasi%': 'false',
2626
'node_shared_nghttp2%': 'false',
2727
'node_use_openssl%': 'true',
28+
'node_use_sqlite%': 'true',
2829
'node_shared_openssl%': 'false',
2930
'node_v8_options%': '',
3031
'node_enable_v8_vtunejit%': 'false',
@@ -140,7 +141,6 @@
140141
'src/node_shadow_realm.cc',
141142
'src/node_snapshotable.cc',
142143
'src/node_sockaddr.cc',
143-
'src/node_sqlite.cc',
144144
'src/node_stat_watcher.cc',
145145
'src/node_symbols.cc',
146146
'src/node_task_queue.cc',
@@ -153,7 +153,6 @@
153153
'src/node_wasi.cc',
154154
'src/node_wasm_web_api.cc',
155155
'src/node_watchdog.cc',
156-
'src/node_webstorage.cc',
157156
'src/node_worker.cc',
158157
'src/node_zlib.cc',
159158
'src/path.cc',
@@ -273,7 +272,6 @@
273272
'src/node_snapshot_builder.h',
274273
'src/node_sockaddr.h',
275274
'src/node_sockaddr-inl.h',
276-
'src/node_sqlite.h',
277275
'src/node_stat_watcher.h',
278276
'src/node_union_bytes.h',
279277
'src/node_url.h',
@@ -282,7 +280,6 @@
282280
'src/node_v8_platform-inl.h',
283281
'src/node_wasi.h',
284282
'src/node_watchdog.h',
285-
'src/node_webstorage.h',
286283
'src/node_worker.h',
287284
'src/path.h',
288285
'src/permission/child_process_permission.h',
@@ -415,6 +412,12 @@
415412
'test/cctest/test_inspector_socket.cc',
416413
'test/cctest/test_inspector_socket_server.cc',
417414
],
415+
'node_sqlite_sources': [
416+
'src/node_sqlite.cc',
417+
'src/node_webstorage.cc',
418+
'src/node_sqlite.h',
419+
'src/node_webstorage.h',
420+
],
418421
'node_mksnapshot_exec': '<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)node_mksnapshot<(EXECUTABLE_SUFFIX)',
419422
'node_js2c_exec': '<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)node_js2c<(EXECUTABLE_SUFFIX)',
420423
'conditions': [
@@ -899,6 +902,12 @@
899902
'src/node_snapshot_stub.cc',
900903
]
901904
}],
905+
[ 'node_use_sqlite=="true"', {
906+
'sources': [
907+
'<@(node_sqlite_sources)',
908+
],
909+
'defines': [ 'HAVE_SQLITE=1' ],
910+
}],
902911
[ 'node_shared=="true" and node_module_version!="" and OS!="win"', {
903912
'product_extension': '<(shlib_suffix)',
904913
'xcode_settings': {
@@ -943,6 +952,12 @@
943952
'deps/ncrypto/ncrypto.gyp:ncrypto',
944953
],
945954
}],
955+
[ 'node_use_sqlite=="true"', {
956+
'sources': [
957+
'<@(node_sqlite_sources)',
958+
],
959+
'defines': [ 'HAVE_SQLITE=1' ],
960+
}],
946961
[ 'OS in "linux freebsd mac solaris" and '
947962
'target_arch=="x64" and '
948963
'node_target_type=="executable"', {

node.gypi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@
236236
'dependencies': [ 'deps/brotli/brotli.gyp:brotli' ],
237237
}],
238238

239-
[ 'node_shared_sqlite=="false"', {
239+
[ 'node_use_sqlite=="true" and node_shared_sqlite=="false"', {
240240
'dependencies': [ 'deps/sqlite/sqlite.gyp:sqlite' ],
241241
}],
242242

src/node_binding.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@
7474
V(serdes) \
7575
V(signal_wrap) \
7676
V(spawn_sync) \
77-
V(sqlite) \
7877
V(stream_pipe) \
7978
V(stream_wrap) \
8079
V(string_decoder) \
@@ -93,7 +92,6 @@
9392
V(wasi) \
9493
V(wasm_web_api) \
9594
V(watchdog) \
96-
V(webstorage) \
9795
V(worker) \
9896
V(zlib)
9997

@@ -103,7 +101,8 @@
103101
NODE_BUILTIN_ICU_BINDINGS(V) \
104102
NODE_BUILTIN_PROFILER_BINDINGS(V) \
105103
NODE_BUILTIN_DEBUG_BINDINGS(V) \
106-
NODE_BUILTIN_QUIC_BINDINGS(V)
104+
NODE_BUILTIN_QUIC_BINDINGS(V) \
105+
NODE_BUILTIN_SQLITE_BINDINGS(V)
107106

108107
// This is used to load built-in bindings. Instead of using
109108
// __attribute__((constructor)), we call the _register_<modname>

src/node_binding.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ static_assert(static_cast<int>(NM_F_LINKED) ==
3636
#define NODE_BUILTIN_QUIC_BINDINGS(V)
3737
#endif
3838

39+
#if HAVE_SQLITE
40+
#define NODE_BUILTIN_SQLITE_BINDINGS(V) \
41+
V(sqlite) \
42+
V(webstorage)
43+
#else
44+
#define NODE_BUILTIN_SQLITE_BINDINGS(V)
45+
#endif
46+
3947
#define NODE_BINDINGS_WITH_PER_ISOLATE_INIT(V) \
4048
V(async_wrap) \
4149
V(blob) \

src/node_builtins.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ BuiltinLoader::BuiltinCategories BuiltinLoader::GetBuiltinCategories() const {
145145
"sqlite", // Experimental.
146146
"sys", // Deprecated.
147147
"wasi", // Experimental.
148+
#if !HAVE_SQLITE
149+
"internal/webstorage", // Experimental.
150+
#endif
148151
"internal/test/binding", "internal/v8_prof_polyfill",
149152
"internal/v8_prof_processor",
150153
};

src/node_metadata.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
#include "node.h"
1212
#include "simdjson.h"
1313
#include "simdutf.h"
14+
#if HAVE_SQLITE
1415
#include "sqlite3.h"
16+
#endif // HAVE_SQLITE
1517
#include "undici_version.h"
1618
#include "util.h"
1719
#include "uv.h"
@@ -152,7 +154,9 @@ Metadata::Versions::Versions() {
152154

153155
simdjson = SIMDJSON_VERSION;
154156
simdutf = SIMDUTF_VERSION;
157+
#if HAVE_SQLITE
155158
sqlite = SQLITE_VERSION;
159+
#endif // HAVE_SQLITE
156160
ada = ADA_VERSION;
157161
nbytes = NBYTES_VERSION;
158162
}

src/node_metadata.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ namespace node {
5555
V(acorn) \
5656
V(simdjson) \
5757
V(simdutf) \
58-
V(sqlite) \
5958
V(ada) \
6059
V(nbytes) \
6160
NODE_VERSIONS_KEY_AMARO(V) \
@@ -86,11 +85,18 @@ namespace node {
8685
#define NODE_VERSIONS_KEY_QUIC(V)
8786
#endif
8887

88+
#if HAVE_SQLITE
89+
#define NODE_VERSIONS_KEY_SQLITE(V) V(sqlite)
90+
#else
91+
#define NODE_VERSIONS_KEY_SQLITE(V)
92+
#endif
93+
8994
#define NODE_VERSIONS_KEYS(V) \
9095
NODE_VERSIONS_KEYS_BASE(V) \
9196
NODE_VERSIONS_KEY_CRYPTO(V) \
9297
NODE_VERSIONS_KEY_INTL(V) \
93-
NODE_VERSIONS_KEY_QUIC(V)
98+
NODE_VERSIONS_KEY_QUIC(V) \
99+
NODE_VERSIONS_KEY_SQLITE(V)
94100

95101
class Metadata {
96102
public:

test/common/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,12 @@ Indicates if [internationalization][] is supported.
257257

258258
Indicates whether `IPv6` is supported on this platform.
259259

260+
### `hasSQLite`
261+
262+
* [\<boolean>][<boolean>]
263+
264+
Indicates whether SQLite is available.
265+
260266
### `inFreeBSDJail`
261267

262268
* [\<boolean>][<boolean>]
@@ -481,6 +487,11 @@ at `tools/eslint/node_modules/eslint`
481487
Skip the rest of the tests in the current file when the Inspector
482488
was disabled at compile time.
483489

490+
### `skipIfSQLiteMissing()`
491+
492+
Skip the rest of the tests in the current file when the SQLite
493+
was disabled at compile time.
494+
484495
### `skipIf32Bits()`
485496

486497
Skip the rest of the tests in the current file when the Node.js executable

test/common/index.js

100644100755
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ const noop = () => {};
5454
const hasCrypto = Boolean(process.versions.openssl) &&
5555
!process.env.NODE_SKIP_CRYPTO;
5656

57+
const hasSQLite = Boolean(process.versions.sqlite);
58+
5759
const hasQuic = hasCrypto && !!process.config.variables.openssl_quic;
5860

5961
function parseTestFlags(filename = process.argv[1]) {
@@ -682,6 +684,12 @@ function skipIf32Bits() {
682684
}
683685
}
684686

687+
function skipIfSQLiteMissing() {
688+
if (!hasSQLite) {
689+
skip('missing SQLite');
690+
}
691+
}
692+
685693
function getArrayBufferViews(buf) {
686694
const { buffer, byteOffset, byteLength } = buf;
687695

@@ -883,6 +891,7 @@ const common = {
883891
hasIntl,
884892
hasCrypto,
885893
hasQuic,
894+
hasSQLite,
886895
invalidArgTypeHelper,
887896
isAlive,
888897
isASan,
@@ -912,6 +921,7 @@ const common = {
912921
skipIf32Bits,
913922
skipIfEslintMissing,
914923
skipIfInspectorDisabled,
924+
skipIfSQLiteMissing,
915925
spawnPromisified,
916926

917927
get enoughTestMem() {

test/common/index.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const {
1616
getBufferSources,
1717
getTTYfd,
1818
hasCrypto,
19+
hasSQLite,
1920
hasIntl,
2021
hasIPv6,
2122
isAIX,
@@ -44,6 +45,7 @@ const {
4445
skipIf32Bits,
4546
skipIfEslintMissing,
4647
skipIfInspectorDisabled,
48+
skipIfSQLiteMissing,
4749
spawnPromisified,
4850
} = common;
4951

@@ -64,6 +66,7 @@ export {
6466
getPort,
6567
getTTYfd,
6668
hasCrypto,
69+
hasSQLite,
6770
hasIntl,
6871
hasIPv6,
6972
isAIX,
@@ -92,5 +95,6 @@ export {
9295
skipIf32Bits,
9396
skipIfEslintMissing,
9497
skipIfInspectorDisabled,
98+
skipIfSQLiteMissing,
9599
spawnPromisified,
96100
};

test/fixtures/rc/non-readable/node.config.json

100755100644
File mode changed.

test/parallel/test-config-file.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

3-
const { spawnPromisified } = require('../common');
3+
const { spawnPromisified, skipIfSQLiteMissing } = require('../common');
4+
skipIfSQLiteMissing();
45
const fixtures = require('../common/fixtures');
56
const { match, strictEqual } = require('node:assert');
67
const { test } = require('node:test');

test/parallel/test-permission-sqlite-load-extension.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22
const common = require('../common');
3+
common.skipIfSQLiteMissing();
34
const assert = require('node:assert');
45

56
const code = `const sqlite = require('node:sqlite');

test/parallel/test-process-get-builtin.mjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { hasCrypto, hasIntl } from '../common/index.mjs';
1+
import { hasCrypto, hasIntl, hasSQLite } from '../common/index.mjs';
22
import assert from 'node:assert';
33
import { builtinModules } from 'node:module';
44
import { isMainThread } from 'node:worker_threads';
@@ -37,6 +37,10 @@ if (!hasIntl) {
3737
publicBuiltins.delete('trace_events');
3838
}
3939

40+
if (!hasSQLite) {
41+
publicBuiltins.delete('node:sqlite');
42+
}
43+
4044
for (const id of publicBuiltins) {
4145
assert.strictEqual(process.getBuiltinModule(id), require(id));
4246
}

0 commit comments

Comments
 (0)