mirror of
https://github.com/pimalaya/himalaya.git
synced 2026-06-17 21:37:55 +08:00
Allow passing in GIT_DESCRIBE/GIT_REV to avoid git repo
This should allow building inside a flake
This commit is contained in:
@@ -3,11 +3,26 @@ use std::env;
|
||||
use git2::Repository;
|
||||
|
||||
fn main() {
|
||||
if let Ok(repo) = Repository::open(".") {
|
||||
let head = repo.head().expect("should get git HEAD");
|
||||
let commit = head.peel_to_commit().expect("should get git HEAD commit");
|
||||
println!("cargo::rustc-env=GIT_REV={}", commit.id());
|
||||
}
|
||||
let branch = if let Ok(describe) = env::var("GIT_DESCRIBE") {
|
||||
describe
|
||||
} else {
|
||||
let repo = Repository::open(".").expect("should open git repository");
|
||||
let head = repo.head().expect("should get HEAD");
|
||||
head.shorthand()
|
||||
.expect("should get branch name")
|
||||
.to_string()
|
||||
};
|
||||
println!("cargo::rustc-env=GIT_DESCRIBE={branch}");
|
||||
|
||||
let rev = if let Ok(rev) = env::var("GIT_REV") {
|
||||
rev
|
||||
} else {
|
||||
let repo = Repository::open(".").expect("should open git repository");
|
||||
let head = repo.head().expect("should get HEAD");
|
||||
let commit = head.peel_to_commit().expect("should get HEAD commit");
|
||||
commit.id().to_string()
|
||||
};
|
||||
println!("cargo::rustc-env=GIT_REV={rev}");
|
||||
|
||||
let os = env::var("CARGO_CFG_TARGET_OS").expect("should get CARGO_CFG_TARGET_OS");
|
||||
println!("cargo::rustc-env=TARGET_OS={os}");
|
||||
|
||||
@@ -134,7 +134,8 @@
|
||||
nativeBuildInputs = with pkgs; [ pkg-config ];
|
||||
CARGO_BUILD_TARGET = targetConfig.rustTarget;
|
||||
CARGO_BUILD_RUSTFLAGS = [ "-Ctarget-feature=+crt-static" ];
|
||||
GIT_REV = self.rev or self.dirtyRev or "dirty";
|
||||
GIT_REV = self.rev or self.dirtyRev or "unknown-rev";
|
||||
GIT_DESCRIBE = "flake-" + self.shortRev or self.dirtyShortRev or "unknown";
|
||||
postInstall = ''
|
||||
export WINEPREFIX="$(mktemp -d)"
|
||||
|
||||
|
||||
+3
-1
@@ -84,7 +84,9 @@ impl Cli {
|
||||
env!("TARGET_ENV"),
|
||||
" ",
|
||||
env!("TARGET_ARCH"),
|
||||
", git rev ",
|
||||
", git ",
|
||||
env!("GIT_DESCRIBE"),
|
||||
" rev ",
|
||||
env!("GIT_REV"),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user