From 65065800577ea0bfc3d86ec946c5bb144a304b6b Mon Sep 17 00:00:00 2001 From: Alex Huszagh Date: Wed, 8 Jun 2022 10:45:45 -0500 Subject: [PATCH] Refactor code. --- Cargo.lock | 28 ++ Cargo.toml | 11 +- cross-dev/Cargo.lock | 621 ----------------------------- cross-dev/Cargo.toml | 17 - cross-dev/{src => }/main.rs | 22 +- cross-dev/{src => }/target_info.sh | 0 src/bin/cross-util.rs | 118 ++++-- 7 files changed, 118 insertions(+), 699 deletions(-) delete mode 100644 cross-dev/Cargo.lock delete mode 100644 cross-dev/Cargo.toml rename cross-dev/{src => }/main.rs (84%) rename cross-dev/{src => }/target_info.sh (100%) diff --git a/Cargo.lock b/Cargo.lock index c21d9cb09..71ac3856e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -160,6 +160,7 @@ dependencies = [ "serde", "serde_ignored", "serde_json", + "serde_yaml", "shell-escape", "toml", "walkdir", @@ -259,6 +260,12 @@ version = "0.2.124" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "21a41fed9d98f27ab1c6d161da622a4fa35e8a54a8adc24bbf3ddd0ef70b0e50" +[[package]] +name = "linked-hash-map" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3" + [[package]] name = "memchr" version = "2.4.1" @@ -453,6 +460,18 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_yaml" +version = "0.8.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "707d15895415db6628332b737c838b88c598522e4dc70647e59b72312924aebc" +dependencies = [ + "indexmap", + "ryu", + "serde", + "yaml-rust", +] + [[package]] name = "sharded-slab" version = "0.1.4" @@ -630,3 +649,12 @@ name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "yaml-rust" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85" +dependencies = [ + "linked-hash-map", +] diff --git a/Cargo.toml b/Cargo.toml index b2fd528ff..3f0e68a6d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,10 @@ name = "cross" repository = "https://github.com/cross-rs/cross" version = "0.2.1" edition = "2021" -readme = "docs/crates_io.md" + +[features] +default = [] +dev = ["serde_yaml"] [dependencies] atty = "0.2" @@ -22,6 +25,7 @@ which = { version = "4", default_features = false } shell-escape = "0.1" serde = { version = "1", features = ["derive"] } serde_json = "1" +serde_yaml = { version = "0.8", optional = true } serde_ignored = "0.1.2" [target.'cfg(not(windows))'.dependencies] @@ -39,3 +43,8 @@ lto = true regex = "1" once_cell = "1" walkdir = "2" + +[[bin]] +name = "cross-dev" +path = "cross-dev/main.rs" +required-features = ["dev"] diff --git a/cross-dev/Cargo.lock b/cross-dev/Cargo.lock deleted file mode 100644 index 71842ee2a..000000000 --- a/cross-dev/Cargo.lock +++ /dev/null @@ -1,621 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "addr2line" -version = "0.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9ecd88a8c8378ca913a680cd98f0f13ac67383d35993f86c90a70e3f137816b" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi", - "libc", - "winapi", -] - -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - -[[package]] -name = "backtrace" -version = "0.3.65" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11a17d453482a265fd5f8479f2a3f405566e6ca627837aaddb85af8b1ab8ef61" -dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", -] - -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "cc" -version = "1.0.73" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "clap" -version = "3.1.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2dbdf4bdacb33466e854ce889eee8dfd5729abf7ccd7664d0a2d60cd384440b" -dependencies = [ - "atty", - "bitflags", - "clap_derive", - "clap_lex", - "indexmap", - "lazy_static", - "strsim", - "termcolor", - "textwrap", -] - -[[package]] -name = "clap_derive" -version = "3.1.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25320346e922cffe59c0bbc5410c8d8784509efb321488971081313cb1e1a33c" -dependencies = [ - "heck", - "proc-macro-error", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "clap_lex" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a37c35f1112dad5e6e0b1adaff798507497a18fceeb30cceb3bae7d1427b9213" -dependencies = [ - "os_str_bytes", -] - -[[package]] -name = "color-eyre" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ebf286c900a6d5867aeff75cfee3192857bb7f24b547d4f0df2ed6baa812c90" -dependencies = [ - "backtrace", - "color-spantrace", - "eyre", - "indenter", - "once_cell", - "owo-colors", - "tracing-error", -] - -[[package]] -name = "color-spantrace" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ba75b3d9449ecdccb27ecbc479fdc0b87fa2dd43d2f8298f9bf0e59aacc8dce" -dependencies = [ - "once_cell", - "owo-colors", - "tracing-core", - "tracing-error", -] - -[[package]] -name = "cross" -version = "0.2.1" -dependencies = [ - "atty", - "clap", - "color-eyre", - "dunce", - "eyre", - "home", - "libc", - "nix", - "rustc_version", - "serde", - "serde_ignored", - "serde_json", - "shell-escape", - "toml", - "which", - "winapi", -] - -[[package]] -name = "cross-dev" -version = "0.0.1" -dependencies = [ - "clap", - "cross", - "serde", - "serde_yaml", - "which", -] - -[[package]] -name = "dunce" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "453440c271cf5577fd2a40e4942540cb7d0d2f85e27c8d07dd0023c925a67541" - -[[package]] -name = "either" -version = "1.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" - -[[package]] -name = "eyre" -version = "0.6.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c2b6b5a29c02cdc822728b7d7b8ae1bab3e3b05d44522770ddd49722eeac7eb" -dependencies = [ - "indenter", - "once_cell", -] - -[[package]] -name = "gimli" -version = "0.26.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78cc372d058dcf6d5ecd98510e7fbc9e5aec4d21de70f65fea8fecebcd881bd4" - -[[package]] -name = "hashbrown" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" - -[[package]] -name = "heck" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" - -[[package]] -name = "hermit-abi" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] - -[[package]] -name = "home" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2456aef2e6b6a9784192ae780c0f15bc57df0e918585282325e8c8ac27737654" -dependencies = [ - "winapi", -] - -[[package]] -name = "indenter" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" - -[[package]] -name = "indexmap" -version = "1.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6012d540c5baa3589337a98ce73408de9b5a25ec9fc2c6fd6be8f0d39e0ca5a" -dependencies = [ - "autocfg", - "hashbrown", -] - -[[package]] -name = "itoa" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d" - -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - -[[package]] -name = "libc" -version = "0.2.126" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" - -[[package]] -name = "linked-hash-map" -version = "0.5.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3" - -[[package]] -name = "memchr" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" - -[[package]] -name = "miniz_oxide" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f5c75688da582b8ffc1f1799e9db273f32133c49e048f614d22ec3256773ccc" -dependencies = [ - "adler", -] - -[[package]] -name = "nix" -version = "0.24.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f17df307904acd05aa8e32e97bb20f2a0df1728bbc2d771ae8f9a90463441e9" -dependencies = [ - "bitflags", - "cfg-if", - "libc", -] - -[[package]] -name = "object" -version = "0.28.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e42c982f2d955fac81dd7e1d0e1426a7d702acd9c98d19ab01083a6a0328c424" -dependencies = [ - "memchr", -] - -[[package]] -name = "once_cell" -version = "1.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7709cef83f0c1f58f666e746a08b21e0085f7440fa6a29cc194d68aac97a4225" - -[[package]] -name = "os_str_bytes" -version = "6.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21326818e99cfe6ce1e524c2a805c189a99b5ae555a35d19f9a284b427d86afa" - -[[package]] -name = "owo-colors" -version = "3.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "decf7381921fea4dcb2549c5667eda59b3ec297ab7e2b5fc33eac69d2e7da87b" - -[[package]] -name = "pin-project-lite" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" - -[[package]] -name = "proc-macro-error" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" -dependencies = [ - "proc-macro-error-attr", - "proc-macro2", - "quote", - "syn", - "version_check", -] - -[[package]] -name = "proc-macro-error-attr" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" -dependencies = [ - "proc-macro2", - "quote", - "version_check", -] - -[[package]] -name = "proc-macro2" -version = "1.0.39" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "rustc-demangle" -version = "0.1.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" - -[[package]] -name = "rustc_version" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" -dependencies = [ - "semver", -] - -[[package]] -name = "ryu" -version = "1.0.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3f6f92acf49d1b98f7a81226834412ada05458b7364277387724a237f062695" - -[[package]] -name = "semver" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cb243bdfdb5936c8dc3c45762a19d12ab4550cdc753bc247637d4ec35a040fd" - -[[package]] -name = "serde" -version = "1.0.137" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.137" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f26faba0c3959972377d3b2d306ee9f71faee9714294e41bb777f83f88578be" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "serde_ignored" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1940036ca2411651a40012009d062087dfe62817b2191a03750fb569e11fa633" -dependencies = [ - "serde", -] - -[[package]] -name = "serde_json" -version = "1.0.81" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b7ce2b32a1aed03c558dc61a5cd328f15aff2dbc17daad8fb8af04d2100e15c" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "serde_yaml" -version = "0.8.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707d15895415db6628332b737c838b88c598522e4dc70647e59b72312924aebc" -dependencies = [ - "indexmap", - "ryu", - "serde", - "yaml-rust", -] - -[[package]] -name = "sharded-slab" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31" -dependencies = [ - "lazy_static", -] - -[[package]] -name = "shell-escape" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45bb67a18fa91266cc7807181f62f9178a6873bfad7dc788c42e6430db40184f" - -[[package]] -name = "strsim" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" - -[[package]] -name = "syn" -version = "1.0.96" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0748dd251e24453cb8717f0354206b91557e4ec8703673a4b30208f2abaf1ebf" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "termcolor" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" -dependencies = [ - "winapi-util", -] - -[[package]] -name = "textwrap" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" - -[[package]] -name = "thread_local" -version = "1.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5516c27b78311c50bf42c071425c560ac799b11c30b31f87e3081965fe5e0180" -dependencies = [ - "once_cell", -] - -[[package]] -name = "toml" -version = "0.5.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7" -dependencies = [ - "serde", -] - -[[package]] -name = "tracing" -version = "0.1.34" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d0ecdcb44a79f0fe9844f0c4f33a342cbcbb5117de8001e6ba0dc2351327d09" -dependencies = [ - "cfg-if", - "pin-project-lite", - "tracing-core", -] - -[[package]] -name = "tracing-core" -version = "0.1.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7709595b8878a4965ce5e87ebf880a7d39c9afc6837721b21a5a816a8117d921" -dependencies = [ - "once_cell", - "valuable", -] - -[[package]] -name = "tracing-error" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d686ec1c0f384b1277f097b2f279a2ecc11afe8c133c1aabf036a27cb4cd206e" -dependencies = [ - "tracing", - "tracing-subscriber", -] - -[[package]] -name = "tracing-subscriber" -version = "0.3.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bc28f93baff38037f64e6f43d34cfa1605f27a49c34e8a04c5e78b0babf2596" -dependencies = [ - "sharded-slab", - "thread_local", - "tracing-core", -] - -[[package]] -name = "unicode-ident" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee" - -[[package]] -name = "valuable" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "which" -version = "4.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c4fb54e6113b6a8772ee41c3404fb0301ac79604489467e0a9ce1f3e97c24ae" -dependencies = [ - "either", - "lazy_static", - "libc", -] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-util" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" -dependencies = [ - "winapi", -] - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "yaml-rust" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85" -dependencies = [ - "linked-hash-map", -] diff --git a/cross-dev/Cargo.toml b/cross-dev/Cargo.toml deleted file mode 100644 index eb46ab6ba..000000000 --- a/cross-dev/Cargo.toml +++ /dev/null @@ -1,17 +0,0 @@ -[package] -description = "Development utilities for cross" -documentation = "https://github.com/cross-rs/cross" -keywords = ["cross", "compilation", "testing", "tool"] -license = "MIT OR Apache-2.0" -name = "cross-dev" -repository = "https://github.com/cross-rs/cross" -version = "0.0.1" -edition = "2021" -readme = "../docs/crates_io.md" - -[dependencies] -clap = { version = "3.1.18", features = ["derive"] } -cross = { path = "..", version = "0.2.1" } -which = { version = "4", default_features = false } -serde = { version = "1.0", features = ["derive"] } -serde_yaml = "0.8" diff --git a/cross-dev/src/main.rs b/cross-dev/main.rs similarity index 84% rename from cross-dev/src/main.rs rename to cross-dev/main.rs index ce6bf3444..29f603ef1 100644 --- a/cross-dev/src/main.rs +++ b/cross-dev/main.rs @@ -10,7 +10,7 @@ use serde::Deserialize; // Store raw text data in the binary so we don't need a data directory // when extracting all targets, or running our target info script. const TARGET_INFO_SCRIPT: &str = include_str!("target_info.sh"); -const WORKFLOW: &str = include_str!("../../.github/workflows/ci.yml"); +const WORKFLOW: &str = include_str!("../.github/workflows/ci.yml"); #[derive(Parser, Debug)] #[clap(version, about, long_about = None)] @@ -22,14 +22,6 @@ struct Cli { #[derive(Subcommand, Debug)] enum Commands { /// Extract and print info for targets. - /// - /// If no arguments are provided, this script will provide info - /// for all targets. The output will be similar to the following: - /// | `aarch64-unknown-linux-musl` | 1.2.0 | 9.2.0 | ✓ | 5.1.0 | - /// | `i686-linux-android` | 9.0.8 | 9.0.8 | ✓ | 5.1.0 | - /// | `i686-unknown-linux-musl` | 1.2.0 | 9.2.0 | ✓ | N/A | - /// ... - #[clap(verbatim_doc_comment)] TargetInfo { /// If not provided, get info for all targets. targets: Vec, @@ -80,17 +72,9 @@ struct Env { #[derive(Debug, PartialEq, Deserialize)] struct Matrix { target: String, - os: String, - #[serde(default)] - cpp: i64, - #[serde(default)] - std: i64, - #[serde(default)] - run: i64, - runners: Option, } -fn get_container_engine(engine: &Option) -> Result { +fn get_container_engine(engine: &Option<&str>) -> Result { if let Some(ce) = engine { which::which(ce) } else { @@ -192,7 +176,7 @@ pub fn main() -> cross::Result<()> { tag, engine, } => { - let engine = get_container_engine(engine)?; + let engine = get_container_engine(&engine.as_deref())?; target_info( targets.to_vec(), &engine, diff --git a/cross-dev/src/target_info.sh b/cross-dev/target_info.sh similarity index 100% rename from cross-dev/src/target_info.sh rename to cross-dev/target_info.sh diff --git a/src/bin/cross-util.rs b/src/bin/cross-util.rs index c3044cf1a..974f9dbb5 100644 --- a/src/bin/cross-util.rs +++ b/src/bin/cross-util.rs @@ -44,13 +44,30 @@ enum Commands { /// Remove local (development) images. #[clap(short, long)] local: bool, + /// Remove images. Default is a dry run. + #[clap(short, long)] + execute: bool, /// Container engine (such as docker or podman). #[clap(long)] engine: Option, }, } -fn get_container_engine(engine: &Option) -> Result { +#[derive(Debug, PartialOrd, Ord, PartialEq, Eq)] +struct Image { + repository: String, + tag: String, + // need to remove images by ID, not just tag + id: String, +} + +impl Image { + fn name(&self) -> String { + format!("{}:{}", self.repository, self.tag) + } +} + +fn get_container_engine(engine: &Option<&str>) -> Result { if let Some(ce) = engine { which::which(ce) } else { @@ -58,28 +75,37 @@ fn get_container_engine(engine: &Option) -> Result bool { - IMAGE_PREFIXES.iter().any(|i| image.starts_with(i)) +fn parse_image(image: &str) -> Image { + // this cannot panic: we've formatted our image list as `${repo}:${tag} ${id}` + let (repository, rest) = image.split_once(':').unwrap(); + let (tag, id) = rest.split_once(' ').unwrap(); + Image { + repository: repository.to_string(), + tag: tag.to_string(), + id: id.to_string(), + } +} + +fn is_cross_image(repository: &str) -> bool { + IMAGE_PREFIXES.iter().any(|i| repository.starts_with(i)) } -fn is_local_image(image: &str) -> bool { - // this cannot panic: we've formatted our image as ${repo}:${tag} - let tag = image.split_once(':').unwrap().1; +fn is_local_image(tag: &str) -> bool { tag.starts_with("local") } -fn get_cross_images(engine: &Path, verbose: bool, local: bool) -> cross::Result> { +fn get_cross_images(engine: &Path, verbose: bool, local: bool) -> cross::Result> { let stdout = Command::new(engine) .arg("images") .arg("--format") - .arg("{{.Repository}}:{{.Tag}}") + .arg("{{.Repository}}:{{.Tag}} {{.ID}}") .run_and_get_stdout(verbose)?; - let mut images: Vec = stdout + let mut images: Vec = stdout .lines() - .filter(|image| is_cross_image(image)) - .filter(|image| local || !is_local_image(image)) - .map(|image| image.to_string()) + .map(parse_image) + .filter(|image| is_cross_image(&image.repository)) + .filter(|image| local || !is_local_image(&image.tag)) .collect(); images.sort(); @@ -90,7 +116,7 @@ fn get_cross_images(engine: &Path, verbose: bool, local: bool) -> cross::Result< // repository = (${registry}/)?rustembedded/cross // tag = ${target}(-${version})? // our target triple must match `[A-Za-z0-9_-]` -fn rustembedded_target(tag: &str) -> Option { +fn rustembedded_target(tag: &str) -> String { let is_target_char = |c: char| c == '_' || c.is_ascii_alphanumeric(); let mut components = vec![]; for component in tag.split('-') { @@ -99,39 +125,35 @@ fn rustembedded_target(tag: &str) -> Option { } } - Some(components.join("-")) + components.join("-") } -fn get_image_target(image: &str) -> cross::Result { - let option = if let Some(stripped) = image.strip_prefix(GHCR_IO) { - stripped.split(':').next().map(|t| t.to_string()) - } else if let Some(tag) = image.strip_prefix(RUST_EMBEDDED) { - rustembedded_target(tag) - } else if let Some(tag) = image.strip_prefix(DOCKER_IO) { - rustembedded_target(tag) +fn get_image_target(image: &Image) -> cross::Result { + if let Some(stripped) = image.repository.strip_prefix(GHCR_IO) { + Ok(stripped.to_string()) + } else if let Some(tag) = image.tag.strip_prefix(RUST_EMBEDDED) { + Ok(rustembedded_target(tag)) + } else if let Some(tag) = image.tag.strip_prefix(DOCKER_IO) { + Ok(rustembedded_target(tag)) } else { - None - }; - - match option { - Some(target) => Ok(target), - None => eyre::bail!("Cannot get target for image {}", image), + eyre::bail!("Cannot get target for image {}", image.name()) } } fn list_images(engine: &Path, verbose: bool) -> cross::Result<()> { get_cross_images(engine, verbose, true)? .iter() - .for_each(|line| println!("{}", line)); + .for_each(|line| println!("{}", line.name())); Ok(()) } fn remove_images( engine: &Path, - images: &[String], + images: &[&str], verbose: bool, force: bool, + execute: bool, ) -> cross::Result<()> { let mut command = Command::new(engine); command.arg("rmi"); @@ -139,12 +161,24 @@ fn remove_images( command.arg("--force"); } command.args(images); - command.run(verbose) + if execute { + command.run(verbose) + } else { + println!("{:?}", command); + Ok(()) + } } -fn remove_all_images(engine: &Path, verbose: bool, force: bool, local: bool) -> cross::Result<()> { +fn remove_all_images( + engine: &Path, + verbose: bool, + force: bool, + local: bool, + execute: bool, +) -> cross::Result<()> { let images = get_cross_images(engine, verbose, local)?; - remove_images(engine, &images, verbose, force) + let ids: Vec<&str> = images.iter().map(|i| i.id.as_ref()).collect(); + remove_images(engine, &ids, verbose, force, execute) } fn remove_target_images( @@ -153,16 +187,17 @@ fn remove_target_images( verbose: bool, force: bool, local: bool, + execute: bool, ) -> cross::Result<()> { let images = get_cross_images(engine, verbose, local)?; - let mut filtered = vec![]; - for image in images { - let target = get_image_target(&image)?; + let mut ids = vec![]; + for image in images.iter() { + let target = get_image_target(image)?; if targets.contains(&target) { - filtered.push(image); + ids.push(image.id.as_ref()); } } - remove_images(engine, &filtered, verbose, force) + remove_images(engine, &ids, verbose, force, execute) } pub fn main() -> cross::Result<()> { @@ -170,7 +205,7 @@ pub fn main() -> cross::Result<()> { let cli = Cli::parse(); match &cli.command { Commands::ListImages { verbose, engine } => { - let engine = get_container_engine(engine)?; + let engine = get_container_engine(&engine.as_deref())?; list_images(&engine, *verbose)?; } Commands::RemoveImages { @@ -178,13 +213,14 @@ pub fn main() -> cross::Result<()> { verbose, force, local, + execute, engine, } => { - let engine = get_container_engine(engine)?; + let engine = get_container_engine(&engine.as_deref())?; if targets.is_empty() { - remove_all_images(&engine, *verbose, *force, *local)?; + remove_all_images(&engine, *verbose, *force, *local, *execute)?; } else { - remove_target_images(&engine, targets, *verbose, *force, *local)?; + remove_target_images(&engine, targets, *verbose, *force, *local, *execute)?; } } }