Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 8, 2025

This PR adds support for FreeBSD and other Unix-like systems (OpenBSD, NetBSD, DragonFly BSD) to the sysutil package, fixing build failures on these platforms.

Problem

The goutil library fails to build on FreeBSD and other Unix systems because platform-specific functions like IsWindows() and OpenURL() are only defined in files for Linux (sysutil_linux.go), Darwin (sysutil_darwin.go), and Windows (sysutil_windows.go). When building on FreeBSD or other Unix variants, these functions are undefined, causing compilation errors:

# github.com/gookit/goutil/sysutil
sysutil/exec.go:74:5: undefined: IsWindows
sysutil/sysenv.go:186:15: undefined: IsWindows
sysutil/sysutil.go:31:44: undefined: OpenURL
sysutil/sysutil.go:34:51: undefined: OpenURL
sysutil/sysutil.go:42:9: undefined: OpenURL

Solution

Created a new sysutil_unix.go file with build constraints //go:build freebsd || openbsd || netbsd || dragonfly that provides implementations for the missing functions:

  • OS Detection Functions: IsWin(), IsWindows(), IsMac(), IsDarwin(), IsLinux() all return false for these Unix systems
  • OpenURL Function: Uses a similar approach to the Linux implementation, trying common browser launchers like xdg-open, x-www-browser, and fallback browsers
  • OsName Variable: Uses runtime.GOOS to return the actual OS name (freebsd, openbsd, netbsd, dragonfly)

Testing

Validated the fix through cross-compilation testing:

  • ✅ FreeBSD builds successfully
  • ✅ OpenBSD builds successfully
  • ✅ NetBSD builds successfully
  • ✅ DragonFly BSD builds successfully
  • ✅ All existing tests continue to pass
  • ✅ No regressions on Linux, Darwin, or Windows

The implementation follows the same patterns as existing platform-specific files and maintains backward compatibility.

Fixes #230.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI changed the title [WIP] goutil fails to build on FreeBSD (missing non-Linux/Unix support) Add FreeBSD/Unix support to sysutil package Sep 8, 2025
Copilot AI requested a review from inhere September 8, 2025 01:25
@inhere inhere marked this pull request as ready for review September 8, 2025 02:36
@inhere inhere merged commit 3da5f32 into master Sep 8, 2025
41 of 43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

goutil fails to build on FreeBSD (missing non-Linux/Unix support)

2 participants