Skip to content
Merged
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
1 change: 1 addition & 0 deletions internal/build/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ func (c *context) collectCommonInputs(m *manifestBuilder) {
m.common.Target = c.buildConf.Target
m.common.TargetABI = c.crossCompile.TargetABI
m.common.GoGlobalDCE = c.buildConf.goGlobalDCEEnabled()
m.common.EnableLTOPlugin = c.buildConf.LTOPlugin.Enabled()
m.common.EmitDWARF = shouldEmitDebugInfo(c.buildConf, &c.crossCompile)
m.common.PCLNMode = effectivePCLNMode(c.buildConf).String()

Expand Down
48 changes: 48 additions & 0 deletions internal/build/collect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,54 @@ func TestDevLTOGlobalDCECollectFingerprint(t *testing.T) {
}
}

func TestCollectFingerprintIncludesLTOPlugin(t *testing.T) {
td := t.TempDir()
goFile := filepath.Join(td, "main.go")
if err := os.WriteFile(goFile, []byte("package main"), 0644); err != nil {
t.Fatal(err)
}

collect := func(plugin lto.PassPlugin) *aPackage {
pkg := &aPackage{Package: &packages.Package{
PkgPath: "test/pkg",
GoFiles: []string{goFile},
}}
ctx := &context{
conf: &packages.Config{},
buildConf: &Config{
Goos: "linux",
Goarch: "amd64",
LTO: lto.Full,
LTOPlugin: plugin,
},
crossCompile: crosscompile.Export{LLVMTarget: "x86_64-unknown-linux"},
}
if err := ctx.collectFingerprint(pkg); err != nil {
t.Fatal(err)
}
return pkg
}

withoutPlugin := collect(lto.PassPlugin{})
withPlugin := collect(lto.PassPlugin{Path: "/tmp/LLGOLTOPlugin.so"})
withOtherPluginPath := collect(lto.PassPlugin{Path: "/opt/LLGOLTOPlugin.so"})

if withoutPlugin.Fingerprint == withPlugin.Fingerprint {
t.Fatal("plugin and non-plugin builds should not share a cache fingerprint")
}
if withPlugin.Fingerprint != withOtherPluginPath.Fingerprint {
t.Fatal("plugin path should not affect package cache fingerprint")
}

data, err := decodeManifest(withPlugin.Manifest)
if err != nil {
t.Fatal(err)
}
if data.Common == nil || !data.Common.EnableLTOPlugin {
t.Fatalf("manifest should contain ENABLE_LTO_PLUGIN=true:\n%s", withPlugin.Manifest)
}
}

func TestCollectFingerprintDependencies(t *testing.T) {
td := t.TempDir()

Expand Down
29 changes: 15 additions & 14 deletions internal/build/fingerprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,24 +112,25 @@ func (s *envSection) empty() bool {
}

type commonSection struct {
AbiMode string `yaml:"ABI_MODE,omitempty"`
BuildTags []string `yaml:"BUILD_TAGS,omitempty"`
Target string `yaml:"TARGET,omitempty"`
TargetABI string `yaml:"TARGET_ABI,omitempty"`
GoGlobalDCE bool `yaml:"GO_GLOBAL_DCE,omitempty"`
EmitDWARF bool `yaml:"EMIT_DWARF,omitempty"`
PCLNMode string `yaml:"PCLN_MODE,omitempty"`
CC string `yaml:"CC,omitempty"`
CCFlags []string `yaml:"CCFLAGS,omitempty"`
CFlags []string `yaml:"CFLAGS,omitempty"`
LDFlags []string `yaml:"LDFLAGS,omitempty"`
Linker string `yaml:"LINKER,omitempty"`
ExtraFiles []fileDigest `yaml:"EXTRA_FILES,omitempty"`
AbiMode string `yaml:"ABI_MODE,omitempty"`
BuildTags []string `yaml:"BUILD_TAGS,omitempty"`
Target string `yaml:"TARGET,omitempty"`
TargetABI string `yaml:"TARGET_ABI,omitempty"`
GoGlobalDCE bool `yaml:"GO_GLOBAL_DCE,omitempty"`
EnableLTOPlugin bool `yaml:"ENABLE_LTO_PLUGIN,omitempty"`
EmitDWARF bool `yaml:"EMIT_DWARF,omitempty"`
PCLNMode string `yaml:"PCLN_MODE,omitempty"`
CC string `yaml:"CC,omitempty"`
CCFlags []string `yaml:"CCFLAGS,omitempty"`
CFlags []string `yaml:"CFLAGS,omitempty"`
LDFlags []string `yaml:"LDFLAGS,omitempty"`
Linker string `yaml:"LINKER,omitempty"`
ExtraFiles []fileDigest `yaml:"EXTRA_FILES,omitempty"`
}

func (s *commonSection) empty() bool {
return s.AbiMode == "" && len(s.BuildTags) == 0 && s.Target == "" && s.TargetABI == "" &&
!s.GoGlobalDCE && !s.EmitDWARF && s.PCLNMode == "" && s.CC == "" && len(s.CCFlags) == 0 && len(s.CFlags) == 0 && len(s.LDFlags) == 0 &&
!s.GoGlobalDCE && !s.EnableLTOPlugin && !s.EmitDWARF && s.PCLNMode == "" && s.CC == "" && len(s.CCFlags) == 0 && len(s.CFlags) == 0 && len(s.LDFlags) == 0 &&
s.Linker == "" && len(s.ExtraFiles) == 0
}

Expand Down
Loading