1// Copyright 2019 The Android Open Source Project 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15package config 16 17import ( 18 "strings" 19 20 "android/soong/android" 21) 22 23var ( 24 Arm64RustFlags = []string{} 25 Arm64ArchFeatureRustFlags = map[string][]string{} 26 Arm64LinkFlags = []string{} 27 28 Arm64ArchVariantRustFlags = map[string][]string{ 29 "armv8-a": []string{}, 30 "armv8-a-branchprot": []string{}, 31 "armv8-2a": []string{}, 32 "armv8-2a-dotprod": []string{}, 33 } 34) 35 36func init() { 37 registerToolchainFactory(android.Android, android.Arm64, Arm64ToolchainFactory) 38 39 pctx.StaticVariable("Arm64ToolchainRustFlags", strings.Join(Arm64RustFlags, " ")) 40 pctx.StaticVariable("Arm64ToolchainLinkFlags", strings.Join(Arm64LinkFlags, " ")) 41 42 for variant, rustFlags := range Arm64ArchVariantRustFlags { 43 pctx.StaticVariable("Arm64"+variant+"VariantRustFlags", 44 strings.Join(rustFlags, " ")) 45 } 46 47} 48 49type toolchainArm64 struct { 50 toolchain64Bit 51 toolchainRustFlags string 52} 53 54func (t *toolchainArm64) RustTriple() string { 55 return "aarch64-linux-android" 56} 57 58func (t *toolchainArm64) ToolchainLinkFlags() string { 59 // Prepend the lld flags from cc_config so we stay in sync with cc 60 return "${config.DeviceGlobalLinkFlags} ${cc_config.Arm64Lldflags} ${config.Arm64ToolchainLinkFlags}" 61} 62 63func (t *toolchainArm64) ToolchainRustFlags() string { 64 return t.toolchainRustFlags 65} 66 67func (t *toolchainArm64) RustFlags() string { 68 return "${config.Arm64ToolchainRustFlags}" 69} 70 71func (t *toolchainArm64) Supported() bool { 72 return true 73} 74 75func (toolchainArm64) LibclangRuntimeLibraryArch() string { 76 return "aarch64" 77} 78 79func Arm64ToolchainFactory(arch android.Arch) Toolchain { 80 archVariant := arch.ArchVariant 81 if archVariant == "" { 82 // arch variants defaults to armv8-a. This is mostly for 83 // the host target which borrows toolchain configs from here. 84 archVariant = "armv8-a" 85 } 86 87 toolchainRustFlags := []string{ 88 "${config.Arm64ToolchainRustFlags}", 89 "${config.Arm64" + archVariant + "VariantRustFlags}", 90 } 91 92 toolchainRustFlags = append(toolchainRustFlags, deviceGlobalRustFlags...) 93 94 for _, feature := range arch.ArchFeatures { 95 toolchainRustFlags = append(toolchainRustFlags, Arm64ArchFeatureRustFlags[feature]...) 96 } 97 98 return &toolchainArm64{ 99 toolchainRustFlags: strings.Join(toolchainRustFlags, " "), 100 } 101} 102