Replace xtask with justfile

This commit is contained in:
Ajeet D'Souza 2023-05-06 03:16:13 +05:30
parent a7c8231e56
commit 5de13befbc
9 changed files with 174 additions and 432 deletions

View File

@ -26,14 +26,22 @@ jobs:
- uses: actions-rs/toolchain@v1
if: ${{ matrix.os == 'windows-latest' }}
with:
toolchain: stable
components: rustfmt, clippy
components: clippy
profile: minimal
override: true
toolchain: stable
- uses: actions-rs/toolchain@v1
if: ${{ matrix.os == 'windows-latest' }}
with:
components: rustfmt
profile: minimal
toolchain: nightly
- uses: cachix/install-nix-action@v20
if: ${{ matrix.os != 'windows-latest' }}
with:
nix_path: nixpkgs=channel:nixos-unstable
- uses: cachix/cachix-action@v12
if: ${{ matrix.os != 'windows-latest' && env.CACHIX_AUTH_TOKEN != '' }}
with:
@ -45,7 +53,13 @@ jobs:
with:
key: ${{ matrix.os }}
- run: cargo xtask ci
if: ${{ matrix.os == 'windows-latest' }}
- run: nix-shell --cores 0 --pure --run 'rm -rf ~/.cargo/bin; cargo xtask ci'
if: ${{ matrix.os != 'windows-latest' }}
- name: Install just
uses: taiki-e/install-action@v2
with:
tool: just
- name: Run lints
run: just lint
- name: Run tests
run: just test

298
Cargo.lock generated
View File

@ -8,15 +8,6 @@ version = "0.11.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3"
[[package]]
name = "aho-corasick"
version = "0.7.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac"
dependencies = [
"memchr",
]
[[package]]
name = "aliasable"
version = "0.1.3"
@ -25,9 +16,9 @@ checksum = "250f629c0161ad8107cf89319e990051fae62832fd343083bea452d93e2205fd"
[[package]]
name = "anstream"
version = "0.3.0"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e579a7752471abc2a8268df8b20005e3eadd975f585398f17efcfd8d4927371"
checksum = "0ca84f3628370c59db74ee214b3263d58f9aadd9b4fe7e711fd87dc452b7f163"
dependencies = [
"anstyle",
"anstyle-parse",
@ -64,9 +55,9 @@ dependencies = [
[[package]]
name = "anstyle-wincon"
version = "1.0.0"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4bcd8291a340dd8ac70e18878bc4501dd7b4ff970cfa21c207d36ece51ea88fd"
checksum = "180abfa45703aebe0093f79badacc01b8fd4ea2e35118747e5811127f926e188"
dependencies = [
"anstyle",
"windows-sys 0.48.0",
@ -74,30 +65,32 @@ dependencies = [
[[package]]
name = "anyhow"
version = "1.0.70"
version = "1.0.71"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7de8ce5e0f9f8d88245311066a578d72b7af3e7088f32783804676302df237e4"
checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8"
[[package]]
name = "askama"
version = "0.11.1"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb98f10f371286b177db5eeb9a6e5396609555686a35e1d4f7b9a9c6d8af0139"
checksum = "47cbc3cf73fa8d9833727bbee4835ba5c421a0d65b72daf9a7b5d0e0f9cfb57e"
dependencies = [
"askama_derive",
"askama_escape",
"askama_shared",
]
[[package]]
name = "askama_derive"
version = "0.11.2"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87bf87e6e8b47264efa9bde63d6225c6276a52e05e91bf37eaa8afd0032d6b71"
checksum = "c22fbe0413545c098358e56966ff22cdd039e10215ae213cfbd65032b119fc94"
dependencies = [
"askama_shared",
"mime",
"mime_guess",
"nom",
"proc-macro2",
"syn 1.0.109",
"quote",
"syn 2.0.15",
]
[[package]]
@ -106,21 +99,6 @@ version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "619743e34b5ba4e9703bba34deac3427c72507c7159f5fd030aea8cac0cfe341"
[[package]]
name = "askama_shared"
version = "0.12.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf722b94118a07fcbc6640190f247334027685d4e218b794dbfe17c32bf38ed0"
dependencies = [
"askama_escape",
"mime",
"mime_guess",
"nom",
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]]
name = "assert_cmd"
version = "2.0.11"
@ -177,9 +155,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clap"
version = "4.2.2"
version = "4.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b802d85aaf3a1cdb02b224ba472ebdea62014fccfcb269b95a4d76443b5ee5a"
checksum = "34d21f9bf1b425d2968943631ec91202fe5e837264063503708b83013f8fc938"
dependencies = [
"clap_builder",
"clap_derive",
@ -188,9 +166,9 @@ dependencies = [
[[package]]
name = "clap_builder"
version = "4.2.2"
version = "4.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14a1a858f532119338887a4b8e1af9c60de8249cd7bafd68036a489e261e37b6"
checksum = "914c8c79fb560f238ef6429439a30023c862f7a28e688c58f7203f12b29970bd"
dependencies = [
"anstream",
"anstyle",
@ -201,9 +179,9 @@ dependencies = [
[[package]]
name = "clap_complete"
version = "4.2.0"
version = "4.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "01c22dcfb410883764b29953103d9ef7bb8fe21b3fa1158bc99986c2067294bd"
checksum = "1a19591b2ab0e3c04b588a0e04ddde7b9eaa423646d1b4a8092879216bf47473"
dependencies = [
"clap",
]
@ -271,22 +249,23 @@ checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8"
[[package]]
name = "dirs"
version = "4.0.0"
version = "5.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059"
checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225"
dependencies = [
"dirs-sys",
]
[[package]]
name = "dirs-sys"
version = "0.3.7"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6"
checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c"
dependencies = [
"libc",
"option-ext",
"redox_users",
"winapi",
"windows-sys 0.48.0",
]
[[package]]
@ -297,9 +276,9 @@ checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10"
[[package]]
name = "dunce"
version = "1.0.3"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0bd4b30a6560bbd9b4620f4de34c3f14f60848e58a9b7216801afcb4c7b31c3c"
checksum = "56ce8c6da7551ec6c462cbaf3bfbc75131ebbfa1c944aeaa9dab51ca1c5f0c3b"
[[package]]
name = "either"
@ -337,12 +316,6 @@ dependencies = [
"instant",
]
[[package]]
name = "fnv"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
name = "getrandom"
version = "0.2.9"
@ -360,19 +333,6 @@ version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
[[package]]
name = "globset"
version = "0.4.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "029d74589adefde59de1a0c4f4732695c32805624aec7b68d91503d4dba79afc"
dependencies = [
"aho-corasick",
"bstr",
"fnv",
"log",
"regex",
]
[[package]]
name = "heck"
version = "0.4.1"
@ -385,23 +345,6 @@ version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286"
[[package]]
name = "ignore"
version = "0.4.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dbe7873dab538a9a44ad79ede1faf5f30d49f9a5c883ddbab48bce81b64b7492"
dependencies = [
"globset",
"lazy_static",
"log",
"memchr",
"regex",
"same-file",
"thread_local",
"walkdir",
"winapi-util",
]
[[package]]
name = "instant"
version = "0.1.12"
@ -443,32 +386,17 @@ dependencies = [
"either",
]
[[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.141"
version = "0.2.142"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3304a64d199bb964be99741b7a14d26972741915b3649639149b2479bb46f4b5"
checksum = "6a987beff54b60ffa6d51982e1aa1146bc42f19bd26be28b0586f252fccf5317"
[[package]]
name = "linux-raw-sys"
version = "0.3.1"
version = "0.3.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d59d8c75012853d2e872fb56bc8a2e53718e2cafe1a4c823143141c6d90c322f"
[[package]]
name = "log"
version = "0.4.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
dependencies = [
"cfg-if",
]
checksum = "ece97ea872ece730aed82664c424eb4c8291e1ff2480247ccf7409044bc6479f"
[[package]]
name = "memchr"
@ -526,6 +454,12 @@ version = "1.17.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3"
[[package]]
name = "option-ext"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
[[package]]
name = "ouroboros"
version = "0.15.6"
@ -549,6 +483,12 @@ dependencies = [
"syn 1.0.109",
]
[[package]]
name = "ppv-lite86"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
name = "predicates"
version = "3.0.3"
@ -619,6 +559,36 @@ dependencies = [
"proc-macro2",
]
[[package]]
name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
]
[[package]]
name = "rand_chacha"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
dependencies = [
"getrandom",
]
[[package]]
name = "redox_syscall"
version = "0.2.16"
@ -648,34 +618,17 @@ dependencies = [
"thiserror",
]
[[package]]
name = "regex"
version = "1.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b1f693b24f6ac912f4893ef08244d70b6067480d2f1a46e950c9691e6749d1d"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
]
[[package]]
name = "regex-automata"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
[[package]]
name = "regex-syntax"
version = "0.6.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1"
[[package]]
name = "rstest"
version = "0.16.0"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b07f2d176c472198ec1e6551dc7da28f1c089652f66a7b722676c2238ebc0edf"
checksum = "de1bb486a691878cd320c2f0d319ba91eeaa2e894066d8b5f8f117c000e9d962"
dependencies = [
"rstest_macros",
"rustc_version",
@ -683,9 +636,9 @@ dependencies = [
[[package]]
name = "rstest_macros"
version = "0.16.0"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7229b505ae0706e64f37ffc54a9c163e11022a6636d58fe1f3f52018257ff9f7"
checksum = "290ca1a1c8ca7edb7c3283bd44dc35dd54fdec6253a3912e201ba1072018fca8"
dependencies = [
"cfg-if",
"proc-macro2",
@ -697,11 +650,12 @@ dependencies = [
[[package]]
name = "rstest_reuse"
version = "0.4.0"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9b5aed35457441e7e0db509695ba3932d4c47e046777141c167efe584d0ec17"
checksum = "45f80dcc84beab3a327bbe161f77db25f336a1452428176787c8c79ac79d7073"
dependencies = [
"quote",
"rand",
"rustc_version",
"syn 1.0.109",
]
@ -717,9 +671,9 @@ dependencies = [
[[package]]
name = "rustix"
version = "0.37.11"
version = "0.37.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85597d61f83914ddeba6a47b3b8ffe7365107221c2e557ed94426489fefb5f77"
checksum = "acf8729d8542766f1b2cf77eb034d52f40d375bb8b615d0b147089946e16613d"
dependencies = [
"bitflags",
"errno",
@ -729,15 +683,6 @@ dependencies = [
"windows-sys 0.48.0",
]
[[package]]
name = "same-file"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
dependencies = [
"winapi-util",
]
[[package]]
name = "semver"
version = "1.0.17"
@ -746,30 +691,24 @@ checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed"
[[package]]
name = "serde"
version = "1.0.160"
version = "1.0.162"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb2f3770c8bce3bcda7e149193a069a0f4365bda1fa5cd88e03bca26afc1216c"
checksum = "71b2f6e1ab5c2b98c05f0f35b236b22e8df7ead6ffbf51d7808da7f8817e7ab6"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.160"
version = "1.0.162"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "291a097c63d8497e00160b166a967a4a79c64f3facdd01cbd7502231688d77df"
checksum = "a2a0814352fd64b58489904a44ea8d90cb1a91dcb6b4f5ebabc32c8318e93cb6"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.15",
]
[[package]]
name = "shell-words"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde"
[[package]]
name = "static_assertions"
version = "1.1.0"
@ -843,16 +782,6 @@ dependencies = [
"syn 2.0.15",
]
[[package]]
name = "thread_local"
version = "1.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152"
dependencies = [
"cfg-if",
"once_cell",
]
[[package]]
name = "unicase"
version = "2.6.0"
@ -889,16 +818,6 @@ dependencies = [
"libc",
]
[[package]]
name = "walkdir"
version = "2.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36df944cda56c7d8d8b7496af378e6b16de9284591917d307c9b4d313c44e698"
dependencies = [
"same-file",
"winapi-util",
]
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
@ -916,37 +835,6 @@ dependencies = [
"once_cell",
]
[[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 = "windows-sys"
version = "0.45.0"
@ -1079,16 +967,6 @@ version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a"
[[package]]
name = "xtask"
version = "0.1.0"
dependencies = [
"anyhow",
"clap",
"ignore",
"shell-words",
]
[[package]]
name = "zoxide"
version = "0.9.0"

View File

@ -15,65 +15,39 @@ version = "0.9.0"
[badges]
maintenance = { status = "actively-developed" }
[workspace]
members = ["xtask/"]
[workspace.dependencies]
[dependencies]
anyhow = "1.0.32"
askama = { version = "0.11.0", default-features = false }
assert_cmd = "2.0.0"
askama = { version = "0.12.0", default-features = false }
bincode = "1.3.1"
clap = { version = "4.0.0", features = ["derive"] }
clap_complete = "4.0.0"
clap_complete_fig = "4.0.0"
color-print = "0.3.4"
dirs = "4.0.0"
dirs = "5.0.0"
dunce = "1.0.1"
fastrand = "1.7.0"
glob = "0.3.0"
ignore = "0.4.18"
ouroboros = "0.15.5"
serde = { version = "1.0.116", features = ["derive"] }
[target.'cfg(unix)'.dependencies]
nix = { version = "0.26.1", default-features = false, features = [
"fs",
"user",
] }
ouroboros = "0.15.5"
rstest = { version = "0.16.0", default-features = false }
rstest_reuse = "0.4.0"
serde = { version = "1.0.116", features = ["derive"] }
shell-words = "1.0.0"
tempfile = "3.1.0"
which = "4.2.5"
[dependencies]
anyhow.workspace = true
askama.workspace = true
bincode.workspace = true
clap.workspace = true
color-print.workspace = true
dirs.workspace = true
dunce.workspace = true
fastrand.workspace = true
glob.workspace = true
ouroboros.workspace = true
serde.workspace = true
[target.'cfg(unix)'.dependencies]
nix.workspace = true
[target.'cfg(windows)'.dependencies]
which.workspace = true
which = "4.2.5"
[build-dependencies]
clap.workspace = true
clap_complete.workspace = true
clap_complete_fig.workspace = true
color-print.workspace = true
clap = { version = "4.0.0", features = ["derive"] }
clap_complete = "4.0.0"
clap_complete_fig = "4.0.0"
color-print = "0.3.4"
[dev-dependencies]
assert_cmd.workspace = true
rstest.workspace = true
rstest_reuse.workspace = true
tempfile.workspace = true
assert_cmd = "2.0.0"
rstest = { version = "0.17.0", default-features = false }
rstest_reuse = "0.5.0"
tempfile = "3.1.0"
[features]
default = []

View File

@ -105,9 +105,9 @@ _arguments "${_arguments_options[@]}" \
;;
(init)
_arguments "${_arguments_options[@]}" \
'--cmd=[Changes the prefix of the `z` and `zi` commands]:CMD: ' \
'--cmd=[Changes the prefix of the \`z\` and \`zi\` commands]:CMD: ' \
'--hook=[Changes how often zoxide increments a directory'\''s score]:HOOK:(none prompt pwd)' \
'--no-cmd[Prevents zoxide from defining the `z` and `zi` commands]' \
'--no-cmd[Prevents zoxide from defining the \`z\` and \`zi\` commands]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \

34
justfile Normal file
View File

@ -0,0 +1,34 @@
default:
@just --list
[unix]
fmt:
nix-shell --cores 0 --pure --run 'cargo-fmt --all'
nix-shell --cores 0 --pure --run 'nixfmt -- *.nix'
[windows]
fmt:
cargo +nightly fmt --all
[unix]
lint:
nix-shell --cores 0 --pure --run 'cargo-fmt --all --check'
nix-shell --cores 0 --pure --run 'cargo clippy --all-features --all-targets -- -Dwarnings'
nix-shell --cores 0 --pure --run 'nixfmt --check -- ./*.nix'
nix-shell --cores 0 --pure --run 'markdownlint ./*.md'
nix-shell --cores 0 --pure --run 'mandoc -man -Wall -Tlint -- ./man/man1/*.1'
nix-shell --cores 0 --pure --run 'cargo msrv verify'
nix-shell --cores 0 --pure --run 'cargo udeps --all-features --all-targets --workspace'
[windows]
lint:
cargo +nightly fmt --all --check
cargo +stable clippy --all-features --all-targets -- -Dwarnings
[unix]
test *args:
nix-shell --cores 0 --pure --run 'cargo nextest run --all-features --no-fail-fast --workspace {{args}}'
[windows]
test *args:
cargo +stable test --no-fail-fast --workspace {{args}}

View File

@ -5,9 +5,18 @@ let
"https://github.com/NixOS/nixpkgs/archive/5f902ae769594aaeaf326e8623a48482eeacfe89.tar.gz") {
overlays = [ rust ];
};
rust-nightly =
pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.minimal);
cargo-udeps = pkgs.writeShellScriptBin "cargo-udeps" ''
export RUSTC="${rust-nightly}/bin/rustc";
export CARGO="${rust-nightly}/bin/cargo";
exec "${pkgs.cargo-udeps}/bin/cargo-udeps" "$@"
'';
in pkgs.mkShell {
buildInputs = [
# Rust
(pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.rustfmt))
pkgs.rust-bin.stable.latest.default
# Shells
@ -21,8 +30,11 @@ in pkgs.mkShell {
pkgs.zsh
# Tools
cargo-udeps
pkgs.cargo-msrv
pkgs.cargo-nextest
pkgs.cargo-udeps
pkgs.just
pkgs.mandoc
pkgs.nixfmt
pkgs.nodePackages.markdownlint-cli
@ -39,6 +51,5 @@ in pkgs.mkShell {
pkgs.libiconv
];
CARGO_INCREMENTAL = builtins.getEnv "CI" != "";
CARGO_TARGET_DIR = "target_nix";
}

View File

@ -375,9 +375,5 @@ pub fn resolve_path(path: impl AsRef<Path>) -> Result<PathBuf> {
/// Convert a string to lowercase, with a fast path for ASCII strings.
pub fn to_lowercase(s: impl AsRef<str>) -> String {
let s = s.as_ref();
if s.is_ascii() {
s.to_ascii_lowercase()
} else {
s.to_lowercase()
}
if s.is_ascii() { s.to_ascii_lowercase() } else { s.to_lowercase() }
}

View File

@ -1,11 +0,0 @@
[package]
name = "xtask"
version = "0.1.0"
edition = "2021"
publish = false
[dependencies]
anyhow.workspace = true
clap.workspace = true
ignore.workspace = true
shell-words.workspace = true

View File

@ -1,154 +0,0 @@
use std::env;
use std::ffi::OsStr;
use std::path::PathBuf;
use std::process::{self, Command};
use anyhow::{bail, Context, Result};
use clap::Parser;
use ignore::Walk;
fn main() -> Result<()> {
let dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let dir = dir
.parent()
.with_context(|| format!("could not find workspace root: {}", dir.display()))?;
env::set_current_dir(dir)
.with_context(|| format!("could not set current directory: {}", dir.display()))?;
let nix_enabled = enable_nix();
let app = App::parse();
match app {
App::CI => run_ci(nix_enabled)?,
App::Fmt { check } => run_fmt(nix_enabled, check)?,
App::Lint => run_lint(nix_enabled)?,
App::Test { name } => run_tests(nix_enabled, &name)?,
}
Ok(())
}
#[derive(Parser)]
enum App {
CI,
Fmt {
#[clap(long)]
check: bool,
},
Lint,
Test {
#[clap(default_value = "")]
name: String,
},
}
trait CommandExt {
fn run(self) -> Result<()>;
}
impl CommandExt for &mut Command {
fn run(self) -> Result<()> {
println!(">>> {self:?}");
let status = self.status().with_context(|| format!("command failed to start: {self:?}"))?;
if !status.success() {
bail!("command failed: {self:?} with status: {status:?}");
}
Ok(())
}
}
fn run_ci(nix_enabled: bool) -> Result<()> {
run_fmt(nix_enabled, true)?;
run_lint(nix_enabled)?;
run_tests(nix_enabled, "")?;
run_msrv(nix_enabled)
}
fn run_fmt(nix_enabled: bool, check: bool) -> Result<()> {
// Run cargo-fmt.
// let check_args: &[&str] = if check {&["--check", "--files-with-diff"] } else
// { &[] }; Command::new("cargo").args(&["fmt", "--all",
// "--"]).args(check_args).run()?;
// Run nixfmt.
if nix_enabled {
for result in Walk::new("./") {
let entry = result.unwrap();
let path = entry.path();
if path.is_file() && path.extension() == Some(OsStr::new("nix")) {
let check_args: &[&str] = if check { &["--check"] } else { &[] };
Command::new("nixfmt").args(check_args).arg("--").arg(path).run()?;
}
}
}
Ok(())
}
fn run_lint(nix_enabled: bool) -> Result<()> {
// Run cargo-clippy.
Command::new("cargo")
.args(["clippy", "--all-features", "--all-targets"])
.args(["--", "-Dwarnings"])
.run()?;
if nix_enabled {
// Run markdownlint.
for result in Walk::new("./") {
let entry = result.unwrap();
let path = entry.path();
if path.is_file() && path.extension() == Some(OsStr::new("md")) {
Command::new("markdownlint").arg(path).run()?;
}
}
// Run mandoc with linting enabled.
for result in Walk::new("./man/") {
let entry = result.unwrap();
let path = entry.path();
if path.is_file() && path.extension() == Some(OsStr::new("1")) {
Command::new("mandoc").args(["-man", "-Wall", "-Tlint", "--"]).arg(path).run()?;
}
}
}
Ok(())
}
fn run_msrv(nix_enabled: bool) -> Result<()> {
if nix_enabled {
// Run cargo-msrv.
Command::new("cargo-msrv").arg("verify").run()?;
}
Ok(())
}
fn run_tests(nix_enabled: bool, name: &str) -> Result<()> {
let args: &[&str] = if nix_enabled { &["nextest", "run", "--all-features"] } else { &["test"] };
Command::new("cargo").args(args).args(["--no-fail-fast", "--workspace", "--", name]).run()
}
fn enable_nix() -> bool {
let nix_supported = cfg!(any(target_os = "linux", target_os = "macos"));
if !nix_supported {
return false;
}
let nix_enabled = env::var_os("IN_NIX_SHELL").unwrap_or_default() == "pure";
if nix_enabled {
return true;
}
let nix_detected =
Command::new("nix-shell").arg("--version").status().map(|s| s.success()).unwrap_or(false);
if !nix_detected {
return false;
}
println!("Detected Nix in environment, re-running in Nix.");
let args = env::args();
let cmd = shell_words::join(args);
let status = Command::new("nix-shell")
.args(["--pure", "--run", &cmd, "--", "shell.nix"])
.status()
.unwrap();
process::exit(status.code().unwrap_or(1));
}