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 LinuxRustFlags = []string{} 25 LinuxRustLinkFlags = []string{ 26 "-B${ccConfig.ClangBin}", 27 "-fuse-ld=lld", 28 } 29 linuxX86Rustflags = []string{} 30 linuxX86Linkflags = []string{} 31 linuxX8664Rustflags = []string{} 32 linuxX8664Linkflags = []string{} 33) 34 35func init() { 36 registerToolchainFactory(android.Linux, android.X86_64, linuxX8664ToolchainFactory) 37 registerToolchainFactory(android.Linux, android.X86, linuxX86ToolchainFactory) 38 39 pctx.StaticVariable("LinuxToolchainRustFlags", strings.Join(LinuxRustFlags, " ")) 40 pctx.StaticVariable("LinuxToolchainLinkFlags", strings.Join(LinuxRustLinkFlags, " ")) 41 pctx.StaticVariable("LinuxToolchainX86RustFlags", strings.Join(linuxX86Rustflags, " ")) 42 pctx.StaticVariable("LinuxToolchainX86LinkFlags", strings.Join(linuxX86Linkflags, " ")) 43 pctx.StaticVariable("LinuxToolchainX8664RustFlags", strings.Join(linuxX8664Rustflags, " ")) 44 pctx.StaticVariable("LinuxToolchainX8664LinkFlags", strings.Join(linuxX8664Linkflags, " ")) 45 46} 47 48type toolchainLinux struct { 49 toolchainRustFlags string 50 toolchainLinkFlags string 51} 52 53type toolchainLinuxX86 struct { 54 toolchain32Bit 55 toolchainLinux 56} 57 58type toolchainLinuxX8664 struct { 59 toolchain64Bit 60 toolchainLinux 61} 62 63func (toolchainLinuxX8664) Supported() bool { 64 return true 65} 66 67func (toolchainLinuxX8664) Bionic() bool { 68 return false 69} 70 71func (t *toolchainLinuxX8664) Name() string { 72 return "x86_64" 73} 74 75func (t *toolchainLinuxX8664) RustTriple() string { 76 return "x86_64-unknown-linux-gnu" 77} 78 79func (t *toolchainLinuxX8664) ToolchainLinkFlags() string { 80 return "${config.LinuxToolchainLinkFlags} ${config.LinuxToolchainX8664LinkFlags}" 81} 82 83func (t *toolchainLinuxX8664) ToolchainRustFlags() string { 84 return "${config.LinuxToolchainRustFlags} ${config.LinuxToolchainX8664RustFlags}" 85} 86 87func linuxX8664ToolchainFactory(arch android.Arch) Toolchain { 88 return toolchainLinuxX8664Singleton 89} 90 91func (toolchainLinuxX86) Supported() bool { 92 return true 93} 94 95func (toolchainLinuxX86) Bionic() bool { 96 return false 97} 98 99func (t *toolchainLinuxX86) Name() string { 100 return "x86" 101} 102 103func (t *toolchainLinuxX86) RustTriple() string { 104 return "i686-unknown-linux-gnu" 105} 106 107func (t *toolchainLinuxX86) ToolchainLinkFlags() string { 108 return "${config.LinuxToolchainLinkFlags} ${config.LinuxToolchainX86LinkFlags}" 109} 110 111func (t *toolchainLinuxX86) ToolchainRustFlags() string { 112 return "${config.LinuxToolchainRustFlags} ${config.LinuxToolchainX86RustFlags}" 113} 114 115func linuxX86ToolchainFactory(arch android.Arch) Toolchain { 116 return toolchainLinuxX86Singleton 117} 118 119var toolchainLinuxX8664Singleton Toolchain = &toolchainLinuxX8664{} 120var toolchainLinuxX86Singleton Toolchain = &toolchainLinuxX86{} 121