Skip to content

Commit

Permalink
use Go 1.18 buildinfo instead of ldflags
Browse files Browse the repository at this point in the history
  • Loading branch information
vito committed Mar 21, 2022
1 parent 5d3092c commit 1b8efda
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 17 deletions.
42 changes: 33 additions & 9 deletions cmd/bass/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,43 @@ package main
import (
"context"
"fmt"
"os"
"runtime/debug"
)

// overridden with ldflags
var Version = "dev"
var Commit = ""
var Date = ""

func version(ctx context.Context) {
version := Version
info, ok := debug.ReadBuildInfo()
if !ok {
fmt.Fprintln(os.Stderr, "impossible: build info unavailable")
os.Exit(1)
}

var rev, date string
var dirty bool
for _, setting := range info.Settings {
switch setting.Key {
case "vcs.revision":
rev = setting.Value
case "vcs.time":
date = setting.Value
case "vcs.modified":
if setting.Value == "true" {
dirty = true
}
}
}

if Date != "" && Commit != "" {
version += " (" + Date + " commit " + Commit + ")"
if dirty && rev != "" {
rev += "*"
}

fmt.Printf("bass %s\n", version)
fmt.Printf("bass\t%s\n", info.Main.Version)

if rev != "" {
fmt.Printf("commit\t%s\n", rev)
}

if date != "" {
fmt.Printf("date\t%s\n", date)
}
}
6 changes: 4 additions & 2 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
{ lib
, pkgs
}:
pkgs.buildGoModule rec {
pkgs.buildGo118Module rec {
name = "bass";
src = ./.;

vendorSha256 = lib.fileContents ./nix/vendorSha256.txt;

nativeBuildInputs = [ pkgs.upx ];
nativeBuildInputs = with pkgs; [
upx
];

buildPhase = ''
make -j
Expand Down
8 changes: 4 additions & 4 deletions flake.lock

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

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
description = "a low fidelity scripting language for building reproducible artifacts";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
nixpkgs.url = "github:NixOS/nixpkgs/master";
flake-utils.url = "github:numtide/flake-utils";
};

Expand Down
2 changes: 1 addition & 1 deletion nix/deps.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pkgs.dockerTools.streamLayeredImage {
# https (for fetching go mods, etc.)
cacert
# go building + testing
go
go_1_18
gcc
gotestsum
# runtime tests
Expand Down

0 comments on commit 1b8efda

Please sign in to comment.