aboutsummaryrefslogtreecommitdiffstats
path: root/xtask
diff options
context:
space:
mode:
authorToby Vincent <tobyv@tobyvin.dev>2023-07-27 15:24:09 -0500
committerToby Vincent <tobyv@tobyvin.dev>2023-07-27 15:24:09 -0500
commit021b2c00583b71052107cf6f10af3d05e13dbf6c (patch)
tree55e49907be1516f31359e33f53b55f1cd290ecce /xtask
parente141dcda531f7c0f8569d3385bea6f45e6723bd8 (diff)
build: clean up build dependenciesHEADmain
Diffstat (limited to 'xtask')
-rw-r--r--xtask/Cargo.toml13
-rw-r--r--xtask/build.rs10
-rw-r--r--xtask/src/main.rs66
3 files changed, 40 insertions, 49 deletions
diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml
index caba05a..c09cdea 100644
--- a/xtask/Cargo.toml
+++ b/xtask/Cargo.toml
@@ -15,16 +15,5 @@ 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"
-default-features = false
-features = ["std", "clock"]
-
-[dev-dependencies]
-similar-asserts = "1.4.2"
-
-[build-dependencies]
-build-info-build = "0.0.31"
+chrono = { version = "0.4.26", default-features = false, features = ["clock"] }
diff --git a/xtask/build.rs b/xtask/build.rs
index 6755961..e545a5d 100644
--- a/xtask/build.rs
+++ b/xtask/build.rs
@@ -1,5 +1,9 @@
+use std::env;
+
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();
+ println!(
+ "cargo:rustc-env=TARGET={}",
+ &env::var("TARGET").unwrap()
+ );
+ println!("cargo:rerun-if-changed-env=TARGET")
}
diff --git a/xtask/src/main.rs b/xtask/src/main.rs
index 263c281..f4f8f82 100644
--- a/xtask/src/main.rs
+++ b/xtask/src/main.rs
@@ -12,14 +12,14 @@ use std::{
path::{Path, PathBuf},
};
-use anyhow::{anyhow, bail, ensure, Context, Result};
-use build_info::BuildInfo;
+use anyhow::{ensure, Context, Result};
use clap::{Parser, Subcommand, ValueEnum};
use flate2::{write::GzEncoder, Compression};
use once_cell::sync::Lazy;
use semver::{Prerelease, Version};
use tar::Builder;
+const TARGET: &str = env!("TARGET");
const PKG_NAME: &str = "projectr";
const PKG_VER: &str = env!("CARGO_PKG_VERSION");
const PKG_INCLUDE: &[&str] = &[
@@ -29,6 +29,22 @@ const PKG_INCLUDE: &[&str] = &[
"LICENSE",
];
+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"));
+
fn main() -> Result<()> {
let cli = Cli::parse();
@@ -108,21 +124,22 @@ impl std::str::FromStr for Level {
}
fn version(force: bool) -> Result<Version> {
- use build_info::VersionControl::Git;
-
let version: Version = PKG_VER.parse()?;
- let BuildInfo {
- version_control: Some(Git(git)),
- ..
- } = build_info() else {
- bail!("Failed to get version control info.");
- };
-
- if force || git.tags.contains(&format!("v{version}")) {
+ if force {
Ok(version)
} else {
- Err(anyhow!("Failed to find git tag matching package version."))
+ let stdout = Command::new("git")
+ .arg("tag")
+ .arg("--points-at=HEAD")
+ .output()?
+ .stdout;
+
+ String::from_utf8(stdout)?
+ .lines()
+ .any(|s| s == format!("v{version}"))
+ .then_some(version)
+ .context("Failed to find git tag matching package version.")
}
}
@@ -130,7 +147,7 @@ fn out_dir() -> Result<PathBuf> {
RELEASE_DIR
.join("build")
.read_dir()
- .context("Failed to read build directory.")?
+ .context("Failed to read `target/release/build` directory.")?
.flatten()
.filter_map(|d| {
d.file_name()
@@ -152,8 +169,7 @@ fn out_dir() -> Result<PathBuf> {
}
fn generate_tar_gz(version: Version) -> Result<PathBuf> {
- let target = build_info::format!("{}", $.target.triple);
- let dist_pkg = DIST_DIR.join(format!("{PKG_NAME}-v{version}-{target}.tar.gz"));
+ 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",);
@@ -305,21 +321,3 @@ where
Ok(())
}
-
-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);