targetTriple function

String? targetTriple(
  1. CodeConfig code
)

The target triple of a code config (the names bb native and the release archives use), or null for a target emon does not ship a library for and an app can build anyway: the Intel iOS simulator (DEVLOG D885: Flutter builds both simulator slices; the Apple-silicon one is what runs on a Mac of this decade). An app built only for it fails at run time, by name.

Implementation

String? targetTriple(CodeConfig code) {
  final arch = code.targetArchitecture;
  String bad() => throw UnsupportedError('emon has no prebuilt library for ${code.targetOS} on $arch');
  switch (code.targetOS) {
    case OS.macOS:
      return switch (arch) {
        Architecture.arm64 => 'aarch64-apple-darwin',
        Architecture.x64 => 'x86_64-apple-darwin',
        _ => bad(),
      };
    case OS.linux:
      return switch (arch) {
        Architecture.x64 => 'x86_64-unknown-linux-gnu',
        Architecture.arm64 => 'aarch64-unknown-linux-gnu',
        _ => bad(),
      };
    case OS.windows:
      return switch (arch) {
        Architecture.x64 => 'x86_64-pc-windows-msvc',
        Architecture.arm64 => 'aarch64-pc-windows-msvc',
        _ => bad(),
      };
    case OS.android:
      final api = code.android.targetNdkApi;
      if (api < 24) throw UnsupportedError('emon needs Android API 24 or newer (targetNdkApi is $api)');
      return switch (arch) {
        Architecture.arm64 => 'aarch64-linux-android',
        Architecture.arm => 'armv7-linux-androideabi',
        Architecture.x64 => 'x86_64-linux-android',
        _ => bad(),
      };
    case OS.iOS:
      final sim = code.iOS.targetSdk == IOSSdk.iPhoneSimulator;
      if (arch == Architecture.arm64) return sim ? 'aarch64-apple-ios-sim' : 'aarch64-apple-ios';
      if (sim && arch == Architecture.x64) return null;
      return bad();
    default:
      return bad();
  }
}