Skip to content

Commit 468cef9

Browse files
Initial project setup.
0 parents  commit 468cef9

15 files changed

+337
-0
lines changed

.editorconfig

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
insert_final_newline = true
6+
7+
[*.{js,json,.yml}]
8+
charset = utf-8
9+
indent_style = space
10+
indent_size = 2

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/.yarn/** linguist-vendored

.gitignore

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# https://yarnpkg.com/getting-started/qa/#which-files-should-be-gitignored
2+
.yarn/*
3+
!.yarn/patches
4+
!.yarn/releases
5+
!.yarn/plugins
6+
!.yarn/sdks
7+
!.yarn/versions
8+
.pnp.*
9+
10+
/cache
11+
/deps
12+
/dist
13+
/tmp

.yarn/releases/yarn-2.4.1.cjs

+55
Large diffs are not rendered by default.

.yarnrc.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
yarnPath: .yarn/releases/yarn-2.4.1.cjs

ACKNOWLEDGMENTS.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Acknowledgments
2+
This project uses or derives material from the following sources.
3+
4+
## [sqlite-wasm](https://github.com/mandel59/sqlite-wasm)
5+
Copyright 2017 Ryusei Yamaguchi
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy of
8+
this software and associated documentation files (the "Software"), to deal in
9+
the Software without restriction, including without limitation the rights to
10+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11+
the Software, and to permit persons to whom the Software is furnished to do so,
12+
subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in all
15+
copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Makefile

+165
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
# dependencies
2+
3+
SQLITE_AMALGAMATION = sqlite-amalgamation-3330000
4+
SQLITE_AMALGAMATION_ZIP_URL = https://www.sqlite.org/2020/sqlite-amalgamation-3330000.zip
5+
SQLITE_AMALGAMATION_ZIP_SHA1 = 5b0a95fc6090499c0cdf7f15fcec9c132f8e021e
6+
7+
EXTENSION_FUNCTIONS = extension-functions.c
8+
EXTENSION_FUNCTIONS_URL = https://www.sqlite.org/contrib/download/extension-functions.c?get=25
9+
EXTENSION_FUNCTIONS_SHA1 = c68fa706d6d9ff98608044c00212473f9c14892f
10+
11+
# source files
12+
13+
C_FILES = src/vfs.c
14+
JS_FILES = src/vfs.js
15+
16+
EXPORTED_FUNCTIONS = src/exported_functions.json
17+
EXTRA_EXPORTED_RUNTIME_METHODS = src/extra_exported_runtime_methods.json
18+
ASYNCIFY_IMPORTS = src/asyncify_imports.json
19+
20+
# build options
21+
22+
EMCC ?= emcc
23+
24+
25+
CFLAGS = \
26+
-O3 \
27+
-I'deps/$(SQLITE_AMALGAMATION)'
28+
29+
EMFLAGS = \
30+
-s ALLOW_MEMORY_GROWTH=1 \
31+
-s RESERVED_FUNCTION_POINTERS=64 \
32+
-s WASM=1
33+
34+
EMFLAGS_DEBUG = \
35+
-s INLINING_LIMIT=10 \
36+
-O1
37+
38+
EMFLAGS_DIST = \
39+
-s INLINING_LIMIT=50 \
40+
-O3 \
41+
--closure 1
42+
43+
EMFLAGS_INTERFACES = \
44+
-s EXPORTED_FUNCTIONS=@$(EXPORTED_FUNCTIONS) \
45+
-s EXTRA_EXPORTED_RUNTIME_METHODS=@$(EXTRA_EXPORTED_RUNTIME_METHODS)
46+
47+
EMFLAGS_LIBRARIES = \
48+
--js-library src/vfs.js
49+
50+
EMFLAGS_ASYNCIFY = \
51+
-s ASYNCIFY \
52+
-s ASYNCIFY_STACK_SIZE=8192 \
53+
-s ASYNCIFY_IMPORTS=@src/asyncify_imports.json
54+
55+
# https://www.sqlite.org/compile.html
56+
SQLITE_DEFINES = \
57+
-DSQLITE_OMIT_DEPRECATED \
58+
-DSQLITE_OMIT_LOAD_EXTENSION \
59+
-DSQLITE_OMIT_SHARED_CACHE \
60+
-DSQLITE_DISABLE_LFS \
61+
-DSQLITE_THREADSAFE=0 \
62+
-DSQLITE_ENABLE_NORMALIZE
63+
64+
# directories
65+
66+
.PHONY: all
67+
all: dist
68+
69+
.PHONY: clean
70+
clean:
71+
rm -rf dist debug tmp
72+
73+
.PHONY: spotless
74+
spotless:
75+
rm -rf dist debug tmp deps cache
76+
77+
## cache
78+
79+
.PHONY: clean-cache
80+
clean-cache:
81+
rm -rf cache
82+
83+
cache/$(SQLITE_AMALGAMATION).zip:
84+
mkdir -p cache
85+
curl -LsSf '$(SQLITE_AMALGAMATION_ZIP_URL)' -o $@
86+
87+
cache/$(EXTENSION_FUNCTIONS):
88+
mkdir -p cache
89+
curl -LsSf '$(EXTENSION_FUNCTIONS_URL)' -o $@
90+
91+
## deps
92+
93+
.PHONY: clean-deps
94+
clean-deps:
95+
rm -rf deps
96+
97+
.PHONY: deps
98+
deps: deps/$(SQLITE_AMALGAMATION) deps/$(EXTENSION_FUNCTIONS) deps/$(EXPORTED_FUNCTIONS)
99+
100+
deps/$(SQLITE_AMALGAMATION): cache/$(SQLITE_AMALGAMATION).zip
101+
mkdir -p deps
102+
echo '$(SQLITE_AMALGAMATION_ZIP_SHA1)' 'cache/$(SQLITE_AMALGAMATION).zip' | sha1sum -c
103+
rm -rf $@
104+
unzip 'cache/$(SQLITE_AMALGAMATION).zip' -d deps/
105+
touch $@
106+
107+
deps/$(EXTENSION_FUNCTIONS): cache/$(EXTENSION_FUNCTIONS)
108+
mkdir -p deps
109+
echo '$(EXTENSION_FUNCTIONS_SHA1)' 'cache/$(EXTENSION_FUNCTIONS)' | sha1sum -c
110+
cp 'cache/$(EXTENSION_FUNCTIONS)' $@
111+
112+
## tmp
113+
114+
.PHONY: clean-tmp
115+
clean-tmp:
116+
rm -rf tmp
117+
118+
tmp/bc/sqlite3.bc: deps/$(SQLITE_AMALGAMATION)
119+
mkdir -p tmp/bc
120+
$(EMCC) $(CFLAGS) $(SQLITE_DEFINES) 'deps/$(SQLITE_AMALGAMATION)/sqlite3.c' -c -o $@
121+
122+
tmp/bc/extension-functions.bc: deps/$(EXTENSION_FUNCTIONS)
123+
mkdir -p tmp/bc
124+
$(EMCC) $(CFLAGS) $(SQLITE_DEFINES) 'deps/$(EXTENSION_FUNCTIONS)' -c -o $@
125+
126+
tmp/bc/vfs.bc: src/vfs.c
127+
mkdir -p tmp/bc
128+
$(EMCC) $(CFLAGS) $(SQLITE_DEFINES) $^ -c -o $@
129+
130+
## debug
131+
.PHONY: clean-debug
132+
clean-debug:
133+
rm -rf debug
134+
135+
.PHONY: debug
136+
debug: debug/sqlite3.html
137+
138+
debug/sqlite3.mjs: tmp/bc/sqlite3.bc tmp/bc/extension-functions.bc $(EXPORTED_FUNCTIONS) $(EXTRA_EXPORTED_RUNTIME_METHODS)
139+
mkdir -p debug
140+
$(EMCC) $(EMFLAGS) $(EMFLAG_INTERFACES) $(EMFLAGS_DEBUG) \
141+
tmp/bc/sqlite3.bc -o $@
142+
143+
## dist
144+
145+
.PHONY: clean-dist
146+
clean-dist:
147+
rm -rf dist
148+
149+
.PHONY: dist
150+
dist: dist/sqlite3.mjs dist/sqlite3-async.mjs
151+
152+
dist/sqlite3.mjs: tmp/bc/sqlite3.bc tmp/bc/extension-functions.bc tmp/bc/vfs.bc src/vfs.js $(EXPORTED_FUNCTIONS_JSON) $(EXTRA_EXPORTED_RUNTIME_METHODS)
153+
mkdir -p dist
154+
$(EMCC) $(EMFLAGS) $(EMFLAGS_DIST) \
155+
$(EMFLAGS_INTERFACES) \
156+
$(EMFLAGS_LIBRARIES) \
157+
tmp/bc/sqlite3.bc tmp/bc/extension-functions.bc tmp/bc/vfs.bc -o $@
158+
159+
dist/sqlite3-async.mjs: tmp/bc/sqlite3.bc tmp/bc/extension-functions.bc tmp/bc/vfs.bc src/vfs.js $(EXPORTED_FUNCTIONS_JSON) $(EXTRA_EXPORTED_RUNTIME_METHODS) $(ASYNCIFY_IMPORTS)
160+
mkdir -p dist
161+
$(EMCC) $(EMFLAGS) $(EMFLAGS_DIST) \
162+
$(EMFLAGS_INTERFACES) \
163+
$(EMFLAGS_LIBRARIES) \
164+
$(EMFLAGS_ASYNCIFY) \
165+
tmp/bc/sqlite3.bc tmp/bc/extension-functions.bc tmp/bc/vfs.bc -o $@

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# wa-sqlite

package.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "wa-sqlite",
3+
"version": "0.1.0"
4+
}

src/asyncify_imports.json

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[
2+
]

src/exported_functions.json

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
[
2+
"_sqlite3_bind_blob",
3+
"_sqlite3_bind_double",
4+
"_sqlite3_bind_int",
5+
"_sqlite3_bind_parameter_index",
6+
"_sqlite3_bind_text",
7+
"_sqlite3_changes",
8+
"_sqlite3_clear_bindings",
9+
"_sqlite3_close_v2",
10+
"_sqlite3_column_blob",
11+
"_sqlite3_column_bytes",
12+
"_sqlite3_column_count",
13+
"_sqlite3_column_double",
14+
"_sqlite3_column_name",
15+
"_sqlite3_column_text",
16+
"_sqlite3_column_type",
17+
"_sqlite3_create_function_v2",
18+
"_sqlite3_data_count",
19+
"_sqlite3_errmsg",
20+
"_sqlite3_exec",
21+
"_sqlite3_finalize",
22+
"_sqlite3_free",
23+
"_sqlite3_malloc",
24+
"_sqlite3_normalized_sql",
25+
"_sqlite3_open",
26+
"_sqlite3_prepare_v2",
27+
"_sqlite3_result_blob",
28+
"_sqlite3_result_double",
29+
"_sqlite3_result_error",
30+
"_sqlite3_result_int",
31+
"_sqlite3_result_int64",
32+
"_sqlite3_result_null",
33+
"_sqlite3_result_text",
34+
"_sqlite3_sql",
35+
"_sqlite3_step",
36+
"_sqlite3_value_blob",
37+
"_sqlite3_value_bytes",
38+
"_sqlite3_value_double",
39+
"_sqlite3_value_int",
40+
"_sqlite3_value_text",
41+
"_sqlite3_value_type"
42+
]
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[
2+
"ccall",
3+
"cwrap",
4+
"getValue",
5+
"setValue",
6+
"UTF8ToString",
7+
"stringToUTF8",
8+
"lengthBytesUTF8"
9+
]

src/vfs.c

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include <sqlite3.h>

src/vfs.js

Whitespace-only changes.

yarn.lock

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# This file is generated by running "yarn install" inside your project.
2+
# Manual changes might be lost - proceed with caution!
3+
4+
__metadata:
5+
version: 4
6+
7+
"wa-sqlite@workspace:.":
8+
version: 0.0.0-use.local
9+
resolution: "wa-sqlite@workspace:."
10+
languageName: unknown
11+
linkType: soft

0 commit comments

Comments
 (0)