Skip to content

Commit 4d8a374

Browse files
fix(v3:obfuscation): address CodeRabbit review feedback on garble PR
- Pin garble install to @v0.16.0 in all three platform Taskfiles to avoid incompatibility with Go versions outside the garble-supported range - Normalize obfuscated-output path via filepath.Abs before self-package lookup in resolveObfuscatedOutput, fixing the relative-path bug that caused empty selfPkgPath and invalid self-imports - Reserve "application" alias in buildPackageAliases to prevent alias collision when a service package is also named "application" - Add UnregisterBindingMethodID for test-cleanup and use it in TestRegisteredBindingMethodID to keep the global registry hermetic Fixes coderabbitai review threads 1-4 on PR wailsapp#5337. Co-authored-by: multica-agent <github@multica.ai>
1 parent 5e41b69 commit 4d8a374

6 files changed

Lines changed: 25 additions & 5 deletions

File tree

v3/internal/commands/build_assets/darwin/Taskfile.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ tasks:
4444
- task: common:generate:icons
4545
preconditions:
4646
- sh: '{{if eq .OBFUSCATED "true"}}command -v garble >/dev/null 2>&1{{else}}true{{end}}'
47-
msg: "garble is required for obfuscated builds. Install it with: go install mvdan.cc/garble@latest"
47+
msg: "garble is required for obfuscated builds. Install it with: go install mvdan.cc/garble@v0.16.0 (requires Go 1.24+). See https://github.com/burrowers/garble/releases for version/toolchain compatibility."
4848
cmds:
4949
- '{{if eq .OBFUSCATED "true"}}garble {{.GARBLE_ARGS}} build{{else}}go build{{end}} {{.BUILD_FLAGS}} -o "{{.OUTPUT}}"'
5050
vars:

v3/internal/commands/build_assets/linux/Taskfile.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ tasks:
5555
- task: generate:dotdesktop
5656
preconditions:
5757
- sh: '{{if eq .OBFUSCATED "true"}}command -v garble >/dev/null 2>&1{{else}}true{{end}}'
58-
msg: "garble is required for obfuscated builds. Install it with: go install mvdan.cc/garble@latest"
58+
msg: "garble is required for obfuscated builds. Install it with: go install mvdan.cc/garble@v0.16.0 (requires Go 1.24+). See https://github.com/burrowers/garble/releases for version/toolchain compatibility."
5959
cmds:
6060
- '{{if eq .OBFUSCATED "true"}}garble {{.GARBLE_ARGS}} build{{else}}go build{{end}} {{.BUILD_FLAGS}} -o {{.OUTPUT}}'
6161
vars:

v3/internal/commands/build_assets/windows/Taskfile.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ tasks:
4646
- task: common:generate:icons
4747
preconditions:
4848
- sh: '{{if eq .OBFUSCATED "true"}}command -v garble >/dev/null 2>&1{{else}}true{{end}}'
49-
msg: "garble is required for obfuscated builds. Install it with: go install mvdan.cc/garble@latest"
49+
msg: "garble is required for obfuscated builds. Install it with: go install mvdan.cc/garble@v0.16.0 (requires Go 1.24+). See https://github.com/burrowers/garble/releases for version/toolchain compatibility."
5050
cmds:
5151
- task: generate:syso
5252
vars:

v3/internal/generator/binding_ids.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,14 @@ func (generator *Generator) resolveObfuscatedOutput() (dir, packageName string,
9090
)
9191
}
9292

93-
packageName, err := resolveTargetPackageName(dir)
93+
absDir, err := filepath.Abs(dir)
94+
if err != nil {
95+
generator.logger.Errorf("obfuscated bindings: resolve output dir %s: %v", dir, err)
96+
return "", "", false
97+
}
98+
dir = absDir
99+
100+
packageName, err = resolveTargetPackageName(dir)
94101
if err != nil {
95102
fallback := filepath.Base(dir)
96103
generator.logger.Warningf(
@@ -235,7 +242,9 @@ func writeMetadataInit(buf *bytes.Buffer, registrations []bindingIDRegistration,
235242
// to without an import.
236243
func buildPackageAliases(registrations []bindingIDRegistration, selfPkgPath string) map[string]string {
237244
aliases := make(map[string]string)
238-
used := make(map[string]bool)
245+
used := map[string]bool{
246+
"application": true,
247+
}
239248

240249
seen := make(map[string]string)
241250
var paths []string

v3/pkg/application/bindings.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,16 @@ func RegisterBindingMethodID(method any, id uint32) {
103103
registeredBindingMethodIDs.Store(value.Pointer(), id)
104104
}
105105

106+
// UnregisterBindingMethodID removes the stable binding ID for a service method.
107+
// Intended for use in tests to restore global state after calling RegisterBindingMethodID.
108+
func UnregisterBindingMethodID(method any) {
109+
value := reflect.ValueOf(method)
110+
if value.Kind() != reflect.Func {
111+
return
112+
}
113+
registeredBindingMethodIDs.Delete(value.Pointer())
114+
}
115+
106116
func getRegisteredBindingMethodID(method reflect.Method) (uint32, bool) {
107117
id, ok := registeredBindingMethodIDs.Load(method.Func.Pointer())
108118
if !ok {

v3/pkg/application/bindings_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ func TestRegisteredBindingMethodID(t *testing.T) {
197197
_ = application.New(application.Options{})
198198

199199
application.RegisterBindingMethodID((*TestService).String, stableID)
200+
t.Cleanup(func() { application.UnregisterBindingMethodID((*TestService).String) })
200201

201202
bindings := application.NewBindings(nil, nil)
202203
if err := bindings.Add(application.NewService(&TestService{})); err != nil {

0 commit comments

Comments
 (0)