blob: 506642861b308bb5c2591894bcf7cd2c8d3dd7db [file] [log] [blame]
Ivan Lozanof1c84332019-09-20 11:00:37 -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 Arm64RustFlags = []string{}
25 Arm64ArchFeatureRustFlags = map[string][]string{}
Ivan Lozano6d45a982020-09-09 09:08:44 -040026 Arm64LinkFlags = []string{}
Ivan Lozanof1c84332019-09-20 11:00:37 -070027
28 Arm64ArchVariantRustFlags = map[string][]string{
Ivan Lozano6cd99e62020-02-11 08:24:25 -050029 "armv8-a": []string{},
30 "armv8-2a": []string{},
Raphael Gault70b96b02020-06-18 09:56:53 +000031 "armv8-2a-dotprod": []string{},
Ivan Lozanof1c84332019-09-20 11:00:37 -070032 }
33)
34
35func init() {
36 registerToolchainFactory(android.Android, android.Arm64, Arm64ToolchainFactory)
37
38 pctx.StaticVariable("Arm64ToolchainRustFlags", strings.Join(Arm64RustFlags, " "))
39 pctx.StaticVariable("Arm64ToolchainLinkFlags", strings.Join(Arm64LinkFlags, " "))
40
41 for variant, rustFlags := range Arm64ArchVariantRustFlags {
42 pctx.StaticVariable("Arm64"+variant+"VariantRustFlags",
43 strings.Join(rustFlags, " "))
44 }
45
46}
47
48type toolchainArm64 struct {
49 toolchain64Bit
50 toolchainRustFlags string
51}
52
53func (t *toolchainArm64) RustTriple() string {
54 return "aarch64-linux-android"
55}
56
57func (t *toolchainArm64) ToolchainLinkFlags() string {
Ivan Lozano6d45a982020-09-09 09:08:44 -040058 // Prepend the lld flags from cc_config so we stay in sync with cc
59 return "${config.DeviceGlobalLinkFlags} ${cc_config.Arm64Lldflags} ${config.Arm64ToolchainLinkFlags}"
Ivan Lozanof1c84332019-09-20 11:00:37 -070060}
61
62func (t *toolchainArm64) ToolchainRustFlags() string {
63 return t.toolchainRustFlags
64}
65
66func (t *toolchainArm64) RustFlags() string {
67 return "${config.Arm64ToolchainRustFlags}"
68}
69
70func (t *toolchainArm64) Supported() bool {
71 return true
72}
73
Ivan Lozano6cd99e62020-02-11 08:24:25 -050074func (toolchainArm64) LibclangRuntimeLibraryArch() string {
75 return "aarch64"
76}
77
Ivan Lozanof1c84332019-09-20 11:00:37 -070078func Arm64ToolchainFactory(arch android.Arch) Toolchain {
Jiyong Park4afa2e22020-07-13 15:43:45 +090079 archVariant := arch.ArchVariant
80 if archVariant == "" {
81 // arch variants defaults to armv8-a. This is mostly for
82 // the host target which borrows toolchain configs from here.
83 archVariant = "armv8-a"
84 }
85
Ivan Lozanof1c84332019-09-20 11:00:37 -070086 toolchainRustFlags := []string{
87 "${config.Arm64ToolchainRustFlags}",
Jiyong Park4afa2e22020-07-13 15:43:45 +090088 "${config.Arm64" + archVariant + "VariantRustFlags}",
Ivan Lozanof1c84332019-09-20 11:00:37 -070089 }
90
91 toolchainRustFlags = append(toolchainRustFlags, deviceGlobalRustFlags...)
92
93 for _, feature := range arch.ArchFeatures {
94 toolchainRustFlags = append(toolchainRustFlags, Arm64ArchFeatureRustFlags[feature]...)
95 }
96
97 return &toolchainArm64{
98 toolchainRustFlags: strings.Join(toolchainRustFlags, " "),
99 }
100}