Skip to content

Commit 77e79c4

Browse files
authored
Merge pull request #20 from milyin/generate_fix
in the generated file put version and publish=false
2 parents b464a86 + da90246 commit 77e79c4

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

prebindgen-project-root/src/lib.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ use std::path::PathBuf;
77
pub fn get_project_root() -> Result<PathBuf, &'static str> {
88
let project_root = env!("PROJECT_ROOT");
99
if project_root.is_empty() {
10-
let error =
11-
"The crate `prebindgen-project-root` is being used as a Cargo dependency.\n\
12-
Since it is not located inside your workspace, it cannot determine the path to the workspace root.\n\
13-
Please add `prebindgen-project-root` as a member of your workspace and patch dependencies to use it locally.\n\n\
14-
This can be done using the helper tool:\n\n\
10+
let error =
11+
"The crate `prebindgen-project-root` is being used as a regular Cargo dependency.\n\
12+
Because it is not located within your workspace, it cannot determine the path to the workspace root.\n\
13+
Please add `prebindgen-project-root` as a member of your workspace and patch your dependencies to use the local path.\n\n\
14+
You can do this with the helper tool:\n\n\
1515
cargo install prebindgen-project-root\n\
1616
cargo prebindgen-project-root install <path>\n\n\
17-
where `<path>` is the path to your workspace root.\n";
17+
where `<path>` is the path to your workspace root.\n\n\
18+
If the patch is already applied and the error persists, verify the version of the patched crate.";
1819
Err(error)
1920
} else {
2021
Ok(project_root.into())

prebindgen-project-root/src/main.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,22 @@ fn install(input: &Path) -> Result<()> {
8888
// 2) Write Cargo.toml for the local crate (library only)
8989
let local_cargo = local_crate_dir.join("Cargo.toml");
9090
if !local_cargo.exists() {
91-
let cargo_toml = r#"[package]
91+
// Use this binary's package version for the generated crate version.
92+
let version = env!("CARGO_PKG_VERSION");
93+
let cargo_toml = format!(
94+
r#"[package]
9295
name = "prebindgen-project-root"
96+
version = "{version}"
9397
edition = "2021"
9498
license = "MIT OR Apache-2.0"
9599
description = "Utility to expose the workspace project root at build time"
100+
publish = false
96101
97102
[build-dependencies]
98103
project-root = "0.2"
99104
quote = "1"
100-
"#;
105+
"#
106+
);
101107
fs::write(&local_cargo, cargo_toml)
102108
.with_context(|| format!("writing {}", local_cargo.display()))?;
103109
}

prebindgen-project-root/tests/install_standalone.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,7 @@ fn cargo_run_and_assert_workspace(dir: &Path, pkg: Option<&str>) {
166166
eprintln!("[test] program printed: {}", printed);
167167
eprintln!("[test] expected root : {}", expected_str);
168168
assert_eq!(
169-
printed,
170-
expected_str,
169+
printed, expected_str,
171170
"printed workspace root does not match expected"
172171
);
173172
}

0 commit comments

Comments
 (0)