• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// 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{}
26	Arm64LinkFlags            = []string{}
27
28	Arm64ArchVariantRustFlags = map[string][]string{
29		"armv8-a":            []string{},
30		"armv8-a-branchprot": []string{},
31		"armv8-2a":           []string{},
32		"armv8-2a-dotprod":   []string{},
33		"armv9-a":            []string{},
34	}
35)
36
37func init() {
38	registerToolchainFactory(android.Android, android.Arm64, Arm64ToolchainFactory)
39
40	pctx.StaticVariable("Arm64ToolchainRustFlags", strings.Join(Arm64RustFlags, " "))
41	pctx.StaticVariable("Arm64ToolchainLinkFlags", strings.Join(Arm64LinkFlags, " "))
42
43	for variant, rustFlags := range Arm64ArchVariantRustFlags {
44		pctx.StaticVariable("Arm64"+variant+"VariantRustFlags",
45			strings.Join(rustFlags, " "))
46	}
47
48}
49
50type toolchainArm64 struct {
51	toolchain64Bit
52	toolchainRustFlags string
53}
54
55func (t *toolchainArm64) RustTriple() string {
56	return "aarch64-linux-android"
57}
58
59func (t *toolchainArm64) ToolchainLinkFlags() string {
60	// Prepend the lld flags from cc_config so we stay in sync with cc
61	return "${config.DeviceGlobalLinkFlags} ${cc_config.Arm64Lldflags} ${config.Arm64ToolchainLinkFlags}"
62}
63
64func (t *toolchainArm64) ToolchainRustFlags() string {
65	return t.toolchainRustFlags
66}
67
68func (t *toolchainArm64) RustFlags() string {
69	return "${config.Arm64ToolchainRustFlags}"
70}
71
72func (t *toolchainArm64) Supported() bool {
73	return true
74}
75
76func (toolchainArm64) LibclangRuntimeLibraryArch() string {
77	return "aarch64"
78}
79
80func Arm64ToolchainFactory(arch android.Arch) Toolchain {
81	archVariant := arch.ArchVariant
82	if archVariant == "" {
83		// arch variants defaults to armv8-a. This is mostly for
84		// the host target which borrows toolchain configs from here.
85		archVariant = "armv8-a"
86	}
87
88	toolchainRustFlags := []string{
89		"${config.Arm64ToolchainRustFlags}",
90		"${config.Arm64" + archVariant + "VariantRustFlags}",
91	}
92
93	toolchainRustFlags = append(toolchainRustFlags, deviceGlobalRustFlags...)
94
95	for _, feature := range arch.ArchFeatures {
96		toolchainRustFlags = append(toolchainRustFlags, Arm64ArchFeatureRustFlags[feature]...)
97	}
98
99	return &toolchainArm64{
100		toolchainRustFlags: strings.Join(toolchainRustFlags, " "),
101	}
102}
103