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