Skip to content

Commit dc5babf

Browse files
committed
Compile for apple targets
1 parent d38e297 commit dc5babf

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

.github/workflows/compile_sqlite.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
# We only really need this for Ubuntu, but we recommend users run the same
4646
# steps so we better make sure they work on all platforms.
4747
#os: [ubuntu-latest, macos-latest, windows-latest]
48-
os: [ubuntu-latest]
48+
os: [ubuntu-latest, macos-latest]
4949

5050
runs-on: ${{ matrix.os }}
5151
name: Compile sqlite3
@@ -73,7 +73,6 @@ jobs:
7373
run: |
7474
sudo apt install -y gcc-aarch64-linux-gnu gcc-riscv64-linux-gnu gcc-arm-linux-gnueabihf gcc-i686-linux-gnu
7575
76-
7776
- name: Compile sqlite3
7877
# if: steps.cache_build.outputs.cache-hit != 'true'
7978
run: |

tool/compile_sqlite.dart

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ void main() async {
1616
for (final sqlite3mc in [false, true])
1717
_compileLinux(compiler, abi, sqlite3mc)
1818
], eagerError: true);
19+
} else if (Platform.isMacOS) {
20+
await Future.wait([
21+
for (final (triple, name) in _appleAbis)
22+
for (final sqlite3mc in [false, true])
23+
_compileApple(triple, name, sqlite3mc)
24+
], eagerError: true);
1925
}
2026
}
2127

@@ -48,6 +54,31 @@ Future<void> _compileLinux(
4854
}
4955
}
5056

57+
Future<void> _compileApple(
58+
String triple, String prefix, bool sqlite3Ciphers) async {
59+
final args = [
60+
'-target',
61+
triple,
62+
'-shared',
63+
'-O3',
64+
...defines,
65+
sqlite3Ciphers
66+
? 'sqlite3-src/sqlite3mc/sqlite3mc_amalgamation.c'
67+
: 'sqlite3-src/sqlite3/sqlite3.c',
68+
'-I',
69+
sqlite3Ciphers ? 'sqlite3-src/sqlite3mc/' : 'sqlite3-src/sqlite3',
70+
'-o',
71+
'out/$prefix-sqlite3${sqlite3Ciphers ? 'mc' : ''}.dylib',
72+
];
73+
74+
print('Running clang ${args.join(' ')}');
75+
final result = await Process.run('clang', args);
76+
77+
if (result.exitCode != 0) {
78+
throw 'Compiling for $triple (ciphers: $sqlite3Ciphers) failed: ${result.stdout}\n ${result.stderr}';
79+
}
80+
}
81+
5182
const _linuxAbis = [
5283
('x86_64-linux-gnu-gcc', 'x64'),
5384
('i686-linux-gnu-gcc', 'x86'),
@@ -56,6 +87,14 @@ const _linuxAbis = [
5687
('riscv64-linux-gnu-gcc', 'riscv64gc'),
5788
];
5889

90+
const _appleAbis = [
91+
('aarch64-apple-macos', 'macos-aarch64'),
92+
('x86_64-apple-macos', 'macos-x64'),
93+
('x86_64-apple-ios13.0-simulator', 'ios-sim-x64'),
94+
('arm64-apple-ios13.0-simulator', 'ios-sim-aarch64'),
95+
('arm64-apple-ios13.0', 'ios-aarch64'),
96+
];
97+
5998
// Keep in sync with sqlite3/lib/src/hook/description.dart
6099
const _defaultDefines = '''
61100
SQLITE_ENABLE_DBSTAT_VTAB

tool/download_sqlite.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ const sqliteMultipleCiphersSource =
77

88
const tmpDir = 'tmp';
99

10+
/// This runs as part of a GitHub actions workflow in this repository. It's not
11+
/// really supposed to be used outside of that.
1012
void main(List<String> args) async {
1113
await Directory(tmpDir).create();
1214

0 commit comments

Comments
 (0)