feat(deps): add support for Nix package manager (#116)

This serves as an alternative to Homebrew. It should be much more stable
and cause less headaches over time for automated builds.

There should be no change to the end user experience of using the build
script, as it should still work with and use Homebrew by default.

Additionally, Nix provides older Apple SDKs, allowing us to run against
macOS 11.x SDKs. This allows the resulting Emacs.app builds to be
compatible with macOS 11.x and later versions.

In testing, this seems to be the case on macOS 11.x (x86_64) and macOS
12.x (arm64).
This commit is contained in:
2024-11-25 02:31:47 +00:00
committed by GitHub
parent 2758cc93cb
commit 6e2b9aa44a
17 changed files with 833 additions and 190 deletions

View File

@@ -116,7 +116,6 @@ func NewLicense() License {
return License{}
}
//nolint:goconst
func (s *License) Render() []string {
var l []string

View File

@@ -1,41 +1,65 @@
package osinfo
import (
"os"
"os/exec"
"strconv"
"strings"
)
type OSInfo struct {
Name string `yaml:"name" json:"name"`
Version string `yaml:"version" json:"version"`
Arch string `yaml:"arch" json:"arch"`
Name string `yaml:"name" json:"name"`
Version string `yaml:"version" json:"version"`
SDKVersion string `yaml:"sdk_version" json:"sdk_version"`
Arch string `yaml:"arch" json:"arch"`
}
func New() (*OSInfo, error) {
version, err := exec.Command("sw_vers", "-productVersion").CombinedOutput()
version, err := exec.Command("sw_vers", "-productVersion").Output()
if err != nil {
return nil, err
}
sdkVersion := os.Getenv("MACOSX_DEPLOYMENT_TARGET")
if sdkVersion == "" {
var ver []byte
ver, err = exec.Command("xcrun", "--show-sdk-version").Output()
if err != nil {
return nil, err
}
sdkVersion = string(ver)
}
arch, err := exec.Command("uname", "-m").CombinedOutput()
if err != nil {
return nil, err
}
return &OSInfo{
Name: "macOS",
Version: strings.TrimSpace(string(version)),
Arch: strings.TrimSpace(string(arch)),
Name: "macOS",
Version: strings.TrimSpace(string(version)),
SDKVersion: strings.TrimSpace(sdkVersion),
Arch: strings.TrimSpace(string(arch)),
}, nil
}
// DistinctVersion returns macOS version down to a distinct "major"
// version. For macOS 10.x, this will include the first two numeric parts of the
// version (10.15), while for 11.x and later, the first numeric part is enough
// (11).
// DistinctVersion returns macOS version down to a distinct "major" version. For
// macOS 10.x, this will include the first two numeric parts of the version
// (10.15), while for 11.x and later, the first numeric part is enough (11).
func (s *OSInfo) DistinctVersion() string {
parts := strings.Split(s.Version, ".")
return s.distinctVersion(s.Version)
}
// DistinctSDKVersion returns macOS version down to a distinct "major" version.
// For macOS 10.x, this will include the first two numeric parts of the version
// (10.15), while for 11.x and later, the first numeric part is enough (11).
func (s *OSInfo) DistinctSDKVersion() string {
return s.distinctVersion(s.SDKVersion)
}
func (s *OSInfo) distinctVersion(version string) string {
parts := strings.Split(version, ".")
if n, _ := strconv.Atoi(parts[0]); n >= 11 {
return parts[0]

View File

@@ -95,10 +95,17 @@ func Create(ctx context.Context, opts *Options) (*Plan, error) { //nolint:funlen
releaseName = "Emacs." + version
}
// Attempt to get the macOS SDK version from the environment, if it's not
// available, use the version from the system.
targetMacOSVersion := osInfo.DistinctSDKVersion()
if targetMacOSVersion == "" {
targetMacOSVersion = osInfo.DistinctVersion()
}
buildName := fmt.Sprintf(
"Emacs.%s.%s.%s",
absoluteVersion,
sanitize.String(osInfo.Name+"-"+osInfo.DistinctVersion()),
sanitize.String(osInfo.Name+"-"+targetMacOSVersion),
sanitize.String(osInfo.Arch),
)
diskImage := buildName + ".dmg"

View File

@@ -123,7 +123,7 @@ func signCLIHelper(ctx context.Context, appBundle string, opts *Options) error {
// app bundle itself.
func elnFiles(emacsApp string) ([]string, error) {
var files []string
walkDirFunc := func(path string, d fs.DirEntry, _err error) error {
walkDirFunc := func(path string, d fs.DirEntry, _ error) error {
if d.Type().IsRegular() && strings.HasSuffix(path, ".eln") &&
!strings.Contains(path, ".app/Contents/Frameworks/") {
files = append(files, path)