Skip to content

build: use gix to populate build envs#30

Merged
tisonkun merged 3 commits into
mainfrom
gix-for-build
May 7, 2026
Merged

build: use gix to populate build envs#30
tisonkun merged 3 commits into
mainfrom
gix-for-build

Conversation

@tisonkun
Copy link
Copy Markdown
Contributor

@tisonkun tisonkun commented May 7, 2026

No description provided.

tisonkun added 2 commits May 8, 2026 00:04
Signed-off-by: tison <wander4096@gmail.com>
Signed-off-by: tison <wander4096@gmail.com>
@tisonkun tisonkun changed the title build: use gix to populate build envs build: use gix to populate build envs May 7, 2026
Comment thread scopeql/build.rs
Comment on lines +38 to +63
fn is_dirty(repo: &gix::Repository) -> Result<bool, gix::Error> {
let status_platform = repo
.status(gix::progress::Discard)
.map_err(gix::Error::from_error)?;
let status_iter = status_platform
.untracked_files(gix::status::UntrackedFiles::Collapsed)
.into_iter(None)
.map_err(gix::Error::from_error)?;
for item in status_iter {
let item = item.map_err(gix::Error::from_error)?;
let dirty = match item {
gix::status::Item::IndexWorktree(item) => match item {
gix::status::index_worktree::Item::Modification { .. } => true,
gix::status::index_worktree::Item::DirectoryContents { entry, .. } => {
matches!(entry.status, gix::dir::entry::Status::Untracked)
}
gix::status::index_worktree::Item::Rewrite { .. } => true,
},
gix::status::Item::TreeIndex { .. } => true,
};
if dirty {
return Ok(true);
}
};
}

Ok(false)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@Byron FYI this is where I come to GitoxideLabs/gitoxide#2583.

I wrote my own is_dirty to ensure that an untracked file can properly report dirty=true.

Not sure if there are any caveats (on iterating the status platform) I miss. And I'd like to know if it's desired to report as a downstream use case on the GitoxideLabs/gitoxide forum or anywhere else.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for reeling me in.

I wonder why you had to implement your own instead of using gix::Repository::is_dirty().
Maybe there is a genuine bug to be fixed here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes I tried it. Let's move the discussion to a dedicated gix issue - GitoxideLabs/gitoxide#2587

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not sure if there are any caveats (on iterating the status platform) I miss. And I'd like to know if it's desired to report as a downstream use case on the GitoxideLabs/gitoxide forum or anywhere else.

BTW is there a gallery I can submit this use case? Just want to show and tell with other gix users ><

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request replaces the shadow-rs crate with a custom build script implementation using gix to capture build-time metadata, such as Git branch, commit hash, and build timestamps. This change improves build reproducibility and reduces dependencies. The review identified a potential panic in scopeql/src/version.rs when splitting the commit hash, which has been addressed with a suggested fix.

Comment thread scopeql/src/version.rs
Comment thread scopeql/Cargo.toml Outdated
shadow-rs = { version = "2.0.0", default-features = false, features = [
"build",
] }
gix = { version = "0.83.0", default-features = false, features = ["sha1", "status"] }
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@Byron BTW I'd like to know if I can eliminate more dependencies that are not in use.

Generally, they are build-time only deps, so it should be fine to add some. But given that gix provides small crates, I'd like to know whether I should use gix or combine the sub-crates myself. And if I use gix, how can I (or should I) opt out of code I don't need?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

gix is already built so that without features you get basic support for objects and refs, and nothing else. The idea is that with plumbing crates you won't save anything, unless you only use individual ones for specific use-cases.

You could take a look at the crates it pulls in and if these seem to be related to features you don't expect for status, then it could be considered a bug. However, I also recommend not to fixate on one or two crates that you think may not be needed because it's likely that they are and that not including them would also not save time meaningfully.

Overall, I think you can save the time, but looking into it might reveal genuine things to improve, which is always appreciated.

Copy link
Copy Markdown
Contributor Author

@tisonkun tisonkun May 7, 2026

Choose a reason for hiding this comment

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

Thanks for your advice! I'm fine with the current status then.

Signed-off-by: tison <wander4096@gmail.com>
@tisonkun tisonkun merged commit ca4720e into main May 7, 2026
12 checks passed
@tisonkun tisonkun deleted the gix-for-build branch May 7, 2026 23:41
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