Add Darwin+Arm64 toolchain support

This just sets up the toolchain and allows Darwin+Arm64 to be specified
as a HostCross target. These variants will not be exported to Make, or
be installed on a Soong-only build. A future CL will add support for
universal binaries using these variants.

This config is a bit stranger than the regular 64/32 multilib, as it's
two primary 64-bit configs. And on a Darwin/X86 machine, the Arm64
versions are HostCross (doesn't work on the current machines), while a
Darwin/Arm64 machine, either version works (if Rosetta is installed).

Bug: 203607969
Change-Id: Iacaed77d267773672da027cd74917e33fb1c1e94
This commit is contained in:
Dan Willemsen 2021-10-19 00:22:06 -07:00
parent 1caea35278
commit 8528f4ec5e
7 changed files with 98 additions and 15 deletions

View file

@ -921,6 +921,11 @@ func shouldSkipAndroidMkProcessing(module *ModuleBase) bool {
return true
}
// Only expose the primary Darwin target, as Make does not understand Darwin+Arm64
if module.Os() == Darwin && module.Target().HostCross {
return true
}
return !module.Enabled() ||
module.commonProperties.HideFromMake ||
// Make does not understand LinuxBionic

View file

@ -308,7 +308,7 @@ var (
// LinuxMusl is the OS for the Linux kernel plus the musl runtime.
LinuxMusl = newOsType("linux_musl", Host, false, X86, X86_64)
// Darwin is the OS for MacOS/Darwin host machines.
Darwin = newOsType("darwin", Host, false, X86_64)
Darwin = newOsType("darwin", Host, false, Arm64, X86_64)
// LinuxBionic is the OS for the Linux kernel plus the Bionic libc runtime, but without the
// rest of Android.
LinuxBionic = newOsType("linux_bionic", Host, false, Arm64, X86_64)
@ -696,6 +696,11 @@ func archMutator(bpctx blueprint.BottomUpMutatorContext) {
for i, m := range modules {
addTargetProperties(m, targets[i], multiTargets, i == 0)
m.base().setArchProperties(mctx)
// Install support doesn't understand Darwin+Arm64
if os == Darwin && targets[i].HostCross {
m.base().commonProperties.SkipInstall = true
}
}
}

View file

@ -39,6 +39,7 @@ const (
osArchAndroidArm64 = "android_arm64"
osArchAndroidX86 = "android_x86"
osArchAndroidX86_64 = "android_x86_64"
osArchDarwinArm64 = "darwin_arm64"
osArchDarwinX86_64 = "darwin_x86_64"
osArchLinuxX86 = "linux_glibc_x86"
osArchLinuxX86_64 = "linux_glibc_x86_64"
@ -96,6 +97,7 @@ var (
osArchAndroidArm64: "//build/bazel/platforms/os_arch:android_arm64",
osArchAndroidX86: "//build/bazel/platforms/os_arch:android_x86",
osArchAndroidX86_64: "//build/bazel/platforms/os_arch:android_x86_64",
osArchDarwinArm64: "//build/bazel/platforms/os_arch:darwin_arm64",
osArchDarwinX86_64: "//build/bazel/platforms/os_arch:darwin_x86_64",
osArchLinuxX86: "//build/bazel/platforms/os_arch:linux_glibc_x86",
osArchLinuxX86_64: "//build/bazel/platforms/os_arch:linux_glibc_x86_64",

View file

@ -24,7 +24,7 @@ bootstrap_go_package {
"x86_device.go",
"x86_64_device.go",
"x86_darwin_host.go",
"darwin_host.go",
"x86_linux_host.go",
"x86_linux_bionic_host.go",
"x86_windows_host.go",

View file

@ -174,19 +174,43 @@ type toolchainDarwin struct {
toolchain64Bit
}
func (t *toolchainDarwin) Name() string {
type toolchainDarwinX86 struct {
toolchainDarwin
}
type toolchainDarwinArm struct {
toolchainDarwin
}
func (t *toolchainDarwinArm) Name() string {
return "arm64"
}
func (t *toolchainDarwinX86) Name() string {
return "x86_64"
}
func (t *toolchainDarwin) GccRoot() string {
func (t *toolchainDarwinArm) GccRoot() string {
panic("unimplemented")
}
func (t *toolchainDarwinArm) GccTriple() string {
panic("unimplemented")
}
func (t *toolchainDarwinArm) GccVersion() string {
panic("unimplemented")
}
func (t *toolchainDarwinX86) GccRoot() string {
return "${config.DarwinGccRoot}"
}
func (t *toolchainDarwin) GccTriple() string {
func (t *toolchainDarwinX86) GccTriple() string {
return "${config.DarwinGccTriple}"
}
func (t *toolchainDarwin) GccVersion() string {
func (t *toolchainDarwinX86) GccVersion() string {
return darwinGccVersion
}
@ -194,7 +218,11 @@ func (t *toolchainDarwin) IncludeFlags() string {
return ""
}
func (t *toolchainDarwin) ClangTriple() string {
func (t *toolchainDarwinArm) ClangTriple() string {
return "aarch64-apple-darwin"
}
func (t *toolchainDarwinX86) ClangTriple() string {
return "x86_64-apple-darwin"
}
@ -230,12 +258,18 @@ func (t *toolchainDarwin) ToolPath() string {
return "${config.MacToolPath}"
}
var toolchainDarwinSingleton Toolchain = &toolchainDarwin{}
var toolchainDarwinArmSingleton Toolchain = &toolchainDarwinArm{}
var toolchainDarwinX86Singleton Toolchain = &toolchainDarwinX86{}
func darwinToolchainFactory(arch android.Arch) Toolchain {
return toolchainDarwinSingleton
func darwinArmToolchainFactory(arch android.Arch) Toolchain {
return toolchainDarwinArmSingleton
}
func darwinX86ToolchainFactory(arch android.Arch) Toolchain {
return toolchainDarwinX86Singleton
}
func init() {
registerToolchainFactory(android.Darwin, android.X86_64, darwinToolchainFactory)
registerToolchainFactory(android.Darwin, android.Arm64, darwinArmToolchainFactory)
registerToolchainFactory(android.Darwin, android.X86_64, darwinX86ToolchainFactory)
}

View file

@ -16,7 +16,7 @@ bootstrap_go_package {
"lints.go",
"toolchain.go",
"allowed_list.go",
"x86_darwin_host.go",
"darwin_host.go",
"x86_linux_bionic_host.go",
"x86_linux_host.go",
"x86_device.go",

View file

@ -25,41 +25,64 @@ var (
DarwinRustLinkFlags = []string{
"-B${cc_config.MacToolPath}",
}
darwinArm64Rustflags = []string{}
darwinArm64Linkflags = []string{}
darwinX8664Rustflags = []string{}
darwinX8664Linkflags = []string{}
)
func init() {
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, " "))
pctx.StaticVariable("DarwinToolchainArm64RustFlags", strings.Join(darwinArm64Rustflags, " "))
pctx.StaticVariable("DarwinToolchainArm64LinkFlags", strings.Join(darwinArm64Linkflags, " "))
pctx.StaticVariable("DarwinToolchainX8664RustFlags", strings.Join(darwinX8664Rustflags, " "))
pctx.StaticVariable("DarwinToolchainX8664LinkFlags", strings.Join(darwinX8664Linkflags, " "))
}
type toolchainDarwin struct {
toolchain64Bit
toolchainRustFlags string
toolchainLinkFlags string
}
type toolchainDarwinX8664 struct {
toolchain64Bit
type toolchainDarwinArm64 struct {
toolchainDarwin
}
type toolchainDarwinX8664 struct {
toolchainDarwin
}
func (toolchainDarwinArm64) Supported() bool {
return true
}
func (toolchainDarwinX8664) Supported() bool {
return true
}
func (toolchainDarwinX8664) Bionic() bool {
func (toolchainDarwin) Bionic() bool {
return false
}
func (t *toolchainDarwinArm64) Name() string {
return "arm64"
}
func (t *toolchainDarwinX8664) Name() string {
return "x86_64"
}
func (t *toolchainDarwinArm64) RustTriple() string {
return "aarch64-apple-darwin"
}
func (t *toolchainDarwinX8664) RustTriple() string {
return "x86_64-apple-darwin"
}
@ -76,6 +99,15 @@ func (t *toolchainDarwin) ProcMacroSuffix() string {
return ".dylib"
}
func (t *toolchainDarwinArm64) ToolchainLinkFlags() string {
// Prepend the lld flags from cc_config so we stay in sync with cc
return "${cc_config.DarwinLldflags} ${config.DarwinToolchainLinkFlags} ${config.DarwinToolchainArm64LinkFlags}"
}
func (t *toolchainDarwinArm64) ToolchainRustFlags() string {
return "${config.DarwinToolchainRustFlags} ${config.DarwinToolchainArm64RustFlags}"
}
func (t *toolchainDarwinX8664) ToolchainLinkFlags() string {
// Prepend the lld flags from cc_config so we stay in sync with cc
return "${cc_config.DarwinLldflags} ${config.DarwinToolchainLinkFlags} ${config.DarwinToolchainX8664LinkFlags}"
@ -85,8 +117,13 @@ func (t *toolchainDarwinX8664) ToolchainRustFlags() string {
return "${config.DarwinToolchainRustFlags} ${config.DarwinToolchainX8664RustFlags}"
}
func darwinArm64ToolchainFactory(arch android.Arch) Toolchain {
return toolchainDarwinArm64Singleton
}
func darwinX8664ToolchainFactory(arch android.Arch) Toolchain {
return toolchainDarwinX8664Singleton
}
var toolchainDarwinArm64Singleton Toolchain = &toolchainDarwinArm64{}
var toolchainDarwinX8664Singleton Toolchain = &toolchainDarwinX8664{}