Skip to content

Commit 21c2c78

Browse files
committed
Compile for Linux
1 parent f679dc1 commit 21c2c78

File tree

3 files changed

+122
-0
lines changed

3 files changed

+122
-0
lines changed

.github/workflows/compile_sqlite.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,43 @@ jobs:
3737
path: out/
3838
if-no-files-found: error
3939
retention-days: 1
40+
41+
build_sqlite:
42+
strategy:
43+
matrix:
44+
# We only really need this for Ubuntu, but we recommend users run the same
45+
# steps so we better make sure they work on all platforms.
46+
os: [ubuntu-latest, macos-latest, windows-latest]
47+
48+
runs-on: ${{ matrix.os }}
49+
name: Compile sqlite3
50+
steps:
51+
- uses: actions/checkout@v4
52+
# - uses: actions/cache@v4
53+
# id: cache_build
54+
# with:
55+
# path: out/
56+
# key: sqlite-prebuilt-${{ runner.os }}-${{ hashFiles('tool/') }}
57+
58+
- name: Download sqlite3 sources
59+
# if: steps.cache_build.outputs.cache-hit != 'true'
60+
uses: actions/download-artifact@v4
61+
with:
62+
name: sqlite3-src
63+
path: sqlite3-src
64+
65+
- uses: dart-lang/setup-dart@v1
66+
# if: steps.cache_build.outputs.cache-hit != 'true'
67+
68+
- name: Compile sqlite3
69+
# if: steps.cache_build.outputs.cache-hit != 'true'
70+
run: |
71+
dart run tool/compile_sqlite.dart
72+
73+
- name: Upload sqlite3 binaries
74+
uses: actions/upload-artifact@v4
75+
with:
76+
name: sqlite3-libs-${{ runner.os }}
77+
path: out/
78+
if-no-files-found: error
79+
retention-days: 1

sqlite3/lib/src/hook/description.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ extension type const CompilerDefines(Map<String, String?> flags)
185185
}
186186
}
187187

188+
// Keep in sync with tool/compile_sqlite.dart
188189
const _defaultDefines = '''
189190
SQLITE_ENABLE_DBSTAT_VTAB
190191
SQLITE_ENABLE_FTS5

tool/compile_sqlite.dart

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import 'dart:convert';
2+
import 'dart:io';
3+
4+
final defines = const LineSplitter()
5+
.convert(_defaultDefines)
6+
.map((line) => line.trim())
7+
.map((line) => '-D$line')
8+
.toList();
9+
10+
void main() async {
11+
await Directory('out').create();
12+
13+
if (Platform.isLinux) {
14+
await Future.wait([
15+
for (final (compiler, abi) in _linuxAbis)
16+
for (final sqlite3mc in [false, true])
17+
_compileLinux(compiler, abi, sqlite3mc)
18+
], eagerError: true);
19+
}
20+
}
21+
22+
Future<void> _compileLinux(
23+
String compiler, String abi, bool sqlite3Ciphers) async {
24+
final args = [
25+
'-fPIC',
26+
'-shared',
27+
'-O3',
28+
...defines,
29+
sqlite3Ciphers
30+
? 'sqlite3-src/sqlite3mc/sqlite3mc_amalgamation.c'
31+
: 'sqlite3-src/sqlite3/sqlite3.c',
32+
'-I',
33+
sqlite3Ciphers ? 'sqlite3-src/sqlite3mc/' : 'sqlite3-src/sqlite3',
34+
'-o',
35+
'out/linux-$abi-sqlite3${sqlite3Ciphers ? 'mc' : ''}.so',
36+
];
37+
38+
print('Running $compiler ${args.join(' ')}');
39+
final result = await Process.run(compiler, args);
40+
41+
if (result.exitCode != 0) {
42+
throw 'Compiling for $abi (ciphers: $sqlite3Ciphers) failed: ${result.stdout}\n ${result.stderr}';
43+
}
44+
}
45+
46+
const _linuxAbis = [
47+
('x86_64-linux-gnu-gcc', 'x64'),
48+
('i686-linux-gnu-gcc', 'x86'),
49+
('aarch64-linux-gnu-gcc', 'aarch64'),
50+
('arm-linux-gnueabihf-gcc', 'armv7'),
51+
('riscv64-linux-gnu-gcc', 'riscv64gc'),
52+
];
53+
54+
// Keep in sync with sqlite3/lib/src/hook/description.dart
55+
const _defaultDefines = '''
56+
SQLITE_ENABLE_DBSTAT_VTAB
57+
SQLITE_ENABLE_FTS5
58+
SQLITE_ENABLE_RTREE
59+
SQLITE_ENABLE_MATH_FUNCTIONS
60+
SQLITE_DQS=0
61+
SQLITE_DEFAULT_MEMSTATUS=0
62+
SQLITE_TEMP_STORE=2
63+
SQLITE_MAX_EXPR_DEPTH=0
64+
SQLITE_STRICT_SUBTYPE=1
65+
SQLITE_OMIT_AUTHORIZATION
66+
SQLITE_OMIT_DECLTYPE
67+
SQLITE_OMIT_DEPRECATED
68+
SQLITE_OMIT_PROGRESS_CALLBACK
69+
SQLITE_OMIT_SHARED_CACHE
70+
SQLITE_OMIT_TCL_VARIABLE
71+
SQLITE_OMIT_TRACE
72+
SQLITE_USE_ALLOCA
73+
SQLITE_ENABLE_SESSION
74+
SQLITE_ENABLE_PREUPDATE_HOOK
75+
SQLITE_UNTESTABLE
76+
SQLITE_HAVE_ISNAN
77+
SQLITE_HAVE_LOCALTIME_R
78+
SQLITE_HAVE_LOCALTIME_S
79+
SQLITE_HAVE_MALLOC_USABLE_SIZE
80+
SQLITE_HAVE_STRCHRNUL
81+
''';

0 commit comments

Comments
 (0)