| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -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 ( | 
| Ivan Lozano | 085efff | 2023-09-12 12:33:42 -0400 | [diff] [blame] | 24 | x86_64RustFlags = []string{ | 
|  | 25 | "-C force-frame-pointers=y", | 
|  | 26 | } | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 27 | x86_64ArchFeatureRustFlags = map[string][]string{} | 
|  | 28 | x86_64LinkFlags            = []string{} | 
|  | 29 |  | 
|  | 30 | x86_64ArchVariantRustFlags = map[string][]string{ | 
| Satoshi Niwa | b6d818d | 2024-01-24 16:17:00 +0900 | [diff] [blame] | 31 | "":                            []string{}, | 
|  | 32 | "broadwell":                   []string{"-C target-cpu=broadwell"}, | 
|  | 33 | "goldmont":                    []string{"-C target-cpu=goldmont"}, | 
|  | 34 | "goldmont-plus":               []string{"-C target-cpu=goldmont-plus"}, | 
|  | 35 | "goldmont-without-sha-xsaves": []string{"-C target-cpu=goldmont", "-C target-feature=-sha,-xsaves"}, | 
|  | 36 | "haswell":                     []string{"-C target-cpu=haswell"}, | 
|  | 37 | "ivybridge":                   []string{"-C target-cpu=ivybridge"}, | 
|  | 38 | "sandybridge":                 []string{"-C target-cpu=sandybridge"}, | 
|  | 39 | "silvermont":                  []string{"-C target-cpu=silvermont"}, | 
|  | 40 | "skylake":                     []string{"-C target-cpu=skylake"}, | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 41 | //TODO: Add target-cpu=stoneyridge when rustc supports it. | 
|  | 42 | "stoneyridge": []string{""}, | 
| Ryo Hashimoto | f68c18f | 2022-11-16 17:25:01 +0900 | [diff] [blame] | 43 | "tremont":     []string{"-C target-cpu=tremont"}, | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 44 | } | 
|  | 45 | ) | 
|  | 46 |  | 
|  | 47 | func init() { | 
|  | 48 | registerToolchainFactory(android.Android, android.X86_64, x86_64ToolchainFactory) | 
|  | 49 |  | 
| Matthew Maurer | 51feafa | 2019-10-31 10:46:17 -0700 | [diff] [blame] | 50 | pctx.StaticVariable("X86_64ToolchainRustFlags", strings.Join(x86_64RustFlags, " ")) | 
|  | 51 | pctx.StaticVariable("X86_64ToolchainLinkFlags", strings.Join(x86_64LinkFlags, " ")) | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 52 |  | 
|  | 53 | for variant, rustFlags := range x86_64ArchVariantRustFlags { | 
|  | 54 | pctx.StaticVariable("X86_64"+variant+"VariantRustFlags", | 
|  | 55 | strings.Join(rustFlags, " ")) | 
|  | 56 | } | 
| Cole Faust | 8982b1c | 2024-04-08 16:54:45 -0700 | [diff] [blame] | 57 | pctx.StaticVariable("DEVICE_X86_64_RUSTC_FLAGS", strings.Join(x86_64RustFlags, " ")) | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 58 | } | 
|  | 59 |  | 
|  | 60 | type toolchainX86_64 struct { | 
|  | 61 | toolchain64Bit | 
|  | 62 | toolchainRustFlags string | 
|  | 63 | } | 
|  | 64 |  | 
|  | 65 | func (t *toolchainX86_64) RustTriple() string { | 
| Matthew Maurer | 51feafa | 2019-10-31 10:46:17 -0700 | [diff] [blame] | 66 | return "x86_64-linux-android" | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 67 | } | 
|  | 68 |  | 
|  | 69 | func (t *toolchainX86_64) ToolchainLinkFlags() string { | 
| Ivan Lozano | 6d45a98 | 2020-09-09 09:08:44 -0400 | [diff] [blame] | 70 | // Prepend the lld flags from cc_config so we stay in sync with cc | 
|  | 71 | return "${config.DeviceGlobalLinkFlags} ${cc_config.X86_64Lldflags} ${config.X86_64ToolchainLinkFlags}" | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 72 | } | 
|  | 73 |  | 
|  | 74 | func (t *toolchainX86_64) ToolchainRustFlags() string { | 
|  | 75 | return t.toolchainRustFlags | 
|  | 76 | } | 
|  | 77 |  | 
|  | 78 | func (t *toolchainX86_64) RustFlags() string { | 
| Matthew Maurer | 51feafa | 2019-10-31 10:46:17 -0700 | [diff] [blame] | 79 | return "${config.X86_64ToolchainRustFlags}" | 
|  | 80 | } | 
|  | 81 |  | 
|  | 82 | func (t *toolchainX86_64) Supported() bool { | 
|  | 83 | return true | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 84 | } | 
|  | 85 |  | 
| Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 86 | func (toolchainX86_64) LibclangRuntimeLibraryArch() string { | 
|  | 87 | return "x86_64" | 
|  | 88 | } | 
|  | 89 |  | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 90 | func x86_64ToolchainFactory(arch android.Arch) Toolchain { | 
|  | 91 | toolchainRustFlags := []string{ | 
| Matthew Maurer | 51feafa | 2019-10-31 10:46:17 -0700 | [diff] [blame] | 92 | "${config.X86_64ToolchainRustFlags}", | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 93 | "${config.X86_64" + arch.ArchVariant + "VariantRustFlags}", | 
|  | 94 | } | 
|  | 95 |  | 
| Matthew Maurer | 51feafa | 2019-10-31 10:46:17 -0700 | [diff] [blame] | 96 | toolchainRustFlags = append(toolchainRustFlags, deviceGlobalRustFlags...) | 
|  | 97 |  | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 98 | for _, feature := range arch.ArchFeatures { | 
|  | 99 | toolchainRustFlags = append(toolchainRustFlags, x86_64ArchFeatureRustFlags[feature]...) | 
|  | 100 | } | 
|  | 101 |  | 
|  | 102 | return &toolchainX86_64{ | 
|  | 103 | toolchainRustFlags: strings.Join(toolchainRustFlags, " "), | 
|  | 104 | } | 
|  | 105 | } |