blob: 43f73400e5b59428d5979880f11a54101184c986 [file] [log] [blame]
Chih-Hung Hsieh1f202e92019-12-11 15:25:47 -08001// 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{
Ryo Hashimotof68c18f2022-11-16 17:25:01 +090029 "": []string{},
30 "atom": []string{"-C target-cpu=atom"},
31 "broadwell": []string{"-C target-cpu=broadwell"},
32 "goldmont": []string{"-C target-cpu=goldmont"},
33 "goldmont-plus": []string{"-C target-cpu=goldmont-plus"},
34 "haswell": []string{"-C target-cpu=haswell"},
35 "ivybridge": []string{"-C target-cpu=ivybridge"},
36 "sandybridge": []string{"-C target-cpu=sandybridge"},
37 "silvermont": []string{"-C target-cpu=silvermont"},
38 "skylake": []string{"-C target-cpu=skylake"},
Chih-Hung Hsieh1f202e92019-12-11 15:25:47 -080039 //TODO: Add target-cpu=stoneyridge when rustc supports it.
40 "stoneyridge": []string{""},
Ryo Hashimotof68c18f2022-11-16 17:25:01 +090041 "tremont": []string{"-C target-cpu=tremont"},
Chih-Hung Hsieh1f202e92019-12-11 15:25:47 -080042 // use prescott for x86_64, like cc/config/x86_device.go
43 "x86_64": []string{"-C target-cpu=prescott"},
44 }
45)
46
47func init() {
48 registerToolchainFactory(android.Android, android.X86, x86ToolchainFactory)
49
50 pctx.StaticVariable("X86ToolchainRustFlags", strings.Join(x86RustFlags, " "))
51 pctx.StaticVariable("X86ToolchainLinkFlags", strings.Join(x86LinkFlags, " "))
52
53 for variant, rustFlags := range x86ArchVariantRustFlags {
54 pctx.StaticVariable("X86"+variant+"VariantRustFlags",
55 strings.Join(rustFlags, " "))
56 }
57
58}
59
60type toolchainX86 struct {
61 toolchain32Bit
62 toolchainRustFlags string
63}
64
65func (t *toolchainX86) RustTriple() string {
66 return "i686-linux-android"
67}
68
69func (t *toolchainX86) ToolchainLinkFlags() string {
Ivan Lozano6d45a982020-09-09 09:08:44 -040070 // Prepend the lld flags from cc_config so we stay in sync with cc
Colin Cross0523ba22021-07-14 18:45:05 -070071 return "${config.DeviceGlobalLinkFlags} ${cc_config.X86Lldflags} ${config.X86ToolchainLinkFlags}"
Chih-Hung Hsieh1f202e92019-12-11 15:25:47 -080072}
73
74func (t *toolchainX86) ToolchainRustFlags() string {
75 return t.toolchainRustFlags
76}
77
78func (t *toolchainX86) RustFlags() string {
79 return "${config.X86ToolchainRustFlags}"
80}
81
82func (t *toolchainX86) Supported() bool {
83 return true
84}
85
Ivan Lozano6cd99e62020-02-11 08:24:25 -050086func (toolchainX86) LibclangRuntimeLibraryArch() string {
87 return "i686"
88}
89
Chih-Hung Hsieh1f202e92019-12-11 15:25:47 -080090func x86ToolchainFactory(arch android.Arch) Toolchain {
91 toolchainRustFlags := []string{
92 "${config.X86ToolchainRustFlags}",
93 "${config.X86" + arch.ArchVariant + "VariantRustFlags}",
94 }
95
96 toolchainRustFlags = append(toolchainRustFlags, deviceGlobalRustFlags...)
97
98 for _, feature := range arch.ArchFeatures {
99 toolchainRustFlags = append(toolchainRustFlags, x86ArchFeatureRustFlags[feature]...)
100 }
101
102 return &toolchainX86{
103 toolchainRustFlags: strings.Join(toolchainRustFlags, " "),
104 }
105}