Skip to content
Open
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
29 changes: 29 additions & 0 deletions v2/internal/system/system.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package system

import (
"bytes"
"fmt"
"log"
"os/exec"
"strings"

Expand Down Expand Up @@ -122,6 +125,32 @@ func checkLibrary(name string) func() *packagemanager.Dependency {
output, _, _ := shell.RunCommand(".", "pkg-config", "--cflags", name)
installed := len(strings.TrimSpace(output)) > 0

// As a fallback, attempt to look for presence of the library using find
if !installed {
pattern := fmt.Sprintf("%s*.so*", name)

// Use the shell to keep the globbing (/usr/lib*, /lib*)
cmdStr := fmt.Sprintf(
`find /usr/lib* /lib* -type f -name %q`,
pattern,
)

cmd := exec.Command("sh", "-c", cmdStr)

var out bytes.Buffer
cmd.Stdout = &out
cmd.Stderr = nil

if err := cmd.Run(); err != nil {
log.Printf("error running sh -c: %v", err)
}

raw := strings.TrimSpace(out.String())
if raw != "" {
installed = true
}
}
Comment on lines +128 to +152

@coderabbitai coderabbitai Bot Jan 4, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Add platform guard for Linux-only fallback.

According to the PR objectives, this fallback is intended for Linux only and does not apply to Windows or macOS. However, the code lacks a platform check and will execute on all operating systems. On Windows and macOS, the paths /usr/lib* and /lib* don't exist in the expected form, causing unnecessary command failures.

🔎 Suggested fix to add platform guard
 	// As a fallback, attempt to look for presence of the library using find
 	if !installed {
+		// Only attempt filesystem fallback on Linux
+		if runtime.GOOS != "linux" {
+			return &packagemanager.Dependency{
+				Name:           "lib" + name + " ",
+				PackageName:    "N/A",
+				Installed:      false,
+				InstallCommand: "Install via your package manager",
+				Version:        "N/A",
+				Optional:       false,
+				External:       false,
+			}
+		}
+
 		pattern := fmt.Sprintf("%s*.so*", name)
 
 		// We'll use the shell to keep the globbing (/usr/lib*, /lib*) and pipeline.

Note: You'll also need to add "runtime" to the imports at the top of the file.

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In v2/internal/system/system.go around lines 128 to 152, the fallback that runs
a shell find over /usr/lib* and /lib* must only run on Linux; add a platform
guard using runtime.GOOS (import "runtime") and only execute the shell+find
branch when runtime.GOOS == "linux". Leave the existing logic untouched for
other OSes, and ensure the function returns or skips the fallback early when not
linux so the find command is not invoked on Windows or macOS.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is only called on Linux so your suggestion is irrelevant

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash

# Find where checkLibrary is called in the codebase
echo "=== Finding checkLibrary invocations ==="
rg -n "checkLibrary" --type=go -C5

echo -e "\n=== Checking for OS-specific logic in system package ==="
# Look for runtime.GOOS checks in the system package
rg -n "runtime\.GOOS|build.*linux|build.*darwin|build.*windows" v2/internal/system/ --type=go -C3

echo -e "\n=== Looking for discover method implementation ==="
# Find the discover method that might have OS-specific dependency checking
ast-grep --pattern $'func ($$$) discover() $$$'

Length of output: 9747


🏁 Script executed:

#!/bin/bash

# Also check for any build tags in the system package files
echo "=== Checking for build tags in system package ==="
fd --type f --extension go . v2/internal/system/ --exec head -3 {}

echo -e "\n=== Looking at dependency list population ==="
# Find where Dependencies are populated
rg -n "Dependencies.*=" v2/internal/system/ --type=go -C5

Length of output: 3541


@symball, you're absolutely right, and I apologize for the incorrect suggestion.

I've verified that checkLibrary is only called from system_linux.go (lines 58-59), which has //go:build linux build constraints. This means the function will never execute on Windows or macOS, even though it's defined in the shared system.go file. The Go build system ensures the call sites are only compiled for Linux.

The runtime platform guard would be redundant. Thank you for the clarification!


🧬 Code Graph Analysis Results

[v2/internal/system/packagemanager/packagemanager.go:59-101]
func Dependencies(p PackageManager) (DependencyList, error) {

var dependencies DependencyList

for name, packages := range p.Packages() {
	dependency := &Dependency{Name: name}
	for _, pkg := range packages {
		dependency.Optional = pkg.Optional
		dependency.External = !pkg.SystemPackage
		dependency.InstallCommand = p.InstallCommand(pkg)
		packageavailable, err := p.PackageAvailable(pkg)
		if err != nil {
			return nil, err
		}
		if packageavailable {
			dependency.Version = pkg.Version
			dependency.PackageName = pkg.Name
			installed, err := p.PackageInstalled(pkg)
			if err != nil {
				return nil, err
			}
			if installed {
				dependency.Installed = true
				dependency.Version = pkg.Version
				if !pkg.SystemPackage {
					dependency.Version = AppVersion(name)
				}
			} else {
				dependency.InstallCommand = p.InstallCommand(pkg)
			}
			break
		}
	}
	dependencies = append(dependencies, dependency)
}

// Sort dependencies
sort.Slice(dependencies, func(i, j int) bool {
	return dependencies[i].Name < dependencies[j].Name
})

return dependencies, nil

}

[v2/internal/system/packagemanager/pm.go:16-22]
PackageManager interface {
Name() string
Packages() packagemap
PackageInstalled(pkg *Package) (bool, error)
PackageAvailable(pkg *Package) (bool, error)
InstallCommand(pkg *Package) string
}

[v2/internal/system/operatingsystem/os.go:4-9]
OS struct {
ID string
Name string
Version string
Branding string
}

[v2/internal/shell/shell.go:9-15]
Command struct {
command string
args []string
env []string
dir string
stdo, stde bytes.Buffer
}


[v2/internal/shell/shell.go:63-65]
func RunCommand(directory string, command string, args ...string) (string, string, error) {
return RunCommandWithEnv(nil, directory, command, args...)
}


✏️ Learnings added
Learnt from: symball
Repo: wailsapp/wails PR: 4853
File: v2/internal/system/system.go:128-152
Timestamp: 2026-01-04T08:01:00.038Z
Learning: In the wails repository, v2/internal/system/system.go contains shared functions like checkLibrary that are defined without build tags, but these functions are only invoked from platform-specific files (system_linux.go, system_windows.go, system_darwin.go) that have appropriate build constraints. The build tags on the calling files ensure platform-specific behavior without needing runtime checks.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


return &packagemanager.Dependency{
Name: "lib" + name + " ",
PackageName: "N/A",
Expand Down
1 change: 1 addition & 0 deletions website/src/pages/changelog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed link to CoC in Community Guide when there was a trailing slash by @agilgur5 in [#4732](https://github.com/wailsapp/wails/pull/4732)
- Fixed indentation in "How does it work?" page by @agilgur5 in [#4733](https://github.com/wailsapp/wails/pull/4733)
- Updated wails installation documentation to allow copying the `install wails` command with one click by @tilak999 in [#4692](https://github.com/wailsapp/wails/pull/4692)
- Added fallback code path in checkLibrary if pkg-config couldn't detect the installation which uses find to hunt through /lib and /usr/lib [#4853](https://github.com/wailsapp/wails/pull/4853)

## v2.11.0 - 2025-11-08

Expand Down
Loading