-
Notifications
You must be signed in to change notification settings - Fork 9
/
Makefile
275 lines (214 loc) · 8.07 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
COMMIT=$(shell git rev-parse HEAD)
VERSION=$(shell cat VERSION)
DATE=$(shell date +'%FT%TZ%z')
ifeq ($(shell uname -s),Darwin)
CONFIG_DARWIN=y
else
CONFIG_LINUX=y
endif
ifdef CONFIG_DARWIN
LOADABLE_EXTENSION=dylib
endif
ifdef CONFIG_LINUX
LOADABLE_EXTENSION=so
endif
ifdef python
PYTHON=$(python)
else
PYTHON=python3
endif
ifdef IS_MACOS_ARM
RENAME_WHEELS_ARGS=--is-macos-arm
else
RENAME_WHEELS_ARGS=
endif
DEFINE_SQLITE_LINES_DATE=-DSQLITE_LINES_DATE="\"$(DATE)\""
DEFINE_SQLITE_LINES_VERSION=-DSQLITE_LINES_VERSION="\"v$(VERSION)\""
DEFINE_SQLITE_LINES_SOURCE=-DSQLITE_LINES_SOURCE="\"$(COMMIT)\""
DEFINE_SQLITE_LINES=$(DEFINE_SQLITE_LINES_DATE) $(DEFINE_SQLITE_LINES_VERSION) $(DEFINE_SQLITE_LINES_SOURCE)
prefix=dist
TARGET_OBJ=$(prefix)/lines.o
TARGET_CLI=$(prefix)/sqlite-lines
TARGET_LOADABLE=$(prefix)/lines0.$(LOADABLE_EXTENSION)
TARGET_STATIC=$(prefix)/libsqlite_lines0.a
TARGET_H=$(prefix)/sqlite-lines.h
TARGET_WHEELS=$(prefix)/wheels
TARGET_SQLITE3_EXTRA_C=$(prefix)/sqlite3-extra.c
TARGET_SQLITE3=$(prefix)/sqlite3
TARGET_PACKAGE=$(prefix)/package.zip
TARGET_SQLJS_JS=$(prefix)/sqljs.js
TARGET_SQLJS_WASM=$(prefix)/sqljs.wasm
TARGET_SQLJS=$(TARGET_SQLJS_JS) $(TARGET_SQLJS_WASM)
INTERMEDIATE_PYPACKAGE_EXTENSION=python/sqlite_lines/sqlite_lines/lines0.$(LOADABLE_EXTENSION)
$(prefix):
mkdir -p $(prefix)
$(TARGET_WHEELS): $(prefix)
mkdir -p $(TARGET_WHEELS)
all: $(TARGET_PACKAGE) $(TARGET_SQLJS)
clean:
rm dist/*
FORMAT_FILES=sqlite-lines.h sqlite-lines.c cli.c core_init.c
format: $(FORMAT_FILES)
clang-format -i $(FORMAT_FILES)
loadable: $(TARGET_LOADABLE)
static: $(TARGET_STATIC) $(TARGET_H)
cli: $(TARGET_CLI)
sqlite3: $(TARGET_SQLITE3)
sqljs: $(TARGET_SQLJS)
$(TARGET_PACKAGE): $(prefix) $(TARGET_LOADABLE) $(TARGET_OBJ) sqlite-lines.h sqlite-lines.c $(TARGET_SQLITE3) $(TARGET_CLI)
zip --junk-paths $(TARGET_PACKAGE) $(TARGET_LOADABLE) $(TARGET_OBJ) sqlite-lines.h sqlite-lines.c $(TARGET_SQLITE3) $(TARGET_CLI)
$(TARGET_LOADABLE): $(prefix) sqlite-lines.c
gcc -Isqlite \
-fPIC -shared $(CFLAGS) \
$(DEFINE_SQLITE_LINES) \
sqlite-lines.c -o $@
$(TARGET_STATIC): $(prefix) sqlite-lines.c
gcc -Isqlite \
-DSQLITE_CORE -c $(CFLAGS) \
$(DEFINE_SQLITE_LINES) \
sqlite-lines.c -o $(prefix)/lines.o
ar rcs $@ $(prefix)/lines.o
$(TARGET_H): sqlite-lines.h
cp $< $@
$(TARGET_CLI): $(prefix) cli.c sqlite-lines.c $(TARGET_SQLITE3_EXTRA_C) sqlite/shell.c
gcc -O3 \
$(DEFINE_SQLITE_LINES) \
-DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION=1 \
-I./ -Isqlite \
sqlite/sqlite3.c \
cli.c sqlite-lines.c -o $@
$(TARGET_SQLITE3): $(prefix) $(TARGET_SQLITE3_EXTRA_C) sqlite/shell.c sqlite-lines.c
gcc \
$(DEFINE_SQLITE_LINES) \
-DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION=1 \
-DSQLITE_EXTRA_INIT=core_init \
-I./ -I./sqlite $(TARGET_SQLITE3_EXTRA_C) sqlite/shell.c sqlite-lines.c -o $@
$(TARGET_OBJ): $(prefix) sqlite-lines.c sqlite-lines.h
gcc -Isqlite \
-c \
$(DEFINE_SQLITE_LINES) \
sqlite-lines.c -o $@
$(TARGET_SQLITE3_EXTRA_C): sqlite/sqlite3.c core_init.c
cat sqlite/sqlite3.c core_init.c > $@
python: $(TARGET_WHEELS) $(TARGET_LOADABLE) $(TARGET_WHEELS) scripts/rename-wheels.py $(shell find python/sqlite_lines -type f -name '*.py')
cp $(TARGET_LOADABLE) $(INTERMEDIATE_PYPACKAGE_EXTENSION)
rm $(TARGET_WHEELS)/sqlite_lines* || true
pip3 wheel python/sqlite_lines/ -w $(TARGET_WHEELS)
python3 scripts/rename-wheels.py $(TARGET_WHEELS) $(RENAME_WHEELS_ARGS)
echo "✅ generated python wheel"
python-versions: python/version.py.tmpl
VERSION=$(VERSION) envsubst < python/version.py.tmpl > python/sqlite_lines/sqlite_lines/version.py
echo "✅ generated python/sqlite_lines/sqlite_lines/version.py"
VERSION=$(VERSION) envsubst < python/version.py.tmpl > python/datasette_sqlite_lines/datasette_sqlite_lines/version.py
echo "✅ generated python/datasette_sqlite_lines/datasette_sqlite_lines/version.py"
datasette: $(TARGET_WHEELS) $(shell find python/datasette_sqlite_lines -type f -name '*.py')
rm $(TARGET_WHEELS)/datasette* || true
pip3 wheel python/datasette_sqlite_lines/ --no-deps -w $(TARGET_WHEELS)
bindings/sqlite-utils/pyproject.toml: bindings/sqlite-utils/pyproject.toml.tmpl VERSION
VERSION=$(VERSION) envsubst < $< > $@
echo "✅ generated $@"
bindings/sqlite-utils/sqlite_utils_sqlite_lines/version.py: bindings/sqlite-utils/sqlite_utils_sqlite_lines/version.py.tmpl VERSION
VERSION=$(VERSION) envsubst < $< > $@
echo "✅ generated $@"
sqlite-utils: $(TARGET_WHEELS) bindings/sqlite-utils/pyproject.toml bindings/sqlite-utils/sqlite_utils_sqlite_lines/version.py
python3 -m build bindings/sqlite-utils -w -o $(TARGET_WHEELS)
npm: VERSION npm/platform-package.README.md.tmpl npm/platform-package.package.json.tmpl npm/sqlite-lines/package.json.tmpl scripts/npm_generate_platform_packages.sh
scripts/npm_generate_platform_packages.sh
deno: VERSION deno/deno.json.tmpl
scripts/deno_generate_package.sh
bindings/ruby/lib/version.rb: bindings/ruby/lib/version.rb.tmpl VERSION
VERSION=$(VERSION) envsubst < $< > $@
ruby: bindings/ruby/lib/version.rb
version:
make python
make python-versions
make bindings/sqlite-utils/pyproject.toml bindings/sqlite-utils/sqlite_utils_sqlite_lines/version.py
make npm
make deno
make ruby
test_files/big.txt:
seq 1 1000000 > $@
test_files/big-line-line.txt:
dd if=/dev/zero of=$@ bs=1000000 count=1001
test_files: test_files/big.txt test_files/big-line-line.txt
test:
make test-loadable
make test-python
make test-npm
make test-deno
make test-cli
make test-sqlite3
lint: SHELL:=/bin/bash
lint:
diff -u <(cat $(FORMAT_FILES)) <(clang-format $(FORMAT_FILES))
test-loadable: $(TARGET_LOADABLE)
$(PYTHON) tests/test-loadable.py
test-python:
$(PYTHON) tests/test-python.py
test-npm:
node npm/sqlite-lines/test.js
test-deno:
deno task --config deno/deno.json test
test-cli: $(TARGET_CLI)
python3 tests/test-cli.py
test-sqlite3: $(TARGET_SQLITE3)
python3 tests/test-sqlite3.py
test-sqljs: $(TARGET_SQLJS)
python3 -m http.server & open http://localhost:8000/tests/test-sqljs.lines
test-watch:
watchexec -w sqlite-lines.c -w tests/ -w tests/ --clear make test
test-loadable-watch: $(TARGET_LOADABLE)
watchexec -w sqlite-lines.c -w $(TARGET_LOADABLE) -w tests/test-loadable.py --clear -- make test-loadable
test-cli-watch: $(TARGET_CLI) tests/test-cli.py
watchexec -w cli.c -w $(TARGET_CLI) -w tests/test-cli.py --clear -- make test-cli
test-sqlite3-watch: $(TARAGET_SQLITE3)
watchexec -w $(TARAGET_SQLITE3) -w tests/test-sqlite3.py --clear -- make test-sqlite3
publish-release:
./scripts/publish_release.sh
.PHONY: all clean format version publish-release \
python python-versions datasette sqlite-utils npm deno ruby version \
test test-watch test-loadable-watch test-cli-watch test-sqlite3-watch \
test-format test-loadable test-cli test-sqlite3 test-sqljs test-python \
test_files \
loadable cli sqlite3 sqljs
# The below is mostly borrowed from https://github.com/sql-js/sql.js/blob/master/Makefile
# WASM has no (easy) filesystem for the demo, so disable lines_read
SQLJS_CFLAGS = \
-O2 \
-DSQLITE_OMIT_LOAD_EXTENSION \
-DSQLITE_DISABLE_LFS \
-DSQLITE_ENABLE_JSON1 \
-DSQLITE_THREADSAFE=0 \
-DSQLITE_ENABLE_NORMALIZE \
$(DEFINE_SQLITE_LINES) -DSQLITE_LINES_DISABLE_FILESYSTEM \
-DSQLITE_EXTRA_INIT=core_init
SQLJS_EMFLAGS = \
--memory-init-file 0 \
-s RESERVED_FUNCTION_POINTERS=64 \
-s ALLOW_TABLE_GROWTH=1 \
-s EXPORTED_FUNCTIONS=@wasm/exported_functions.json \
-s EXPORTED_RUNTIME_METHODS=@wasm/exported_runtime_methods.json \
-s SINGLE_FILE=0 \
-s NODEJS_CATCH_EXIT=0 \
-s NODEJS_CATCH_REJECTION=0 \
-s LLD_REPORT_UNDEFINED
SQLJS_EMFLAGS_WASM = \
-s WASM=1 \
-s ALLOW_MEMORY_GROWTH=1
SQLJS_EMFLAGS_OPTIMIZED= \
-s INLINING_LIMIT=1 \
-O3 \
-flto \
--closure 1
SQLJS_EMFLAGS_DEBUG = \
-s INLINING_LIMIT=1 \
-s ASSERTIONS=1 \
-O1
$(TARGET_SQLJS): $(prefix) $(shell find wasm/ -type f) sqlite-lines.c $(TARGET_SQLITE3_EXTRA_C)
emcc $(SQLJS_CFLAGS) $(SQLJS_EMFLAGS) $(SQLJS_EMFLAGS_DEBUG) $(SQLJS_EMFLAGS_WASM) \
-I./sqlite -I./ sqlite-lines.c $(TARGET_SQLITE3_EXTRA_C) \
--pre-js wasm/api.js \
-o $(TARGET_SQLJS_JS)
mv $(TARGET_SQLJS_JS) tmp.js
cat wasm/shell-pre.js tmp.js wasm/shell-post.js > $(TARGET_SQLJS_JS)
rm tmp.js