diff --git a/.ci/packaging.groovy b/.ci/packaging.groovy index 78cae98f82f6..62910a89ad0c 100644 --- a/.ci/packaging.groovy +++ b/.ci/packaging.groovy @@ -211,6 +211,8 @@ def linuxPlatforms() { 'windows/amd64', 'windows/386', 'darwin/amd64' + // TODO(AndersonQ): comment in after the tests pass + // 'darwin/arm64' ].join(' ') } diff --git a/auditbeat/magefile.go b/auditbeat/magefile.go index 6b712d925126..d2d3ddc16e60 100644 --- a/auditbeat/magefile.go +++ b/auditbeat/magefile.go @@ -28,6 +28,7 @@ import ( auditbeat "github.com/elastic/beats/v7/auditbeat/scripts/mage" devtools "github.com/elastic/beats/v7/dev-tools/mage" + "github.com/elastic/beats/v7/dev-tools/mage/target/build" // mage:import "github.com/elastic/beats/v7/dev-tools/mage/target/common" @@ -74,6 +75,13 @@ func CrossBuildGoDaemon() error { return devtools.CrossBuildGoDaemon() } +// AssembleDarwinUniversal merges the darwin/amd64 and darwin/arm64 into a single +// universal binary using `lipo`. It assumes the darwin/amd64 and darwin/arm64 +// were built and only performs the merge. +func AssembleDarwinUniversal() error { + return build.AssembleDarwinUniversal() +} + // Package packages the Beat for distribution. // Use SNAPSHOT=true to build snapshots. // Use PLATFORMS to control the target platforms. diff --git a/dev-tools/mage/common.go b/dev-tools/mage/common.go index fd8c60e5c4e3..3c53c1ddab5f 100644 --- a/dev-tools/mage/common.go +++ b/dev-tools/mage/common.go @@ -235,6 +235,25 @@ func HaveKubectl() error { return nil } +// IsDarwinUniversal indicates whether ot not the darwin/universal should be +// assembled. If both platforms darwin/adm64 and darwin/arm64 are listed, then +// IsDarwinUniversal returns true. +// Note: Platforms might be edited at different moments, therefore it's necessary +// to perform this check on the fly. +func IsDarwinUniversal() bool { + var darwinAMD64, darwinARM64 bool + for _, p := range Platforms { + if p.Name == "darwin/arm64" { + darwinARM64 = true + } + if p.Name == "darwin/amd64" { + darwinAMD64 = true + } + } + + return darwinAMD64 && darwinARM64 +} + // FindReplace reads a file, performs a find/replace operation, then writes the // output to the same file path. func FindReplace(file string, re *regexp.Regexp, repl string) error { @@ -586,7 +605,7 @@ func ParallelCtx(ctx context.Context, fns ...interface{}) { // Parallel runs the given functions in parallel with an upper limit set based // on GOMAXPROCS. func Parallel(fns ...interface{}) { - ParallelCtx(context.Background(), fns...) + ParallelCtx(context.TODO(), fns...) } // funcTypeWrap wraps a valid FuncType to FuncContextError diff --git a/dev-tools/mage/crossbuild.go b/dev-tools/mage/crossbuild.go index a6bdd9324470..11fa3d7853cb 100644 --- a/dev-tools/mage/crossbuild.go +++ b/dev-tools/mage/crossbuild.go @@ -172,7 +172,7 @@ func CrossBuild(options ...CrossBuildOption) error { mg.Deps(func() error { return gotool.Mod.Download() }) } - // Build the magefile for Linux so we can run it inside the container. + // Build the magefile for Linux, so we can run it inside the container. mg.Deps(buildMage) log.Println("crossBuild: Platform list =", params.Platforms) @@ -194,6 +194,33 @@ func CrossBuild(options ...CrossBuildOption) error { // Each build runs in parallel. Parallel(deps...) + + // It needs to run after all the builds, as it needs the darwin binaries. + if err := assembleDarwinUniversal(params); err != nil { + return err + } + + return nil +} + +// assembleDarwinUniversal checks if darwin/amd64 and darwin/arm64 were build, +// if so, it generates a darwin/universal binary that is the merge fo them two. +func assembleDarwinUniversal(params crossBuildParams) error { + if IsDarwinUniversal() { + builder := GolangCrossBuilder{ + // the docker image for darwin/arm64 is the one capable of merging the binaries. + Platform: "darwin/arm64", + Target: "assembleDarwinUniversal", + InDir: params.InDir, + ImageSelector: params.ImageSelector} + if err := builder.Build(); err != nil { + return errors.Wrapf(err, + "failed merging darwin/amd64 and darwin/arm64 into darwin/universal target=%v for platform=%v", + builder.Target, + builder.Platform) + } + } + return nil } @@ -223,6 +250,8 @@ func CrossBuildImage(platform string) (string, error) { tagSuffix = "darwin-debian10" case platform == "darwin/arm64": tagSuffix = "darwin-arm64-debian10" + case platform == "darwin/universal": + tagSuffix = "darwin-arm64-debian10" case platform == "linux/arm64": tagSuffix = "arm" // when it runs on a ARM64 host/worker. diff --git a/dev-tools/mage/pkg.go b/dev-tools/mage/pkg.go index 379042ae1043..b287b5dcc6e5 100644 --- a/dev-tools/mage/pkg.go +++ b/dev-tools/mage/pkg.go @@ -43,8 +43,10 @@ func Package() error { "UseCommunityBeatPackaging, UseElasticBeatPackaging or USeElasticBeatWithoutXPackPackaging first.") } + platforms := updateWithDarwinUniversal(Platforms) + var tasks []interface{} - for _, target := range Platforms { + for _, target := range platforms { for _, pkg := range Packages { if pkg.OS != target.GOOS() || pkg.Arch != "" && pkg.Arch != target.Arch() { continue @@ -112,6 +114,20 @@ func Package() error { return nil } +// updateWithDarwinUniversal checks if darwin/amd64 and darwin/arm64, are listed +// if so, the universal binary was built, then we need to package it as well. +func updateWithDarwinUniversal(platforms BuildPlatformList) BuildPlatformList { + if IsDarwinUniversal() { + platforms = append(platforms, + BuildPlatform{ + Name: "darwin/universal", + Flags: CGOSupported | CrossBuildSupported | Default, + }) + } + + return platforms +} + // isPackageTypeSelected returns true if SelectedPackageTypes is empty or if // pkgType is present on SelectedPackageTypes. It returns false otherwise. func isPackageTypeSelected(pkgType PackageType) bool { diff --git a/dev-tools/mage/pkgtypes.go b/dev-tools/mage/pkgtypes.go index fb87255221d1..a5e9e308a183 100644 --- a/dev-tools/mage/pkgtypes.go +++ b/dev-tools/mage/pkgtypes.go @@ -121,8 +121,10 @@ var OSArchNames = map[string]map[PackageType]map[string]string{ }, "darwin": map[PackageType]map[string]string{ TarGz: map[string]string{ - "386": "x86", - "amd64": "x86_64", + "386": "x86", + "amd64": "x86_64", + "arm64": "aarch64", + "universal": "universal", }, }, "linux": map[PackageType]map[string]string{ @@ -423,12 +425,12 @@ func (s PackageSpec) Evaluate(args ...map[string]interface{}) PackageSpec { } f.Source = filepath.Join(s.packageDir, filepath.Base(f.Target)) - if err = ioutil.WriteFile(createDir(f.Source), []byte(content), 0644); err != nil { + if err = ioutil.WriteFile(CreateDir(f.Source), []byte(content), 0644); err != nil { panic(errors.Wrapf(err, "failed to write file containing content for target=%v", target)) } case f.Template != "": f.Source = filepath.Join(s.packageDir, filepath.Base(f.Template)) - if err := s.ExpandFile(f.Template, createDir(f.Source)); err != nil { + if err := s.ExpandFile(f.Template, CreateDir(f.Source)); err != nil { panic(errors.Wrapf(err, "failed to expand template file for target=%v", target)) } default: @@ -566,7 +568,7 @@ func PackageZip(spec PackageSpec) error { spec.OutputFile = Zip.AddFileExtension(spec.OutputFile) // Write the zip file. - if err := ioutil.WriteFile(createDir(spec.OutputFile), buf.Bytes(), 0644); err != nil { + if err := ioutil.WriteFile(CreateDir(spec.OutputFile), buf.Bytes(), 0644); err != nil { return errors.Wrap(err, "failed to write zip file") } @@ -588,6 +590,27 @@ func PackageTarGz(spec PackageSpec) error { w := tar.NewWriter(buf) baseDir := spec.rootDir() + // Replace the darwin-universal by darwin-x86_64 and darwin-arm64. Also + // keep the other files. + if spec.Name == "elastic-agent" && spec.OS == "darwin" && spec.Arch == "universal" { + newFiles := map[string]PackageFile{} + for filename, pkgFile := range spec.Files { + if strings.Contains(pkgFile.Target, "darwin-universal") && + strings.Contains(pkgFile.Target, "downloads") { + + amdFilename, amdpkgFile := replaceFileArch(filename, pkgFile, "x86_64") + armFilename, armpkgFile := replaceFileArch(filename, pkgFile, "aarch64") + + newFiles[amdFilename] = amdpkgFile + newFiles[armFilename] = armpkgFile + } else { + newFiles[filename] = pkgFile + } + } + + spec.Files = newFiles + } + // Add files to tar. for _, pkgFile := range spec.Files { if pkgFile.Symlink { @@ -632,7 +655,7 @@ func PackageTarGz(spec PackageSpec) error { // Open the output file. log.Println("Creating output file at", spec.OutputFile) - outFile, err := os.Create(createDir(spec.OutputFile)) + outFile, err := os.Create(CreateDir(spec.OutputFile)) if err != nil { return err } @@ -658,6 +681,14 @@ func PackageTarGz(spec PackageSpec) error { return errors.Wrap(CreateSHA512File(spec.OutputFile), "failed to create .sha512 file") } +func replaceFileArch(filename string, pkgFile PackageFile, arch string) (string, PackageFile) { + filename = strings.ReplaceAll(filename, "universal", arch) + pkgFile.Source = strings.ReplaceAll(pkgFile.Source, "universal", arch) + pkgFile.Target = strings.ReplaceAll(pkgFile.Target, "universal", arch) + + return filename, pkgFile +} + // PackageDeb packages a deb file. This requires Docker to execute FPM. func PackageDeb(spec PackageSpec) error { return runFPM(spec, Deb) diff --git a/dev-tools/mage/platforms.go b/dev-tools/mage/platforms.go index f583ed6d02dd..68cddd247f2b 100644 --- a/dev-tools/mage/platforms.go +++ b/dev-tools/mage/platforms.go @@ -35,7 +35,7 @@ var BuildPlatforms = BuildPlatformList{ {"darwin/386", CGOSupported | CrossBuildSupported}, {"darwin/amd64", CGOSupported | CrossBuildSupported | Default}, {"darwin/arm", CGOSupported}, - {"darwin/arm64", CGOSupported}, + {"darwin/arm64", CGOSupported | CrossBuildSupported | Default}, {"dragonfly/amd64", CGOSupported}, {"freebsd/386", CGOSupported}, {"freebsd/amd64", CGOSupported}, @@ -326,13 +326,13 @@ func newPlatformExpression(expr string) (*platformExpression, error) { // NewPlatformList returns a new BuildPlatformList based on given expression. // -// By default the initial set include only the platforms designated as defaults. +// By default, the initial set include only the platforms designated as defaults. // To add additional platforms to list use an addition term that is designated // with a plug sign (e.g. "+netbsd" or "+linux/armv7"). Or you may use "+all" // to change the initial set to include all possible platforms then filter // from there (e.g. "+all linux windows"). // -// The expression can consists of selections (e.g. "linux") and/or +// The expression can consist of selections (e.g. "linux") and/or // removals (e.g."!windows"). Each term can be valid GOOS or a valid GOOS/Arch // pair. // diff --git a/dev-tools/mage/settings.go b/dev-tools/mage/settings.go index fbcc916fbe92..d55a436e2d8d 100644 --- a/dev-tools/mage/settings.go +++ b/dev-tools/mage/settings.go @@ -63,8 +63,8 @@ var ( PLATFORMS = EnvOr("PLATFORMS", "") PACKAGES = EnvOr("PACKAGES", "") - // CrossBuildMountModcache, if true, mounts $GOPATH/pkg/mod into - // the crossbuild images at /go/pkg/mod, read-only. + // CrossBuildMountModcache mounts $GOPATH/pkg/mod into + // the crossbuild images at /go/pkg/mod, read-only, when set to true. CrossBuildMountModcache = true BeatName = EnvOr("BEAT_NAME", filepath.Base(CWD())) diff --git a/dev-tools/mage/target/build/build.go b/dev-tools/mage/target/build/build.go index 4e668fc78691..d0a8b8cf22c0 100644 --- a/dev-tools/mage/target/build/build.go +++ b/dev-tools/mage/target/build/build.go @@ -18,6 +18,11 @@ package build import ( + "fmt" + "os/exec" + + "github.com/magefile/mage/sh" + devtools "github.com/elastic/beats/v7/dev-tools/mage" ) @@ -46,3 +51,28 @@ func CrossBuild() error { func CrossBuildGoDaemon() error { return devtools.CrossBuildGoDaemon() } + +// AssembleDarwinUniversal merges the darwin/amd64 and darwin/arm64 into a single +// universal binary using `lipo`. It's automatically invoked by CrossBuild whenever +// the darwin/amd64 and darwin/arm64 are present. +func AssembleDarwinUniversal() error { + cmd := "lipo" + + if _, err := exec.LookPath(cmd); err != nil { + return fmt.Errorf("'%s' is required to assemble the universal binary: %w", + cmd, err) + } + + var lipoArgs []string + args := []string{ + "build/golang-crossbuild/%s-darwin-universal", + "build/golang-crossbuild/%s-darwin-arm64", + "build/golang-crossbuild/%s-darwin-amd64"} + + for _, arg := range args { + lipoArgs = append(lipoArgs, fmt.Sprintf(arg, devtools.BeatName)) + } + + lipo := sh.RunCmd(cmd, "-create", "-output") + return lipo(lipoArgs...) +} diff --git a/filebeat/magefile.go b/filebeat/magefile.go index c806cf34c67a..4c9f7ea162eb 100644 --- a/filebeat/magefile.go +++ b/filebeat/magefile.go @@ -28,6 +28,7 @@ import ( "github.com/magefile/mage/mg" devtools "github.com/elastic/beats/v7/dev-tools/mage" + "github.com/elastic/beats/v7/dev-tools/mage/target/build" filebeat "github.com/elastic/beats/v7/filebeat/scripts/mage" // mage:import @@ -73,6 +74,13 @@ func CrossBuildGoDaemon() error { return devtools.CrossBuildGoDaemon() } +// AssembleDarwinUniversal merges the darwin/amd64 and darwin/arm64 into a single +// universal binary using `lipo`. It assumes the darwin/amd64 and darwin/arm64 +// were built and only performs the merge. +func AssembleDarwinUniversal() error { + return build.AssembleDarwinUniversal() +} + // Package packages the Beat for distribution. // Use SNAPSHOT=true to build snapshots. // Use PLATFORMS to control the target platforms. diff --git a/libbeat/magefile.go b/libbeat/magefile.go index 937b3f880015..191959e15261 100644 --- a/libbeat/magefile.go +++ b/libbeat/magefile.go @@ -22,6 +22,7 @@ package main import ( devtools "github.com/elastic/beats/v7/dev-tools/mage" + "github.com/elastic/beats/v7/dev-tools/mage/target/build" // mage:import _ "github.com/elastic/beats/v7/dev-tools/mage/target/common" @@ -53,3 +54,10 @@ func Fields() error { func Config() error { return devtools.Config(devtools.ShortConfigType|devtools.ReferenceConfigType, devtools.DefaultConfigFileParams(), ".") } + +// AssembleDarwinUniversal merges the darwin/amd64 and darwin/arm64 into a single +// universal binary using `lipo`. It assumes the darwin/amd64 and darwin/arm64 +// were built and only performs the merge. +func AssembleDarwinUniversal() error { + return build.AssembleDarwinUniversal() +} diff --git a/packetbeat/magefile.go b/packetbeat/magefile.go index 8ebed12122a5..7f1342bea7c5 100644 --- a/packetbeat/magefile.go +++ b/packetbeat/magefile.go @@ -27,6 +27,7 @@ import ( "github.com/magefile/mage/mg" devtools "github.com/elastic/beats/v7/dev-tools/mage" + "github.com/elastic/beats/v7/dev-tools/mage/target/build" packetbeat "github.com/elastic/beats/v7/packetbeat/scripts/mage" // mage:import @@ -72,6 +73,13 @@ func CrossBuildGoDaemon() error { return devtools.CrossBuildGoDaemon() } +// AssembleDarwinUniversal merges the darwin/amd64 and darwin/arm64 into a single +// universal binary using `lipo`. It assumes the darwin/amd64 and darwin/arm64 +// were built and only performs the merge. +func AssembleDarwinUniversal() error { + return build.AssembleDarwinUniversal() +} + // Package packages the Beat for distribution. // Use SNAPSHOT=true to build snapshots. // Use PLATFORMS to control the target platforms. diff --git a/x-pack/auditbeat/magefile.go b/x-pack/auditbeat/magefile.go index 72253937d475..2ccef25bc017 100644 --- a/x-pack/auditbeat/magefile.go +++ b/x-pack/auditbeat/magefile.go @@ -15,6 +15,7 @@ import ( auditbeat "github.com/elastic/beats/v7/auditbeat/scripts/mage" devtools "github.com/elastic/beats/v7/dev-tools/mage" + "github.com/elastic/beats/v7/dev-tools/mage/target/build" // mage:import "github.com/elastic/beats/v7/dev-tools/mage/target/common" @@ -61,6 +62,13 @@ func CrossBuildGoDaemon() error { return devtools.CrossBuildGoDaemon() } +// AssembleDarwinUniversal merges the darwin/amd64 and darwin/arm64 into a single +// universal binary using `lipo`. It assumes the darwin/amd64 and darwin/arm64 +// were built and only performs the merge. +func AssembleDarwinUniversal() error { + return build.AssembleDarwinUniversal() +} + // Package packages the Beat for distribution. // Use SNAPSHOT=true to build snapshots. // Use PLATFORMS to control the target platforms. diff --git a/x-pack/dockerlogbeat/magefile.go b/x-pack/dockerlogbeat/magefile.go index d46106bb356b..6adb7c944d7d 100644 --- a/x-pack/dockerlogbeat/magefile.go +++ b/x-pack/dockerlogbeat/magefile.go @@ -28,7 +28,6 @@ import ( "github.com/pkg/errors" devtools "github.com/elastic/beats/v7/dev-tools/mage" - // mage:import _ "github.com/elastic/beats/v7/dev-tools/mage/target/common" // mage:import @@ -118,7 +117,7 @@ func createContainer(ctx context.Context, cli *client.Client, arch string) error Tags: []string{rootImageName}, Dockerfile: dockerfile, } - //build, wait for output + // build, wait for output buildResp, err := cli.ImageBuild(ctx, buildContext, buildOpts) if err != nil { return errors.Wrap(err, "error building final container image") @@ -201,7 +200,7 @@ func BuildContainer(ctx context.Context) error { return errors.Wrap(err, "error writing exported container") } - //misc prepare operations + // misc prepare operations err = devtools.Copy("config.json", filepath.Join(buildDir, "config.json")) if err != nil { @@ -240,7 +239,7 @@ func Uninstall(ctx context.Context) error { return errors.Wrap(err, "error creating docker client") } - //check to see if we have a plugin we need to remove + // check to see if we have a plugin we need to remove plugins, err := cli.PluginList(ctx, filters.Args{}) if err != nil { return errors.Wrap(err, "error getting list of plugins") @@ -359,7 +358,7 @@ func Build() { mg.SerialDeps(CrossBuild, BuildContainer) } -// GolangCrossBuild build the Beat binary inside of the golang-builder. +// GolangCrossBuild build the Beat binary inside the golang-builder. // Do not use directly, use crossBuild instead. func GolangCrossBuild() error { buildArgs := devtools.DefaultBuildArgs() diff --git a/x-pack/filebeat/magefile.go b/x-pack/filebeat/magefile.go index 499b106a93ef..ca6763d6fe00 100644 --- a/x-pack/filebeat/magefile.go +++ b/x-pack/filebeat/magefile.go @@ -16,6 +16,7 @@ import ( "github.com/magefile/mage/mg" devtools "github.com/elastic/beats/v7/dev-tools/mage" + "github.com/elastic/beats/v7/dev-tools/mage/target/build" filebeat "github.com/elastic/beats/v7/filebeat/scripts/mage" // mage:import @@ -64,6 +65,13 @@ func CrossBuildGoDaemon() error { return devtools.CrossBuildGoDaemon() } +// AssembleDarwinUniversal merges the darwin/amd64 and darwin/arm64 into a single +// universal binary using `lipo`. It assumes the darwin/amd64 and darwin/arm64 +// were built and only performs the merge. +func AssembleDarwinUniversal() error { + return build.AssembleDarwinUniversal() +} + // Package packages the Beat for distribution. // Use SNAPSHOT=true to build snapshots. // Use PLATFORMS to control the target platforms. diff --git a/x-pack/functionbeat/magefile.go b/x-pack/functionbeat/magefile.go index 7a755bc4b875..e4332fcdae34 100644 --- a/x-pack/functionbeat/magefile.go +++ b/x-pack/functionbeat/magefile.go @@ -17,6 +17,7 @@ import ( "github.com/magefile/mage/mg" devtools "github.com/elastic/beats/v7/dev-tools/mage" + "github.com/elastic/beats/v7/dev-tools/mage/target/build" functionbeat "github.com/elastic/beats/v7/x-pack/functionbeat/scripts/mage" // mage:import @@ -140,6 +141,13 @@ func Fields() { mg.Deps(functionbeat.Update.Fields) } // https://github.com/magefile/mage/issues/217. func Config() { mg.Deps(functionbeat.Update.Config) } +// AssembleDarwinUniversal merges the darwin/amd64 and darwin/arm64 into a single +// universal binary using `lipo`. It assumes the darwin/amd64 and darwin/arm64 +// were built and only performs the merge. +func AssembleDarwinUniversal() error { + return build.AssembleDarwinUniversal() +} + // Package packages the Beat for distribution. // Use SNAPSHOT=true to build snapshots. // Use PLATFORMS to control the target platforms. diff --git a/x-pack/libbeat/magefile.go b/x-pack/libbeat/magefile.go index 5e941dc5aa07..3390803d5185 100644 --- a/x-pack/libbeat/magefile.go +++ b/x-pack/libbeat/magefile.go @@ -9,6 +9,7 @@ package main import ( devtools "github.com/elastic/beats/v7/dev-tools/mage" + "github.com/elastic/beats/v7/dev-tools/mage/target/build" // mage:import _ "github.com/elastic/beats/v7/dev-tools/mage/target/common" @@ -33,3 +34,10 @@ func Build() error { func Fields() error { return devtools.GenerateFieldsYAML() } + +// AssembleDarwinUniversal merges the darwin/amd64 and darwin/arm64 into a single +// universal binary using `lipo`. It assumes the darwin/amd64 and darwin/arm64 +// were built and only performs the merge. +func AssembleDarwinUniversal() error { + return build.AssembleDarwinUniversal() +} diff --git a/x-pack/metricbeat/magefile.go b/x-pack/metricbeat/magefile.go index 85f8cf074d29..2ea0e78cd3f1 100644 --- a/x-pack/metricbeat/magefile.go +++ b/x-pack/metricbeat/magefile.go @@ -20,6 +20,7 @@ import ( "github.com/magefile/mage/sh" devtools "github.com/elastic/beats/v7/dev-tools/mage" + "github.com/elastic/beats/v7/dev-tools/mage/target/build" metricbeat "github.com/elastic/beats/v7/metricbeat/scripts/mage" // mage:import @@ -134,6 +135,13 @@ func BuildSystemTestBinary() error { return sh.RunV("go", args...) } +// AssembleDarwinUniversal merges the darwin/amd64 and darwin/arm64 into a single +// universal binary using `lipo`. It assumes the darwin/amd64 and darwin/arm64 +// were built and only performs the merge. +func AssembleDarwinUniversal() error { + return build.AssembleDarwinUniversal() +} + // Package packages the Beat for distribution. // Use SNAPSHOT=true to build snapshots. // Use PLATFORMS to control the target platforms. diff --git a/x-pack/osquerybeat/dev-tools/packaging/packages.yml b/x-pack/osquerybeat/dev-tools/packaging/packages.yml index 1e8c67f1b6f9..74e1162bb5a9 100644 --- a/x-pack/osquerybeat/dev-tools/packaging/packages.yml +++ b/x-pack/osquerybeat/dev-tools/packaging/packages.yml @@ -91,6 +91,14 @@ specs: source: build/golang-crossbuild/{{.BeatName}}-{{.GOOS}}-{{.Platform.Arch}}{{.BinaryExt}} - os: darwin + arch: amd64 + types: [tgz] + spec: + <<: *unix_binary_spec + <<: *elastic_license_for_binaries + + - os: darwin + arch: arm64 types: [tgz] spec: <<: *unix_binary_spec diff --git a/x-pack/osquerybeat/internal/distro/distro.go b/x-pack/osquerybeat/internal/distro/distro.go index 6fd071048474..e3ac226bc3b2 100644 --- a/x-pack/osquerybeat/internal/distro/distro.go +++ b/x-pack/osquerybeat/internal/distro/distro.go @@ -138,6 +138,7 @@ var specs = map[OSArch]Spec{ {"linux", "amd64"}: {"_1.linux_x86_64.tar.gz", osqueryDistroLinuxSHA256, true}, {"linux", "arm64"}: {"_1.linux_aarch64.tar.gz", osqueryDistroLinuxARMSHA256, true}, {"darwin", "amd64"}: {osqueryPkgExt, osqueryDistroDarwinSHA256, false}, + {"darwin", "arm64"}: {osqueryPkgExt, osqueryDistroDarwinSHA256, false}, {"windows", "amd64"}: {osqueryMSIExt, osqueryDistroWindowsSHA256, false}, } diff --git a/x-pack/osquerybeat/magefile.go b/x-pack/osquerybeat/magefile.go index 272d9a70fac9..631b6c39a7ed 100644 --- a/x-pack/osquerybeat/magefile.go +++ b/x-pack/osquerybeat/magefile.go @@ -20,6 +20,7 @@ import ( "github.com/magefile/mage/mg" devtools "github.com/elastic/beats/v7/dev-tools/mage" + "github.com/elastic/beats/v7/dev-tools/mage/target/build" "github.com/elastic/beats/v7/x-pack/osquerybeat/internal/command" "github.com/elastic/beats/v7/x-pack/osquerybeat/internal/distro" osquerybeat "github.com/elastic/beats/v7/x-pack/osquerybeat/scripts/mage" @@ -189,6 +190,13 @@ func CrossBuildGoDaemon() error { return devtools.CrossBuildGoDaemon() } +// AssembleDarwinUniversal merges the darwin/amd64 and darwin/arm64 into a single +// universal binary using `lipo`. It assumes the darwin/amd64 and darwin/arm64 +// were built and only performs the merge. +func AssembleDarwinUniversal() error { + return build.AssembleDarwinUniversal() +} + // Package packages the Beat for distribution. // Use SNAPSHOT=true to build snapshots. // Use PLATFORMS to control the target platforms. diff --git a/x-pack/packetbeat/magefile.go b/x-pack/packetbeat/magefile.go index aed4d9babb3b..99ea3325c4e3 100644 --- a/x-pack/packetbeat/magefile.go +++ b/x-pack/packetbeat/magefile.go @@ -18,6 +18,7 @@ import ( "github.com/magefile/mage/sh" devtools "github.com/elastic/beats/v7/dev-tools/mage" + "github.com/elastic/beats/v7/dev-tools/mage/target/build" packetbeat "github.com/elastic/beats/v7/packetbeat/scripts/mage" //mage:import @@ -116,6 +117,13 @@ func CrossBuildGoDaemon() error { return devtools.CrossBuildGoDaemon() } +// AssembleDarwinUniversal merges the darwin/amd64 and darwin/arm64 into a single +// universal binary using `lipo`. It assumes the darwin/amd64 and darwin/arm64 +// were built and only performs the merge. +func AssembleDarwinUniversal() error { + return build.AssembleDarwinUniversal() +} + // Package packages the Beat for distribution. // Use SNAPSHOT=true to build snapshots. // Use PLATFORMS to control the target platforms.