Skip to content

Commit b368079

Browse files
committed
Remove Cargo.toml-based configuration property handling
1 parent b91ae0d commit b368079

2 files changed

Lines changed: 12 additions & 127 deletions

File tree

src/cli.rs

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ use filetime::FileTime;
2121

2222
use crate::{
2323
cargo::{build_env, clang_target},
24-
meta::{Ndk, Target},
24+
meta::{default_targets, Target},
2525
shell::{Shell, Verbosity},
26+
2627
};
2728

2829
#[derive(Debug, Parser)]
@@ -32,8 +33,8 @@ struct ArgsEnv {
3233
target: Target,
3334

3435
/// platform (also known as API level)
35-
#[arg(long)]
36-
platform: Option<u8>,
36+
#[arg(long, default_value_t = 21)]
37+
platform: u8,
3738

3839
/// use PowerShell syntax
3940
#[arg(long)]
@@ -51,8 +52,8 @@ struct Args {
5152
target: Vec<Target>,
5253

5354
/// platform (also known as API level)
54-
#[arg(long)]
55-
platform: Option<u8>,
55+
#[arg(long, default_value_t = 21)]
56+
platform: u8,
5657

5758
/// output to a jniLibs directory in the correct sub-directories
5859
#[arg(short, long, value_name = "DIR")]
@@ -330,7 +331,7 @@ pub fn run_env(args: Vec<String>) -> anyhow::Result<()> {
330331

331332
let clang_target = clang_target(
332333
args.target.triple(),
333-
args.platform.unwrap_or(Ndk::default().platform),
334+
args.platform,
334335
);
335336

336337
// Try command line, then config. Config falls back to defaults in any case.
@@ -490,18 +491,6 @@ pub fn run(args: Vec<String>) -> anyhow::Result<()> {
490491
std::process::exit(1);
491492
}
492493

493-
let build_mode = if args.contains(&"--release".into()) {
494-
BuildMode::Release
495-
} else if let Some(i) = args.iter().position(|x| x == "--profile") {
496-
args.get(i + 1)
497-
.map(|p| BuildMode::from(p.as_str()))
498-
.unwrap_or(BuildMode::Debug)
499-
} else {
500-
args.iter()
501-
.find_map(|a| a.strip_prefix("--profile=").map(BuildMode::from))
502-
.unwrap_or(BuildMode::Debug)
503-
};
504-
505494
let args = match parse_mixed_args(args) {
506495
Ok(args) => args,
507496
Err(e) => {
@@ -594,15 +583,6 @@ pub fn run(args: Vec<String>) -> anyhow::Result<()> {
594583
})
595584
.unwrap_or_else(|| working_dir.join("Cargo.toml"));
596585

597-
let config = match crate::meta::config(&cargo_manifest, &build_mode) {
598-
Ok(v) => v,
599-
Err(e) => {
600-
shell.error("Failed loading manifest")?;
601-
shell.error(e)?;
602-
std::process::exit(1);
603-
}
604-
};
605-
606586
let cmake_toolchain_path = ndk_home
607587
.join("build")
608588
.join("cmake")
@@ -617,13 +597,13 @@ pub fn run(args: Vec<String>) -> anyhow::Result<()> {
617597
})?;
618598
env::set_var("CARGO_NDK_CMAKE_TOOLCHAIN_PATH", cmake_toolchain_path);
619599

620-
let platform = args.platform.unwrap_or(config.platform);
600+
let platform = args.platform;
621601

622602
// Try command line, then config. Config falls back to defaults in any case.
623603
let targets = if !args.target.is_empty() {
624604
args.target
625605
} else {
626-
config.targets
606+
default_targets().to_vec()
627607
};
628608

629609
if let Some(output_dir) = args.output_dir.as_ref() {

src/meta.rs

Lines changed: 3 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,18 @@
11
use std::fmt::Display;
2-
use std::path::Path;
32
use std::str::FromStr;
43

54
use clap::builder::PossibleValue;
65
use clap::ValueEnum;
76
use serde::Deserialize;
87

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]
4410
}
4511

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)]
7813
pub enum Target {
7914
#[serde(rename = "armeabi-v7a")]
8015
ArmeabiV7a,
81-
#[default]
8216
#[serde(rename = "arm64-v8a")]
8317
Arm64V8a,
8418
#[serde(rename = "x86")]
@@ -143,32 +77,3 @@ impl Target {
14377
}
14478
}
14579
}
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

Comments
 (0)