Ivan Lozano | e91823e | 2019-09-20 13:45:59 -0700 | [diff] [blame] | 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 | |
| 15 | package config |
| 16 | |
| 17 | import ( |
| 18 | "strings" |
| 19 | |
| 20 | "android/soong/android" |
| 21 | ) |
| 22 | |
| 23 | var ( |
| 24 | ArmRustFlags = []string{} |
| 25 | ArmArchFeatureRustFlags = map[string][]string{} |
Ivan Lozano | 6d45a98 | 2020-09-09 09:08:44 -0400 | [diff] [blame] | 26 | ArmLinkFlags = []string{} |
Ivan Lozano | e91823e | 2019-09-20 13:45:59 -0700 | [diff] [blame] | 27 | |
| 28 | ArmArchVariantRustFlags = map[string][]string{ |
| 29 | "armv7-a": []string{}, |
| 30 | "armv7-a-neon": []string{}, |
| 31 | "armv8-a": []string{}, |
| 32 | "armv8-2a": []string{}, |
| 33 | } |
| 34 | ) |
| 35 | |
| 36 | func init() { |
| 37 | registerToolchainFactory(android.Android, android.Arm, ArmToolchainFactory) |
| 38 | |
| 39 | pctx.StaticVariable("ArmToolchainRustFlags", strings.Join(ArmRustFlags, " ")) |
| 40 | pctx.StaticVariable("ArmToolchainLinkFlags", strings.Join(ArmLinkFlags, " ")) |
| 41 | |
| 42 | for variant, rustFlags := range ArmArchVariantRustFlags { |
| 43 | pctx.StaticVariable("Arm"+variant+"VariantRustFlags", |
| 44 | strings.Join(rustFlags, " ")) |
| 45 | } |
| 46 | |
| 47 | } |
| 48 | |
| 49 | type toolchainArm struct { |
Ivan Lozano | 9d1df10 | 2020-04-28 10:10:23 -0400 | [diff] [blame] | 50 | toolchain32Bit |
Ivan Lozano | e91823e | 2019-09-20 13:45:59 -0700 | [diff] [blame] | 51 | toolchainRustFlags string |
| 52 | } |
| 53 | |
| 54 | func (t *toolchainArm) RustTriple() string { |
Matthew Maurer | ad64c39 | 2020-09-24 14:19:27 -0700 | [diff] [blame] | 55 | return "armv7-linux-androideabi" |
Ivan Lozano | e91823e | 2019-09-20 13:45:59 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | func (t *toolchainArm) ToolchainLinkFlags() string { |
Ivan Lozano | 6d45a98 | 2020-09-09 09:08:44 -0400 | [diff] [blame] | 59 | // Prepend the lld flags from cc_config so we stay in sync with cc |
| 60 | return "${config.DeviceGlobalLinkFlags} ${cc_config.ArmLldflags} ${config.ArmToolchainLinkFlags}" |
Ivan Lozano | e91823e | 2019-09-20 13:45:59 -0700 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | func (t *toolchainArm) ToolchainRustFlags() string { |
| 64 | return t.toolchainRustFlags |
| 65 | } |
| 66 | |
| 67 | func (t *toolchainArm) RustFlags() string { |
| 68 | return "${config.ArmToolchainRustFlags}" |
| 69 | } |
| 70 | |
| 71 | func (t *toolchainArm) Supported() bool { |
| 72 | return true |
| 73 | } |
| 74 | |
Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame^] | 75 | func (toolchainArm) LibclangRuntimeLibraryArch() string { |
| 76 | return "arm" |
| 77 | } |
| 78 | |
Ivan Lozano | e91823e | 2019-09-20 13:45:59 -0700 | [diff] [blame] | 79 | func ArmToolchainFactory(arch android.Arch) Toolchain { |
| 80 | toolchainRustFlags := []string{ |
| 81 | "${config.ArmToolchainRustFlags}", |
| 82 | "${config.Arm" + arch.ArchVariant + "VariantRustFlags}", |
| 83 | } |
| 84 | |
| 85 | toolchainRustFlags = append(toolchainRustFlags, deviceGlobalRustFlags...) |
| 86 | |
| 87 | for _, feature := range arch.ArchFeatures { |
| 88 | toolchainRustFlags = append(toolchainRustFlags, ArmArchFeatureRustFlags[feature]...) |
| 89 | } |
| 90 | |
| 91 | return &toolchainArm{ |
| 92 | toolchainRustFlags: strings.Join(toolchainRustFlags, " "), |
| 93 | } |
| 94 | } |