blob: a0c496d4a97511635d48abe3502c05a78643c34a [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{
29 "armv8-a": []string{},
30 "armv8-2a": []string{},
31 }
32)
33
34func init() {
35 registerToolchainFactory(android.Android, android.Arm64, Arm64ToolchainFactory)
36
37 pctx.StaticVariable("Arm64ToolchainRustFlags", strings.Join(Arm64RustFlags, " "))
38 pctx.StaticVariable("Arm64ToolchainLinkFlags", strings.Join(Arm64LinkFlags, " "))
39
40 for variant, rustFlags := range Arm64ArchVariantRustFlags {
41 pctx.StaticVariable("Arm64"+variant+"VariantRustFlags",
42 strings.Join(rustFlags, " "))
43 }
44
45}
46
47type toolchainArm64 struct {
48 toolchain64Bit
49 toolchainRustFlags string
50}
51
52func (t *toolchainArm64) RustTriple() string {
53 return "aarch64-linux-android"
54}
55
56func (t *toolchainArm64) ToolchainLinkFlags() string {
Ivan Lozano6d45a982020-09-09 09:08:44 -040057 // Prepend the lld flags from cc_config so we stay in sync with cc
58 return "${config.DeviceGlobalLinkFlags} ${cc_config.Arm64Lldflags} ${config.Arm64ToolchainLinkFlags}"
Ivan Lozanof1c84332019-09-20 11:00:37 -070059}
60
61func (t *toolchainArm64) ToolchainRustFlags() string {
62 return t.toolchainRustFlags
63}
64
65func (t *toolchainArm64) RustFlags() string {
66 return "${config.Arm64ToolchainRustFlags}"
67}
68
69func (t *toolchainArm64) Supported() bool {
70 return true
71}
72
73func Arm64ToolchainFactory(arch android.Arch) Toolchain {
74 toolchainRustFlags := []string{
75 "${config.Arm64ToolchainRustFlags}",
76 "${config.Arm64" + arch.ArchVariant + "VariantRustFlags}",
77 }
78
79 toolchainRustFlags = append(toolchainRustFlags, deviceGlobalRustFlags...)
80
81 for _, feature := range arch.ArchFeatures {
82 toolchainRustFlags = append(toolchainRustFlags, Arm64ArchFeatureRustFlags[feature]...)
83 }
84
85 return &toolchainArm64{
86 toolchainRustFlags: strings.Join(toolchainRustFlags, " "),
87 }
88}