Skip to content

Various minor fixes and improvements#1

Merged
RMPR merged 8 commits intozivid:masterfrom
Osse:various
Mar 17, 2026
Merged

Various minor fixes and improvements#1
RMPR merged 8 commits intozivid:masterfrom
Osse:various

Conversation

@Osse
Copy link
Contributor

@Osse Osse commented Mar 16, 2026

  • Add top-level Cargo.toml defining workspace

  • Run cargo fmt

  • lager: Fix tests

    Test tests wouldn't compile because of wrong array size.

  • halide-cache: Add crude system test

    This started out as a shell script, but add a very simple Rust wrapper
    in order to be able to call it as cargo test. Rewrite later.

  • lager: Make additional error variant and simplify

    With the extra InvalidAddress variant the Runtime variant does not need
    an optional source error inside it. This makes lager::Error interact
    more nicely with anyhow.

    Leverage the #[from] attribute of thiserror to simplify errors from
    dependent libraries.

  • halide-cache: Use anyhow for top-level errors

    Error propagation because easier and main() easier to read.

  • halide-cache: Be stricter about cache errors

    Comparted to the previous implementation of cache_hit() this one
    attempts to retrieve both the header and object before doing any error
    handling. In the happy path we end up calling both anyway so that's not
    an issue.

    It might not be a good ideea in the future to let cache failures be
    fatal like this, but it helps with development.

  • halide-cache: Collect dependencies in a struct

    Instead of converting things to vector of strings and so on, make a
    simple struct to store the dependency info. Add make_address() to that
    struct to generate the required address directly. We now hash the data
    directly instead of doing hashes of hashes.

    Additionally, generate the 64 bytes directly.

Copy link
Member

@RMPR RMPR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very nice! If you rebase you should be able to build on Windows.

I am not a big fan of the last commit as it most likely breaks the build on Windows, but we will see what the CI says.

Osse added 7 commits March 16, 2026 21:07
Test tests wouldn't compile because of wrong array size.
This started out as a shell script, but add a very simple Rust wrapper
in order to be able to call it as `cargo test`. Rewrite later.
With the extra InvalidAddress variant the Runtime variant does not need
an optional source error inside it. This makes lager::Error interact
more nicely with anyhow.

Leverage the #[from] attribute of thiserror to simplify errors from
dependent libraries.
Error propagation because easier and main() easier to read.
Comparted to the previous implementation of cache_hit() this one
attempts to retrieve both the header and object before doing any error
handling. In the happy path we end up calling both anyway so that's not
an issue.

It might not be a good ideea in the future to let cache failures be
fatal like this, but it helps with development.
@Osse Osse changed the title various Various minor fixes and improvements Mar 16, 2026
@Osse
Copy link
Contributor Author

Osse commented Mar 16, 2026

Looks very nice! If you rebase you should be able to build on Windows.

I am not a big fan of the last commit as it most likely breaks the build on Windows, but we will see what the CI says.

The last, really? Do you actually mean the system test commit? Or perhaps the workspace one? I have no issue removing either one.

@RMPR
Copy link
Member

RMPR commented Mar 17, 2026

The last, really?

Yup, the one that introduces the unix specific extensions

error[E0433]: failed to resolve: could not find `unix` in `os`
 --> halide-cache\src\main.rs:4:14
  |
4 | use std::os::unix::ffi::OsStrExt;
  |              ^^^^ could not find `unix` in `os`
  |
note: found an item that was configured out
 --> /rustc/01f6ddf7588f42ae2d7eb0a2f21d44e8e96674cf\library\std\src\os\mod.rs:29:5
  |
  = note: the item is gated here
note: found an item that was configured out
 --> /rustc/01f6ddf7588f42ae2d7eb0a2f21d44e8e96674cf\library\std\src\os\mod.rs:84:41
  |
  = note: the item is gated here
error[E0599]: no method named `as_bytes` found for reference `&std::ffi::OsStr` in the current scope
  --> halide-cache\src\main.rs:33:45
   |
33 |         hasher.update(self.path.as_os_str().as_bytes());
   |                                             ^^^^^^^^
   |
help: there is a method `as_encoded_bytes` with a similar name
   |
33 |         hasher.update(self.path.as_os_str().as_encoded_bytes());
   |                                                ++++++++
Some errors have detailed explanations: E0433, E0599.
For more information about an error, try `rustc --explain E0433`.
error: could not compile `halide-cache` (bin "halide-cache") due to 2 previous errors
Caused by:

https://github.com/zivid/halide-cache/actions/runs/23163614443/job/67370342216?pr=1

Now that we have CI that actually works.

use clap::Parser;
use lager::{Address, LRU, Lager};
use named_lock::NamedLock;
use std::os::unix::ffi::OsStrExt;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't build on Windows.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't notice it. Using as_encoded_bytes() is good enough for this usecase. No OS-specific traits needed.

Instead of converting things to vector of strings and so on, make a
simple struct to store the dependency info. Add `make_address()` to that
struct to generate the required address directly. We now hash the data
directly instead of doing hashes of hashes.

Additionally, generate the 64 bytes directly.
Copy link
Member

@RMPR RMPR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@RMPR RMPR merged commit 3bb6bc6 into zivid:master Mar 17, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants