Skip to content

Commit 69c2b86

Browse files
committed
Make git tag a single source of truth for versions, available in compile-time
1 parent 67a6633 commit 69c2b86

File tree

9 files changed

+108
-9
lines changed

9 files changed

+108
-9
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build.rs export-subst

.github/workflows/ci.yml

+6-4
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,21 @@ on:
77

88
jobs:
99
test:
10-
name: make test
10+
name: just test
1111
runs-on: ubuntu-latest
1212
steps:
1313
- uses: actions/checkout@v3
14+
- uses: taiki-e/install-action@just
1415
- run: sudo apt-get update
1516
- run: sudo apt-get -y install v4l-utils libv4l-dev libudev-dev libvulkan-dev libdbus-1-dev
16-
- run: make test
17+
- run: WLUMA_VERSION=0.0.0-ci just test
1718

1819
lint:
19-
name: make lint
20+
name: just lint
2021
runs-on: ubuntu-latest
2122
steps:
2223
- uses: actions/checkout@v3
24+
- uses: taiki-e/install-action@just
2325
- run: sudo apt-get update
2426
- run: sudo apt-get -y install v4l-utils libv4l-dev libudev-dev libvulkan-dev libdbus-1-dev
25-
- run: make lint
27+
- run: WLUMA_VERSION=0.0.0-ci just lint

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/dist
22
/target
3+
/vendor

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[package]
22
name = "wluma"
3-
version = "4.6.1"
43
authors = ["Maxim Baz", "Cyril Levis"]
54
edition = "2021"
5+
license = "ISC"
66

77
[dependencies]
88
ash = { version = "~0.38", features = ["linked"], default-features = false }

build.rs

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use std::process::Command;
2+
3+
fn main() {
4+
let version = match std::env::var("WLUMA_VERSION") {
5+
Ok(v) => v,
6+
Err(_) => {
7+
let version = "$Format:%(describe)$"; // Replaced by git-archive.
8+
let version = if version.starts_with('$') {
9+
match Command::new("git").args(["describe", "--tags"]).output() {
10+
Ok(o) if o.status.success() => {
11+
String::from_utf8_lossy(&o.stdout).trim().to_string()
12+
}
13+
Ok(o) => panic!("git-describe exited non-zero: {}", o.status),
14+
Err(err) => panic!("failed to execute git-describe: {err}"),
15+
}
16+
} else {
17+
version.to_string()
18+
};
19+
20+
let version = version.strip_prefix('v').unwrap_or(&version);
21+
println!("cargo:rustc-env=WLUMA_VERSION={version}");
22+
version.to_string()
23+
}
24+
};
25+
26+
let parts = version
27+
.split(|c: char| !c.is_ascii_digit())
28+
.collect::<Vec<_>>();
29+
30+
if parts.len() < 3 {
31+
panic!("Unable to parse 'major.minor.patch' from version: {version}");
32+
}
33+
34+
println!("cargo:rustc-env=WLUMA_VERSION_MAJOR={}", parts[0]);
35+
println!("cargo:rustc-env=WLUMA_VERSION_MINOR={}", parts[1]);
36+
println!("cargo:rustc-env=WLUMA_VERSION_PATCH={}", parts[2]);
37+
}

justfile

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
default: release
2+
3+
app := "wluma"
4+
version := `git describe --tags`
5+
vendor-config := """
6+
[source.crates-io]
7+
replace-with = "vendored-sources"
8+
9+
[source.vendored-sources]
10+
directory = "vendor"
11+
"""
12+
13+
release: clean vendor
14+
mkdir -p dist
15+
16+
git -c tar.tar.gz.command="gzip -cn" archive -o "dist/{{app}}-{{version}}.tar.gz" --format tar.gz --prefix "{{app}}-{{version}}/" "{{version}}"
17+
18+
git -c tar.tar.gz.command="gzip -cn" archive -o "dist/{{app}}-{{version}}-vendored.tar.gz" --format tar.gz \
19+
`find vendor -type f -printf '--prefix={{app}}-{{version}}/%h/ --add-file=%p '` \
20+
--add-virtual-file '{{app}}-{{version}}/.cargo/config.toml:{{vendor-config}}' \
21+
--prefix "{{app}}-{{version}}/" "{{version}}"
22+
23+
for file in dist/*; do \
24+
gpg --detach-sign --armor "$file"; \
25+
done
26+
27+
rm -f "dist/{{app}}-{{version}}.tar.gz"
28+
29+
run *args:
30+
cargo run {{args}}
31+
32+
build *args:
33+
cargo build --locked {{args}}
34+
35+
lint:
36+
cargo fmt -- --check
37+
cargo clippy -- -Dwarnings
38+
39+
test:
40+
cargo test --locked
41+
42+
vendor:
43+
cargo vendor vendor
44+
45+
clean:
46+
rm -rf dist
47+
rm -rf vendor

src/frame/vulkan.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use std::ffi::CString;
88
use std::ops::Drop;
99
use std::os::fd::{AsRawFd, FromRawFd, OwnedFd};
1010

11-
const WLUMA_VERSION: u32 = vk::make_api_version(0, 4, 6, 1);
1211
const VULKAN_VERSION: u32 = vk::make_api_version(0, 1, 2, 0);
1312

1413
const FINAL_MIP_LEVEL: u32 = 4; // Don't generate mipmaps beyond this level - GPU is doing too poor of a job averaging the colors
@@ -37,11 +36,18 @@ pub struct Vulkan {
3736
impl Vulkan {
3837
pub fn new() -> Result<Self, Box<dyn Error>> {
3938
let app_name = CString::new("wluma")?;
39+
let app_version: u32 = vk::make_api_version(
40+
0,
41+
env!("WLUMA_VERSION_MAJOR").parse()?,
42+
env!("WLUMA_VERSION_MINOR").parse()?,
43+
env!("WLUMA_VERSION_PATCH").parse()?,
44+
);
45+
4046
let app_info = vk::ApplicationInfo::default()
4147
.application_name(&app_name)
42-
.application_version(WLUMA_VERSION)
48+
.application_version(app_version)
4349
.engine_name(&app_name)
44-
.engine_version(WLUMA_VERSION)
50+
.engine_version(app_version)
4551
.api_version(VULKAN_VERSION);
4652

4753
let instance_extensions = &[

src/main.rs

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ mod device_file;
88
mod frame;
99
mod predictor;
1010

11+
/// Current app version (determined at compile-time).
12+
pub const VERSION: &str = env!("WLUMA_VERSION");
13+
1114
fn main() {
1215
let panic_hook = std::panic::take_hook();
1316
std::panic::set_hook(Box::new(move |panic_info| {
@@ -20,6 +23,8 @@ fn main() {
2023
.parse_default_env()
2124
.init();
2225

26+
log::debug!("== wluma v{} ==", VERSION);
27+
2328
let config = match config::load() {
2429
Ok(config) => config,
2530
Err(err) => panic!("Unable to load config: {}", err),

0 commit comments

Comments
 (0)