1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-29 08:01:23 +03:00

Replace use of cpp with the fit-to-purpose c-pp to avoid cpp's C-centric/JS-unfriendly quirks.

FossilOrigin-Name: 49d70f071e918d5d095c807575bb7ce2b287a123261e789e938521b3b409429a
This commit is contained in:
stephan
2022-11-18 02:29:59 +00:00
parent c7c15d1b83
commit ee026c5479
6 changed files with 1573 additions and 48 deletions

View File

@ -235,8 +235,8 @@ $(foreach X,$(SOAP.js) $(sqlite3-worker1.js) $(sqlite3-worker1-promiser.js),\
all: $(sqlite3-api.ext.jses) all: $(sqlite3-api.ext.jses)
sqlite3-api.js := $(dir.tmp)/sqlite3-api.js sqlite3-api.js := $(dir.tmp)/sqlite3-api.js
sqlite3-api.pre-cpp.js := $(dir.tmp)/sqlite3-api.pre-cpp.js sqlite3-api.c-pp.js := $(dir.tmp)/sqlite3-api.c-pp.js
$(sqlite3-api.pre-cpp.js): $(sqlite3-api.jses) $(MAKEFILE) $(sqlite3-api.c-pp.js): $(sqlite3-api.jses) $(MAKEFILE)
@echo "Making $@..." @echo "Making $@..."
@for i in $(sqlite3-api.jses); do \ @for i in $(sqlite3-api.jses); do \
echo "/* BEGIN FILE: $$i */"; \ echo "/* BEGIN FILE: $$i */"; \
@ -257,7 +257,6 @@ $(sqlite3-api-build-version.js): $(bin.version-info) $(MAKEFILE)
######################################################################## ########################################################################
# --post-js and --pre-js are emcc flags we use to append/prepend JS to # --post-js and --pre-js are emcc flags we use to append/prepend JS to
# the generated emscripten module file. # the generated emscripten module file.
pre-js.pre-cpp.js := $(dir.api)/pre-js.pre-cpp.js
pre-js.js := $(dir.tmp)/pre-js.js pre-js.js := $(dir.tmp)/pre-js.js
post-js.js := $(dir.tmp)/post-js.js post-js.js := $(dir.tmp)/post-js.js
post-jses := \ post-jses := \
@ -291,47 +290,47 @@ $(sqlite3-license-version.js): $(sqlite3.h) $(sqlite3-license-version-header.js)
} > $@ } > $@
######################################################################## ########################################################################
# Transform $(1) to $(2) via cpp -E -CC $(1) ... # Transform $(1) to $(2) via ./c-pp -f $(1) ...
# #
# DO NOT use gcc as the preprocessor because it will emit its own # Historical notes:
# license header to our output because that's a comment in its
# stdc-predef.h, which we cannot tell it to _not_ include. The only
# workaround to that is to allow gcc -E to strip all comments. The
# wasm build uses clang behind emcc, anyway, so we already have a
# clang dependency. However, the clang cpp refuses to read empty
# strings in the form '', so we have to be sure to use "" in JS code
# for those.
# #
# It's tempting to build a custom mini-cpp-like binary for this # - We first attempted to use gcc and/or clang to preprocess JS files
# purpose to avoid these dependencies and quirks. Maybe we could use # in the same way we would normally do C files, but C-specific quirks
# lemon to do the heavy lifting for that, noting that we'd still need # of each makes that untennable.
# to tokenize it by hand (but only lines which start with "#" or
# backslash-continued lines, and we could treat all other lines as
# opaque content).
# #
# In this build we may have #ifdef's (and the like) in arbitrary input # - We implemented c-pp.c (the C-Minus Pre-processor) as a custom
# JS files and we need to preprocess those before Emscripten gets # generic/file-format-agnostic preprocessor to enable us to pack
# ahold of them. We cannot simply preprocess the resulting # code for different target builds into the same JS files. Most
# Emscripten-generated sqlite3.js because (A) Emscripten may choke on # notably, some ES6 module (a.k.a. ESM) features cannot legally be
# C preprocessor directives in the input and (B) Emscripten's output # referenced at all in non-ESM code, e.g. the "import" and "export"
# may contain things which cpp cannot read (like single-quoted empty # keywords. This preprocessing step permits us to swap out sections
# strings: ''). # of code where necessary for ESM and non-ESM (a.k.a. vanilla JS)
bin.cpp ?= clang # require different implementations. The alternative to such
ifneq (,$(filter ems,$(MAKECMDGOALS))) # preprocessing, would be to have separate source files for ES6
# builds, which would have a higher maintenance burden than c-pp.c
# seems likely to.
#
# c-pp.c was written specifically for the sqlite project's JavaScript
# builds but is maintained as a standalone project:
# https://fossil.wanderinghorse.net/r/c-pp
bin.c-pp := ./c-pp
$(bin.c-pp): c-pp.c $(sqlite3.c) $(MAKEFILE)
$(CC) -O0 -o $@ c-pp.c $(sqlite3.c) '-DCMPP_DEFAULT_DELIM="//#"' -I$(dir.top)
ifneq (,$(filter esm,$(MAKECMDGOALS)))
js.cpp.defines ?= -DSQLITE_JS_ESM js.cpp.defines ?= -DSQLITE_JS_ESM
ems: $(filter-out ems,$(MAKECMDGOALS)) esm: $(filter-out esm,$(MAKECMDGOALS))
else else
js.cpp.defines ?= js.cpp.defines ?=
endif endif
define CPP_JS define C-PP_JS
# $1 = X.js. $2 = output file to generate by filtering $(1) through # $1 = X.js. $2 = output file to generate by filtering $(1) through
# $(bin.cpp) -E -CC. # $(bin.cpp) -E -CC.
$(2): $(1) $$(MAKEFILE) $(2): $(1) $$(MAKEFILE) $$(bin.c-pp)
$$(bin.cpp) -E -CC -undef $(js.cpp.defines) -x c $(1) | sed -e '/^#/d' > $$@ $$(bin.c-pp) $(js.cpp.defines) -f $(1) -o $$@
CLEAN_FILES += $(2) CLEAN_FILES += $(2)
endef endef
$(eval $(call CPP_JS,$(dir.tmp)/sqlite3-api.pre-cpp.js,$(dir.tmp)/sqlite3-api.js)) $(eval $(call C-PP_JS,$(dir.tmp)/sqlite3-api.c-pp.js,$(dir.tmp)/sqlite3-api.js))
$(eval $(call CPP_JS,$(dir.api)/pre-js.js,$(dir.tmp)/pre-js.js)) $(eval $(call C-PP_JS,$(dir.api)/pre-js.js,$(dir.tmp)/pre-js.js))
# /end CPP-of-JS bits # /end CPP-of-JS bits
######################################################################## ########################################################################

View File

@ -29,9 +29,9 @@ sqlite3InitModuleState.debugModule('self.location =',self.location);
4) If none of the above apply, (prefix+path) is returned. 4) If none of the above apply, (prefix+path) is returned.
*/ */
Module['locateFile'] = function(path, prefix) { Module['locateFile'] = function(path, prefix) {
#ifdef SQLITE_JS_ESM //#if SQLITE_JS_ESM
return new URL(path, import.meta.url).href; return new URL(path, import.meta.url).href;
#else //#else
'use strict'; 'use strict';
let theFile; let theFile;
const up = this.urlParams; const up = this.urlParams;
@ -51,7 +51,7 @@ Module['locateFile'] = function(path, prefix) {
"result =", theFile "result =", theFile
); );
return theFile; return theFile;
#endif /* SQLITE_JS_EMS */ //#endif /* SQLITE_JS_EMS */
}.bind(sqlite3InitModuleState); }.bind(sqlite3InitModuleState);
/** /**

View File

@ -167,11 +167,11 @@ const installOpfsVfs = function callee(options){
return promiseReject_(err); return promiseReject_(err);
}; };
const W = const W =
#ifdef SQLITE_JS_ESM //#if SQLITE_JS_ESM
new Worker(new URL(options.proxyUri, import.meta.url)); new Worker(new URL(options.proxyUri, import.meta.url));
#else //#else
new Worker(options.proxyUri); new Worker(options.proxyUri);
#endif //#endif
W._originalOnError = W.onerror /* will be restored later */; W._originalOnError = W.onerror /* will be restored later */;
W.onerror = function(err){ W.onerror = function(err){
// The error object doesn't contain any useful info when the // The error object doesn't contain any useful info when the

1525
ext/wasm/c-pp.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
C Merge\strunk\sinto\sjs-cpp\sbranch. C Replace\suse\sof\scpp\swith\sthe\sfit-to-purpose\sc-pp\sto\savoid\scpp's\sC-centric/JS-unfriendly\squirks.
D 2022-11-17T15:21:49.967 D 2022-11-18T02:29:59.533
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -488,7 +488,7 @@ F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3
F ext/userauth/user-auth.txt e6641021a9210364665fe625d067617d03f27b04 F ext/userauth/user-auth.txt e6641021a9210364665fe625d067617d03f27b04
F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb F ext/userauth/userauth.c 7f00cded7dcaa5d47f54539b290a43d2e59f4b1eb5f447545fa865f002fc80cb
F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c F ext/wasm/EXPORTED_FUNCTIONS.fiddle.in 27450c8b8c70875a260aca55435ec927068b34cef801a96205adb81bdcefc65c
F ext/wasm/GNUmakefile 5034e5c0ebbf15479887d7253dcb2efb292906fb78d3e69701191c6257c45a9c F ext/wasm/GNUmakefile 3c97824ce76c7678344844e581a07ba75901a06def4d0046a2a410d9dd635a83
F ext/wasm/README-dist.txt 2d670b426fc7c613b90a7d2f2b05b433088fe65181abead970980f0a4a75ea20 F ext/wasm/README-dist.txt 2d670b426fc7c613b90a7d2f2b05b433088fe65181abead970980f0a4a75ea20
F ext/wasm/README.md ef39861aa21632fdbca0bdd469f78f0096f6449a720f3f39642594af503030e9 F ext/wasm/README.md ef39861aa21632fdbca0bdd469f78f0096f6449a720f3f39642594af503030e9
F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-api 9120c2f8f51fa85f46dcf4dcb6b12f4a807d428f6089b99cdb08d8ddfcfd88b2 F ext/wasm/api/EXPORTED_FUNCTIONS.sqlite3-api 9120c2f8f51fa85f46dcf4dcb6b12f4a807d428f6089b99cdb08d8ddfcfd88b2
@ -498,11 +498,11 @@ F ext/wasm/api/extern-post-js.js c197b7567496fc27766842f8c4f4963054bf8c667926ab3
F ext/wasm/api/extern-pre-js.js cc61c09c7a24a07dbecb4c352453c3985170cec12b4e7e7e7a4d11d43c5c8f41 F ext/wasm/api/extern-pre-js.js cc61c09c7a24a07dbecb4c352453c3985170cec12b4e7e7e7a4d11d43c5c8f41
F ext/wasm/api/post-js-footer.js cd0a8ec768501d9bd45d325ab0442037fb0e33d1f3b4f08902f15c34720ee4a1 F ext/wasm/api/post-js-footer.js cd0a8ec768501d9bd45d325ab0442037fb0e33d1f3b4f08902f15c34720ee4a1
F ext/wasm/api/post-js-header.js d6ab3dfef4a06960d28a7eaa338d4e2a1a5981e9b38718168bbde8fdb2a439b8 F ext/wasm/api/post-js-header.js d6ab3dfef4a06960d28a7eaa338d4e2a1a5981e9b38718168bbde8fdb2a439b8
F ext/wasm/api/pre-js.js 9620327120abb15b3af96f72ef9efbcf69e78d90e501328521108b93547a8eb8 F ext/wasm/api/pre-js.js 749bbbac2f1a2192eaba80cf5e00a3219da78b3c0a84e3019b5eef30e0bc9b88
F ext/wasm/api/sqlite3-api-cleanup.js ecdc69dbfccfe26146f04799fcfd4a6f5790d46e7e3b9b6e9b0491f92ed8ae34 F ext/wasm/api/sqlite3-api-cleanup.js ecdc69dbfccfe26146f04799fcfd4a6f5790d46e7e3b9b6e9b0491f92ed8ae34
F ext/wasm/api/sqlite3-api-glue.js 056f44b82c126358a0175e08a892d56fadfce177b0d7a0012502a6acf67ea6d5 F ext/wasm/api/sqlite3-api-glue.js 056f44b82c126358a0175e08a892d56fadfce177b0d7a0012502a6acf67ea6d5
F ext/wasm/api/sqlite3-api-oo1.js e9a83489bbb4838ce0aee46eaaa9350e0e25a5b926b565e4f5ae8e840e4fbaed F ext/wasm/api/sqlite3-api-oo1.js e9a83489bbb4838ce0aee46eaaa9350e0e25a5b926b565e4f5ae8e840e4fbaed
F ext/wasm/api/sqlite3-api-opfs.js 1def5fd676142ebe69594c77c5cf8523be1ca0880846a441bf5f981ff529672b F ext/wasm/api/sqlite3-api-opfs.js 4368a30586df3e11339a72082c77bdef670d619c6185c2dd1ebf5208c3ab0a5c
F ext/wasm/api/sqlite3-api-prologue.js fd526fa017fa2578673ca18158354515c719e719a5d93f2f6d0e43f39170430e F ext/wasm/api/sqlite3-api-prologue.js fd526fa017fa2578673ca18158354515c719e719a5d93f2f6d0e43f39170430e
F ext/wasm/api/sqlite3-api-worker1.js e94ba98e44afccfa482874cd9acb325883ade50ed1f9f9526beb9de1711f182f F ext/wasm/api/sqlite3-api-worker1.js e94ba98e44afccfa482874cd9acb325883ade50ed1f9f9526beb9de1711f182f
F ext/wasm/api/sqlite3-license-version-header.js a661182fc93fc2cf212dfd0b987f8e138a3ac98f850b1112e29b5fbdaecc87c3 F ext/wasm/api/sqlite3-license-version-header.js a661182fc93fc2cf212dfd0b987f8e138a3ac98f850b1112e29b5fbdaecc87c3
@ -513,6 +513,7 @@ F ext/wasm/api/sqlite3-worker1-promiser.js 0c7a9826dbf82a5ed4e4f7bf7816e825a52af
F ext/wasm/api/sqlite3-worker1.js 1e54ea3d540161bcfb2100368a2fc0cad871a207b8336afee1c445715851ec54 F ext/wasm/api/sqlite3-worker1.js 1e54ea3d540161bcfb2100368a2fc0cad871a207b8336afee1c445715851ec54
F ext/wasm/batch-runner.html 4deeed44fe41496dc6898d9fb17938ea3291f40f4bfb977e29d0cef96fbbe4c8 F ext/wasm/batch-runner.html 4deeed44fe41496dc6898d9fb17938ea3291f40f4bfb977e29d0cef96fbbe4c8
F ext/wasm/batch-runner.js 49609e89aaac9989d6c1ad3fae268e4878e1ad7bc5fd3e5c2f44959660780b2e F ext/wasm/batch-runner.js 49609e89aaac9989d6c1ad3fae268e4878e1ad7bc5fd3e5c2f44959660780b2e
F ext/wasm/c-pp.c 92285f7bce67ed7b7020b40fde8ed0982c442b63dc33df9dfd4b658d4a6c0779
F ext/wasm/common/SqliteTestUtil.js d8bf97ecb0705a2299765c8fc9e11b1a5ac7f10988bbf375a6558b7ca287067b F ext/wasm/common/SqliteTestUtil.js d8bf97ecb0705a2299765c8fc9e11b1a5ac7f10988bbf375a6558b7ca287067b
F ext/wasm/common/emscripten.css 3d253a6fdb8983a2ac983855bfbdd4b6fa1ff267c28d69513dd6ef1f289ada3f F ext/wasm/common/emscripten.css 3d253a6fdb8983a2ac983855bfbdd4b6fa1ff267c28d69513dd6ef1f289ada3f
F ext/wasm/common/testing.css 35889709547d89a6109ff83b25c11bbc91d8dd43aab8722e428655ca98880a06 F ext/wasm/common/testing.css 35889709547d89a6109ff83b25c11bbc91d8dd43aab8722e428655ca98880a06
@ -2055,8 +2056,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 718a6d371e61359d73c8f80afdb248e3d9b4d8df4c4e5c122ac884344e31035b 7c572d02e60a83b36543ba4d9d45f61e9fc111b61fee085410c2d87558c732d6 P e047b33d1fb7d6a32e967f03f9952249cd2da4d21dc301fe92bd7baa0da5d6a9
R dcd3d37cda21e5021973ee2a87f95321 R f08c58c3d67343dbb1484f5dc6d0d557
U stephan U stephan
Z 83259d3e3081896d2aa5795af34840f7 Z df00239aed9bf555d5579b7e3a06d443
# Remove this line to create a well-formed Fossil manifest. # Remove this line to create a well-formed Fossil manifest.

View File

@ -1 +1 @@
e047b33d1fb7d6a32e967f03f9952249cd2da4d21dc301fe92bd7baa0da5d6a9 49d70f071e918d5d095c807575bb7ce2b287a123261e789e938521b3b409429a