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