Skip to content

Commit

Permalink
Make git tag a single source of truth for versions, available in comp…
Browse files Browse the repository at this point in the history
…ile-time
  • Loading branch information
maximbaz committed Jan 10, 2025
1 parent 67a6633 commit 8365677
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build.rs export-subst
10 changes: 6 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@ on:

jobs:
test:
name: make test
name: just test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: taiki-e/install-action@just
- run: sudo apt-get update
- run: sudo apt-get -y install v4l-utils libv4l-dev libudev-dev libvulkan-dev libdbus-1-dev
- run: make test
- run: WLUMA_VERSION=0.0.0-ci just test

lint:
name: make lint
name: just lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: taiki-e/install-action@just
- run: sudo apt-get update
- run: sudo apt-get -y install v4l-utils libv4l-dev libudev-dev libvulkan-dev libdbus-1-dev
- run: make lint
- run: WLUMA_VERSION=0.0.0-ci just lint
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/dist
/target
/vendor
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "wluma"
version = "4.6.1"
authors = ["Maxim Baz", "Cyril Levis"]
edition = "2021"
license = "ISC"

[dependencies]
ash = { version = "~0.38", features = ["linked"], default-features = false }
Expand Down
37 changes: 37 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use std::process::Command;

fn main() {
let version = match std::env::var("WLUMA_VERSION") {
Ok(v) => v,
Err(_) => {
let version = "$Format:%(describe)$"; // Replaced by git-archive.
let version = if version.starts_with('$') {
match Command::new("git").args(["describe", "--tags"]).output() {
Ok(o) if o.status.success() => {
String::from_utf8_lossy(&o.stdout).trim().to_string()
}
Ok(o) => panic!("git-describe exited non-zero: {}", o.status),
Err(err) => panic!("failed to execute git-describe: {err}"),
}
} else {
version.to_string()
};

let version = version.strip_prefix('v').unwrap_or(&version);
println!("cargo:rustc-env=WLUMA_VERSION={version}");
version.to_string()
}
};

let parts = version
.split(|c: char| !c.is_ascii_digit())
.collect::<Vec<_>>();

if parts.len() < 3 {
panic!("Unable to parse 'major.minor.patch' from version: {version}");
}

println!("cargo:rustc-env=WLUMA_VERSION_MAJOR={}", parts[0]);
println!("cargo:rustc-env=WLUMA_VERSION_MINOR={}", parts[1]);
println!("cargo:rustc-env=WLUMA_VERSION_PATCH={}", parts[2]);
}
47 changes: 47 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
default: release

app := "wluma"
version := `echo ${WLUMA_VERSION:-$(git describe --tags)}`
vendor-config := """
[source.crates-io]
replace-with = "vendored-sources"
[source.vendored-sources]
directory = "vendor"
"""

release: clean vendor
mkdir -p dist

git -c tar.tar.gz.command="gzip -cn" archive -o "dist/{{app}}-{{version}}.tar.gz" --format tar.gz --prefix "{{app}}-{{version}}/" "{{version}}"

git -c tar.tar.gz.command="gzip -cn" archive -o "dist/{{app}}-{{version}}-vendored.tar.gz" --format tar.gz \
`find vendor -type f -printf '--prefix={{app}}-{{version}}/%h/ --add-file=%p '` \
--add-virtual-file '{{app}}-{{version}}/.cargo/config.toml:{{vendor-config}}' \
--prefix "{{app}}-{{version}}/" "{{version}}"

for file in dist/*; do \
gpg --detach-sign --armor "$file"; \
done

rm -f "dist/{{app}}-{{version}}.tar.gz"

run *args:
cargo run {{args}}

build *args:
cargo build --locked {{args}}

lint:
cargo fmt -- --check
cargo clippy -- -Dwarnings

test:
cargo test --locked

vendor:
cargo vendor vendor

clean:
rm -rf dist
rm -rf vendor
12 changes: 9 additions & 3 deletions src/frame/vulkan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use std::ffi::CString;
use std::ops::Drop;
use std::os::fd::{AsRawFd, FromRawFd, OwnedFd};

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

const FINAL_MIP_LEVEL: u32 = 4; // Don't generate mipmaps beyond this level - GPU is doing too poor of a job averaging the colors
Expand Down Expand Up @@ -37,11 +36,18 @@ pub struct Vulkan {
impl Vulkan {
pub fn new() -> Result<Self, Box<dyn Error>> {
let app_name = CString::new("wluma")?;
let app_version: u32 = vk::make_api_version(
0,
env!("WLUMA_VERSION_MAJOR").parse()?,
env!("WLUMA_VERSION_MINOR").parse()?,
env!("WLUMA_VERSION_PATCH").parse()?,
);

let app_info = vk::ApplicationInfo::default()
.application_name(&app_name)
.application_version(WLUMA_VERSION)
.application_version(app_version)
.engine_name(&app_name)
.engine_version(WLUMA_VERSION)
.engine_version(app_version)
.api_version(VULKAN_VERSION);

let instance_extensions = &[
Expand Down
5 changes: 5 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ mod device_file;
mod frame;
mod predictor;

/// Current app version (determined at compile-time).
pub const VERSION: &str = env!("WLUMA_VERSION");

fn main() {
let panic_hook = std::panic::take_hook();
std::panic::set_hook(Box::new(move |panic_info| {
Expand All @@ -20,6 +23,8 @@ fn main() {
.parse_default_env()
.init();

log::debug!("== wluma v{} ==", VERSION);

let config = match config::load() {
Ok(config) => config,
Err(err) => panic!("Unable to load config: {}", err),
Expand Down

0 comments on commit 8365677

Please sign in to comment.