Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce strongly-typed strings, starting with TargetTriple #1474

Merged
merged 5 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ schemars = "0.8.21"
serde_yml = "0.0.10"
spdx = "0.10.6"
base64 = "0.22.1"
lazy_static = "1.4.0"

[workspace.metadata.release]
shared-version = true
Expand Down
1 change: 0 additions & 1 deletion axoproject/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ pub mod generic;
#[cfg(feature = "npm-projects")]
pub mod javascript;
pub mod local_repo;
pub mod platforms;
mod repo;
#[cfg(feature = "cargo-projects")]
pub mod rust;
Expand Down
241 changes: 0 additions & 241 deletions axoproject/src/platforms.rs

This file was deleted.

61 changes: 59 additions & 2 deletions cargo-dist-schema/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,69 @@
//!
//! The root type of the schema is [`DistManifest`][].

pub mod macros;

use std::collections::BTreeMap;

use schemars::JsonSchema;
use semver::Version;
use serde::{Deserialize, Serialize};

declare_strongly_typed_string! {
/// A rust target-triple (e.g. "x86_64-pc-windows-msvc")
pub struct TargetTriple => &TargetTripleRef;
}

impl TargetTripleRef {
/// Returns true if this target triple contains the word "musl"
pub fn is_musl(&self) -> bool {
self.0.contains("musl")
}

/// Returns true if this target triple contains the word "linux"
pub fn is_linux(&self) -> bool {
self.0.contains("linux")
}

/// Returns true if this target triple contains the word "apple"
pub fn is_apple(&self) -> bool {
self.0.contains("apple")
}

/// Returns true if this target triple contains the word "darwin"
pub fn is_darwin(&self) -> bool {
self.0.contains("darwin")
}

/// Returns true if this target triple contains the word "windows"
pub fn is_windows(&self) -> bool {
self.0.contains("windows")
}

/// Returns true if this target triple contains the word "x86_64"
pub fn is_x86_64(&self) -> bool {
self.0.contains("x86_64")
}

/// Returns true if this target triple contains the word "aarch64"
pub fn is_aarch64(&self) -> bool {
self.0.contains("aarch64")
}

//---------------------------
// common combinations

/// Returns true if this target triple contains the string "linux-musl"
pub fn is_linux_musl(&self) -> bool {
self.0.contains("linux-musl")
}

/// Returns true if this target triple contains the string "windows-msvc"
pub fn is_windows_msvc(&self) -> bool {
self.0.contains("windows-msvc")
}
}

/// A local system path on the machine cargo-dist was run.
///
/// This is a String because when deserializing this may be a path format from a different OS!
Expand Down Expand Up @@ -176,7 +233,7 @@ pub struct AssetInfo {
/// * length 0: not a meaningful question, maybe some static file
/// * length 1: typical of binaries
/// * length 2+: some kind of universal binary
pub target_triples: Vec<String>,
pub target_triples: Vec<TargetTriple>,
/// the linkage of this Asset
pub linkage: Option<Linkage>,
}
Expand Down Expand Up @@ -346,7 +403,7 @@ pub struct Artifact {
/// The target triple of the bundle
#[serde(skip_serializing_if = "Vec::is_empty")]
#[serde(default)]
pub target_triples: Vec<String>,
pub target_triples: Vec<TargetTriple>,
/// The location of the artifact on the local system
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
Expand Down
Loading
Loading