Skip to content

Commit 943e73b

Browse files
Introduce strongly-typed strings, starting with TargetTriple
As discussed, for the price of having to think about `TargetTriple` (like `String`) vs `&TargetTripleRef` (like `&str`), we get: * No accidentally passing some other kind of string to a thing expecting a `TargetTriple` * Serialization/deserialization is still transparent, no schema changes or anything * We can add methods to it (like `is_windows()` in this PR - note that I dream of a `ParsedTargetTriple` in a separate PR) * Those methods are the only place where we check properties of the string (before this commit, we have `.contains("windows")` and `.contains("pc-windows")` for example) * We can "find all references" to the type itself ("where do we care about targets?") * We can "find all references" to `TargetTriple::new` ("where do we build targets from strings?") * We can "find all references" to `TargetTripleRef::as_str` ("where do we coerce it back into a string to pass it to a tool like cargo/wix/etc.) That kind of change is invaluable for me when working on cross-compilation support, and I suspect it will be invaluable for any current and future maintainers of cargo-dist as well (I've used it with great success in other large codebases). You can still treat `TargetTriple` as a string, but it'll be uglier (on purpose). There is however, some ugliness that isn't on purpose. In this changeset I discovered some annoyances around `.iter()` (which returns an `Iterator<Item = &TargetTriple>` instead of an `Iterator<Item = &TargetTripleRef>`. I've added `.as_explicit_ref` to work around those cases. Similarly, calling `Vec<TargetTriple>::contains()` with a `&TargetTripleRef` doesn't work (and you cannot convert a `&TargetTripleRef` into a `&TargetTriple`, the same way you cannot convert a `&str` back into a `&String` - you don't know where it's allocated from!). Finally, I ran into <rust-lang/rfcs#1445> while making this change: there was a big `match` for converting target triples to their display names, and although that works with `&str` constants, it doesn't work with `&TargetTripleRef` constants, due to Rust limitations right now. That explains the lazy_static (which we already depended on transitively, so at least that). I would've used `LazyLock` but our MSRV is currently 1.79 and LazyLock is since 1.80 :(
1 parent 03dfa67 commit 943e73b

File tree

31 files changed

+903
-450
lines changed

31 files changed

+903
-450
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
[workspace]
2-
members = [
3-
"axoproject",
4-
"cargo-dist",
5-
"cargo-dist-schema",
6-
]
2+
members = ["axoproject", "cargo-dist", "cargo-dist-schema"]
73
resolver = "2"
84
exclude = ["axoproject/tests/projects/"]
95

@@ -17,13 +13,23 @@ version = "0.23.0"
1713
[workspace.dependencies]
1814
# intra-workspace deps (you need to bump these versions when you cut releases too!
1915
cargo-dist-schema = { version = "=0.23.0", path = "cargo-dist-schema" }
20-
axoproject = { version = "=0.23.0", path = "axoproject", default-features = false, features = ["cargo-projects", "generic-projects", "npm-projects"] }
16+
axoproject = { version = "=0.23.0", path = "axoproject", default-features = false, features = [
17+
"cargo-projects",
18+
"generic-projects",
19+
"npm-projects",
20+
] }
2121

2222
# first-party deps
2323
axocli = { version = "0.2.0" }
2424
axoupdater = { version = "0.7.2" }
2525
axotag = "0.2.0"
26-
axoasset = { version = "1.0.0", features = ["json-serde", "toml-serde", "toml-edit", "compression", "remote"] }
26+
axoasset = { version = "1.0.0", features = [
27+
"json-serde",
28+
"toml-serde",
29+
"toml-edit",
30+
"compression",
31+
"remote",
32+
] }
2733
axoprocess = { version = "0.2.0" }
2834
gazenot = { version = "0.3.3" }
2935

@@ -43,7 +49,13 @@ semver = "1.0.23"
4349
newline-converter = "0.3.0"
4450
dialoguer = "0.11.0"
4551
sha2 = "0.10.6"
46-
minijinja = { version = "2.3.1", features = ["debug", "loader", "builtins", "json", "custom_syntax"] }
52+
minijinja = { version = "2.3.1", features = [
53+
"debug",
54+
"loader",
55+
"builtins",
56+
"json",
57+
"custom_syntax",
58+
] }
4759
include_dir = "0.7.4"
4860
itertools = "0.13.0"
4961
cargo-wix = "0.3.8"
@@ -65,6 +77,7 @@ schemars = "0.8.21"
6577
serde_yml = "0.0.10"
6678
spdx = "0.10.6"
6779
base64 = "0.22.1"
80+
lazy_static = "1.4.0"
6881

6982
[workspace.metadata.release]
7083
shared-version = true

axoproject/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ pub mod generic;
2626
#[cfg(feature = "npm-projects")]
2727
pub mod javascript;
2828
pub mod local_repo;
29-
pub mod platforms;
3029
mod repo;
3130
#[cfg(feature = "cargo-projects")]
3231
pub mod rust;

axoproject/src/platforms.rs

Lines changed: 0 additions & 241 deletions
This file was deleted.

0 commit comments

Comments
 (0)