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