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() { |
| 22 | android.RegisterModuleType("rust_prebuilt_dylib", PrebuiltDylibFactory) |
| 23 | } |
| 24 | |
| 25 | type PrebuiltProperties struct { |
| 26 | // path to the prebuilt file |
| 27 | Srcs []string `android:"path,arch_variant"` |
| 28 | } |
| 29 | |
| 30 | type prebuiltLibraryDecorator struct { |
| 31 | *libraryDecorator |
| 32 | Properties PrebuiltProperties |
| 33 | } |
| 34 | |
| 35 | var _ compiler = (*prebuiltLibraryDecorator)(nil) |
| 36 | |
| 37 | func PrebuiltDylibFactory() android.Module { |
| 38 | module, _ := NewPrebuiltDylib(android.HostAndDeviceSupported) |
| 39 | return module.Init() |
| 40 | } |
| 41 | |
| 42 | func NewPrebuiltDylib(hod android.HostOrDeviceSupported) (*Module, *prebuiltLibraryDecorator) { |
| 43 | module, library := NewRustLibrary(hod) |
| 44 | library.BuildOnlyDylib() |
Matthew Maurer | 99020b0 | 2019-10-31 10:44:40 -0700 | [diff] [blame] | 45 | library.setNoStdlibs() |
Ivan Lozano | ffee334 | 2019-08-27 12:03:00 -0700 | [diff] [blame] | 46 | library.setDylib() |
| 47 | prebuilt := &prebuiltLibraryDecorator{ |
| 48 | libraryDecorator: library, |
| 49 | } |
| 50 | module.compiler = prebuilt |
| 51 | module.AddProperties(&library.Properties) |
| 52 | return module, prebuilt |
| 53 | } |
| 54 | |
| 55 | func (prebuilt *prebuiltLibraryDecorator) compilerProps() []interface{} { |
| 56 | return append(prebuilt.baseCompiler.compilerProps(), |
| 57 | &prebuilt.Properties) |
| 58 | } |
| 59 | |
| 60 | func (prebuilt *prebuiltLibraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path { |
| 61 | srcPath := srcPathFromModuleSrcs(ctx, prebuilt.Properties.Srcs) |
| 62 | |
| 63 | prebuilt.unstrippedOutputFile = srcPath |
| 64 | |
| 65 | return srcPath |
| 66 | } |
Ivan Lozano | f1c8433 | 2019-09-20 11:00:37 -0700 | [diff] [blame] | 67 | |
| 68 | func (prebuilt *prebuiltLibraryDecorator) compilerDeps(ctx DepsContext, deps Deps) Deps { |
| 69 | deps = prebuilt.baseCompiler.compilerDeps(ctx, deps) |
| 70 | return deps |
| 71 | } |
Ivan Lozano | a0cd8f9 | 2020-04-09 09:56:02 -0400 | [diff] [blame^] | 72 | |
| 73 | func (prebuilt *prebuiltLibraryDecorator) nativeCoverage() bool { |
| 74 | return false |
| 75 | } |