Skip to content

Commit 930d414

Browse files
committed
Compile for Android too
1 parent dc5babf commit 930d414

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed

tool/compile_sqlite.dart

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ void main() async {
1818
], eagerError: true);
1919
} else if (Platform.isMacOS) {
2020
await Future.wait([
21-
for (final (triple, name) in _appleAbis)
22-
for (final sqlite3mc in [false, true])
23-
_compileApple(triple, name, sqlite3mc)
21+
for (final sqlite3mc in [false, true]) ...[
22+
for (final (triple, name) in _appleAbis)
23+
_compileApple(triple, name, sqlite3mc),
24+
for (final (triple, name) in _androidAbis)
25+
_compileAndroid(triple, name, sqlite3mc)
26+
]
2427
], eagerError: true);
2528
}
2629
}
@@ -56,9 +59,26 @@ Future<void> _compileLinux(
5659

5760
Future<void> _compileApple(
5861
String triple, String prefix, bool sqlite3Ciphers) async {
62+
await _clangCompile('clang', triple, sqlite3Ciphers,
63+
'$prefix-sqlite3${sqlite3Ciphers ? 'mc' : ''}.dylib');
64+
}
65+
66+
Future<void> _compileAndroid(
67+
String triple, String abiName, bool sqlite3Ciphers) async {
68+
await _clangCompile(
69+
'/Users/simon/Library/Android/sdk/ndk/28.1.13356709/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang-19',
70+
triple,
71+
sqlite3Ciphers,
72+
'android-$abiName-sqlite3${sqlite3Ciphers ? 'mc' : ''}.so',
73+
);
74+
}
75+
76+
Future<void> _clangCompile(String executable, String triple,
77+
bool sqlite3Ciphers, String filename) async {
5978
final args = [
6079
'-target',
6180
triple,
81+
'-fPIC',
6282
'-shared',
6383
'-O3',
6484
...defines,
@@ -68,11 +88,11 @@ Future<void> _compileApple(
6888
'-I',
6989
sqlite3Ciphers ? 'sqlite3-src/sqlite3mc/' : 'sqlite3-src/sqlite3',
7090
'-o',
71-
'out/$prefix-sqlite3${sqlite3Ciphers ? 'mc' : ''}.dylib',
91+
'out/$filename',
7292
];
7393

74-
print('Running clang ${args.join(' ')}');
75-
final result = await Process.run('clang', args);
94+
print('Running $executable ${args.join(' ')}');
95+
final result = await Process.run(executable, args);
7696

7797
if (result.exitCode != 0) {
7898
throw 'Compiling for $triple (ciphers: $sqlite3Ciphers) failed: ${result.stdout}\n ${result.stderr}';
@@ -95,6 +115,13 @@ const _appleAbis = [
95115
('arm64-apple-ios13.0', 'ios-aarch64'),
96116
];
97117

118+
const _androidAbis = [
119+
('armv7a-linux-androideabi24', 'armv7a'),
120+
('aarch64-linux-android24', 'aarch64'),
121+
('i686-linux-android24', 'x86'),
122+
('x86_64-linux-android24', 'x64'),
123+
];
124+
98125
// Keep in sync with sqlite3/lib/src/hook/description.dart
99126
const _defaultDefines = '''
100127
SQLITE_ENABLE_DBSTAT_VTAB

0 commit comments

Comments
 (0)