Source file src/internal/platform/supported_test.go

     1  // Copyright 2026 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package platform_test
     6  
     7  import (
     8  	"internal/platform"
     9  	"testing"
    10  )
    11  
    12  func TestMustLinkExternalWithoutHostObj(t *testing.T) {
    13  	for _, tt := range []struct {
    14  		goos, goarch string
    15  		want         bool
    16  	}{
    17  		{"android", "arm64", false},
    18  		{"android", "amd64", true},
    19  		{"android", "386", true},
    20  		{"android", "arm", true},
    21  		{"ios", "arm64", true},
    22  		{"aix", "ppc64", true},
    23  		{"linux", "mips64le", true},
    24  		{"dragonfly", "amd64", true},
    25  		{"linux", "amd64", false},
    26  		{"darwin", "arm64", false},
    27  		{"windows", "amd64", false},
    28  	} {
    29  		if got := platform.MustLinkExternalWithoutHostObj(tt.goos, tt.goarch); got != tt.want {
    30  			t.Errorf("MustLinkExternalWithoutHostObj(%q, %q) = %v, want %v", tt.goos, tt.goarch, got, tt.want)
    31  		}
    32  	}
    33  
    34  	// Without host objects, external linking is always required whenever
    35  	// it is required without cgo, is never required where it is not
    36  	// required with host objects, and otherwise only android/arm64 differs.
    37  	for _, p := range platform.List {
    38  		withoutCgo := platform.MustLinkExternal(p.GOOS, p.GOARCH, false)
    39  		withHostObj := platform.MustLinkExternal(p.GOOS, p.GOARCH, true)
    40  		withoutHostObj := platform.MustLinkExternalWithoutHostObj(p.GOOS, p.GOARCH)
    41  		if withoutCgo && !withoutHostObj {
    42  			t.Errorf("%s: MustLinkExternal(withCgo=false) = true, but MustLinkExternalWithoutHostObj = false", p)
    43  		}
    44  		if withoutHostObj && !withHostObj {
    45  			t.Errorf("%s: MustLinkExternalWithoutHostObj = true, but MustLinkExternal(withCgo=true) = false", p)
    46  		}
    47  		if withoutHostObj != withHostObj && p != (platform.OSArch{GOOS: "android", GOARCH: "arm64"}) {
    48  			t.Errorf("%s: MustLinkExternalWithoutHostObj = %v, MustLinkExternal(withCgo=true) = %v", p, withoutHostObj, withHostObj)
    49  		}
    50  	}
    51  }
    52  

View as plain text