Skip to content

Commit 535c2f7

Browse files
committed
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 1350ade commit 535c2f7

33 files changed

+144
-34
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',
@@ -1816,6 +1822,16 @@ def without_ssl_error(option):
18161822

18171823
configure_library('openssl', o)
18181824

1825+
def configure_sqlite(o):
1826+
o['variables']['node_use_sqlite'] = b(not options.without_sqlite)
1827+
if options.without_sqlite:
1828+
def without_sqlite_error(option):
1829+
error(f'--without-sqlite is incompatible with {option}')
1830+
if options.shared_sqlite:
1831+
without_sqlite_error('--shared-sqlite')
1832+
return
1833+
1834+
configure_library('sqlite', o, pkgname='sqlite3')
18191835

18201836
def configure_static(o):
18211837
if options.fully_static or options.partly_static:
@@ -2259,7 +2275,7 @@ def make_bin_override():
22592275
configure_library('nghttp2', output, pkgname='libnghttp2')
22602276
configure_library('nghttp3', output, pkgname='libnghttp3')
22612277
configure_library('ngtcp2', output, pkgname='libngtcp2')
2262-
configure_library('sqlite', output, pkgname='sqlite3')
2278+
configure_sqlite(output);
22632279
configure_library('uvwasi', output, pkgname='libuvwasi')
22642280
configure_library('zstd', output, pkgname='libzstd')
22652281
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',
@@ -154,7 +154,6 @@
154154
'src/node_wasi.cc',
155155
'src/node_wasm_web_api.cc',
156156
'src/node_watchdog.cc',
157-
'src/node_webstorage.cc',
158157
'src/node_worker.cc',
159158
'src/node_zlib.cc',
160159
'src/path.cc',
@@ -275,7 +274,6 @@
275274
'src/node_snapshot_builder.h',
276275
'src/node_sockaddr.h',
277276
'src/node_sockaddr-inl.h',
278-
'src/node_sqlite.h',
279277
'src/node_stat_watcher.h',
280278
'src/node_union_bytes.h',
281279
'src/node_url.h',
@@ -285,7 +283,6 @@
285283
'src/node_v8_platform-inl.h',
286284
'src/node_wasi.h',
287285
'src/node_watchdog.h',
288-
'src/node_webstorage.h',
289286
'src/node_worker.h',
290287
'src/path.h',
291288
'src/permission/child_process_permission.h',
@@ -418,6 +415,12 @@
418415
'test/cctest/test_inspector_socket.cc',
419416
'test/cctest/test_inspector_socket_server.cc',
420417
],
418+
'node_sqlite_sources': [
419+
'src/node_sqlite.cc',
420+
'src/node_webstorage.cc',
421+
'src/node_sqlite.h',
422+
'src/node_webstorage.h',
423+
],
421424
'node_mksnapshot_exec': '<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)node_mksnapshot<(EXECUTABLE_SUFFIX)',
422425
'node_js2c_exec': '<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)node_js2c<(EXECUTABLE_SUFFIX)',
423426
'conditions': [
@@ -892,6 +895,12 @@
892895
'src/node_snapshot_stub.cc',
893896
]
894897
}],
898+
[ 'node_use_sqlite=="true"', {
899+
'sources': [
900+
'<@(node_sqlite_sources)',
901+
],
902+
'defines': [ 'HAVE_SQLITE=1' ],
903+
}],
895904
[ 'node_shared=="true" and node_module_version!="" and OS!="win"', {
896905
'product_extension': '<(shlib_suffix)',
897906
'xcode_settings': {
@@ -940,6 +949,12 @@
940949
'<@(node_quic_sources)',
941950
],
942951
}],
952+
[ 'node_use_sqlite=="true"', {
953+
'sources': [
954+
'<@(node_sqlite_sources)',
955+
],
956+
'defines': [ 'HAVE_SQLITE=1' ],
957+
}],
943958
[ 'OS in "linux freebsd mac solaris" and '
944959
'target_arch=="x64" and '
945960
'node_target_type=="executable"', {

node.gypi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@
233233
'dependencies': [ 'deps/brotli/brotli.gyp:brotli' ],
234234
}],
235235

236-
[ 'node_shared_sqlite=="false"', {
236+
[ 'node_use_sqlite=="true" and node_shared_sqlite=="false"', {
237237
'dependencies': [ 'deps/sqlite/sqlite.gyp:sqlite' ],
238238
}],
239239

src/node_binding.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@
7575
V(serdes) \
7676
V(signal_wrap) \
7777
V(spawn_sync) \
78-
V(sqlite) \
7978
V(stream_pipe) \
8079
V(stream_wrap) \
8180
V(string_decoder) \
@@ -95,7 +94,6 @@
9594
V(wasi) \
9695
V(wasm_web_api) \
9796
V(watchdog) \
98-
V(webstorage) \
9997
V(worker) \
10098
V(zlib)
10199

@@ -105,7 +103,8 @@
105103
NODE_BUILTIN_ICU_BINDINGS(V) \
106104
NODE_BUILTIN_PROFILER_BINDINGS(V) \
107105
NODE_BUILTIN_DEBUG_BINDINGS(V) \
108-
NODE_BUILTIN_QUIC_BINDINGS(V)
106+
NODE_BUILTIN_QUIC_BINDINGS(V) \
107+
NODE_BUILTIN_SQLITE_BINDINGS(V)
109108

110109
// This is used to load built-in bindings. Instead of using
111110
// __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: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ BuiltinLoader::BuiltinCategories BuiltinLoader::GetBuiltinCategories() const {
139139
"sqlite", // Experimental.
140140
"sys", // Deprecated.
141141
"wasi", // Experimental.
142+
#if !HAVE_SQLITE
143+
"internal/webstorage", // Experimental.
144+
#endif
142145
"internal/test/binding", "internal/v8_prof_polyfill",
143146
"internal/v8_prof_processor",
144147
};
@@ -686,8 +689,8 @@ void BuiltinLoader::CompileFunction(const FunctionCallbackInfo<Value>& args) {
686689
void BuiltinLoader::HasCachedBuiltins(const FunctionCallbackInfo<Value>& args) {
687690
auto instance = Environment::GetCurrent(args)->builtin_loader();
688691
RwLock::ScopedReadLock lock(instance->code_cache_->mutex);
689-
args.GetReturnValue().Set(Boolean::New(
690-
args.GetIsolate(), instance->code_cache_->has_code_cache));
692+
args.GetReturnValue().Set(
693+
Boolean::New(args.GetIsolate(), instance->code_cache_->has_code_cache));
691694
}
692695

693696
void SetInternalLoaders(const FunctionCallbackInfo<Value>& args) {

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.node_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';
@@ -39,6 +39,10 @@ if (!hasIntl) {
3939
// TODO(@jasnell): Remove this once node:quic graduates from unflagged.
4040
publicBuiltins.delete('node:quic');
4141

42+
if (!hasSQLite) {
43+
publicBuiltins.delete('node:sqlite');
44+
}
45+
4246
for (const id of publicBuiltins) {
4347
assert.strictEqual(process.getBuiltinModule(id), require(id));
4448
}

0 commit comments

Comments
 (0)