blob: 60796d8d84f7d668d519ab6fa7ca7ab1f8da4e69 [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,--execute-only",
31 "-Wl,-z,separate-code",
Ivan Lozanof1c84332019-09-20 11:00:37 -070032 }
33
34 Arm64ArchVariantRustFlags = map[string][]string{
35 "armv8-a": []string{},
36 "armv8-2a": []string{},
37 }
38)
39
40func init() {
41 registerToolchainFactory(android.Android, android.Arm64, Arm64ToolchainFactory)
42
43 pctx.StaticVariable("Arm64ToolchainRustFlags", strings.Join(Arm64RustFlags, " "))
44 pctx.StaticVariable("Arm64ToolchainLinkFlags", strings.Join(Arm64LinkFlags, " "))
45
46 for variant, rustFlags := range Arm64ArchVariantRustFlags {
47 pctx.StaticVariable("Arm64"+variant+"VariantRustFlags",
48 strings.Join(rustFlags, " "))
49 }
50
51}
52
53type toolchainArm64 struct {
54 toolchain64Bit
55 toolchainRustFlags string
56}
57
58func (t *toolchainArm64) RustTriple() string {
59 return "aarch64-linux-android"
60}
61
62func (t *toolchainArm64) ToolchainLinkFlags() string {
63 return "${config.DeviceGlobalLinkFlags} ${config.Arm64ToolchainLinkFlags}"
64}
65
66func (t *toolchainArm64) ToolchainRustFlags() string {
67 return t.toolchainRustFlags
68}
69
70func (t *toolchainArm64) RustFlags() string {
71 return "${config.Arm64ToolchainRustFlags}"
72}
73
74func (t *toolchainArm64) Supported() bool {
75 return true
76}
77
78func Arm64ToolchainFactory(arch android.Arch) Toolchain {
79 toolchainRustFlags := []string{
80 "${config.Arm64ToolchainRustFlags}",
81 "${config.Arm64" + arch.ArchVariant + "VariantRustFlags}",
82 }
83
84 toolchainRustFlags = append(toolchainRustFlags, deviceGlobalRustFlags...)
85
86 for _, feature := range arch.ArchFeatures {
87 toolchainRustFlags = append(toolchainRustFlags, Arm64ArchFeatureRustFlags[feature]...)
88 }
89
90 return &toolchainArm64{
91 toolchainRustFlags: strings.Join(toolchainRustFlags, " "),
92 }
93}