blob: cddd447ec73a981823e81d4694acd7b6b486ebf7 [file] [log] [blame]
Ivan Lozanoffee3342019-08-27 12:03:00 -07001// 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
15package rust
16
17import (
18 "android/soong/android"
19)
20
21func init() {
Matthew Maurerc761eec2020-06-25 00:47:46 -070022 android.RegisterModuleType("rust_prebuilt_library", PrebuiltLibraryFactory)
Ivan Lozanoffee3342019-08-27 12:03:00 -070023 android.RegisterModuleType("rust_prebuilt_dylib", PrebuiltDylibFactory)
Matthew Maurerc761eec2020-06-25 00:47:46 -070024 android.RegisterModuleType("rust_prebuilt_rlib", PrebuiltRlibFactory)
Ivan Lozanoffee3342019-08-27 12:03:00 -070025}
26
27type PrebuiltProperties struct {
28 // path to the prebuilt file
29 Srcs []string `android:"path,arch_variant"`
30}
31
32type prebuiltLibraryDecorator struct {
33 *libraryDecorator
34 Properties PrebuiltProperties
35}
36
37var _ compiler = (*prebuiltLibraryDecorator)(nil)
38
Matthew Maurerc761eec2020-06-25 00:47:46 -070039func PrebuiltLibraryFactory() android.Module {
40 module, _ := NewPrebuiltLibrary(android.HostAndDeviceSupported)
41 return module.Init()
42}
43
Ivan Lozanoffee3342019-08-27 12:03:00 -070044func PrebuiltDylibFactory() android.Module {
45 module, _ := NewPrebuiltDylib(android.HostAndDeviceSupported)
46 return module.Init()
47}
48
Matthew Maurerc761eec2020-06-25 00:47:46 -070049func PrebuiltRlibFactory() android.Module {
50 module, _ := NewPrebuiltRlib(android.HostAndDeviceSupported)
51 return module.Init()
52}
53
54func 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 Lozanoffee3342019-08-27 12:03:00 -070065func NewPrebuiltDylib(hod android.HostOrDeviceSupported) (*Module, *prebuiltLibraryDecorator) {
66 module, library := NewRustLibrary(hod)
67 library.BuildOnlyDylib()
Matthew Maurer99020b02019-10-31 10:44:40 -070068 library.setNoStdlibs()
Matthew Maurerc761eec2020-06-25 00:47:46 -070069 prebuilt := &prebuiltLibraryDecorator{
70 libraryDecorator: library,
71 }
72 module.compiler = prebuilt
73 return module, prebuilt
74}
75
76func NewPrebuiltRlib(hod android.HostOrDeviceSupported) (*Module, *prebuiltLibraryDecorator) {
77 module, library := NewRustLibrary(hod)
78 library.BuildOnlyRlib()
79 library.setNoStdlibs()
Ivan Lozanoffee3342019-08-27 12:03:00 -070080 prebuilt := &prebuiltLibraryDecorator{
81 libraryDecorator: library,
82 }
83 module.compiler = prebuilt
Ivan Lozanoffee3342019-08-27 12:03:00 -070084 return module, prebuilt
85}
86
87func (prebuilt *prebuiltLibraryDecorator) compilerProps() []interface{} {
Matthew Maurer128f53b2020-06-29 13:31:04 -070088 return append(prebuilt.libraryDecorator.compilerProps(),
Ivan Lozanoffee3342019-08-27 12:03:00 -070089 &prebuilt.Properties)
90}
91
92func (prebuilt *prebuiltLibraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Path {
Matthew Maurerc761eec2020-06-25 00:47:46 -070093 srcPath := srcPathFromModuleSrcs(ctx, prebuilt.prebuiltSrcs())
Ivan Lozanoffee3342019-08-27 12:03:00 -070094
95 prebuilt.unstrippedOutputFile = srcPath
96
97 return srcPath
98}
Ivan Lozanof1c84332019-09-20 11:00:37 -070099
100func (prebuilt *prebuiltLibraryDecorator) compilerDeps(ctx DepsContext, deps Deps) Deps {
101 deps = prebuilt.baseCompiler.compilerDeps(ctx, deps)
102 return deps
103}
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400104
105func (prebuilt *prebuiltLibraryDecorator) nativeCoverage() bool {
106 return false
107}
Matthew Maurerc761eec2020-06-25 00:47:46 -0700108
109func (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}