Repository: elastic/go-sysinfo (go)

Issue:
cross compile on aix fails
env
GOOS=aix
GOARCH=ppc64

`# github.com/elastic/go-sysinfo/providers/aix
..\..\..\..\go\pkg\mod\github.com\elastic\go-sysinfo@v1.7.1\providers\aix\os_aix.go:36:23: undefined: getKernelVersion
..\..\..\..\go\pkg\mod\github.com\elastic\go-sysinfo@v1.7.1\providers\aix\os_aix.go:42:19: cannot assign error to err in multiple assignment

Pull request description:
Fix build tags on AIX provider
Add a build tag to an AIX file that depends on CGO, but does not directly using `import "C"`. Also add build tags such that ppc64 is explicitly required.

Add cross-compile checks to CI to catch build tag issues.

Update golang.org/x/sys to get a version that support windows/arm64.

Update README with a list of GOOS/GOARCH pairs on which a provider will be registered.

Fixes #106 

Patch:
diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile
index 0c09033..0e8f5ee 100644
--- a/.ci/Jenkinsfile
+++ b/.ci/Jenkinsfile
@@ -37,7 +37,7 @@ pipeline {
         axes {
           axis {
             name 'GO_VERSION'
-            values '1.17.10', '1.18.2'
+            values '1.17.11', '1.18.3'
           }
           axis {
             name 'PLATFORM'
@@ -48,7 +48,7 @@ pipeline {
           exclude {
             axis {
               name 'GO_VERSION'
-              values '1.17.10'
+              values '1.17.11'
             }
             axis {
               name 'PLATFORM'
@@ -58,7 +58,7 @@ pipeline {
           exclude {
             axis {
               name 'GO_VERSION'
-              values '1.18.2'
+              values '1.18.3'
             }
             axis {
               name 'PLATFORM'
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 902c4ef..9b37a7c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,9 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ### Added
 
+- Added the Oracle Linux ("ol") platform to the "redhat" OS family. [#54](https://github.com/elastic/go-sysinfo/issues/54) [#115](https://github.com/elastic/go-sysinfo/pull/115)
+- Added the Linux Mint ("linuxmint") platform to the "debian" OS family. [#52](https://github.com/elastic/go-sysinfo/issues/52)
+
 ### Changed
 
-- Added the Oracle Linux ("ol") platform to "redhat" OS family. [#54](https://github.com/elastic/go-sysinfo/issues/54) [#115](https://github.com/elastic/go-sysinfo/pull/115)
 - Updated module to require Go 1.17. [#111](https://github.com/elastic/go-sysinfo/pull/111)
 - The boot time value for Windows is now rounded to the nearest second to provide a more stable value. [#53](https://github.com/elastic/go-sysinfo/issues/53) [#114](https://github.com/elastic/go-sysinfo/pull/114)
 
@@ -22,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 ### Fixed
 
 - Fix handling of environment variables without values on macOS. [#94](https://github.com/elastic/go-sysinfo/pull/94)
+- Fix build tags on AIX provider such that CGO is required. [#106](https://github.com/elastic/go-sysinfo/issues/106)
 
 ## [1.7.1] - 2021-10-11
 
diff --git a/README.md b/README.md
index 5ca5b61..f7e7c0b 100644
--- a/README.md
+++ b/README.md
@@ -3,7 +3,6 @@
 [![Build Status](https://beats-ci.elastic.co/job/Library/job/go-sysinfo-mbp/job/main/badge/icon)](https://beats-ci.elastic.co/job/Library/job/go-sysinfo-mbp/job/main/)
 [![Go Documentation](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)][godocs]
 
-[travis]: http://travis-ci.org/elastic/go-sysinfo
 [godocs]: http://godoc.org/github.com/elastic/go-sysinfo
 
 go-sysinfo is a library for collecting system information. This includes
@@ -31,24 +30,49 @@ if handleCounter, ok := process.(types.OpenHandleCounter); ok {
 These tables show what methods are implemented as well as the extra interfaces
 that are implemented.
 
-| `Host` Features  | Darwin | Linux | Windows | AIX/ppc64 |
-|------------------|--------|-------|---------|-----------|
-| `Info()`         | x      | x     | x       | x         |
-| `Memory()`       | x      | x     | x       | x         |
-| `CPUTimer`       | x      | x     | x       | x         |
-| `VMStat`         |        | x     |         |           |
-| `NetworkCounters`|        | x     |         |           |
-
-| `Process` Features     | Darwin | Linux | Windows | AIX/ppc64 |
-|------------------------|--------|-------|---------|-----------|
-| `Info()`               | x      | x     | x       | x         |
-| `Memory()`             | x      | x     | x       | x         |
-| `User()`               | x      | x     | x       | x         |
-| `Parent()`             | x      | x     | x       | x         |
-| `CPUTimer`             | x      | x     | x       | x         |
-| `Environment`          | x      | x     |         | x         |
-| `OpenHandleEnumerator` |        | x     |         |           |
-| `OpenHandleCounter`    |        | x     |         |           |
-| `Seccomp`              |        | x     |         |           |
-| `Capabilities`         |        | x     |         |           |
-| `NetworkCounters`      |        | x     |         |           |
+| `Host` Features  | Darwin | Linux | Windows | AIX |
+|------------------|--------|-------|---------|-----|
+| `Info()`         | x      | x     | x       | x   |
+| `Memory()`       | x      | x     | x       | x   |
+| `CPUTimer`       | x      | x     | x       | x   |
+| `VMStat`         |        | x     |         |     |
+| `NetworkCounters`|        | x     |         |     |
+
+| `Process` Features     | Darwin | Linux | Windows | AIX |
+|------------------------|--------|-------|---------|-----|
+| `Info()`               | x      | x     | x       | x   |
+| `Memory()`             | x      | x     | x       | x   |
+| `User()`               | x      | x     | x       | x   |
+| `Parent()`             | x      | x     | x       | x   |
+| `CPUTimer`             | x      | x     | x       | x   |
+| `Environment`          | x      | x     |         | x   |
+| `OpenHandleEnumerator` |        | x     |         |     |
+| `OpenHandleCounter`    |        | x     |         |     |
+| `Seccomp`              |        | x     |         |     |
+| `Capabilities`         |        | x     |         |     |
+| `NetworkCounters`      |        | x     |         |     |
+
+### GOOS / GOARCH Pairs
+
+This table lists the OS and architectures for which a "provider" is implemented.
+
+| GOOS / GOARCH  | Requires CGO | Tested |
+|----------------|--------------|--------|
+| aix/ppc64      | x            |        |
+| darwin/amd64   | x            | x      |
+| darwin/arm64   | x            | x      |
+| linux/386      |              |        |
+| linux/amd64    |              | x      |
+| linux/arm      |              |        |
+| linux/arm64    |              |        |
+| linux/mips     |              |        |
+| linux/mips64   |              |        |
+| linux/mips64le |              |        |
+| linux/mipsle   |              |        |
+| linux/ppc64    |              |        |
+| linux/ppc64le  |              |        |
+| linux/riscv64  |              |        |
+| linux/s390x    |              |        |
+| windows/amd64  |              | x      |
+| windows/arm64  |              |        |
+| windows/arm    |              |        |
diff --git a/go.mod b/go.mod
index 927b953..8ae92f3 100644
--- a/go.mod
+++ b/go.mod
@@ -8,7 +8,7 @@ require (
 	github.com/pkg/errors v0.8.1
 	github.com/prometheus/procfs v0.0.0-20190425082905-87a4384529e0
 	github.com/stretchr/testify v1.3.0
-	golang.org/x/sys v0.0.0-20191025021431-6c3a3bfe00ae
+	golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a
 	howett.net/plist v0.0.0-20181124034731-591f970eefbb
 )
 
diff --git a/go.sum b/go.sum
index 49a2b60..43db4ec 100644
--- a/go.sum
+++ b/go.sum
@@ -18,8 +18,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
 github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
 github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
 golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
-golang.org/x/sys v0.0.0-20191025021431-6c3a3bfe00ae h1:QoJmnb9uyPCrH8GIg9uRLn4Ta45yhcQtpymCd0AavO8=
-golang.org/x/sys v0.0.0-20191025021431-6c3a3bfe00ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k=
+golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
 gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
 gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
diff --git a/providers/aix/boottime_aix.go b/providers/aix/boottime_aix_ppc64.go
similarity index 97%
rename from providers/aix/boottime_aix.go
rename to providers/aix/boottime_aix_ppc64.go
index fee3428..beaaa55 100644
--- a/providers/aix/boottime_aix.go
+++ b/providers/aix/boottime_aix_ppc64.go
@@ -15,6 +15,9 @@
 // specific language governing permissions and limitations
 // under the License.
 
+//go:build aix && ppc64
+// +build aix,ppc64
+
 package aix
 
 import (
diff --git a/providers/aix/doc.go b/providers/aix/doc.go
index 6bc0787..aadec23 100644
--- a/providers/aix/doc.go
+++ b/providers/aix/doc.go
@@ -16,5 +16,5 @@
 // under the License.
 
 // Package aix implements the HostProvider and ProcessProvider interfaces
-// for providing information about MacOS.
+// for providing information about IBM AIX on ppc64.
 package aix
diff --git a/providers/aix/host_aix.go b/providers/aix/host_aix_ppc64.go
similarity index 98%
rename from providers/aix/host_aix.go
rename to providers/aix/host_aix_ppc64.go
index 7fd83d6..36257cb 100644
--- a/providers/aix/host_aix.go
+++ b/providers/aix/host_aix_ppc64.go
@@ -15,6 +15,9 @@
 // specific language governing permissions and limitations
 // under the License.
 
+//go:build aix && ppc64 && cgo
+// +build aix,ppc64,cgo
+
 package aix
 
 /*
diff --git a/providers/aix/kernel_aix.go b/providers/aix/kernel_aix_ppc64.go
similarity index 96%
rename from providers/aix/kernel_aix.go
rename to providers/aix/kernel_aix_ppc64.go
index 3c05ea4..23bc987 100644
--- a/providers/aix/kernel_aix.go
+++ b/providers/aix/kernel_aix_ppc64.go
@@ -15,6 +15,9 @@
 // specific language governing permissions and limitations
 // under the License.
 
+//go:build aix && ppc64 && cgo
+// +build aix,ppc64,cgo
+
 package aix
 
 /*
diff --git a/providers/aix/machineid_aix.go b/providers/aix/machineid_aix_ppc64.go
similarity index 95%
rename from providers/aix/machineid_aix.go
rename to providers/aix/machineid_aix_ppc64.go
index 3d02ddd..1aab374 100644
--- a/providers/aix/machineid_aix.go
+++ b/providers/aix/machineid_aix_ppc64.go
@@ -15,6 +15,9 @@
 // specific language governing permissions and limitations
 // under the License.
 
+//go:build aix && ppc64 && cgo
+// +build aix,ppc64,cgo
+
 package aix
 
 /*
diff --git a/providers/aix/os_aix.go b/providers/aix/os_aix_ppc64.go
similarity index 96%
rename from providers/aix/os_aix.go
rename to providers/aix/os_aix_ppc64.go
index 61863e5..d10476d 100644
--- a/providers/aix/os_aix.go
+++ b/providers/aix/os_aix_ppc64.go
@@ -15,6 +15,9 @@
 // specific language governing permissions and limitations
 // under the License.
 
+//go:build aix && ppc64 && cgo
+// +build aix,ppc64,cgo
+
 package aix
 
 import (
diff --git a/providers/aix/process_aix.go b/providers/aix/process_aix_ppc64.go
similarity index 99%
rename from providers/aix/process_aix.go
rename to providers/aix/process_aix_ppc64.go
index cccb4bd..e586dec 100644
--- a/providers/aix/process_aix.go
+++ b/providers/aix/process_aix_ppc64.go
@@ -15,6 +15,9 @@
 // specific language governing permissions and limitations
 // under the License.
 
+//go:build aix && ppc64 && cgo
+// +build aix,ppc64,cgo
+
 package aix
 
 /*
diff --git a/providers/aix/ztypes_aix_ppc64.go b/providers/aix/ztypes_aix_ppc64.go
index 20c6b24..fb60e7d 100644
--- a/providers/aix/ztypes_aix_ppc64.go
+++ b/providers/aix/ztypes_aix_ppc64.go
@@ -18,6 +18,9 @@
 // Code generated by cmd/cgo -godefs; DO NOT EDIT.
 // cgo -godefs defs_aix.go
 
+//go:build aix && ppc64
+// +build aix,ppc64
+
 package aix
 
 type prcred struct {
diff --git a/providers/linux/os.go b/providers/linux/os.go
index 19ff00c..b040200 100644
--- a/providers/linux/os.go
+++ b/providers/linux/os.go
@@ -51,7 +51,7 @@ var (
 // familyMap contains a mapping of family -> []platforms.
 var familyMap = map[string][]string{
 	"redhat": {"redhat", "fedora", "centos", "scientific", "oraclelinux", "ol", "amzn", "rhel"},
-	"debian": {"debian", "ubuntu", "raspbian"},
+	"debian": {"debian", "ubuntu", "raspbian", "linuxmint"},
 	"suse":   {"suse", "sles", "opensuse"},
 }
 


Test patch:
diff --git a/.ci/scripts/test.sh b/.ci/scripts/test.sh
index 9c7bf56..2924a60 100755
--- a/.ci/scripts/test.sh
+++ b/.ci/scripts/test.sh
@@ -8,6 +8,31 @@ go-licenser -d
 go run .ci/scripts/check_format.go
 go run .ci/scripts/check_lint.go
 
+# Cross-compile checks (only execute on Linux to avoid running this multiple times).
+if [[ $(go env GOOS) == "linux" ]]; then
+# Test that there are no compilation issues when not using CGO. This does
+# not imply that all of these targets are supported without CGO. It's only
+# a sanity check for build tag issues.
+CGO_ENABLED=0 GOOS=aix     GOARCH=ppc64    go build ./...
+CGO_ENABLED=0 GOOS=darwin  GOARCH=amd64    go build ./...
+CGO_ENABLED=0 GOOS=darwin  GOARCH=arm64    go build ./...
+CGO_ENABLED=0 GOOS=linux   GOARCH=386      go build ./...
+CGO_ENABLED=0 GOOS=linux   GOARCH=amd64    go build ./...
+CGO_ENABLED=0 GOOS=linux   GOARCH=arm      go build ./...
+CGO_ENABLED=0 GOOS=linux   GOARCH=arm64    go build ./...
+CGO_ENABLED=0 GOOS=linux   GOARCH=mips     go build ./...
+CGO_ENABLED=0 GOOS=linux   GOARCH=mips64   go build ./...
+CGO_ENABLED=0 GOOS=linux   GOARCH=mips64le go build ./...
+CGO_ENABLED=0 GOOS=linux   GOARCH=mipsle   go build ./...
+CGO_ENABLED=0 GOOS=linux   GOARCH=ppc64    go build ./...
+CGO_ENABLED=0 GOOS=linux   GOARCH=ppc64le  go build ./...
+CGO_ENABLED=0 GOOS=linux   GOARCH=riscv64  go build ./...
+CGO_ENABLED=0 GOOS=linux   GOARCH=s390x    go build ./...
+CGO_ENABLED=0 GOOS=windows GOARCH=amd64    go build ./...
+CGO_ENABLED=0 GOOS=windows GOARCH=arm      go build ./...
+CGO_ENABLED=0 GOOS=windows GOARCH=arm64    go build ./...
+fi
+
 # Run the tests
 set +e
 export OUT_FILE="build/test-report.out"
diff --git a/providers/aix/boottime_test.go b/providers/aix/boottime_aix_ppc64_test.go
similarity index 95%
rename from providers/aix/boottime_test.go
rename to providers/aix/boottime_aix_ppc64_test.go
index c60bc41..73f8a4d 100644
--- a/providers/aix/boottime_test.go
+++ b/providers/aix/boottime_aix_ppc64_test.go
@@ -15,8 +15,8 @@
 // specific language governing permissions and limitations
 // under the License.
 
-//go:build aix
-// +build aix
+//go:build aix && ppc64
+// +build aix,ppc64
 
 package aix
 
diff --git a/providers/linux/os_test.go b/providers/linux/os_test.go
index 422ab02..9d7a342 100644
--- a/providers/linux/os_test.go
+++ b/providers/linux/os_test.go
@@ -131,6 +131,22 @@ func TestOperatingSystem(t *testing.T) {
 		}, *os)
 		t.Logf("%#v", os)
 	})
+	t.Run("linuxmint20", func(t *testing.T) {
+		os, err := getOSInfo("testdata/linuxmint20")
+		if err != nil {
+			t.Fatal(err)
+		}
+		assert.Equal(t, types.OSInfo{
+			Type:     "linux",
+			Family:   "debian",
+			Platform: "linuxmint",
+			Name:     "Linux Mint",
+			Version:  "20 (Ulyana)",
+			Major:    20,
+			Codename: "ulyana",
+		}, *os)
+		t.Logf("%#v", os)
+	})
 	t.Run("redhat7", func(t *testing.T) {
 		os, err := getOSInfo("testdata/redhat7")
 		if err != nil {
diff --git a/providers/linux/testdata/linuxmint20/etc/lsb-release b/providers/linux/testdata/linuxmint20/etc/lsb-release
new file mode 100644
index 0000000..c27d35f
--- /dev/null
+++ b/providers/linux/testdata/linuxmint20/etc/lsb-release
@@ -0,0 +1,4 @@
+DISTRIB_ID=LinuxMint
+DISTRIB_RELEASE=20
+DISTRIB_CODENAME=ulyana
+DISTRIB_DESCRIPTION="Linux Mint 20 Ulyana"
diff --git a/providers/linux/testdata/linuxmint20/etc/os-release b/providers/linux/testdata/linuxmint20/etc/os-release
new file mode 120000
index 0000000..c4c75b4
--- /dev/null
+++ b/providers/linux/testdata/linuxmint20/etc/os-release
@@ -0,0 +1,1 @@
+../usr/lib/os-release
\ No newline at end of file
diff --git a/providers/linux/testdata/linuxmint20/usr/lib/os-release b/providers/linux/testdata/linuxmint20/usr/lib/os-release
new file mode 100644
index 0000000..825d928
--- /dev/null
+++ b/providers/linux/testdata/linuxmint20/usr/lib/os-release
@@ -0,0 +1,12 @@
+NAME="Linux Mint"
+VERSION="20 (Ulyana)"
+ID=linuxmint
+ID_LIKE=ubuntu
+PRETTY_NAME="Linux Mint 20"
+VERSION_ID="20"
+HOME_URL="https://www.linuxmint.com/"
+SUPPORT_URL="https://forums.linuxmint.com/"
+BUG_REPORT_URL="http://linuxmint-troubleshooting-guide.readthedocs.io/en/latest/"
+PRIVACY_POLICY_URL="https://www.linuxmint.com/"
+VERSION_CODENAME=ulyana
+UBUNTU_CODENAME=focal