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
diff --git a/rust/config/darwin_host.go b/rust/config/darwin_host.go
index a4bc187..df8c6ac 100644
--- a/rust/config/darwin_host.go
+++ b/rust/config/darwin_host.go
@@ -15,6 +15,7 @@
package config
import (
+ "runtime"
"strings"
"android/soong/android"
@@ -35,13 +36,15 @@
registerToolchainFactory(android.Darwin, android.Arm64, darwinArm64ToolchainFactory)
registerToolchainFactory(android.Darwin, android.X86_64, darwinX8664ToolchainFactory)
- pctx.StaticVariable("DarwinToolchainRustFlags", strings.Join(DarwinRustFlags, " "))
- pctx.StaticVariable("DarwinToolchainLinkFlags", strings.Join(DarwinRustLinkFlags, " "))
+ if runtime.GOOS == "darwin" {
+ pctx.StaticVariable("DarwinToolchainRustFlags", strings.Join(DarwinRustFlags, " "))
+ pctx.StaticVariable("DarwinToolchainLinkFlags", strings.Join(DarwinRustLinkFlags, " "))
- pctx.StaticVariable("DarwinToolchainArm64RustFlags", strings.Join(darwinArm64Rustflags, " "))
- pctx.StaticVariable("DarwinToolchainArm64LinkFlags", strings.Join(darwinArm64Linkflags, " "))
- pctx.StaticVariable("DarwinToolchainX8664RustFlags", strings.Join(darwinX8664Rustflags, " "))
- pctx.StaticVariable("DarwinToolchainX8664LinkFlags", strings.Join(darwinX8664Linkflags, " "))
+ pctx.StaticVariable("DarwinToolchainArm64RustFlags", strings.Join(darwinArm64Rustflags, " "))
+ pctx.StaticVariable("DarwinToolchainArm64LinkFlags", strings.Join(darwinArm64Linkflags, " "))
+ pctx.StaticVariable("DarwinToolchainX8664RustFlags", strings.Join(darwinX8664Rustflags, " "))
+ pctx.StaticVariable("DarwinToolchainX8664LinkFlags", strings.Join(darwinX8664Linkflags, " "))
+ }
}