Closed daniejstriata closed 1 year ago
Oh sh. And I know I'll fall into this one again, the project's structure is too painful...
Where is the version of a cli set in a rust project? When you build it or in the code?
For most projects, everything is built from one Cargo.toml version. But for dysk, in order to be able to automatically build a man page, I had to split it with most of the code in a sub project. It means I have to set the version at 4 places (in 2 Cargo.toml files).
I'll probably need to set up something like a git hook to check they're equal...
In retrospect, the automatic man page wasn't worth the pain
This should be fixed at most places now (not when you use crates.io, ie cargo install dysk
).
Please don't close the issue, I need to set up a reliable solution to avoid this problem on next deploys.
Made the build impossible when a version is different:
For most projects, everything is built from one Cargo.toml version. But for dysk, in order to be able to automatically build a man page, I had to split it with most of the code in a sub project. It means I have to set the version at 4 places (in 2 Cargo.toml files).
That weird haha.
That weird haha.
Yeah. If you find a cleaner way to generate the man page, it's welcome
What about using environment variables during the build process to inject the version information?
in Cargo.toml
[package]
name = "project"
version = "0.1.0" # Placeholder version
Use Environment Variables
use std::env;
fn main() {
// Fetch the version environment variable, defaulting to a fallback if not set
let version = env::var("PROJECT_VERSION").unwrap_or_else(|_| "unknown".to_string());
println!("Building version: {}", version);
// The rest of your build logic
}
Can you then build it with cargo like this?
export PROJECT_VERSION="1.2.3"
cargo build
@daniejstriata The Cargo.toml file is used in all kind of processes and tools, it should stay correct. I should rather look for another man page generator when I have some free time.
@daniejstriata The Cargo.toml file is used in all kind of processes and tools, it should stay correct. I should rather for another man page generator when I have some free time.
That makes sense. Thanks.
Hint for bored FOSS authors: there's some market for a convenient man page generator for rust projects ;)
The
--version
output is still 2.7.2 instead of 2.8.0.