| 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() | 
|  | 45 | library.setDylib() | 
|  | 46 | prebuilt := &prebuiltLibraryDecorator{ | 
|  | 47 | libraryDecorator: library, | 
|  | 48 | } | 
|  | 49 | module.compiler = prebuilt | 
|  | 50 | module.AddProperties(&library.Properties) | 
|  | 51 | return module, prebuilt | 
|  | 52 | } | 
|  | 53 |  | 
|  | 54 | func (prebuilt *prebuiltLibraryDecorator) compilerProps() []interface{} { | 
|  | 55 | return append(prebuilt.baseCompiler.compilerProps(), | 
|  | 56 | &prebuilt.Properties) | 
|  | 57 | } | 
|  | 58 |  | 
|  | 59 | func (prebuilt *prebuiltLibraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path { | 
|  | 60 | srcPath := srcPathFromModuleSrcs(ctx, prebuilt.Properties.Srcs) | 
|  | 61 |  | 
|  | 62 | prebuilt.unstrippedOutputFile = srcPath | 
|  | 63 |  | 
|  | 64 | return srcPath | 
|  | 65 | } |