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 x86RustFlags = []string{} 25 x86ArchFeatureRustFlags = map[string][]string{} 26 x86LinkFlags = []string{} 27 28 x86ArchVariantRustFlags = map[string][]string{ 29 "": []string{}, 30 "atom": []string{"-C target-cpu=atom"}, 31 "broadwell": []string{"-C target-cpu=broadwell"}, 32 "haswell": []string{"-C target-cpu=haswell"}, 33 "ivybridge": []string{"-C target-cpu=ivybridge"}, 34 "sandybridge": []string{"-C target-cpu=sandybridge"}, 35 "silvermont": []string{"-C target-cpu=silvermont"}, 36 "skylake": []string{"-C target-cpu=skylake"}, 37 //TODO: Add target-cpu=stoneyridge when rustc supports it. 38 "stoneyridge": []string{""}, 39 // use prescott for x86_64, like cc/config/x86_device.go 40 "x86_64": []string{"-C target-cpu=prescott"}, 41 } 42) 43 44func init() { 45 registerToolchainFactory(android.Android, android.X86, x86ToolchainFactory) 46 47 pctx.StaticVariable("X86ToolchainRustFlags", strings.Join(x86RustFlags, " ")) 48 pctx.StaticVariable("X86ToolchainLinkFlags", strings.Join(x86LinkFlags, " ")) 49 50 for variant, rustFlags := range x86ArchVariantRustFlags { 51 pctx.StaticVariable("X86"+variant+"VariantRustFlags", 52 strings.Join(rustFlags, " ")) 53 } 54 55} 56 57type toolchainX86 struct { 58 toolchain32Bit 59 toolchainRustFlags string 60} 61 62func (t *toolchainX86) RustTriple() string { 63 return "i686-linux-android" 64} 65 66func (t *toolchainX86) ToolchainLinkFlags() string { 67 // Prepend the lld flags from cc_config so we stay in sync with cc 68 return "${config.DeviceGlobalLinkFlags} ${cc_config.X86ClangLldflags} ${config.X86ToolchainLinkFlags}" 69} 70 71func (t *toolchainX86) ToolchainRustFlags() string { 72 return t.toolchainRustFlags 73} 74 75func (t *toolchainX86) RustFlags() string { 76 return "${config.X86ToolchainRustFlags}" 77} 78 79func (t *toolchainX86) Supported() bool { 80 return true 81} 82 83func (toolchainX86) LibclangRuntimeLibraryArch() string { 84 return "i686" 85} 86 87func x86ToolchainFactory(arch android.Arch) Toolchain { 88 toolchainRustFlags := []string{ 89 "${config.X86ToolchainRustFlags}", 90 "${config.X86" + arch.ArchVariant + "VariantRustFlags}", 91 } 92 93 toolchainRustFlags = append(toolchainRustFlags, deviceGlobalRustFlags...) 94 95 for _, feature := range arch.ArchFeatures { 96 toolchainRustFlags = append(toolchainRustFlags, x86ArchFeatureRustFlags[feature]...) 97 } 98 99 return &toolchainX86{ 100 toolchainRustFlags: strings.Join(toolchainRustFlags, " "), 101 } 102} 103