blob: b1f1f169a8df34c8d0e01af5d066037f844e1f55 [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{}
26 Arm64LinkFlags = []string{
27 "-Wl,--icf=safe",
28 "-Wl,-z,max-page-size=4096",
29
Nick Desaulniersdcee1e52019-12-13 12:32:43 -080030 "-Wl,-z,separate-code",
Ivan Lozanof1c84332019-09-20 11:00:37 -070031 }
32
33 Arm64ArchVariantRustFlags = map[string][]string{
34 "armv8-a": []string{},
35 "armv8-2a": []string{},
36 }
37)
38
39func init() {
40 registerToolchainFactory(android.Android, android.Arm64, Arm64ToolchainFactory)
41
42 pctx.StaticVariable("Arm64ToolchainRustFlags", strings.Join(Arm64RustFlags, " "))
43 pctx.StaticVariable("Arm64ToolchainLinkFlags", strings.Join(Arm64LinkFlags, " "))
44
45 for variant, rustFlags := range Arm64ArchVariantRustFlags {
46 pctx.StaticVariable("Arm64"+variant+"VariantRustFlags",
47 strings.Join(rustFlags, " "))
48 }
49
50}
51
52type toolchainArm64 struct {
53 toolchain64Bit
54 toolchainRustFlags string
55}
56
57func (t *toolchainArm64) RustTriple() string {
58 return "aarch64-linux-android"
59}
60
61func (t *toolchainArm64) ToolchainLinkFlags() string {
62 return "${config.DeviceGlobalLinkFlags} ${config.Arm64ToolchainLinkFlags}"
63}
64
65func (t *toolchainArm64) ToolchainRustFlags() string {
66 return t.toolchainRustFlags
67}
68
69func (t *toolchainArm64) RustFlags() string {
70 return "${config.Arm64ToolchainRustFlags}"
71}
72
73func (t *toolchainArm64) Supported() bool {
74 return true
75}
76
77func Arm64ToolchainFactory(arch android.Arch) Toolchain {
Jiyong Park4afa2e22020-07-13 15:43:45 +090078 archVariant := arch.ArchVariant
79 if archVariant == "" {
80 // arch variants defaults to armv8-a. This is mostly for
81 // the host target which borrows toolchain configs from here.
82 archVariant = "armv8-a"
83 }
84
Ivan Lozanof1c84332019-09-20 11:00:37 -070085 toolchainRustFlags := []string{
86 "${config.Arm64ToolchainRustFlags}",
Jiyong Park4afa2e22020-07-13 15:43:45 +090087 "${config.Arm64" + archVariant + "VariantRustFlags}",
Ivan Lozanof1c84332019-09-20 11:00:37 -070088 }
89
90 toolchainRustFlags = append(toolchainRustFlags, deviceGlobalRustFlags...)
91
92 for _, feature := range arch.ArchFeatures {
93 toolchainRustFlags = append(toolchainRustFlags, Arm64ArchFeatureRustFlags[feature]...)
94 }
95
96 return &toolchainArm64{
97 toolchainRustFlags: strings.Join(toolchainRustFlags, " "),
98 }
99}