Skip to content

sqlite: add build option to build without sqlite #58122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -509,16 +509,24 @@ SQLITE_BINDING_SOURCES := \
$(wildcard test/sqlite/*/*.c)

# Implicitly depends on $(NODE_EXE), see the build-sqlite-tests rule for rationale.
ifndef NOSQLITE
test/sqlite/.buildstamp: $(ADDONS_PREREQS) \
$(SQLITE_BINDING_GYPS) $(SQLITE_BINDING_SOURCES)
@$(call run_build_addons,"$$PWD/test/sqlite",$@)
else
test/sqlite/.buildstamp:
endif

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

.PHONY: clear-stalled
clear-stalled: ## Clear any stalled processes.
Expand Down
18 changes: 17 additions & 1 deletion configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,12 @@
default=None,
help='build without NODE_OPTIONS support')

parser.add_argument('--without-sqlite',
action='store_true',
dest='without_sqlite',
default=None,
help='build without SQLite (disables SQLite and Web Stoage API)')

parser.add_argument('--ninja',
action='store_true',
dest='use_ninja',
Expand Down Expand Up @@ -1823,6 +1829,16 @@ def without_ssl_error(option):

configure_library('openssl', o)

def configure_sqlite(o):
o['variables']['node_use_sqlite'] = b(not options.without_sqlite)
if options.without_sqlite:
def without_sqlite_error(option):
error(f'--without-sqlite is incompatible with {option}')
if options.shared_sqlite:
without_sqlite_error('--shared-sqlite')
return

configure_library('sqlite', o, pkgname='sqlite3')

def configure_static(o):
if options.fully_static or options.partly_static:
Expand Down Expand Up @@ -2266,7 +2282,7 @@ def make_bin_override():
configure_library('nghttp2', output, pkgname='libnghttp2')
configure_library('nghttp3', output, pkgname='libnghttp3')
configure_library('ngtcp2', output, pkgname='libngtcp2')
configure_library('sqlite', output, pkgname='sqlite3')
configure_sqlite(output);
configure_library('uvwasi', output, pkgname='libuvwasi')
configure_library('zstd', output, pkgname='libzstd')
configure_v8(output, configurations)
Expand Down
23 changes: 19 additions & 4 deletions node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
'node_shared_uvwasi%': 'false',
'node_shared_nghttp2%': 'false',
'node_use_openssl%': 'true',
'node_use_sqlite%': 'true',
'node_shared_openssl%': 'false',
'node_v8_options%': '',
'node_enable_v8_vtunejit%': 'false',
Expand Down Expand Up @@ -140,7 +141,6 @@
'src/node_shadow_realm.cc',
'src/node_snapshotable.cc',
'src/node_sockaddr.cc',
'src/node_sqlite.cc',
'src/node_stat_watcher.cc',
'src/node_symbols.cc',
'src/node_task_queue.cc',
Expand All @@ -154,7 +154,6 @@
'src/node_wasi.cc',
'src/node_wasm_web_api.cc',
'src/node_watchdog.cc',
'src/node_webstorage.cc',
'src/node_worker.cc',
'src/node_zlib.cc',
'src/path.cc',
Expand Down Expand Up @@ -275,7 +274,6 @@
'src/node_snapshot_builder.h',
'src/node_sockaddr.h',
'src/node_sockaddr-inl.h',
'src/node_sqlite.h',
'src/node_stat_watcher.h',
'src/node_union_bytes.h',
'src/node_url.h',
Expand All @@ -285,7 +283,6 @@
'src/node_v8_platform-inl.h',
'src/node_wasi.h',
'src/node_watchdog.h',
'src/node_webstorage.h',
'src/node_worker.h',
'src/path.h',
'src/permission/child_process_permission.h',
Expand Down Expand Up @@ -418,6 +415,12 @@
'test/cctest/test_inspector_socket.cc',
'test/cctest/test_inspector_socket_server.cc',
],
'node_sqlite_sources': [
'src/node_sqlite.cc',
'src/node_webstorage.cc',
'src/node_sqlite.h',
'src/node_webstorage.h',
],
'node_mksnapshot_exec': '<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)node_mksnapshot<(EXECUTABLE_SUFFIX)',
'node_js2c_exec': '<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)node_js2c<(EXECUTABLE_SUFFIX)',
'conditions': [
Expand Down Expand Up @@ -892,6 +895,12 @@
'src/node_snapshot_stub.cc',
]
}],
[ 'node_use_sqlite=="true"', {
'sources': [
'<@(node_sqlite_sources)',
],
'defines': [ 'HAVE_SQLITE=1' ],
}],
[ 'node_shared=="true" and node_module_version!="" and OS!="win"', {
'product_extension': '<(shlib_suffix)',
'xcode_settings': {
Expand Down Expand Up @@ -940,6 +949,12 @@
'<@(node_quic_sources)',
],
}],
[ 'node_use_sqlite=="true"', {
'sources': [
'<@(node_sqlite_sources)',
],
'defines': [ 'HAVE_SQLITE=1' ],
}],
[ 'OS in "linux freebsd mac solaris" and '
'target_arch=="x64" and '
'node_target_type=="executable"', {
Expand Down
2 changes: 1 addition & 1 deletion node.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@
'dependencies': [ 'deps/brotli/brotli.gyp:brotli' ],
}],

[ 'node_shared_sqlite=="false"', {
[ 'node_use_sqlite=="true" and node_shared_sqlite=="false"', {
'dependencies': [ 'deps/sqlite/sqlite.gyp:sqlite' ],
}],

Expand Down
5 changes: 2 additions & 3 deletions src/node_binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
V(serdes) \
V(signal_wrap) \
V(spawn_sync) \
V(sqlite) \
V(stream_pipe) \
V(stream_wrap) \
V(string_decoder) \
Expand All @@ -95,7 +94,6 @@
V(wasi) \
V(wasm_web_api) \
V(watchdog) \
V(webstorage) \
V(worker) \
V(zlib)

Expand All @@ -105,7 +103,8 @@
NODE_BUILTIN_ICU_BINDINGS(V) \
NODE_BUILTIN_PROFILER_BINDINGS(V) \
NODE_BUILTIN_DEBUG_BINDINGS(V) \
NODE_BUILTIN_QUIC_BINDINGS(V)
NODE_BUILTIN_QUIC_BINDINGS(V) \
NODE_BUILTIN_SQLITE_BINDINGS(V)

// This is used to load built-in bindings. Instead of using
// __attribute__((constructor)), we call the _register_<modname>
Expand Down
8 changes: 8 additions & 0 deletions src/node_binding.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ static_assert(static_cast<int>(NM_F_LINKED) ==
#define NODE_BUILTIN_QUIC_BINDINGS(V)
#endif

#if HAVE_SQLITE
#define NODE_BUILTIN_SQLITE_BINDINGS(V) \
V(sqlite) \
V(webstorage)
#else
#define NODE_BUILTIN_SQLITE_BINDINGS(V)
#endif

#define NODE_BINDINGS_WITH_PER_ISOLATE_INIT(V) \
V(async_wrap) \
V(blob) \
Expand Down
7 changes: 5 additions & 2 deletions src/node_builtins.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ BuiltinLoader::BuiltinCategories BuiltinLoader::GetBuiltinCategories() const {
"sqlite", // Experimental.
"sys", // Deprecated.
"wasi", // Experimental.
#if !HAVE_SQLITE
"internal/webstorage", // Experimental.
#endif
"internal/test/binding", "internal/v8_prof_polyfill",
"internal/v8_prof_processor",
};
Expand Down Expand Up @@ -686,8 +689,8 @@ void BuiltinLoader::CompileFunction(const FunctionCallbackInfo<Value>& args) {
void BuiltinLoader::HasCachedBuiltins(const FunctionCallbackInfo<Value>& args) {
auto instance = Environment::GetCurrent(args)->builtin_loader();
RwLock::ScopedReadLock lock(instance->code_cache_->mutex);
args.GetReturnValue().Set(Boolean::New(
args.GetIsolate(), instance->code_cache_->has_code_cache));
args.GetReturnValue().Set(
Boolean::New(args.GetIsolate(), instance->code_cache_->has_code_cache));
}

void SetInternalLoaders(const FunctionCallbackInfo<Value>& args) {
Expand Down
4 changes: 4 additions & 0 deletions src/node_metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
#include "node.h"
#include "simdjson.h"
#include "simdutf.h"
#if HAVE_SQLITE
#include "sqlite3.h"
#endif // HAVE_SQLITE
#include "undici_version.h"
#include "util.h"
#include "uv.h"
Expand Down Expand Up @@ -152,7 +154,9 @@ Metadata::Versions::Versions() {

simdjson = SIMDJSON_VERSION;
simdutf = SIMDUTF_VERSION;
#if HAVE_SQLITE
sqlite = SQLITE_VERSION;
#endif // HAVE_SQLITE
ada = ADA_VERSION;
nbytes = NBYTES_VERSION;
}
Expand Down
10 changes: 8 additions & 2 deletions src/node_metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ namespace node {
V(acorn) \
V(simdjson) \
V(simdutf) \
V(sqlite) \
V(ada) \
V(nbytes) \
NODE_VERSIONS_KEY_AMARO(V) \
Expand Down Expand Up @@ -86,11 +85,18 @@ namespace node {
#define NODE_VERSIONS_KEY_QUIC(V)
#endif

#if HAVE_SQLITE
#define NODE_VERSIONS_KEY_SQLITE(V) V(sqlite)
#else
#define NODE_VERSIONS_KEY_SQLITE(V)
#endif

#define NODE_VERSIONS_KEYS(V) \
NODE_VERSIONS_KEYS_BASE(V) \
NODE_VERSIONS_KEY_CRYPTO(V) \
NODE_VERSIONS_KEY_INTL(V) \
NODE_VERSIONS_KEY_QUIC(V)
NODE_VERSIONS_KEY_QUIC(V) \
NODE_VERSIONS_KEY_SQLITE(V)

class Metadata {
public:
Expand Down
11 changes: 11 additions & 0 deletions test/common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,12 @@ Indicates if [internationalization][] is supported.

Indicates whether `IPv6` is supported on this platform.

### `hasSQLite`

* [\<boolean>][<boolean>]

Indicates whether SQLite is available.

### `inFreeBSDJail`

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

### `skipIfSQLiteMissing()`

Skip the rest of the tests in the current file when the SQLite
was disabled at compile time.

### `skipIf32Bits()`

Skip the rest of the tests in the current file when the Node.js executable
Expand Down
10 changes: 10 additions & 0 deletions test/common/index.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ const noop = () => {};
const hasCrypto = Boolean(process.versions.openssl) &&
!process.env.NODE_SKIP_CRYPTO;

const hasSQLite = Boolean(process.versions.sqlite);

const hasQuic = hasCrypto && !!process.config.variables.node_quic;

function parseTestFlags(filename = process.argv[1]) {
Expand Down Expand Up @@ -682,6 +684,12 @@ function skipIf32Bits() {
}
}

function skipIfSQLiteMissing() {
if (!hasSQLite) {
skip('missing SQLite');
}
}

function getArrayBufferViews(buf) {
const { buffer, byteOffset, byteLength } = buf;

Expand Down Expand Up @@ -883,6 +891,7 @@ const common = {
hasIntl,
hasCrypto,
hasQuic,
hasSQLite,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move the declaration here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@anonrig can you clarify what you mean on this one?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of having the variable declaration on top of the file, what about:

Suggested change
hasSQLite,
hasSQLite: Boolean(...),

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is not consistent with how any of the other ones are done as far as I can see. I was just trying to follow what seems to be existing practice.

invalidArgTypeHelper,
isAlive,
isASan,
Expand Down Expand Up @@ -912,6 +921,7 @@ const common = {
skipIf32Bits,
skipIfEslintMissing,
skipIfInspectorDisabled,
skipIfSQLiteMissing,
spawnPromisified,

get enoughTestMem() {
Expand Down
4 changes: 4 additions & 0 deletions test/common/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const {
getBufferSources,
getTTYfd,
hasCrypto,
hasSQLite,
hasIntl,
hasIPv6,
isAIX,
Expand Down Expand Up @@ -44,6 +45,7 @@ const {
skipIf32Bits,
skipIfEslintMissing,
skipIfInspectorDisabled,
skipIfSQLiteMissing,
spawnPromisified,
} = common;

Expand All @@ -64,6 +66,7 @@ export {
getPort,
getTTYfd,
hasCrypto,
hasSQLite,
hasIntl,
hasIPv6,
isAIX,
Expand Down Expand Up @@ -92,5 +95,6 @@ export {
skipIf32Bits,
skipIfEslintMissing,
skipIfInspectorDisabled,
skipIfSQLiteMissing,
spawnPromisified,
};
Empty file modified test/fixtures/rc/non-readable/node.config.json
100755 → 100644
Empty file.
3 changes: 2 additions & 1 deletion test/parallel/test-config-file.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const { spawnPromisified } = require('../common');
const { spawnPromisified, skipIfSQLiteMissing } = require('../common');
skipIfSQLiteMissing();
const fixtures = require('../common/fixtures');
const { match, strictEqual } = require('node:assert');
const { test } = require('node:test');
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-permission-sqlite-load-extension.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';
const common = require('../common');
common.skipIfSQLiteMissing();
const assert = require('node:assert');

const code = `const sqlite = require('node:sqlite');
Expand Down
6 changes: 5 additions & 1 deletion test/parallel/test-process-get-builtin.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { hasCrypto, hasIntl } from '../common/index.mjs';
import { hasCrypto, hasIntl, hasSQLite } from '../common/index.mjs';
import assert from 'node:assert';
import { builtinModules } from 'node:module';
import { isMainThread } from 'node:worker_threads';
Expand Down Expand Up @@ -39,6 +39,10 @@ if (!hasIntl) {
// TODO(@jasnell): Remove this once node:quic graduates from unflagged.
publicBuiltins.delete('node:quic');

if (!hasSQLite) {
publicBuiltins.delete('node:sqlite');
}

for (const id of publicBuiltins) {
assert.strictEqual(process.getBuiltinModule(id), require(id));
}
Expand Down
Loading
Loading