Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/goforj/wire

go 1.19
go 1.22

require (
github.com/fsnotify/fsnotify v1.7.0
Expand All @@ -11,7 +11,9 @@ require (
)

require (
github.com/klauspost/cpuid/v2 v2.2.10 // indirect
github.com/zeebo/xxh3 v1.1.0 // indirect
golang.org/x/mod v0.20.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.23.0 // indirect
golang.org/x/sys v0.30.0 // indirect
)
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/subcommands v1.2.0 h1:vWQspBTo2nEqTUFita5/KeEWlUL8kQObDFbub/EN9oE=
github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk=
github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE=
github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/zeebo/xxh3 v1.1.0 h1:s7DLGDK45Dyfg7++yxI0khrfwq9661w9EN78eP/UZVs=
github.com/zeebo/xxh3 v1.1.0/go.mod h1:IisAie1LELR4xhVinxWS5+zf1lA4p0MW4T+w+W07F5s=
golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0=
golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/tools v0.24.1 h1:vxuHLTNS3Np5zrYoPRpcheASHX/7KiGo+8Y4ZM1J2O8=
golang.org/x/tools v0.24.1/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ=
17 changes: 8 additions & 9 deletions internal/loader/artifact_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ package loader

import (
"bytes"
"crypto/sha256"
"encoding/hex"
"go/token"
"go/types"
"io"
"os"
"path/filepath"
"runtime"
"strconv"

"github.com/zeebo/xxh3"
"golang.org/x/tools/go/gcexportdata"

"github.com/goforj/wire/internal/cachepaths"
Expand Down Expand Up @@ -56,8 +56,8 @@ func loaderArtifactPath(env []string, meta *packageMeta, isLocal bool) (string,
}

func loaderArtifactKey(meta *packageMeta, isLocal bool) (string, error) {
sum := sha256.New()
sum.Write([]byte("wire-loader-artifact-v4\n"))
sum := xxh3.New()
sum.Write([]byte("wire-loader-artifact-v5\n"))
sum.Write([]byte(runtime.Version()))
sum.Write([]byte{'\n'})
sum.Write([]byte(meta.ImportPath))
Expand All @@ -83,22 +83,21 @@ func loaderArtifactKey(meta *packageMeta, isLocal bool) (string, error) {
sum.Write([]byte(meta.Error.Err))
sum.Write([]byte{'\n'})
}
return hex.EncodeToString(sum.Sum(nil)), nil
return strconv.FormatUint(sum.Sum64(), 16), nil
}
if err := hashMetaFiles(sum, metaFiles(meta)); err != nil {
return "", err
}
return hex.EncodeToString(sum.Sum(nil)), nil
return strconv.FormatUint(sum.Sum64(), 16), nil
}

// hashFileContent returns the hex-encoded SHA-256 of the file content.
// hashFileContent returns the hex-encoded xxh3 hash of the file content.
func hashFileContent(path string) (string, error) {
data, err := os.ReadFile(path)
if err != nil {
return "", err
}
h := sha256.Sum256(data)
return hex.EncodeToString(h[:]), nil
return strconv.FormatUint(xxh3.Hash(data), 16), nil
}

// hashMetaFiles writes content-based hashes for each file into sum.
Expand Down
14 changes: 7 additions & 7 deletions internal/loader/discovery_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ package loader

import (
"bytes"
"crypto/sha256"
"encoding/gob"
"encoding/hex"
"go/parser"
"go/token"
"os"
"path/filepath"
"runtime"
"sort"
"strconv"

"github.com/zeebo/xxh3"

"github.com/goforj/wire/internal/cachepaths"
)
Expand Down Expand Up @@ -254,15 +255,15 @@ func fingerprintDiscoveryFile(path string) (discoveryFileFingerprint, bool) {
if err != nil {
return discoveryFileFingerprint{}, false
}
sum := sha256.New()
sum := xxh3.New()
sum.Write([]byte(filepath.Base(path)))
sum.Write([]byte{0})
file, err := parser.ParseFile(token.NewFileSet(), path, src, parser.ImportsOnly|parser.ParseComments)
if err != nil {
sum.Write(src)
return discoveryFileFingerprint{
Path: canonicalLoaderPath(path),
Hash: hex.EncodeToString(sum.Sum(nil)),
Hash: strconv.FormatUint(sum.Sum64(), 16),
}, true
}
if offset := int(file.Package) - 1; offset > 0 && offset <= len(src) {
Expand All @@ -280,7 +281,7 @@ func fingerprintDiscoveryFile(path string) (discoveryFileFingerprint, bool) {
}
return discoveryFileFingerprint{
Path: canonicalLoaderPath(path),
Hash: hex.EncodeToString(sum.Sum(nil)),
Hash: strconv.FormatUint(sum.Sum64(), 16),
}, true
}

Expand All @@ -297,6 +298,5 @@ func hashGob(v interface{}) (string, error) {
if err := gob.NewEncoder(&buf).Encode(v); err != nil {
return "", err
}
sum := sha256.Sum256(buf.Bytes())
return hex.EncodeToString(sum[:]), nil
return strconv.FormatUint(xxh3.Hash(buf.Bytes()), 16), nil
}
Loading
Loading