bcacheup: port to jamespfennell/xz, which is a wrapper around the C LZMA library rather than a Go reimplementation

This commit is contained in:
Luke Granger-Brown 2023-01-14 22:07:14 +00:00
parent e92bff517c
commit aae1c8bea0
5 changed files with 36 additions and 12 deletions

View file

@ -16,8 +16,8 @@ import (
"sync"
"time"
"github.com/jamespfennell/xz"
"github.com/numtide/go-nix/nixbase32"
"github.com/ulikunitz/xz"
"gocloud.dev/blob"
"golang.org/x/sync/errgroup"
"golang.org/x/sync/singleflight"
@ -236,10 +236,7 @@ func (u *uploader) uploadContent(ctx context.Context, ni *narinfo.NarInfo, path
fileByteCounter := &byteCounterWriter{}
xzWriter, err := xz.NewWriter(io.MultiWriter(fileHasher, fileByteCounter, dst))
if err != nil {
return fmt.Errorf("creating xz writer: %v", err)
}
xzWriter := xz.NewWriter(io.MultiWriter(fileHasher, fileByteCounter, dst))
w := io.MultiWriter(narHasher, xzWriter)
narSize, err := nar.Pack(w, nar.DirFS(u.storePath), filepath.Base(path))

View file

@ -14,7 +14,7 @@ depot.third_party.buildGo.program {
third_party.gopkgs."gocloud.dev".blob.gcsblob
third_party.gopkgs."golang.org".x.sync.errgroup
third_party.gopkgs."golang.org".x.sync.singleflight
third_party.gopkgs."github.com".ulikunitz.xz
third_party.gopkgs."github.com".jamespfennell.xz
go.nix.nar
go.nix.nar.narinfo
go.nix.nixstore

View file

@ -0,0 +1,18 @@
# SPDX-FileCopyrightText: 2022 Luke Granger-Brown <depot@lukegb.com>
#
# SPDX-License-Identifier: Apache-2.0
{ depot, pkgs, ... }:
depot.third_party.buildGo.external {
path = "github.com/jamespfennell/xz";
src = depot.third_party.nixpkgs.fetchFromGitHub {
owner = "jamespfennell";
repo = "xz";
rev = "v0.1.2";
hash = "sha256:0wdxda81zvzvxvkxazkn48qlw62nhyc4am9vj2yvv9ncas4gp7av";
};
cgo = true;
cgodeps = [ pkgs.lzma ];
cgocflags = [ "-DGOXZ_SKIP_C_COMPILATION" ];
cgoldflags = [ "-llzma" ];
}

View file

@ -50,7 +50,7 @@ let
last = l: elemAt l ((length l) - 1);
toPackage = self: src: path: depMap: entry: cgodeps:
toPackage = self: src: path: depMap: entry: cgodeps: cgocflags: cgoldflags:
let
localDeps = map
(d: lib.attrByPath (d ++ [ "gopkg" ])
@ -79,7 +79,9 @@ let
sfiles = map (f: src + ("/" + f)) entry.sfiles;
cgofiles = map (f: src + ("/" + f)) entry.cgofiles;
inherit cgodeps;
inherit (entry) packageName cgocflags cgoldflags;
cgocflags = entry.cgocflags ++ cgocflags;
cgoldflags = entry.cgoldflags ++ cgoldflags;
inherit (entry) packageName;
cfiles = map (f: src + ("/" + f)) entry.cfiles;
cxxfiles = map (f: src + ("/" + f)) entry.cxxfiles;
};
@ -91,7 +93,7 @@ let
if entry.isCommand then (program binArgs) else (package libArgs);
in
{ src, path, deps ? [ ], tags ? [ ], cgo ? false, cgodeps ? [ ] }:
{ src, path, deps ? [ ], tags ? [ ], cgo ? false, cgodeps ? [ ], cgocflags ? [ ], cgoldflags ? [ ] }:
let
# Build a map of dependencies (from their import paths to their
# derivation) so that they can be conditionally imported only in
@ -110,5 +112,5 @@ let
analysis = fromJSON (readFile analysisOutput);
in
lib.fix (self: foldl' lib.recursiveUpdate { } (
map (entry: mkset entry.locator (toPackage self src path depMap entry cgodeps)) analysis
map (entry: mkset entry.locator (toPackage self src path depMap entry cgodeps cgocflags cgoldflags)) analysis
))

View file

@ -87,6 +87,13 @@ func findGoDirs(at string) ([]string, error) {
return goDirs, nil
}
func forceEmpty[T any](m []T) []T {
if m == nil {
return make([]T, 0)
}
return m
}
// analysePackage loads and analyses the imports of a single Go
// package, returning the data that is required by the Nix code to
// generate a derivation for this package.
@ -153,8 +160,8 @@ func analysePackage(root, source, importpath string, stdlib map[string]bool, tag
LocalDeps: local,
ForeignDeps: foreign,
IsCommand: p.IsCommand(),
CgoCFLAGS: p.CgoCFLAGS,
CgoLDFLAGS: p.CgoLDFLAGS,
CgoCFLAGS: forceEmpty(p.CgoCFLAGS),
CgoLDFLAGS: forceEmpty(p.CgoLDFLAGS),
}, nil
}