1// Copyright 2022 Google Inc. All rights reserved. 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 linuxArmRustflags = []string{} 25 linuxArmLinkflags = []string{} 26 linuxArm64Rustflags = []string{} 27 linuxArm64Linkflags = []string{} 28) 29 30func init() { 31 registerToolchainFactory(android.LinuxMusl, android.Arm64, linuxMuslArm64ToolchainFactory) 32 registerToolchainFactory(android.LinuxMusl, android.Arm, linuxMuslArmToolchainFactory) 33 34 pctx.StaticVariable("LinuxToolchainArmRustFlags", strings.Join(linuxArmRustflags, " ")) 35 pctx.StaticVariable("LinuxToolchainArmLinkFlags", strings.Join(linuxArmLinkflags, " ")) 36 pctx.StaticVariable("LinuxToolchainArm64RustFlags", strings.Join(linuxArm64Rustflags, " ")) 37 pctx.StaticVariable("LinuxToolchainArm64LinkFlags", strings.Join(linuxArm64Linkflags, " ")) 38} 39 40// Base 64-bit linux rust toolchain 41type toolchainLinuxArm64 struct { 42 toolchain64Bit 43} 44 45func (toolchainLinuxArm64) Supported() bool { 46 return true 47} 48 49func (toolchainLinuxArm64) Bionic() bool { 50 return false 51} 52 53func (t *toolchainLinuxArm64) Name() string { 54 return "arm64" 55} 56 57func (t *toolchainLinuxArm64) ToolchainLinkFlags() string { 58 // Prepend the lld flags from cc_config so we stay in sync with cc 59 return "${cc_config.LinuxLldflags} ${cc_config.LinuxArm64Lldflags} " + 60 "${config.LinuxToolchainLinkFlags} ${config.LinuxToolchainArm64LinkFlags}" 61} 62 63func (t *toolchainLinuxArm64) ToolchainRustFlags() string { 64 return "${config.LinuxToolchainRustFlags} ${config.LinuxToolchainArm64RustFlags}" 65} 66 67// Specialization of the 64-bit linux rust toolchain for musl. Adds the musl rust triple and 68// linker flags to avoid using the host sysroot. 69type toolchainLinuxMuslArm64 struct { 70 toolchainLinuxArm64 71} 72 73func (t *toolchainLinuxMuslArm64) RustTriple() string { 74 return "aarch64-unknown-linux-musl" 75} 76 77func (t *toolchainLinuxMuslArm64) ToolchainLinkFlags() string { 78 return t.toolchainLinuxArm64.ToolchainLinkFlags() + " " + "${config.LinuxMuslToolchainLinkFlags}" 79} 80 81func (t *toolchainLinuxMuslArm64) ToolchainRustFlags() string { 82 return t.toolchainLinuxArm64.ToolchainRustFlags() + " " + "${config.LinuxMuslToolchainRustFlags}" 83} 84 85func linuxMuslArm64ToolchainFactory(arch android.Arch) Toolchain { 86 return toolchainLinuxMuslArm64Singleton 87} 88 89// Base 32-bit linux rust toolchain 90type toolchainLinuxArm struct { 91 toolchain32Bit 92} 93 94func (toolchainLinuxArm) Supported() bool { 95 return true 96} 97 98func (toolchainLinuxArm) Bionic() bool { 99 return false 100} 101 102func (t *toolchainLinuxArm) Name() string { 103 return "arm" 104} 105 106func (toolchainLinuxArm) LibclangRuntimeLibraryArch() string { 107 return "arm" 108} 109 110func (toolchainLinuxArm64) LibclangRuntimeLibraryArch() string { 111 return "arm64" 112} 113 114func (t *toolchainLinuxArm) ToolchainLinkFlags() string { 115 // Prepend the lld flags from cc_config so we stay in sync with cc 116 return "${cc_config.LinuxLldflags} ${cc_config.LinuxArmLldflags} " + 117 "${config.LinuxToolchainLinkFlags} ${config.LinuxToolchainArmLinkFlags}" 118} 119 120func (t *toolchainLinuxArm) ToolchainRustFlags() string { 121 return "${config.LinuxToolchainRustFlags} ${config.LinuxToolchainArmRustFlags}" 122} 123 124// Specialization of the 32-bit linux rust toolchain for musl. Adds the musl rust triple and 125// linker flags to avoid using the host sysroot. 126type toolchainLinuxMuslArm struct { 127 toolchainLinuxArm 128} 129 130func (t *toolchainLinuxMuslArm) RustTriple() string { 131 return "arm-unknown-linux-musleabihf" 132} 133 134func (t *toolchainLinuxMuslArm) ToolchainLinkFlags() string { 135 return t.toolchainLinuxArm.ToolchainLinkFlags() + " " + "${config.LinuxMuslToolchainLinkFlags}" 136} 137 138func (t *toolchainLinuxMuslArm) ToolchainRustFlags() string { 139 return t.toolchainLinuxArm.ToolchainRustFlags() + " " + "${config.LinuxMuslToolchainRustFlags}" 140} 141 142func linuxMuslArmToolchainFactory(arch android.Arch) Toolchain { 143 return toolchainLinuxMuslArmSingleton 144} 145 146var toolchainLinuxMuslArm64Singleton Toolchain = &toolchainLinuxMuslArm64{} 147var toolchainLinuxMuslArmSingleton Toolchain = &toolchainLinuxMuslArm{} 148