| Chih-Hung Hsieh | 1f202e9 | 2019-12-11 15:25:47 -0800 | [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 | x86RustFlags            = []string{} | 
|  | 25 | x86ArchFeatureRustFlags = map[string][]string{} | 
|  | 26 | x86LinkFlags            = []string{} | 
|  | 27 |  | 
|  | 28 | x86ArchVariantRustFlags = map[string][]string{ | 
| Satoshi Niwa | b6d818d | 2024-01-24 16:17:00 +0900 | [diff] [blame] | 29 | "":                            []string{}, | 
| Yudhistira Erlandinata | 162b489 | 2024-09-23 11:53:16 +0800 | [diff] [blame] | 30 | "alderlake":                   []string{"-C target-cpu=alderlake"}, | 
| Satoshi Niwa | b6d818d | 2024-01-24 16:17:00 +0900 | [diff] [blame] | 31 | "atom":                        []string{"-C target-cpu=atom"}, | 
|  | 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"}, | 
| Chih-Hung Hsieh | 1f202e9 | 2019-12-11 15:25:47 -0800 | [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"}, | 
| Chih-Hung Hsieh | 1f202e9 | 2019-12-11 15:25:47 -0800 | [diff] [blame] | 44 | // use prescott for x86_64, like cc/config/x86_device.go | 
|  | 45 | "x86_64": []string{"-C target-cpu=prescott"}, | 
|  | 46 | } | 
|  | 47 | ) | 
|  | 48 |  | 
|  | 49 | func init() { | 
|  | 50 | registerToolchainFactory(android.Android, android.X86, x86ToolchainFactory) | 
|  | 51 |  | 
|  | 52 | pctx.StaticVariable("X86ToolchainRustFlags", strings.Join(x86RustFlags, " ")) | 
|  | 53 | pctx.StaticVariable("X86ToolchainLinkFlags", strings.Join(x86LinkFlags, " ")) | 
|  | 54 |  | 
|  | 55 | for variant, rustFlags := range x86ArchVariantRustFlags { | 
|  | 56 | pctx.StaticVariable("X86"+variant+"VariantRustFlags", | 
|  | 57 | strings.Join(rustFlags, " ")) | 
|  | 58 | } | 
|  | 59 |  | 
| Cole Faust | 8982b1c | 2024-04-08 16:54:45 -0700 | [diff] [blame] | 60 | pctx.StaticVariable("DEVICE_X86_RUSTC_FLAGS", strings.Join(x86RustFlags, " ")) | 
| Chih-Hung Hsieh | 1f202e9 | 2019-12-11 15:25:47 -0800 | [diff] [blame] | 61 | } | 
|  | 62 |  | 
|  | 63 | type toolchainX86 struct { | 
|  | 64 | toolchain32Bit | 
|  | 65 | toolchainRustFlags string | 
|  | 66 | } | 
|  | 67 |  | 
|  | 68 | func (t *toolchainX86) RustTriple() string { | 
|  | 69 | return "i686-linux-android" | 
|  | 70 | } | 
|  | 71 |  | 
|  | 72 | func (t *toolchainX86) ToolchainLinkFlags() string { | 
| Ivan Lozano | 6d45a98 | 2020-09-09 09:08:44 -0400 | [diff] [blame] | 73 | // Prepend the lld flags from cc_config so we stay in sync with cc | 
| Colin Cross | 0523ba2 | 2021-07-14 18:45:05 -0700 | [diff] [blame] | 74 | return "${config.DeviceGlobalLinkFlags} ${cc_config.X86Lldflags} ${config.X86ToolchainLinkFlags}" | 
| Chih-Hung Hsieh | 1f202e9 | 2019-12-11 15:25:47 -0800 | [diff] [blame] | 75 | } | 
|  | 76 |  | 
|  | 77 | func (t *toolchainX86) ToolchainRustFlags() string { | 
|  | 78 | return t.toolchainRustFlags | 
|  | 79 | } | 
|  | 80 |  | 
|  | 81 | func (t *toolchainX86) RustFlags() string { | 
|  | 82 | return "${config.X86ToolchainRustFlags}" | 
|  | 83 | } | 
|  | 84 |  | 
|  | 85 | func (t *toolchainX86) Supported() bool { | 
|  | 86 | return true | 
|  | 87 | } | 
|  | 88 |  | 
| Ivan Lozano | 6cd99e6 | 2020-02-11 08:24:25 -0500 | [diff] [blame] | 89 | func (toolchainX86) LibclangRuntimeLibraryArch() string { | 
|  | 90 | return "i686" | 
|  | 91 | } | 
|  | 92 |  | 
| Chih-Hung Hsieh | 1f202e9 | 2019-12-11 15:25:47 -0800 | [diff] [blame] | 93 | func x86ToolchainFactory(arch android.Arch) Toolchain { | 
|  | 94 | toolchainRustFlags := []string{ | 
|  | 95 | "${config.X86ToolchainRustFlags}", | 
|  | 96 | "${config.X86" + arch.ArchVariant + "VariantRustFlags}", | 
|  | 97 | } | 
|  | 98 |  | 
|  | 99 | toolchainRustFlags = append(toolchainRustFlags, deviceGlobalRustFlags...) | 
|  | 100 |  | 
|  | 101 | for _, feature := range arch.ArchFeatures { | 
|  | 102 | toolchainRustFlags = append(toolchainRustFlags, x86ArchFeatureRustFlags[feature]...) | 
|  | 103 | } | 
|  | 104 |  | 
|  | 105 | return &toolchainX86{ | 
|  | 106 | toolchainRustFlags: strings.Join(toolchainRustFlags, " "), | 
|  | 107 | } | 
|  | 108 | } |