blob: 3458ec900498ed3b35c8e61cc01f70e117cc64ba [file] [log] [blame]
Ivan Lozanoffee3342019-08-27 12:03:00 -07001// 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 x86_64RustFlags = []string{}
25 x86_64ArchFeatureRustFlags = map[string][]string{}
26 x86_64LinkFlags = []string{}
27
28 x86_64ArchVariantRustFlags = map[string][]string{
Ryo Hashimotof68c18f2022-11-16 17:25:01 +090029 "": []string{},
30 "broadwell": []string{"-C target-cpu=broadwell"},
31 "goldmont": []string{"-C target-cpu=goldmont"},
32 "goldmont-plus": []string{"-C target-cpu=goldmont-plus"},
33 "haswell": []string{"-C target-cpu=haswell"},
34 "ivybridge": []string{"-C target-cpu=ivybridge"},
35 "sandybridge": []string{"-C target-cpu=sandybridge"},
36 "silvermont": []string{"-C target-cpu=silvermont"},
37 "skylake": []string{"-C target-cpu=skylake"},
Ivan Lozanoffee3342019-08-27 12:03:00 -070038 //TODO: Add target-cpu=stoneyridge when rustc supports it.
39 "stoneyridge": []string{""},
Ryo Hashimotof68c18f2022-11-16 17:25:01 +090040 "tremont": []string{"-C target-cpu=tremont"},
Ivan Lozanoffee3342019-08-27 12:03:00 -070041 }
42)
43
44func init() {
45 registerToolchainFactory(android.Android, android.X86_64, x86_64ToolchainFactory)
46
Matthew Maurer51feafa2019-10-31 10:46:17 -070047 pctx.StaticVariable("X86_64ToolchainRustFlags", strings.Join(x86_64RustFlags, " "))
48 pctx.StaticVariable("X86_64ToolchainLinkFlags", strings.Join(x86_64LinkFlags, " "))
Ivan Lozanoffee3342019-08-27 12:03:00 -070049
50 for variant, rustFlags := range x86_64ArchVariantRustFlags {
51 pctx.StaticVariable("X86_64"+variant+"VariantRustFlags",
52 strings.Join(rustFlags, " "))
53 }
54
55}
56
57type toolchainX86_64 struct {
58 toolchain64Bit
59 toolchainRustFlags string
60}
61
62func (t *toolchainX86_64) RustTriple() string {
Matthew Maurer51feafa2019-10-31 10:46:17 -070063 return "x86_64-linux-android"
Ivan Lozanoffee3342019-08-27 12:03:00 -070064}
65
66func (t *toolchainX86_64) ToolchainLinkFlags() string {
Ivan Lozano6d45a982020-09-09 09:08:44 -040067 // Prepend the lld flags from cc_config so we stay in sync with cc
68 return "${config.DeviceGlobalLinkFlags} ${cc_config.X86_64Lldflags} ${config.X86_64ToolchainLinkFlags}"
Ivan Lozanoffee3342019-08-27 12:03:00 -070069}
70
71func (t *toolchainX86_64) ToolchainRustFlags() string {
72 return t.toolchainRustFlags
73}
74
75func (t *toolchainX86_64) RustFlags() string {
Matthew Maurer51feafa2019-10-31 10:46:17 -070076 return "${config.X86_64ToolchainRustFlags}"
77}
78
79func (t *toolchainX86_64) Supported() bool {
80 return true
Ivan Lozanoffee3342019-08-27 12:03:00 -070081}
82
Ivan Lozano6cd99e62020-02-11 08:24:25 -050083func (toolchainX86_64) LibclangRuntimeLibraryArch() string {
84 return "x86_64"
85}
86
Ivan Lozanoffee3342019-08-27 12:03:00 -070087func x86_64ToolchainFactory(arch android.Arch) Toolchain {
88 toolchainRustFlags := []string{
Matthew Maurer51feafa2019-10-31 10:46:17 -070089 "${config.X86_64ToolchainRustFlags}",
Ivan Lozanoffee3342019-08-27 12:03:00 -070090 "${config.X86_64" + arch.ArchVariant + "VariantRustFlags}",
91 }
92
Matthew Maurer51feafa2019-10-31 10:46:17 -070093 toolchainRustFlags = append(toolchainRustFlags, deviceGlobalRustFlags...)
94
Ivan Lozanoffee3342019-08-27 12:03:00 -070095 for _, feature := range arch.ArchFeatures {
96 toolchainRustFlags = append(toolchainRustFlags, x86_64ArchFeatureRustFlags[feature]...)
97 }
98
99 return &toolchainX86_64{
100 toolchainRustFlags: strings.Join(toolchainRustFlags, " "),
101 }
102}