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 rust |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
| 19 | ) |
| 20 | |
| 21 | func init() { |
Matthew Maurer | c761eec | 2020-06-25 00:47:46 -0700 | [diff] [blame] | 22 | android.RegisterModuleType("rust_prebuilt_library", PrebuiltLibraryFactory) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 23 | android.RegisterModuleType("rust_prebuilt_dylib", PrebuiltDylibFactory) |
Matthew Maurer | c761eec | 2020-06-25 00:47:46 -0700 | [diff] [blame] | 24 | android.RegisterModuleType("rust_prebuilt_rlib", PrebuiltRlibFactory) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | type PrebuiltProperties struct { |
| 28 | // path to the prebuilt file |
| 29 | Srcs []string `android:"path,arch_variant"` |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 30 | // directories containing associated rlib dependencies |
| 31 | Link_dirs []string `android:"path,arch_variant"` |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | type prebuiltLibraryDecorator struct { |
| 35 | *libraryDecorator |
| 36 | Properties PrebuiltProperties |
| 37 | } |
| 38 | |
| 39 | var _ compiler = (*prebuiltLibraryDecorator)(nil) |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 40 | var _ exportedFlagsProducer = (*prebuiltLibraryDecorator)(nil) |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 41 | |
Matthew Maurer | c761eec | 2020-06-25 00:47:46 -0700 | [diff] [blame] | 42 | func PrebuiltLibraryFactory() android.Module { |
| 43 | module, _ := NewPrebuiltLibrary(android.HostAndDeviceSupported) |
| 44 | return module.Init() |
| 45 | } |
| 46 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 47 | func PrebuiltDylibFactory() android.Module { |
| 48 | module, _ := NewPrebuiltDylib(android.HostAndDeviceSupported) |
| 49 | return module.Init() |
| 50 | } |
| 51 | |
Matthew Maurer | c761eec | 2020-06-25 00:47:46 -0700 | [diff] [blame] | 52 | func PrebuiltRlibFactory() android.Module { |
| 53 | module, _ := NewPrebuiltRlib(android.HostAndDeviceSupported) |
| 54 | return module.Init() |
| 55 | } |
| 56 | |
| 57 | func NewPrebuiltLibrary(hod android.HostOrDeviceSupported) (*Module, *prebuiltLibraryDecorator) { |
| 58 | module, library := NewRustLibrary(hod) |
| 59 | library.BuildOnlyRust() |
| 60 | library.setNoStdlibs() |
| 61 | prebuilt := &prebuiltLibraryDecorator{ |
| 62 | libraryDecorator: library, |
| 63 | } |
| 64 | module.compiler = prebuilt |
| 65 | return module, prebuilt |
| 66 | } |
| 67 | |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 68 | func NewPrebuiltDylib(hod android.HostOrDeviceSupported) (*Module, *prebuiltLibraryDecorator) { |
| 69 | module, library := NewRustLibrary(hod) |
| 70 | library.BuildOnlyDylib() |
Matthew Maurer | 99020b0 | 2019-10-31 10:44:40 -0700 | [diff] [blame] | 71 | library.setNoStdlibs() |
Matthew Maurer | c761eec | 2020-06-25 00:47:46 -0700 | [diff] [blame] | 72 | prebuilt := &prebuiltLibraryDecorator{ |
| 73 | libraryDecorator: library, |
| 74 | } |
| 75 | module.compiler = prebuilt |
| 76 | return module, prebuilt |
| 77 | } |
| 78 | |
| 79 | func NewPrebuiltRlib(hod android.HostOrDeviceSupported) (*Module, *prebuiltLibraryDecorator) { |
| 80 | module, library := NewRustLibrary(hod) |
| 81 | library.BuildOnlyRlib() |
| 82 | library.setNoStdlibs() |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 83 | prebuilt := &prebuiltLibraryDecorator{ |
| 84 | libraryDecorator: library, |
| 85 | } |
| 86 | module.compiler = prebuilt |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 87 | return module, prebuilt |
| 88 | } |
| 89 | |
| 90 | func (prebuilt *prebuiltLibraryDecorator) compilerProps() []interface{} { |
Matthew Maurer | 128f53b | 2020-06-29 13:31:04 -0700 | [diff] [blame] | 91 | return append(prebuilt.libraryDecorator.compilerProps(), |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 92 | &prebuilt.Properties) |
| 93 | } |
| 94 | |
| 95 | func (prebuilt *prebuiltLibraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path { |
Matthew Maurer | bb3add1 | 2020-06-25 09:34:12 -0700 | [diff] [blame] | 96 | prebuilt.exportLinkDirs(android.PathsForModuleSrc(ctx, prebuilt.Properties.Link_dirs).Strings()...) |
| 97 | |
Chih-Hung Hsieh | bbd25ae | 2020-05-15 17:36:30 -0700 | [diff] [blame^] | 98 | srcPath, paths := srcPathFromModuleSrcs(ctx, prebuilt.prebuiltSrcs()) |
| 99 | deps.SrcDeps = paths |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 100 | |
| 101 | prebuilt.unstrippedOutputFile = srcPath |
| 102 | |
| 103 | return srcPath |
| 104 | } |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 105 | |
| 106 | func (prebuilt *prebuiltLibraryDecorator) compilerDeps(ctx DepsContext, deps Deps) Deps { |
| 107 | deps = prebuilt.baseCompiler.compilerDeps(ctx, deps) |
| 108 | return deps |
| 109 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame] | 110 | |
| 111 | func (prebuilt *prebuiltLibraryDecorator) nativeCoverage() bool { |
| 112 | return false |
| 113 | } |
Matthew Maurer | c761eec | 2020-06-25 00:47:46 -0700 | [diff] [blame] | 114 | |
| 115 | func (prebuilt *prebuiltLibraryDecorator) prebuiltSrcs() []string { |
| 116 | srcs := prebuilt.Properties.Srcs |
| 117 | if prebuilt.rlib() { |
| 118 | srcs = append(srcs, prebuilt.libraryDecorator.Properties.Rlib.Srcs...) |
| 119 | } |
| 120 | if prebuilt.dylib() { |
| 121 | srcs = append(srcs, prebuilt.libraryDecorator.Properties.Dylib.Srcs...) |
| 122 | } |
| 123 | |
| 124 | return srcs |
| 125 | } |