Skip to content

Commit ccccb33

Browse files
Merge pull request 1Password#187 from darrell-roberts/multiple-target-os-option
Allow multiple target-os
2 parents 980d8d9 + a4e95f4 commit ccccb33

26 files changed

+989
-130
lines changed

Cargo.lock

Lines changed: 54 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ ci = ["github"]
1313
installers = ["shell", "powershell"]
1414
# Target platforms to build apps for (Rust target-triple syntax)
1515
targets = [
16-
"x86_64-unknown-linux-gnu",
17-
"x86_64-apple-darwin",
18-
"x86_64-pc-windows-msvc",
19-
"aarch64-apple-darwin",
16+
"x86_64-unknown-linux-gnu",
17+
"x86_64-apple-darwin",
18+
"x86_64-pc-windows-msvc",
19+
"aarch64-apple-darwin",
2020
]
2121

2222
[profile.test]
@@ -32,3 +32,7 @@ incremental = true
3232
# The profile that 'cargo dist' will build with
3333
[profile.dist]
3434
inherits = "release"
35+
36+
[workspace.dependencies]
37+
log = "0.4"
38+
flexi_logger = "0.28"

cli/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@ rayon = "1.10"
2323
serde = { version = "1", features = ["derive"] }
2424
toml = "0.8"
2525
typeshare-core = { path = "../core", version = "1.10.0-beta.7" }
26+
log.workspace = true
27+
flexi_logger.workspace = true
2628
anyhow = "1"

cli/src/args.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,11 @@ pub(crate) fn build_command() -> Command<'static> {
150150
.min_values(1),
151151
).arg(
152152
Arg::new(ARG_TARGET_OS)
153+
.short('t')
153154
.long("target-os")
154155
.help("Optional restrict to target_os")
155156
.takes_value(true)
157+
.multiple_values(true)
156158
.required(false)
157159
)
158160
}

cli/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub(crate) struct Config {
6565
#[cfg(feature = "go")]
6666
pub go: GoParams,
6767
#[serde(skip)]
68-
pub target_os: Option<String>,
68+
pub target_os: Vec<String>,
6969
}
7070

7171
pub(crate) fn store_config(config: &Config, file_path: Option<&str>) -> anyhow::Result<()> {

cli/src/main.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use args::{
1010
use clap::ArgMatches;
1111
use config::Config;
1212
use ignore::{overrides::OverrideBuilder, types::TypesBuilder, WalkBuilder};
13+
use log::error;
1314
use parse::{all_types, parse_input, parser_inputs};
1415
use rayon::iter::ParallelBridge;
1516
use std::collections::{BTreeMap, HashMap};
@@ -30,6 +31,11 @@ mod parse;
3031
mod writer;
3132

3233
fn main() -> anyhow::Result<()> {
34+
flexi_logger::Logger::try_with_env()
35+
.unwrap()
36+
.start()
37+
.unwrap();
38+
3339
#[allow(unused_mut)]
3440
let mut command = build_command();
3541

@@ -122,7 +128,7 @@ fn main() -> anyhow::Result<()> {
122128
parser_inputs(walker_builder, language_type, multi_file).par_bridge(),
123129
&ignored_types,
124130
multi_file,
125-
target_os,
131+
&target_os,
126132
)?;
127133

128134
// Collect all the types into a map of the file name they
@@ -220,7 +226,10 @@ fn override_configuration(mut config: Config, options: &ArgMatches) -> Config {
220226
config.go.package = go_package.to_string();
221227
}
222228

223-
config.target_os = options.value_of(ARG_TARGET_OS).map(|s| s.to_string());
229+
config.target_os = options
230+
.get_many::<String>(ARG_TARGET_OS)
231+
.map(|arg| arg.into_iter().map(ToString::to_string).collect::<Vec<_>>())
232+
.unwrap_or_default();
224233
config
225234
}
226235

@@ -233,7 +242,7 @@ fn check_parse_errors(parsed_crates: &BTreeMap<CrateName, ParsedData>) -> anyhow
233242
{
234243
errors_encountered = true;
235244
for error in &data.errors {
236-
eprintln!(
245+
error!(
237246
"Parsing error: \"{}\" in crate \"{}\" for file \"{}\"",
238247
error.error, error.crate_name, error.file_name
239248
);

cli/src/parse.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub fn parse_input(
9191
inputs: impl ParallelIterator<Item = ParserInput>,
9292
ignored_types: &[&str],
9393
multi_file: bool,
94-
target_os: Option<String>,
94+
target_os: &[String],
9595
) -> anyhow::Result<BTreeMap<CrateName, ParsedData>> {
9696
inputs
9797
.into_par_iter()
@@ -111,7 +111,7 @@ pub fn parse_input(
111111
file_path,
112112
ignored_types,
113113
multi_file,
114-
target_os.clone(),
114+
target_os,
115115
)
116116
.with_context(|| format!("Failed to parse: {file_name}"))?;
117117

cli/src/writer.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
use crate::args::{ARG_OUTPUT_FILE, ARG_OUTPUT_FOLDER};
33
use anyhow::Context;
44
use clap::ArgMatches;
5+
use log::info;
56
use std::{
67
collections::{BTreeMap, HashMap},
78
fs,
@@ -58,7 +59,7 @@ fn check_write_file(outfile: &PathBuf, output: Vec<u8>) -> anyhow::Result<()> {
5859
// avoid writing the file to leave the mtime intact
5960
// for tools which might use it to know when to
6061
// rebuild.
61-
println!("Skipping writing to {outfile:?} no changes");
62+
info!("Skipping writing to {outfile:?} no changes");
6263
return Ok(());
6364
}
6465
_ => {}

core/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ thiserror = "1"
1414
itertools = "0.12"
1515
lazy_format = "2"
1616
joinery = "2"
17+
log.workspace = true
18+
flexi_logger.workspace = true
1719

1820
[dev-dependencies]
19-
anyhow = "1"
2021
expect-test = "1.5"
2122
once_cell = "1"
2223
cool_asserts = "2"
2324
syn = { version = "2", features = ["full", "visit", "extra-traits"] }
25+
anyhow = "1"

core/data/tests/excluded_by_target_os/input.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use std::collection::HashMap;
55

66
#[typeshare]
7+
#[serde(tag = "type", content = "content")]
78
pub enum TestEnum {
89
Variant1,
910
#[cfg(target_os = "ios")]
@@ -14,6 +15,17 @@ pub enum TestEnum {
1415
Variant4,
1516
#[cfg(target_os = "android")]
1617
Variant5,
18+
#[cfg(target_os = "macos")]
19+
Variant7 {
20+
field1: String,
21+
},
22+
#[cfg(any(target_os = "android", target_os = "ios"))]
23+
Variant8,
24+
Variant9 {
25+
#[cfg(not(target_os = "macos"))]
26+
field1: String,
27+
field2: String,
28+
},
1729
}
1830

1931
#[typeshare]
@@ -32,3 +44,39 @@ pub enum Test {}
3244
#[cfg(feature = "super")]
3345
#[cfg(target_os = "android")]
3446
pub enum SomeEnum {}
47+
48+
#[typeshare]
49+
#[cfg(any(target_os = "ios", target_os = "android"))]
50+
pub struct ManyStruct;
51+
52+
#[typeshare]
53+
#[cfg(any(target_os = "android", target_os = "ios"))]
54+
pub struct MultipleTargets;
55+
56+
#[typeshare]
57+
#[cfg(not(any(target_os = "android", target_os = "ios")))]
58+
pub struct DefinedTwice {
59+
field1: u64,
60+
}
61+
62+
#[typeshare]
63+
#[cfg(any(target_os = "android", target_os = "ios"))]
64+
pub struct DefinedTwice {
65+
field1: String,
66+
}
67+
68+
#[typeshare]
69+
#[cfg(not(any(target_os = "wasm32", target_os = "ios")))]
70+
pub struct Excluded;
71+
72+
#[typeshare]
73+
#[cfg(not(target_os = "wasm32"))]
74+
pub struct OtherExcluded;
75+
76+
#[typeshare]
77+
#[cfg(not(target_os = "android"))]
78+
pub struct AndroidExcluded;
79+
80+
#[typeshare]
81+
#[cfg(all(feature = "my-feature", not(target_os = "ios")))]
82+
pub struct NestedNotTarget1;

0 commit comments

Comments
 (0)