dyld-832.7.1.tar.gz
[apple/dyld.git] / dyld3 / shared-cache / mrm_shared_cache_builder.h
1 /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
2 *
3 * Copyright (c) 2017 Apple Inc. All rights reserved.
4 *
5 * @APPLE_LICENSE_HEADER_START@
6 *
7 * This file contains Original Code and/or Modifications of Original Code
8 * as defined in and that are subject to the Apple Public Source License
9 * Version 2.0 (the 'License'). You may not use this file except in
10 * compliance with the License. Please obtain a copy of the License at
11 * http://www.opensource.apple.com/apsl/ and read it before using this
12 * file.
13 *
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
19 * Please see the License for the specific language governing rights and
20 * limitations under the License.
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24
25 #ifndef mrm_shared_cache_builder_hpp
26 #define mrm_shared_cache_builder_hpp
27
28 #include <Availability.h>
29
30 #include <stdint.h>
31 #include <sys/types.h>
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 // Note, this should match PLATFORM_* values in <mach-o/loader.h>
38 enum Platform {
39 unknown = 0,
40 macOS = 1, // PLATFORM_MACOS
41 iOS = 2, // PLATFORM_IOS
42 tvOS = 3, // PLATFORM_TVOS
43 watchOS = 4, // PLATFORM_WATCHOS
44 bridgeOS = 5, // PLATFORM_BRIDGEOS
45 iOSMac = 6, // PLATFORM_MACCATALYST
46 iOS_simulator = 7, // PLATFORM_IOSIMULATOR
47 tvOS_simulator = 8, // PLATFORM_TVOSSIMULATOR
48 watchOS_simulator = 9 // PLATFORM_WATCHOSSIMULATOR
49 };
50
51 enum Disposition
52 {
53 Unknown = 0,
54 InternalDevelopment = 1,
55 Customer = 2,
56 InternalMinDevelopment = 3
57 };
58
59 enum FileFlags
60 {
61 // Note these are for macho inputs
62 NoFlags = 0,
63 MustBeInCache = 1,
64 ShouldBeExcludedFromCacheIfUnusedLeaf = 2,
65 RequiredClosure = 3,
66
67 // These are for the order files
68 DylibOrderFile = 100,
69 DirtyDataOrderFile = 101,
70 ObjCOptimizationsFile = 102,
71 };
72
73 struct BuildOptions_v1
74 {
75 uint64_t version; // Future proofing, set to 1
76 const char * updateName; // BuildTrain+UpdateNumber
77 const char * deviceName;
78 enum Disposition disposition; // Internal, Customer, etc.
79 enum Platform platform; // Enum: unknown, macOS, iOS, ...
80 const char ** archs;
81 uint64_t numArchs;
82 bool verboseDiagnostics;
83 bool isLocallyBuiltCache;
84 };
85
86 // This is available when getVersion() returns 1.2 or higher
87 struct BuildOptions_v2
88 {
89 uint64_t version; // Future proofing, set to 2
90 const char * updateName; // BuildTrain+UpdateNumber
91 const char * deviceName;
92 enum Disposition disposition; // Internal, Customer, etc.
93 enum Platform platform; // Enum: unknown, macOS, iOS, ...
94 const char ** archs;
95 uint64_t numArchs;
96 bool verboseDiagnostics;
97 bool isLocallyBuiltCache;
98 // Added in v2
99 bool optimizeForSize;
100 };
101
102 enum FileBehavior
103 {
104 AddFile = 0, // New file: uid, gid, mode, data, cdhash fields must be set
105 ChangeFile = 1, // Change the data of file: data, size, and cdhash fields must be set
106 };
107
108 struct FileResult
109 {
110 uint64_t version; // Future proofing, set to 1
111 const char* path;
112 enum FileBehavior behavior;
113 const uint8_t* data; // Owned by the cache builder. Destroyed by destroySharedCacheBuilder
114 uint64_t size;
115 // CDHash, must be set for new or modified files
116 const char* hashArch;
117 const char* hashType;
118 const char* hash;
119 };
120
121
122 struct CacheResult
123 {
124 uint64_t version; // Future proofing, set to 1
125 const char* loggingPrefix; // needed?
126 const char* deviceConfiguration;
127 const char ** warnings; // should this be per-result?
128 uint64_t numWarnings;
129 const char ** errors; // should this be per-result?
130 uint64_t numErrors;
131 const char* uuidString;
132 const char* mapJSON;
133 };
134
135 struct MRMSharedCacheBuilder;
136
137 __API_AVAILABLE(macos(10.12))
138 void getVersion(uint32_t *major, uint32_t *minor);
139
140 __API_AVAILABLE(macos(10.12))
141 struct MRMSharedCacheBuilder* createSharedCacheBuilder(const struct BuildOptions_v1* options);
142
143 // Add a file. Returns true on success.
144 __API_AVAILABLE(macos(10.12))
145 bool addFile(struct MRMSharedCacheBuilder* builder, const char* path, uint8_t* data, uint64_t size, enum FileFlags fileFlags);
146
147 __API_AVAILABLE(macos(10.12))
148 bool addSymlink(struct MRMSharedCacheBuilder* builder, const char* fromPath, const char* toPath);
149
150 __API_AVAILABLE(macos(10.12))
151 bool runSharedCacheBuilder(struct MRMSharedCacheBuilder* builder);
152
153 __API_AVAILABLE(macos(10.12))
154 const char* const* getErrors(const struct MRMSharedCacheBuilder* builder, uint64_t* errorCount);
155
156 __API_AVAILABLE(macos(10.12))
157 const struct FileResult* const* getFileResults(struct MRMSharedCacheBuilder* builder, uint64_t* resultCount);
158
159 __API_AVAILABLE(macos(10.12))
160 const struct CacheResult* const* getCacheResults(struct MRMSharedCacheBuilder* builder, uint64_t* resultCount);
161
162 __API_AVAILABLE(macos(10.12))
163 const char* const* getFilesToRemove(const struct MRMSharedCacheBuilder* builder, uint64_t* fileCount);
164
165 __API_AVAILABLE(macos(10.12))
166 void destroySharedCacheBuilder(struct MRMSharedCacheBuilder* builder);
167
168 #ifdef __cplusplus
169 }
170 #endif
171
172 #endif /* mrm_shared_cache_builder_hpp */