Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/tools/ports/sqlite3.py
4130 views
1
# Copyright 2022 The Emscripten Authors. All rights reserved.
2
# Emscripten is available under two separate licenses, the MIT license and the
3
# University of Illinois/NCSA Open Source License. Both these licenses can be
4
# found in the LICENSE file.
5
6
# sqlite amalgamation download URL uses release year and tag
7
# 2022 and (3, 38, 5) -> '/2022/sqlite-amalgamation-3380500.zip'
8
VERSION = (3, 39, 0)
9
VERSION_YEAR = 2022
10
HASH = 'cbaf4adb3e404d9aa403b34f133c5beca5f641ae1e23f84dbb021da1fb9efdc7c56b5922eb533ae5cb6d26410ac60cb3f026085591bc83ebc1c225aed0cf37ca'
11
12
variants = {'sqlite3-mt': {'PTHREADS': 1}}
13
14
15
def needed(settings):
16
return settings.USE_SQLITE3
17
18
19
def get_lib_name(settings):
20
return 'libsqlite3' + ('-mt' if settings.PTHREADS else '') + '.a'
21
22
23
def get(ports, settings, shared):
24
release = f'sqlite-amalgamation-{VERSION[0]}{VERSION[1]:02}{VERSION[2]:02}00'
25
# TODO: Fetch the file from an emscripten-hosted mirror.
26
ports.fetch_project('sqlite3', f'https://www.sqlite.org/{VERSION_YEAR}/{release}.zip', sha512hash=HASH)
27
28
def create(final):
29
source_path = ports.get_dir('sqlite3', release)
30
31
ports.install_headers(source_path)
32
ports.make_pkg_config('sqlite', ','.join(str(v) for v in VERSION), '-sUSE_SQLITE3')
33
34
# flags are based on sqlite-autoconf output.
35
# SQLITE_HAVE_ZLIB is only used by shell.c
36
flags = [
37
'-DSTDC_HEADERS=1',
38
'-DHAVE_SYS_TYPES_H=1',
39
'-DHAVE_SYS_STAT_H=1',
40
'-DHAVE_STDLIB_H=1',
41
'-DHAVE_STRING_H=1',
42
'-DHAVE_MEMORY_H=1',
43
'-DHAVE_STRINGS_H=1',
44
'-DHAVE_INTTYPES_H=1',
45
'-DHAVE_STDINT_H=1',
46
'-DHAVE_UNISTD_H=1',
47
'-DHAVE_FDATASYNC=1',
48
'-DHAVE_USLEEP=1',
49
'-DHAVE_LOCALTIME_R=1',
50
'-DHAVE_GMTIME_R=1',
51
'-DHAVE_DECL_STRERROR_R=1',
52
'-DHAVE_STRERROR_R=1',
53
'-DHAVE_POSIX_FALLOCATE=1',
54
'-DSQLITE_OMIT_LOAD_EXTENSION=1',
55
'-DSQLITE_ENABLE_MATH_FUNCTIONS=1',
56
'-DSQLITE_ENABLE_FTS4=1',
57
'-DSQLITE_ENABLE_FTS5=1',
58
'-DSQLITE_ENABLE_RTREE=1',
59
'-DSQLITE_ENABLE_GEOPOLY=1',
60
'-DSQLITE_OMIT_POPEN=1',
61
]
62
if settings.PTHREADS:
63
flags += [
64
'-pthread',
65
'-DSQLITE_THREADSAFE=1',
66
]
67
else:
68
flags += ['-DSQLITE_THREADSAFE=0']
69
70
ports.build_port(source_path, final, 'sqlite3', flags=flags, exclude_files=['shell.c'])
71
72
return [shared.cache.get_lib(get_lib_name(settings), create, what='port')]
73
74
75
def clear(ports, settings, shared):
76
shared.cache.erase_lib(get_lib_name(settings))
77
78
79
def show():
80
return 'sqlite3 (-sUSE_SQLITE3=1 or --use-port=sqlite3); public domain)'
81
82