blob: 3c484d894da494b979f4c108a7aa6f159a60558d [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 (
Ivan Lozano085efff2023-09-12 12:33:42 -040024 x86_64RustFlags = []string{
25 "-C force-frame-pointers=y",
26 }
Ivan Lozanoffee3342019-08-27 12:03:00 -070027 x86_64ArchFeatureRustFlags = map[string][]string{}
28 x86_64LinkFlags = []string{}
29
30 x86_64ArchVariantRustFlags = map[string][]string{
Satoshi Niwab6d818d2024-01-24 16:17:00 +090031 "": []string{},
Yudhistira Erlandinata162b4892024-09-23 11:53:16 +080032 "alderlake": []string{"-C target-cpu=alderlake"},
Satoshi Niwab6d818d2024-01-24 16:17:00 +090033 "broadwell": []string{"-C target-cpu=broadwell"},
34 "goldmont": []string{"-C target-cpu=goldmont"},
35 "goldmont-plus": []string{"-C target-cpu=goldmont-plus"},
36 "goldmont-without-sha-xsaves": []string{"-C target-cpu=goldmont", "-C target-feature=-sha,-xsaves"},
37 "haswell": []string{"-C target-cpu=haswell"},
38 "ivybridge": []string{"-C target-cpu=ivybridge"},
39 "sandybridge": []string{"-C target-cpu=sandybridge"},
40 "silvermont": []string{"-C target-cpu=silvermont"},
41 "skylake": []string{"-C target-cpu=skylake"},
Ivan Lozanoffee3342019-08-27 12:03:00 -070042 //TODO: Add target-cpu=stoneyridge when rustc supports it.
43 "stoneyridge": []string{""},
Ryo Hashimotof68c18f2022-11-16 17:25:01 +090044 "tremont": []string{"-C target-cpu=tremont"},
Ivan Lozanoffee3342019-08-27 12:03:00 -070045 }
46)
47
48func init() {
49 registerToolchainFactory(android.Android, android.X86_64, x86_64ToolchainFactory)
50
Matthew Maurer51feafa2019-10-31 10:46:17 -070051 pctx.StaticVariable("X86_64ToolchainRustFlags", strings.Join(x86_64RustFlags, " "))
52 pctx.StaticVariable("X86_64ToolchainLinkFlags", strings.Join(x86_64LinkFlags, " "))
Ivan Lozanoffee3342019-08-27 12:03:00 -070053
54 for variant, rustFlags := range x86_64ArchVariantRustFlags {
55 pctx.StaticVariable("X86_64"+variant+"VariantRustFlags",
56 strings.Join(rustFlags, " "))
57 }
Cole Faust8982b1c2024-04-08 16:54:45 -070058 pctx.StaticVariable("DEVICE_X86_64_RUSTC_FLAGS", strings.Join(x86_64RustFlags, " "))
Ivan Lozanoffee3342019-08-27 12:03:00 -070059}
60
61type toolchainX86_64 struct {
62 toolchain64Bit
63 toolchainRustFlags string
64}
65
66func (t *toolchainX86_64) RustTriple() string {
Matthew Maurer51feafa2019-10-31 10:46:17 -070067 return "x86_64-linux-android"
Ivan Lozanoffee3342019-08-27 12:03:00 -070068}
69
70func (t *toolchainX86_64) ToolchainLinkFlags() string {
Ivan Lozano6d45a982020-09-09 09:08:44 -040071 // Prepend the lld flags from cc_config so we stay in sync with cc
72 return "${config.DeviceGlobalLinkFlags} ${cc_config.X86_64Lldflags} ${config.X86_64ToolchainLinkFlags}"
Ivan Lozanoffee3342019-08-27 12:03:00 -070073}
74
75func (t *toolchainX86_64) ToolchainRustFlags() string {
76 return t.toolchainRustFlags
77}
78
79func (t *toolchainX86_64) RustFlags() string {
Matthew Maurer51feafa2019-10-31 10:46:17 -070080 return "${config.X86_64ToolchainRustFlags}"
81}
82
83func (t *toolchainX86_64) Supported() bool {
84 return true
Ivan Lozanoffee3342019-08-27 12:03:00 -070085}
86
Ivan Lozano6cd99e62020-02-11 08:24:25 -050087func (toolchainX86_64) LibclangRuntimeLibraryArch() string {
88 return "x86_64"
89}
90
Ivan Lozanoffee3342019-08-27 12:03:00 -070091func x86_64ToolchainFactory(arch android.Arch) Toolchain {
92 toolchainRustFlags := []string{
Matthew Maurer51feafa2019-10-31 10:46:17 -070093 "${config.X86_64ToolchainRustFlags}",
Ivan Lozanoffee3342019-08-27 12:03:00 -070094 "${config.X86_64" + arch.ArchVariant + "VariantRustFlags}",
95 }
96
Matthew Maurer51feafa2019-10-31 10:46:17 -070097 toolchainRustFlags = append(toolchainRustFlags, deviceGlobalRustFlags...)
98
Ivan Lozanoffee3342019-08-27 12:03:00 -070099 for _, feature := range arch.ArchFeatures {
100 toolchainRustFlags = append(toolchainRustFlags, x86_64ArchFeatureRustFlags[feature]...)
101 }
102
103 return &toolchainX86_64{
104 toolchainRustFlags: strings.Join(toolchainRustFlags, " "),
105 }
106}