lin
2025-08-20 171e08343a9b6df6c31197f5b4800e8004800f5b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
#pragma once
 
#include <stdlib.h>
 
#include <array>
#include <initializer_list>
#include <optional>
#include <set>
#include <string>
#include <unordered_map>
 
enum class Arch : size_t {
  arm = 0,
  arm64,
  mips,
  mips64,
  x86,
  x86_64,
};
 
std::string to_string(const Arch& arch);
std::optional<Arch> arch_from_string(const std::string& name);
 
template <typename T>
class ArchMapIterator;
 
template <typename T>
class ArchMap {
 public:
  ArchMap() {
  }
 
  ArchMap(std::initializer_list<std::pair<Arch, T>> initializer) {
    for (auto& pair : initializer) {
      this->operator[](pair.first) = pair.second;
    }
  }
 
  T& operator[](Arch arch) {
    return data_[size_t(arch)];
  }
 
  const T& operator[](Arch arch) const {
    return data_[size_t(arch)];
  }
 
  bool operator==(const ArchMap& other) const {
    for (size_t i = 0; i < data_.size(); ++i) {
      if (data_[i] != other.data_[i]) {
        return false;
      }
    }
    return true;
  }
 
  ArchMapIterator<T> begin() const {
    return ArchMapIterator<T>(*this, Arch::arm);
  }
 
  ArchMapIterator<T> end() const {
    return ArchMapIterator<T>(*this, Arch(size_t(Arch::x86_64) + 1));
  }
 
 private:
  std::array<T, size_t(Arch::x86_64) + 1> data_ = {};
};
 
template <typename T>
class ArchMapIterator {
  const ArchMap<T>& map_;
  Arch arch_ = Arch::arm;
 
 public:
  ArchMapIterator() = delete;
 
  ArchMapIterator(const ArchMap<T>& map, Arch arch) : map_(map), arch_(arch) {
  }
 
  bool operator==(const ArchMapIterator<T>& rhs) const {
    return map_ == rhs.map_ && arch_ == rhs.arch_;
  }
 
  bool operator!=(const ArchMapIterator<T>& rhs) const {
    return !(*this == rhs);
  }
 
  ArchMapIterator& operator++() {
    arch_ = Arch(size_t(arch_) + 1);
    return *this;
  }
 
  ArchMapIterator operator++(int) {
    ArchMapIterator result = *this;
    ++*this;
    return result;
  }
 
  std::pair<const Arch&, const T&> operator*() const {
    return std::tie(arch_, map_[arch_]);
  }
 
  std::pair<const Arch&, const T&> operator->() const {
    return std::tie(arch_, map_[arch_]);
  }
};
 
static const std::set<Arch> supported_archs = {
  Arch::arm,
  Arch::arm64,
  Arch::mips,
  Arch::mips64,
  Arch::x86,
  Arch::x86_64,
};
 
static ArchMap<std::string> arch_targets = {
  { Arch::arm, "arm-linux-androideabi" },
  { Arch::arm64, "aarch64-linux-android" },
  { Arch::mips, "mipsel-linux-android" },
  { Arch::mips64, "mips64el-linux-android" },
  { Arch::x86, "i686-linux-android" },
  { Arch::x86_64, "x86_64-linux-android" },
};
 
static const std::set<int> default_levels = { 14, 15, 16, 17, 18, 19, 21, 23, 24, 25, 26, 27, 28, 29 };
 
static const ArchMap<int> arch_min_api = {
  { Arch::arm, 9 },
  { Arch::arm64, 21 },
  { Arch::mips, 9 },
  { Arch::mips64, 21 },
  { Arch::x86, 9 },
  { Arch::x86_64, 21 },
};
 
static const std::unordered_map<std::string, int> api_codename_map{
  {"G", 9},
  {"I", 14},
  {"J", 16},
  {"J-MR1", 17},
  {"J-MR2", 18},
  {"K", 19},
  {"L", 21},
  {"L-MR1", 22},
  {"M", 23},
  {"N", 24},
  {"N-MR1", 25},
  {"O", 26},
  {"O-MR1", 27},
  {"P", 28},
  {"Q", 29},
};