Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2c032769 authored by Yu Liu's avatar Yu Liu
Browse files

Only add darwin specific rules/variables when building on mac.

To support skipping ninja file writing during incremental build, we
add all the global rules/variable/pools from static sources because
when we restore from cache we don't have the build defs available to
build the globals. This means all the global rules and variables are
added blindly, so we need to exclude these darwin specific ones since
they will fail due to they depends on the tool that only exists on MAC.

Bug: 335718784
Test: local tests and CI
Change-Id: Ife835545f0f76ffaec77e48bdd89ab7384a1b995
parent f2e53400
Loading
Loading
Loading
Loading
+22 −10
Original line number Diff line number Diff line
@@ -156,11 +156,17 @@ var (
		"args")

	// Rule to invoke `strip` (to discard symbols and data from object files) on darwin architecture.
	darwinStrip = pctx.AndroidStaticRule("darwinStrip",
	darwinStrip = func() blueprint.Rule {
		if runtime.GOOS == "darwin" {
			return pctx.AndroidStaticRule("darwinStrip",
				blueprint.RuleParams{
					Command:     "${config.MacStripPath} -u -r -o $out $in",
					CommandDeps: []string{"${config.MacStripPath}"},
				})
		} else {
			return nil
		}
	}()

	// b/132822437: objcopy uses a file descriptor per .o file when called on .a files, which runs the system out of
	// file descriptors on darwin.  Limit concurrent calls to 5 on darwin.
@@ -174,11 +180,17 @@ var (
		}
	}()

	darwinLipo = pctx.AndroidStaticRule("darwinLipo",
	darwinLipo = func() blueprint.Rule {
		if runtime.GOOS == "darwin" {
			return pctx.AndroidStaticRule("darwinLipo",
				blueprint.RuleParams{
					Command:     "${config.MacLipoPath} -create -output $out $in",
					CommandDeps: []string{"${config.MacLipoPath}"},
				})
		} else {
			return nil
		}
	}()

	_ = pctx.SourcePathVariable("archiveRepackPath", "build/soong/scripts/archive_repack.sh")

+28 −25
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ import (
	"fmt"
	"os/exec"
	"path/filepath"
	"runtime"
	"strings"
	"sync"

@@ -73,6 +74,7 @@ var (
)

func init() {
	if runtime.GOOS == "darwin" {
		pctx.VariableFunc("macSdkRoot", func(ctx android.PackageVarContext) string {
			return getMacTools(ctx).sdkRoot
		})
@@ -99,6 +101,7 @@ func init() {

		pctx.StaticVariable("DarwinYasmFlags", "-f macho -m amd64")
	}
}

func MacStripPath(ctx android.PathContext) string {
	return getMacTools(ctx).stripPath
+9 −6
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
package config

import (
	"runtime"
	"strings"

	"android/soong/android"
@@ -35,6 +36,7 @@ func init() {
	registerToolchainFactory(android.Darwin, android.Arm64, darwinArm64ToolchainFactory)
	registerToolchainFactory(android.Darwin, android.X86_64, darwinX8664ToolchainFactory)

	if runtime.GOOS == "darwin" {
		pctx.StaticVariable("DarwinToolchainRustFlags", strings.Join(DarwinRustFlags, " "))
		pctx.StaticVariable("DarwinToolchainLinkFlags", strings.Join(DarwinRustLinkFlags, " "))

@@ -42,6 +44,7 @@ func init() {
		pctx.StaticVariable("DarwinToolchainArm64LinkFlags", strings.Join(darwinArm64Linkflags, " "))
		pctx.StaticVariable("DarwinToolchainX8664RustFlags", strings.Join(darwinX8664Rustflags, " "))
		pctx.StaticVariable("DarwinToolchainX8664LinkFlags", strings.Join(darwinX8664Linkflags, " "))
	}

}