|
1 | 1 | use std::fmt::Display; |
2 | | -use std::path::Path; |
3 | 2 | use std::str::FromStr; |
4 | 3 |
|
5 | 4 | use clap::builder::PossibleValue; |
6 | 5 | use clap::ValueEnum; |
7 | 6 | use serde::Deserialize; |
8 | 7 |
|
9 | | -use crate::cli::BuildMode; |
10 | | - |
11 | | -const fn default_platform() -> u8 { |
12 | | - 21 |
13 | | -} |
14 | | - |
15 | | -fn default_targets() -> Vec<Target> { |
16 | | - vec![Target::ArmeabiV7a, Target::Arm64V8a] |
17 | | -} |
18 | | - |
19 | | -#[derive(Debug, Deserialize)] |
20 | | -struct CargoToml { |
21 | | - package: Option<Package>, |
22 | | -} |
23 | | - |
24 | | -#[derive(Debug, Deserialize)] |
25 | | -struct Package { |
26 | | - metadata: Option<Metadata>, |
27 | | -} |
28 | | - |
29 | | -#[derive(Debug, Deserialize)] |
30 | | -struct Metadata { |
31 | | - ndk: Option<Ndk>, |
32 | | -} |
33 | | - |
34 | | -#[derive(Debug, Deserialize, Clone)] |
35 | | -pub(crate) struct Ndk { |
36 | | - #[serde(default = "default_platform")] |
37 | | - pub platform: u8, |
38 | | - |
39 | | - #[serde(default = "default_targets")] |
40 | | - targets: Vec<Target>, |
41 | | - |
42 | | - release: Option<NdkTarget>, |
43 | | - debug: Option<NdkTarget>, |
| 8 | +pub(crate) fn default_targets() -> &'static [Target] { |
| 9 | + &[Target::ArmeabiV7a, Target::Arm64V8a] |
44 | 10 | } |
45 | 11 |
|
46 | | -impl Default for Ndk { |
47 | | - fn default() -> Self { |
48 | | - Self { |
49 | | - platform: default_platform(), |
50 | | - targets: default_targets(), |
51 | | - release: None, |
52 | | - debug: None, |
53 | | - } |
54 | | - } |
55 | | -} |
56 | | - |
57 | | -#[derive(Debug, Deserialize, Clone)] |
58 | | -struct NdkTarget { |
59 | | - targets: Vec<Target>, |
60 | | -} |
61 | | - |
62 | | -#[derive(Debug)] |
63 | | -pub struct Config { |
64 | | - pub platform: u8, |
65 | | - pub targets: Vec<Target>, |
66 | | -} |
67 | | - |
68 | | -impl Default for Config { |
69 | | - fn default() -> Self { |
70 | | - Self { |
71 | | - platform: Ndk::default().platform, |
72 | | - targets: default_targets(), |
73 | | - } |
74 | | - } |
75 | | -} |
76 | | - |
77 | | -#[derive(Debug, Deserialize, Default, Clone)] |
| 12 | +#[derive(Debug, Deserialize, Copy, Clone)] |
78 | 13 | pub enum Target { |
79 | 14 | #[serde(rename = "armeabi-v7a")] |
80 | 15 | ArmeabiV7a, |
81 | | - #[default] |
82 | 16 | #[serde(rename = "arm64-v8a")] |
83 | 17 | Arm64V8a, |
84 | 18 | #[serde(rename = "x86")] |
@@ -143,32 +77,3 @@ impl Target { |
143 | 77 | } |
144 | 78 | } |
145 | 79 | } |
146 | | - |
147 | | -pub(crate) fn config( |
148 | | - cargo_toml_path: &Path, |
149 | | - build_mode: &BuildMode, |
150 | | -) -> Result<Config, anyhow::Error> { |
151 | | - let toml_string = std::fs::read_to_string(cargo_toml_path)?; |
152 | | - let cargo_toml: CargoToml = toml::from_str(&toml_string)?; |
153 | | - |
154 | | - let package = cargo_toml.package; |
155 | | - |
156 | | - let ndk = package |
157 | | - .as_ref() |
158 | | - .and_then(|x| x.metadata.as_ref()) |
159 | | - .and_then(|x| x.ndk.as_ref()) |
160 | | - .cloned() |
161 | | - .unwrap_or_default(); |
162 | | - let base_targets = ndk.targets; |
163 | | - |
164 | | - let targets = if matches!(build_mode, BuildMode::Release) { |
165 | | - ndk.release.map_or_else(|| base_targets, |x| x.targets) |
166 | | - } else { |
167 | | - ndk.debug.map_or_else(|| base_targets, |x| x.targets) |
168 | | - }; |
169 | | - |
170 | | - Ok(Config { |
171 | | - platform: ndk.platform, |
172 | | - targets, |
173 | | - }) |
174 | | -} |
0 commit comments