flipped-aurora/gin-vue-admin · error

不支持的目标系统: %s

Error message

不支持的目标系统: %s

What it means

normalizeBuildTarget validates a requested cross-compile target OS against cliBuildGOOSAllowList. If the caller passes a goos value (or the server runtime.GOOS fallback) that is not in the allow list, the build is rejected early instead of letting `go build` fail with a confusing GOOS error. This is an intentional whitelist guard for the CLI binary compile feature.

Source

Thrown at server/plugin/ai/service/sys_cli_build.go:41

)

var (
	cliBuildGOOSAllowList   = map[string]struct{}{"windows": {}, "linux": {}, "darwin": {}}
	cliBuildGOARCHAllowList = map[string]struct{}{"amd64": {}, "arm64": {}}
)

// normalizeBuildTarget 校验并归一化目标平台。空值回退到当前运行平台。
func normalizeBuildTarget(goos, goarch string) (string, string, error) {
	goos = strings.ToLower(strings.TrimSpace(goos))
	goarch = strings.ToLower(strings.TrimSpace(goarch))
	if goos == "" {
		goos = runtime.GOOS
	}
	if goarch == "" {
		goarch = runtime.GOARCH
	}
	if _, ok := cliBuildGOOSAllowList[goos]; !ok {
		return "", "", fmt.Errorf("不支持的目标系统: %s", goos)
	}
	if _, ok := cliBuildGOARCHAllowList[goarch]; !ok {
		return "", "", fmt.Errorf("不支持的目标架构: %s", goarch)
	}
	return goos, goarch, nil
}

// cliBinaryExt 返回目标平台对应的二进制后缀。
func cliBinaryExt(goos string) string {
	if goos == "windows" {
		return ".exe"
	}
	return ""
}

// BuildCliBinary 把指定 CLI 的 manifest 内嵌进 gva 源码副本,交叉编译出一个开箱即用的二进制。
func (s *cliService) BuildCliBinary(ctx context.Context, req autoReq.BuildSysCliBinaryRequest) (string, []byte, error) {
	goos, goarch, err := normalizeBuildTarget(req.GOOS, req.GOARCH)

View on GitHub (pinned to 3136500ef3)

Solutions

  1. Check the requested goos against the allowlist values (typically linux/darwin/windows) and pick a supported one
  2. Fix typos in the goos parameter (e.g. "linux" not "Linux" or "linus")
  3. If the platform genuinely must be supported, add it to cliBuildGOOSAllowList and verify CGO_ENABLED=0 cross-compilation works
  4. Validate user-supplied target OS at the API/frontend layer before invoking the build service

Example fix

// before
svc.BuildCliBinary(cli, manifest, "freebsd", "amd64")
// after
svc.BuildCliBinary(cli, manifest, "linux", "amd64") // goos must be in cliBuildGOOSAllowList
Defensive patterns

Strategy: validation

Validate before calling

var cliBuildGOOSAllowList = map[string]bool{"linux": true, "darwin": true, "windows": true}
if !cliBuildGOOSAllowList[goos] {
    return fmt.Errorf("unsupported GOOS %q; allowed: linux, darwin, windows", goos)
}

Type guard

func isSupportedGOOS(goos string) bool {
    return map[string]bool{"linux": true, "darwin": true, "windows": true}[goos]
}

Try / catch

goos, goarch, err := normalizeBuildTarget(inGoos, inGoarch)
if err != nil {
    return nil, fmt.Errorf("invalid build target: %w", err)
}

Prevention

When it happens

Trigger: Calling BuildCliBinary or BuildCliSkill with an explicit goos value outside the allow list (e.g. "freebsd", "windows95", typo like "darwin2"), or running the server on a GOOS not in the allow list and relying on the runtime.GOOS default.

Common situations: Typoed target OS in build params; attempting to build for an exotic/embedded platform; a server deployed on an unusual OS whose runtime.GOOS isn't whitelisted; API callers passing raw user input for target OS without pre-validation.

Related errors


AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31). Data as JSON: /api/errors/47839968fe956aac. Report an issue: GitHub.