aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.build.yml4
-rw-r--r--Cargo.lock355
-rw-r--r--Cargo.toml5
-rw-r--r--xtask/Cargo.toml5
-rw-r--r--xtask/build.rs5
-rw-r--r--xtask/src/main.rs166
6 files changed, 498 insertions, 42 deletions
diff --git a/.build.yml b/.build.yml
index 3aaed11..80c7b87 100644
--- a/.build.yml
+++ b/.build.yml
@@ -21,10 +21,10 @@ tasks:
cd projectr
cargo check --frozen --all-targets --all-features
cargo test --frozen --all-targets --all-features
- git describe --exact-match HEAD > pkgver || complete-build
+ cargo xtask dist --check || complete-build
- package: |
cd projectr
- cargo xtask dist --tag=$(<pkgver) > pkgdist
+ cargo xtask dist > pkgdist
- publish: |
cd projectr
hut git artifact upload $(<pkgdist) --rev=$(<pkgver)
diff --git a/Cargo.lock b/Cargo.lock
index 150534b..0a2a9cf 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -103,6 +103,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
+name = "base64"
+version = "0.21.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "604178f6c5c21f02dc555784810edfb88d34ac2c73b2eae109655649ee73ce3d"
+
+[[package]]
+name = "bincode"
+version = "1.3.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad"
+dependencies = [
+ "serde",
+]
+
+[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -130,12 +145,109 @@ dependencies = [
]
[[package]]
+name = "build-info"
+version = "0.0.31"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8b301350c1c448e35b896f32b68c49c8ecd969a71978fbafc4ebd09ec3f4eee2"
+dependencies = [
+ "build-info-common",
+ "build-info-proc",
+ "once_cell",
+]
+
+[[package]]
+name = "build-info-build"
+version = "0.0.31"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "2b314717755dd6a06fc11ad3f7909ba4c0ae2ab516f5cb0404fe924c71bfc7d0"
+dependencies = [
+ "anyhow",
+ "base64",
+ "bincode",
+ "build-info-common",
+ "cargo_metadata",
+ "chrono",
+ "git2",
+ "glob",
+ "once_cell",
+ "pretty_assertions",
+ "rustc_version",
+ "serde_json",
+ "xz2",
+]
+
+[[package]]
+name = "build-info-common"
+version = "0.0.31"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5e040d36472d40ec9424c36a7b54be589072e605596b6f20b0c56c5230b460cc"
+dependencies = [
+ "chrono",
+ "derive_more",
+ "semver",
+ "serde",
+]
+
+[[package]]
+name = "build-info-proc"
+version = "0.0.31"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ffd5f241ddd417436c48d35da9869480891449ddd1ae3fd483bbcfbae741a422"
+dependencies = [
+ "anyhow",
+ "base64",
+ "bincode",
+ "build-info-common",
+ "chrono",
+ "num-bigint",
+ "num-traits",
+ "proc-macro-error",
+ "proc-macro2",
+ "quote",
+ "serde_json",
+ "syn 2.0.16",
+ "xz2",
+]
+
+[[package]]
name = "bumpalo"
version = "3.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1"
[[package]]
+name = "camino"
+version = "1.1.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c530edf18f37068ac2d977409ed5cd50d53d73bc653c7647b48eb78976ac9ae2"
+dependencies = [
+ "serde",
+]
+
+[[package]]
+name = "cargo-platform"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cbdb825da8a5df079a43676dbe042702f1707b1109f713a01420fbb4cc71fa27"
+dependencies = [
+ "serde",
+]
+
+[[package]]
+name = "cargo_metadata"
+version = "0.15.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "eee4243f1f26fc7a42710e7439c149e2b10b05472f88090acce52632f231a73a"
+dependencies = [
+ "camino",
+ "cargo-platform",
+ "semver",
+ "serde",
+ "serde_json",
+ "thiserror",
+]
+
+[[package]]
name = "cc"
version = "1.0.79"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -159,6 +271,7 @@ dependencies = [
"android-tzdata",
"iana-time-zone",
"num-traits",
+ "serde",
"winapi",
]
@@ -204,7 +317,7 @@ dependencies = [
"heck",
"proc-macro2",
"quote",
- "syn",
+ "syn 2.0.16",
]
[[package]]
@@ -242,6 +355,12 @@ dependencies = [
]
[[package]]
+name = "convert_case"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e"
+
+[[package]]
name = "core-foundation-sys"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -257,6 +376,35 @@ dependencies = [
]
[[package]]
+name = "ctor"
+version = "0.1.26"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6d2301688392eb071b0bf1a37be05c469d3cc4dbbd95df672fe28ab021e6a096"
+dependencies = [
+ "quote",
+ "syn 1.0.109",
+]
+
+[[package]]
+name = "derive_more"
+version = "0.99.17"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321"
+dependencies = [
+ "convert_case",
+ "proc-macro2",
+ "quote",
+ "rustc_version",
+ "syn 1.0.109",
+]
+
+[[package]]
+name = "diff"
+version = "0.1.13"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8"
+
+[[package]]
name = "encode_unicode"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -322,9 +470,9 @@ dependencies = [
[[package]]
name = "git2"
-version = "0.15.0"
+version = "0.17.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2994bee4a3a6a51eb90c218523be382fd7ea09b16380b9312e9dbe955ff7c7d1"
+checksum = "7b989d6a7ca95a362cf2cfc5ad688b3a467be1f87e480b8dad07fee8c79b0044"
dependencies = [
"bitflags",
"libc",
@@ -334,6 +482,12 @@ dependencies = [
]
[[package]]
+name = "glob"
+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"
@@ -448,6 +602,12 @@ dependencies = [
]
[[package]]
+name = "itoa"
+version = "1.0.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6"
+
+[[package]]
name = "jobserver"
version = "0.1.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -479,9 +639,9 @@ checksum = "2b00cc1c228a6782d0f076e7b232802e0c5689d41bb5df366f2a6b6621cfdfe1"
[[package]]
name = "libgit2-sys"
-version = "0.14.2+1.5.1"
+version = "0.15.2+1.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7f3d95f6b51075fe9810a7ae22c7095f12b98005ab364d8544797a825ce946a4"
+checksum = "a80df2e11fb4a61f4ba2ab42dbe7f74468da143f1a75c74e11dee7c813f694fa"
dependencies = [
"cc",
"libc",
@@ -517,6 +677,17 @@ dependencies = [
]
[[package]]
+name = "lzma-sys"
+version = "0.1.20"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5fda04ab3764e6cde78b9974eec4f779acaba7c4e84b36eca3cf77c581b85d27"
+dependencies = [
+ "cc",
+ "libc",
+ "pkg-config",
+]
+
+[[package]]
name = "matchers"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -551,6 +722,27 @@ dependencies = [
]
[[package]]
+name = "num-bigint"
+version = "0.4.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f"
+dependencies = [
+ "autocfg",
+ "num-integer",
+ "num-traits",
+]
+
+[[package]]
+name = "num-integer"
+version = "0.1.45"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9"
+dependencies = [
+ "autocfg",
+ "num-traits",
+]
+
+[[package]]
name = "num-traits"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -561,9 +753,18 @@ dependencies = [
[[package]]
name = "once_cell"
-version = "1.17.1"
+version = "1.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3"
+checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"
+
+[[package]]
+name = "output_vt100"
+version = "0.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "628223faebab4e3e40667ee0b2336d34a5b960ff60ea743ddfdbcf7770bcfb66"
+dependencies = [
+ "winapi",
+]
[[package]]
name = "overload"
@@ -590,6 +791,42 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964"
[[package]]
+name = "pretty_assertions"
+version = "1.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a25e9bcb20aa780fd0bb16b72403a9064d6b3f22f026946029acb941a50af755"
+dependencies = [
+ "ctor",
+ "diff",
+ "output_vt100",
+ "yansi",
+]
+
+[[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 1.0.109",
+ "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.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -669,6 +906,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b833d8d034ea094b1ea68aa6d5c740e0d04bad9d16568d08ba6f76823a114316"
[[package]]
+name = "rustc_version"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366"
+dependencies = [
+ "semver",
+]
+
+[[package]]
name = "rustix"
version = "0.37.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -683,6 +929,12 @@ dependencies = [
]
[[package]]
+name = "ryu"
+version = "1.0.13"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041"
+
+[[package]]
name = "same-file"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -696,12 +948,40 @@ name = "semver"
version = "1.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed"
+dependencies = [
+ "serde",
+]
[[package]]
name = "serde"
version = "1.0.163"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2113ab51b87a539ae008b5c6c02dc020ffa39afd2d83cffcb3f4eb2722cebec2"
+dependencies = [
+ "serde_derive",
+]
+
+[[package]]
+name = "serde_derive"
+version = "1.0.163"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8c805777e3930c8883389c602315a24224bcc738b63905ef87cd1420353ea93e"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.16",
+]
+
+[[package]]
+name = "serde_json"
+version = "1.0.97"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bdf3bf93142acad5821c99197022e170842cdbc1c30482b98750c688c640842a"
+dependencies = [
+ "itoa",
+ "ryu",
+ "serde",
+]
[[package]]
name = "serde_spanned"
@@ -755,6 +1035,17 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "syn"
+version = "1.0.109"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "unicode-ident",
+]
+
+[[package]]
+name = "syn"
version = "2.0.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a6f671d4b5ffdb8eadec19c0ae67fe2639df8684bd7bc4b83d986b8db549cf01"
@@ -776,6 +1067,26 @@ dependencies = [
]
[[package]]
+name = "thiserror"
+version = "1.0.40"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac"
+dependencies = [
+ "thiserror-impl",
+]
+
+[[package]]
+name = "thiserror-impl"
+version = "1.0.40"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn 2.0.16",
+]
+
+[[package]]
name = "thread_local"
version = "1.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -842,7 +1153,7 @@ checksum = "0f57e3ca2a01450b1a921183a9c9cbfda207fd822cef4ccb00a65402cbba7a74"
dependencies = [
"proc-macro2",
"quote",
- "syn",
+ "syn 2.0.16",
]
[[package]]
@@ -941,6 +1252,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
[[package]]
+name = "version_check"
+version = "0.9.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
+
+[[package]]
name = "walkdir"
version = "2.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -971,7 +1288,7 @@ dependencies = [
"once_cell",
"proc-macro2",
"quote",
- "syn",
+ "syn 2.0.16",
"wasm-bindgen-shared",
]
@@ -993,7 +1310,7 @@ checksum = "e128beba882dd1eb6200e1dc92ae6c5dbaa4311aa7bb211ca035779e5efc39f8"
dependencies = [
"proc-macro2",
"quote",
- "syn",
+ "syn 2.0.16",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
@@ -1199,11 +1516,29 @@ name = "xtask"
version = "0.3.2"
dependencies = [
"anyhow",
+ "build-info",
+ "build-info-build",
"chrono",
"clap",
"flate2",
+ "once_cell",
"semver",
"similar-asserts",
"tar",
"toml_edit",
]
+
+[[package]]
+name = "xz2"
+version = "0.1.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "388c44dc09d76f1536602ead6d325eb532f5c122f17782bd57fb47baeeb767e2"
+dependencies = [
+ "lzma-sys",
+]
+
+[[package]]
+name = "yansi"
+version = "0.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec"
diff --git a/Cargo.toml b/Cargo.toml
index 553b686..0e5e141 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,4 +1,5 @@
[workspace]
+resolver = "2"
members = ["xtask"]
[workspace.package]
@@ -26,9 +27,9 @@ license = { workspace = true }
[dependencies]
anyhow = { workspace = true }
clap = { workspace = true, features = ["env"] }
-git2 = { version = "0.15.0", default-features = false, optional = true, features = [
+git2 = { version = "0.17.2", default-features = false, features = [
"vendored-libgit2",
-] }
+], optional = true }
ignore = "0.4.18"
tracing = { version = "0.1.37", features = ["attributes"] }
tracing-subscriber = { version = "0.3.16", features = ["env-filter"] }
diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml
index 1694407..caba05a 100644
--- a/xtask/Cargo.toml
+++ b/xtask/Cargo.toml
@@ -15,6 +15,8 @@ tar = "0.4.38"
flate2 = "1.0.26"
semver = "1.0.17"
toml_edit = { version = "0.19.10", features = ["serde"] }
+build-info = { version = "0.0.31" }
+once_cell = "1.18.0"
[dependencies.chrono]
version = "0.4.26"
@@ -23,3 +25,6 @@ features = ["std", "clock"]
[dev-dependencies]
similar-asserts = "1.4.2"
+
+[build-dependencies]
+build-info-build = "0.0.31"
diff --git a/xtask/build.rs b/xtask/build.rs
new file mode 100644
index 0000000..6755961
--- /dev/null
+++ b/xtask/build.rs
@@ -0,0 +1,5 @@
+fn main() {
+ // Calling `build_info_build::build_script` collects all data and makes it available to
+ // `build_info::build_info!` and `build_info::format!` in the main program.
+ build_info_build::build_script();
+}
diff --git a/xtask/src/main.rs b/xtask/src/main.rs
index 7454bf0..1de4147 100644
--- a/xtask/src/main.rs
+++ b/xtask/src/main.rs
@@ -6,26 +6,40 @@
//! This binary is integrated into the `cargo` command line by using an alias in
//! `.cargo/config`.
-use std::path::PathBuf;
+use std::path::{Path, PathBuf};
+use std::{fs::File, process::Command};
-use anyhow::Result;
+use anyhow::{anyhow, bail, ensure, Context, Result};
+use build_info::BuildInfo;
use clap::{Parser, Subcommand};
-use xtask::{dist, release};
+use flate2::{write::GzEncoder, Compression};
+use once_cell::sync::Lazy;
+use tar::Builder;
+use xtask::release;
+
+const PKG_NAME: &str = "projectr";
+const PKG_VER: &str = env!("CARGO_PKG_VERSION");
+const PKG_INCLUDE: &[&str] = &[
+ "bin/tmux-projectr",
+ "CONTRIBUTING.md",
+ "README.md",
+ "LICENSE",
+];
fn main() -> Result<()> {
let cli = Cli::parse();
- std::env::set_current_dir(cli.directory)?;
-
match cli.command {
- Commands::Dist { tag } => {
- let targz = dist::generate_tar_gz(&cli.profile, tag.as_deref())?;
+ Commands::OutDir => println!("{}", out_dir()?.display()),
+ Commands::Dist { check } => {
+ let version = match version(cli.pre_release) {
+ Ok(_) if check => std::process::exit(0),
+ Err(_) if check => std::process::exit(1),
+ res => res?,
+ };
+ let targz = generate_tar_gz(version)?;
println!("{}", targz.display());
}
- Commands::OutDir => {
- let out_dir = dist::find_out_dir(&cli.profile)?;
- println!("{}", out_dir.display());
- }
Commands::Release(release) => release.run()?,
};
@@ -35,16 +49,12 @@ fn main() -> Result<()> {
#[derive(Debug, Clone, Parser)]
#[command(author, version, about)]
struct Cli {
+ /// Disable version/git tag check and appends `-dev` to the version
+ #[arg(short, long, global = true, required = false)]
+ pre_release: bool,
+
#[command(subcommand)]
command: Commands,
-
- /// Cargo profile to use.
- #[arg(short, long, default_value = "release")]
- profile: String,
-
- /// Change to DIRECTORY before doing anything
- #[arg(short='C', long, default_value_os_t = get_package_dir())]
- directory: PathBuf,
}
#[derive(Debug, Clone, Subcommand)]
@@ -52,19 +62,119 @@ enum Commands {
/// Print the default value of OUT_DIR used by cargo when building the package.
OutDir,
- /// Generate distributable package and print it's path
+ /// Generate distributable package
Dist {
- /// Verify the package version matches the provided tag.
- #[arg(short, long)]
- tag: Option<String>,
+ /// Validate a git tag matching the package version exists and exit.
+ #[arg(short, long, required = false)]
+ check: bool,
},
Release(release::Release),
}
-fn get_package_dir() -> PathBuf {
- std::path::Path::new(&env!("CARGO_MANIFEST_DIR"))
- .parent()
- .unwrap()
- .to_path_buf()
+fn version(pre_release: bool) -> Result<String> {
+ use build_info::VersionControl::Git;
+
+ let BuildInfo {
+ version_control: Some(Git(git)),
+ ..
+ } = build_info() else {
+ bail!("Failed to get version control info.");
+ };
+
+ if pre_release {
+ Ok(format!("{PKG_VER}-dev"))
+ } else if git.tags.contains(&format!("v{PKG_VER}")) {
+ Ok(PKG_VER.to_owned())
+ } else {
+ Err(anyhow!("Failed to find git tag matching package version."))
+ }
+}
+
+fn out_dir() -> Result<PathBuf> {
+ RELEASE_DIR
+ .join("build")
+ .read_dir()
+ .context("Failed to read build directory.")?
+ .flatten()
+ .filter_map(|d| {
+ d.file_name()
+ .to_str()?
+ .starts_with(PKG_NAME)
+ .then(|| d.path().join("invoked.timestamp"))
+ .filter(|p| p.exists())
+ })
+ .reduce(|acc, path_buf| {
+ std::cmp::max_by_key(path_buf, acc, |p| {
+ p.metadata()
+ .and_then(|m| m.modified())
+ .unwrap_or(std::time::SystemTime::UNIX_EPOCH)
+ })
+ })
+ .map(|p| p.with_file_name("out"))
+ .filter(|o| o.exists())
+ .context("Failed to find `out` directory for latest build")
}
+
+fn generate_tar_gz(version: String) -> Result<PathBuf> {
+ let target = build_info::format!("{}", $.target.triple);
+ let dist_pkg = DIST_DIR.join(format!("{PKG_NAME}-v{version}-{target}.tar.gz"));
+
+ let binary = build_binary()?;
+ ensure!(binary.exists(), "Failed to find package binary",);
+
+ let _ = std::fs::remove_dir_all(&*DIST_DIR);
+ std::fs::create_dir_all(&*DIST_DIR)?;
+
+ let tar_gz = File::create(&dist_pkg)?;
+ let enc = GzEncoder::new(tar_gz, Compression::default());
+ let mut tar = Builder::new(enc);
+
+ tar.append_path_with_name(binary, PathBuf::from("bin").join(PKG_NAME))?;
+ tar.append_dir_all(".", out_dir()?)?;
+ PKG_INCLUDE.iter().try_for_each(|p| tar.append_path(p))?;
+
+ tar.into_inner()?.finish()?;
+
+ Ok(dist_pkg)
+}
+
+fn build_binary() -> Result<PathBuf> {
+ let status = Command::new("cargo")
+ .arg("build")
+ .arg("--release")
+ .arg(format!("--package={PKG_NAME}"))
+ .status()
+ .context("Failed to invoke `cargo build`")?;
+
+ anyhow::ensure!(status.success(), "Cargo returned an error");
+
+ let mut binary = RELEASE_DIR.join(PKG_NAME);
+ if cfg!(windows) {
+ binary.set_extension("exe");
+ };
+
+ if let Err(e) = Command::new("strip").arg(&binary).status() {
+ eprintln!("Failed to strip the binary: {}", e)
+ }
+
+ Ok(binary)
+}
+
+static PROJECT_ROOT: Lazy<PathBuf> = Lazy::new(|| {
+ let dir = std::env::current_dir().unwrap_or_else(|_| {
+ Path::new(env!("CARGO_MANIFEST_DIR"))
+ .parent()
+ .unwrap()
+ .to_path_buf()
+ });
+
+ dir.ancestors()
+ .find(|p| p.join(".git").is_dir())
+ .unwrap_or(&dir)
+ .to_path_buf()
+});
+static DIST_DIR: Lazy<PathBuf> = Lazy::new(|| PROJECT_ROOT.join("target").join("dist"));
+static RELEASE_DIR: Lazy<PathBuf> = Lazy::new(|| PROJECT_ROOT.join("target").join("release"));
+
+build_info::build_info!(fn build_info);