mirror of
https://github.com/goreleaser/nfpm
synced 2026-11-30 14:04:45 +01:00
Three packagers for macOS, built in pure Go on any platform: - pkg: an installer package (.pkg) from contents and the preinstall and postinstall scripts, as a product archive that declares its architecture. - app: an application bundle delivered as a zip (.app.zip), with a generated Info.plist. - dmg: the same bundle in a disk image (.dmg) next to a link to the Applications folder. app and dmg share the new "app" settings; pkg has its own. All three take name, version, arch and contents from the shared fields, can be signed with a PKCS#12 identity, and report the shared settings macOS has no place for instead of dropping them silently. Refs #535, #536. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
61 lines
1.7 KiB
Go
61 lines
1.7 KiB
Go
// Package macos holds what the macOS packagers (app, dmg and pkg) share:
|
|
// architecture names, path comparison and the handling of shared settings
|
|
// macOS has no place for.
|
|
package macos
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// The architectures a macOS package can be built for.
|
|
const (
|
|
ArchARM64 = "arm64"
|
|
ArchX8664 = "x86_64"
|
|
ArchUniversal = "universal"
|
|
)
|
|
|
|
// nolint: gochecknoglobals
|
|
var archToMacOS = map[string]string{
|
|
"amd64": ArchX8664,
|
|
"x86_64": ArchX8664,
|
|
"arm64": ArchARM64,
|
|
"aarch64": ArchARM64,
|
|
"all": ArchUniversal,
|
|
"universal": ArchUniversal,
|
|
}
|
|
|
|
// ResolveArch returns the architecture a package is built for, in macOS
|
|
// nomenclature. An explicit format-specific value (set through field, for
|
|
// example "pkg.arch") wins and must already be one of the macOS names;
|
|
// otherwise the shared arch is mapped. macOS runs on exactly two
|
|
// architectures, so anything else is an error instead of a package that
|
|
// declares the wrong one.
|
|
func ResolveArch(field, explicit, shared string) (string, error) {
|
|
if explicit != "" {
|
|
switch explicit {
|
|
case ArchARM64, ArchX8664, ArchUniversal:
|
|
return explicit, nil
|
|
default:
|
|
return "", fmt.Errorf(
|
|
"package %s %q is not supported: use %s, %s or %s",
|
|
field, explicit, ArchARM64, ArchX8664, ArchUniversal)
|
|
}
|
|
}
|
|
if arch, ok := archToMacOS[strings.ToLower(shared)]; ok {
|
|
return arch, nil
|
|
}
|
|
return "", fmt.Errorf(
|
|
"package arch %q is not supported by macOS: use amd64, arm64 or all, or set %s",
|
|
shared, field)
|
|
}
|
|
|
|
// HostArchitectures lists the machine architectures an (already resolved)
|
|
// package architecture runs on.
|
|
func HostArchitectures(arch string) []string {
|
|
if arch == ArchUniversal {
|
|
return []string{ArchARM64, ArchX8664}
|
|
}
|
|
return []string{arch}
|
|
}
|