Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 1 | // Copyright (C) 2016 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 art |
| 16 | |
| 17 | // This file implements the "codegen" property to apply different properties based on the currently |
| 18 | // selected codegen arches, which defaults to all arches on the host and the primary and secondary |
| 19 | // arches on the device. |
| 20 | |
| 21 | import ( |
| 22 | "android/soong/android" |
| 23 | "sort" |
| 24 | "strings" |
| 25 | ) |
| 26 | |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 27 | func codegen(ctx android.LoadHookContext, c *codegenProperties, library bool) { |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 28 | var hostArches, deviceArches []string |
| 29 | |
| 30 | e := envDefault(ctx, "ART_HOST_CODEGEN_ARCHS", "") |
| 31 | if e == "" { |
| 32 | hostArches = supportedArches |
| 33 | } else { |
| 34 | hostArches = strings.Split(e, " ") |
| 35 | } |
| 36 | |
| 37 | e = envDefault(ctx, "ART_TARGET_CODEGEN_ARCHS", "") |
| 38 | if e == "" { |
| 39 | deviceArches = defaultDeviceCodegenArches(ctx) |
| 40 | } else { |
| 41 | deviceArches = strings.Split(e, " ") |
| 42 | } |
| 43 | |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 44 | addCodegenArchProperties := func(host bool, archName string) { |
| 45 | type props struct { |
| 46 | Target struct { |
| 47 | Android *CodegenCommonArchProperties |
| 48 | Host *CodegenCommonArchProperties |
| 49 | } |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 50 | } |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 51 | |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 52 | type libraryProps struct { |
| 53 | Target struct { |
| 54 | Android *CodegenLibraryArchProperties |
| 55 | Host *CodegenLibraryArchProperties |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | var arch *codegenArchProperties |
| 60 | switch archName { |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 61 | case "arm": |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 62 | arch = &c.Codegen.Arm |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 63 | case "arm64": |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 64 | arch = &c.Codegen.Arm64 |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 65 | case "mips": |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 66 | arch = &c.Codegen.Mips |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 67 | case "mips64": |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 68 | arch = &c.Codegen.Mips64 |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 69 | case "x86": |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 70 | arch = &c.Codegen.X86 |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 71 | case "x86_64": |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 72 | arch = &c.Codegen.X86_64 |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 73 | default: |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 74 | ctx.ModuleErrorf("Unknown codegen architecture %q", archName) |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 75 | return |
| 76 | } |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 77 | |
| 78 | p := &props{} |
| 79 | l := &libraryProps{} |
| 80 | if host { |
| 81 | p.Target.Host = &arch.CodegenCommonArchProperties |
| 82 | l.Target.Host = &arch.CodegenLibraryArchProperties |
| 83 | } else { |
| 84 | p.Target.Android = &arch.CodegenCommonArchProperties |
| 85 | l.Target.Android = &arch.CodegenLibraryArchProperties |
| 86 | } |
| 87 | |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 88 | ctx.AppendProperties(p) |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 89 | if library { |
| 90 | ctx.AppendProperties(l) |
| 91 | } |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 92 | } |
| 93 | |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 94 | for _, arch := range deviceArches { |
| 95 | addCodegenArchProperties(false, arch) |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 96 | if ctx.Failed() { |
| 97 | return |
| 98 | } |
| 99 | } |
| 100 | |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 101 | for _, arch := range hostArches { |
| 102 | addCodegenArchProperties(true, arch) |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 103 | if ctx.Failed() { |
| 104 | return |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 109 | type CodegenCommonArchProperties struct { |
Roland Levillain | 12dd9ae | 2018-11-06 13:32:06 +0000 | [diff] [blame] | 110 | Srcs []string |
| 111 | Cflags []string |
| 112 | Cppflags []string |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | type CodegenLibraryArchProperties struct { |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 116 | Static struct { |
Paul Duffin | 1533243 | 2019-07-12 15:27:50 +0100 | [diff] [blame^] | 117 | Whole_static_libs []string |
| 118 | Export_static_lib_headers []string |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 119 | } |
| 120 | Shared struct { |
Paul Duffin | 1533243 | 2019-07-12 15:27:50 +0100 | [diff] [blame^] | 121 | Shared_libs []string |
| 122 | Export_shared_lib_headers []string |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 123 | } |
| 124 | } |
| 125 | |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 126 | type codegenArchProperties struct { |
| 127 | CodegenCommonArchProperties |
| 128 | CodegenLibraryArchProperties |
| 129 | } |
| 130 | |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 131 | type codegenProperties struct { |
| 132 | Codegen struct { |
| 133 | Arm, Arm64, Mips, Mips64, X86, X86_64 codegenArchProperties |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | type codegenCustomizer struct { |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 138 | library bool |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 139 | codegenProperties codegenProperties |
| 140 | } |
| 141 | |
Colin Cross | 6e51178 | 2016-09-13 13:41:03 -0700 | [diff] [blame] | 142 | func defaultDeviceCodegenArches(ctx android.LoadHookContext) []string { |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 143 | arches := make(map[string]bool) |
| 144 | for _, a := range ctx.DeviceConfig().Arches() { |
Nicolas Geoffray | e52ac15 | 2016-09-09 15:48:19 +0100 | [diff] [blame] | 145 | s := a.ArchType.String() |
| 146 | arches[s] = true |
| 147 | if s == "arm64" { |
| 148 | arches["arm"] = true |
| 149 | } else if s == "mips64" { |
| 150 | arches["mips"] = true |
| 151 | } else if s == "x86_64" { |
| 152 | arches["x86"] = true |
| 153 | } |
Colin Cross | 1f7f3bd | 2016-07-27 10:12:38 -0700 | [diff] [blame] | 154 | } |
| 155 | ret := make([]string, 0, len(arches)) |
| 156 | for a := range arches { |
| 157 | ret = append(ret, a) |
| 158 | } |
| 159 | sort.Strings(ret) |
| 160 | return ret |
| 161 | } |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 162 | |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 163 | func installCodegenCustomizer(module android.Module, library bool) { |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 164 | c := &codegenProperties{} |
| 165 | android.AddLoadHook(module, func(ctx android.LoadHookContext) { codegen(ctx, c, library) }) |
Colin Cross | ca06ea3 | 2017-06-27 10:38:55 -0700 | [diff] [blame] | 166 | module.AddProperties(c) |
Colin Cross | 6e95dd5 | 2016-09-12 15:37:10 -0700 | [diff] [blame] | 167 | } |