Skip to content

Commit

Permalink
Merge pull request #504 from KoviRobi/master
Browse files Browse the repository at this point in the history
Draft: Long version & nix flakes
  • Loading branch information
soywod authored Nov 22, 2024
2 parents 53dc4c2 + a0485ff commit 14c77e4
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 19 deletions.
21 changes: 15 additions & 6 deletions .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@ jobs:
fail-fast: false
matrix:
include:
- target: x86_64-linux
- host: x86_64-linux
target: x86_64-linux
os: ubuntu-latest
- target: aarch64-linux
- host: x86_64-linux
target: aarch64-linux
os: ubuntu-latest
- target: x86_64-windows
- host: x86_64-linux
target: x86_64-windows
os: ubuntu-latest
- target: x86_64-darwin
- host: x86_64-darwin
target: x86_64-darwin
os: macos-13
- target: aarch64-darwin
- host: aarch64-darwin
target: aarch64-darwin
os: macos-14
steps:
- name: Checkout code
Expand All @@ -37,7 +42,11 @@ jobs:
extraPullNames: nix-community
- name: Build release
run: |
nix build -L .#${{ matrix.target }}
nix build -L --expr "
(builtins.getFlake \"git+file://${PWD}?shallow=1&rev=$(git rev-parse HEAD)\")
.outputs.packages.${{ matrix.host }}.${{ matrix.target }}.overrideAttrs {
GIT_DESCRIBE = \"$(git describe --always)\";
}"
nix run -L .#${{ matrix.target }} -- --version
- name: Upload release artifacts
uses: actions/upload-artifact@v4
Expand Down
21 changes: 15 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,20 @@ jobs:
fail-fast: false
matrix:
include:
- target: x86_64-linux
- host: x86_64-linux
target: x86_64-linux
os: ubuntu-latest
- target: aarch64-linux
- host: x86_64-linux
target: aarch64-linux
os: ubuntu-latest
- target: x86_64-windows
- host: x86_64-linux
target: x86_64-windows
os: ubuntu-latest
- target: x86_64-darwin
- host: x86_64-darwin
target: x86_64-darwin
os: macos-13
- target: aarch64-darwin
- host: aarch64-darwin
target: aarch64-darwin
os: macos-14
steps:
- name: Checkout code
Expand All @@ -55,7 +60,11 @@ jobs:
extraPullNames: nix-community
- name: Build release archive
run: |
nix build -L .#${{ matrix.target }}
nix build -L --expr "
(builtins.getFlake \"git+file://${PWD}?shallow=1&rev=$(git rev-parse HEAD)\")
.outputs.packages.${{ matrix.host }}.${{ matrix.target }}.overrideAttrs {
GIT_DESCRIBE = \"$(git describe)\";
}"
cp result/himalaya* .
- name: Upload tgz release archive
uses: actions/upload-release-asset@v1
Expand Down
25 changes: 20 additions & 5 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
Expand Down
3 changes: 2 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down
4 changes: 3 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ impl Cli {
env!("TARGET_ENV"),
" ",
env!("TARGET_ARCH"),
", git rev ",
", git ",
env!("GIT_DESCRIBE"),
" rev ",
env!("GIT_REV"),
);
}
Expand Down

0 comments on commit 14c77e4

Please sign in to comment.