Skip to content

Commit

Permalink
cli/build-rs: remove metadata command dependency in favor of env vars
Browse files Browse the repository at this point in the history
When building this project with [Nix/Crane](ipetkov/crane#693), if the `jj-cli` dependency is specified in `Cargo.toml` as a git-based crate, `cargo vendor` splits this workspace up into sub-crate directories, which causes `cargo metadata` to fail when searching for relative deps in the workspace root.

This commit simply changes how the crate version is determined, using Cargo's built-in environment variable [`CARGO_PKG_VERSION`](https://doc.rust-lang.org/cargo/reference/environment-variables.html)
  • Loading branch information
kalebpace authored and martinvonz committed Sep 4, 2024
1 parent 250a28b commit dbb579a
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 56 deletions.
42 changes: 0 additions & 42 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ async-trait = "0.1.82"
backoff = "0.4.0"
blake2 = "0.10.6"
bstr = "1.10.0"
cargo_metadata = "0.17.0"
clap = { version = "4.5.16", features = [
"derive",
"deprecated",
Expand Down
3 changes: 0 additions & 3 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ required-features = ["test-fakes"]
[[test]]
name = "runner"

[build-dependencies]
cargo_metadata = { workspace = true }

[dependencies]
bstr = { workspace = true }
chrono = { workspace = true }
Expand Down
11 changes: 1 addition & 10 deletions cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,11 @@ use std::path::Path;
use std::process::Command;
use std::str;

use cargo_metadata::MetadataCommand;

const GIT_HEAD_PATH: &str = "../.git/HEAD";
const JJ_OP_HEADS_PATH: &str = "../.jj/repo/op_heads/heads";

fn main() -> std::io::Result<()> {
let path = std::env::var("CARGO_MANIFEST_DIR").unwrap();
let meta = MetadataCommand::new()
.manifest_path("./Cargo.toml")
.current_dir(&path)
.exec()
.unwrap();
let root = meta.root_package().unwrap();
let version = &root.version;
let version = std::env::var("CARGO_PKG_VERSION").unwrap();

if Path::new(GIT_HEAD_PATH).exists() {
// In colocated repo, .git/HEAD should reflect the working-copy parent.
Expand Down

0 comments on commit dbb579a

Please sign in to comment.