Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,10 @@ pub enum Environment {
Uclibceabi,
Uclibceabihf,
Sgx,
/// The name Rust triples use for the iOS simulator environment.
Sim,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

target-lexicon used to attempt to support Rust triples, but they turned out to diverge in too many ways, so now target-lexicon is just focusing on LLVM-like triples. So I think this means we should only add the LLVM form of the name, and not the Rust triple form.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idk., I think there is a bit of value in supporting both? But I guess that may be because I want to eventually rename the Rust *-apple-darwin triples to *-apple-macos, and then target-lexicon would be able to parse rustc triples again.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I'd also be fine with just removing (or deprecating) this variant.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've come to understand that Rust target names are not even intended to be parsed. There's nothing in Rust that requires a Rust target name to encode the LLVM target triple or the various target attributes it represents.

With that understanding, users that want to write code that recognizes Rust target names should use something like the platforms crate, and if they want the fields broken out like target-lexicon does, then they should obtain the target triple from the platforms crate and then pass that to target-lexicon.

My preference would be to remove the Rustc forms of the variant.

/// The name Clang/LLVM triples use for the iOS simulator environment.
Simulator,
Softfloat,
Spe,
Threads,
Expand Down Expand Up @@ -911,6 +914,7 @@ impl Environment {
Uclibceabihf => Cow::Borrowed("uclibceabihf"),
Sgx => Cow::Borrowed("sgx"),
Sim => Cow::Borrowed("sim"),
Simulator => Cow::Borrowed("simulator"),
Softfloat => Cow::Borrowed("softfloat"),
Spe => Cow::Borrowed("spe"),
Threads => Cow::Borrowed("threads"),
Expand Down Expand Up @@ -1704,6 +1708,7 @@ impl FromStr for Environment {
"uclibceabihf" => Uclibceabihf,
"sgx" => Sgx,
"sim" => Sim,
"simulator" => Simulator,
"softfloat" => Softfloat,
"spe" => Spe,
"threads" => Threads,
Expand Down Expand Up @@ -2212,4 +2217,22 @@ mod tests {
assert!(Triple::from_str("x86_64-apple-darwin.").is_err());
assert!(Triple::from_str("x86_64-apple-darwin23.0.0.0").is_err());
}

#[test]
fn simulators() {
let s = "aarch64-apple-ios16.1.0-simulator";
let expected = Triple {
architecture: Architecture::Aarch64(Aarch64Architecture::Aarch64),
vendor: Vendor::Apple,
operating_system: OperatingSystem::IOS(Some(DeploymentTarget {
major: 16,
minor: 1,
patch: 0,
})),
environment: Environment::Simulator,
binary_format: BinaryFormat::Macho,
};
assert_eq!(Triple::from_str(s), Ok(expected));
assert_eq!(Triple::from_str(s).unwrap().to_string(), s);
}
}
Loading