| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 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 |  | 
|  | 15 | package config | 
|  | 16 |  | 
|  | 17 | import ( | 
|  | 18 | "android/soong/android" | 
|  | 19 | ) | 
|  | 20 |  | 
|  | 21 | type Toolchain interface { | 
|  | 22 | RustTriple() string | 
|  | 23 | ToolchainRustFlags() string | 
|  | 24 | ToolchainLinkFlags() string | 
|  | 25 |  | 
|  | 26 | SharedLibSuffix() string | 
|  | 27 | StaticLibSuffix() string | 
|  | 28 | RlibSuffix() string | 
|  | 29 | DylibSuffix() string | 
|  | 30 | ProcMacroSuffix() string | 
|  | 31 | ExecutableSuffix() string | 
|  | 32 |  | 
|  | 33 | Is64Bit() bool | 
|  | 34 | Supported() bool | 
| Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 35 |  | 
|  | 36 | Bionic() bool | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 37 | } | 
|  | 38 |  | 
|  | 39 | type toolchainBase struct { | 
|  | 40 | } | 
|  | 41 |  | 
|  | 42 | func (toolchainBase) RustTriple() string { | 
|  | 43 | panic("toolchainBase does not define a triple.") | 
|  | 44 | } | 
|  | 45 |  | 
|  | 46 | func (toolchainBase) ToolchainRustFlags() string { | 
|  | 47 | panic("toolchainBase does not provide rust flags.") | 
|  | 48 | } | 
|  | 49 |  | 
|  | 50 | func (toolchainBase) ToolchainLinkFlags() string { | 
|  | 51 | panic("toolchainBase does not provide link flags.") | 
|  | 52 | } | 
|  | 53 |  | 
|  | 54 | func (toolchainBase) Is64Bit() bool { | 
|  | 55 | panic("toolchainBase cannot determine datapath width.") | 
|  | 56 | } | 
|  | 57 |  | 
| Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 58 | func (toolchainBase) Bionic() bool { | 
|  | 59 | return true | 
|  | 60 | } | 
|  | 61 |  | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 62 | type toolchain64Bit struct { | 
|  | 63 | toolchainBase | 
|  | 64 | } | 
|  | 65 |  | 
|  | 66 | func (toolchain64Bit) Is64Bit() bool { | 
|  | 67 | return true | 
|  | 68 | } | 
|  | 69 |  | 
|  | 70 | type toolchain32Bit struct { | 
|  | 71 | toolchainBase | 
|  | 72 | } | 
|  | 73 |  | 
|  | 74 | func (toolchain32Bit) Is64Bit() bool { | 
|  | 75 | return false | 
|  | 76 | } | 
|  | 77 |  | 
|  | 78 | func (toolchain32Bit) Bionic() bool { | 
|  | 79 | return true | 
|  | 80 | } | 
|  | 81 |  | 
|  | 82 | func (toolchainBase) ExecutableSuffix() string { | 
|  | 83 | return "" | 
|  | 84 | } | 
|  | 85 |  | 
|  | 86 | func (toolchainBase) SharedLibSuffix() string { | 
|  | 87 | return ".so" | 
|  | 88 | } | 
|  | 89 |  | 
|  | 90 | func (toolchainBase) StaticLibSuffix() string { | 
|  | 91 | return ".a" | 
|  | 92 | } | 
|  | 93 |  | 
|  | 94 | func (toolchainBase) RlibSuffix() string { | 
|  | 95 | return ".rlib" | 
|  | 96 | } | 
|  | 97 | func (toolchainBase) DylibSuffix() string { | 
| Ivan Lozano | 52767be | 2019-10-18 14:49:46 -0700 | [diff] [blame] | 98 | return ".dylib.so" | 
| Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 99 | } | 
|  | 100 |  | 
|  | 101 | func (toolchainBase) ProcMacroSuffix() string { | 
|  | 102 | return ".so" | 
|  | 103 | } | 
|  | 104 |  | 
|  | 105 | func (toolchainBase) Supported() bool { | 
|  | 106 | return false | 
|  | 107 | } | 
|  | 108 |  | 
|  | 109 | func toolchainBaseFactory() Toolchain { | 
|  | 110 | return &toolchainBase{} | 
|  | 111 | } | 
|  | 112 |  | 
|  | 113 | type toolchainFactory func(arch android.Arch) Toolchain | 
|  | 114 |  | 
|  | 115 | var toolchainFactories = make(map[android.OsType]map[android.ArchType]toolchainFactory) | 
|  | 116 |  | 
|  | 117 | func registerToolchainFactory(os android.OsType, arch android.ArchType, factory toolchainFactory) { | 
|  | 118 | if toolchainFactories[os] == nil { | 
|  | 119 | toolchainFactories[os] = make(map[android.ArchType]toolchainFactory) | 
|  | 120 | } | 
|  | 121 | toolchainFactories[os][arch] = factory | 
|  | 122 | } | 
|  | 123 |  | 
|  | 124 | func FindToolchain(os android.OsType, arch android.Arch) Toolchain { | 
|  | 125 | factory := toolchainFactories[os][arch.ArchType] | 
|  | 126 | if factory == nil { | 
|  | 127 | return toolchainBaseFactory() | 
|  | 128 | } | 
|  | 129 | return factory(arch) | 
|  | 130 | } |