Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- * * Copyright (c) 2017 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in * compliance with the License. Please obtain a copy of the License at * http://www.opensource.apple.com/apsl/ and read it before using this * file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. * Please see the License for the specific language governing rights and * limitations under the License. * * @APPLE_LICENSE_HEADER_END@ */ #ifndef mrm_shared_cache_builder_h #define mrm_shared_cache_builder_h #include <Availability.h> #include <stdint.h> #include <stdbool.h> #include <sys/types.h> #ifdef __cplusplus extern "C" { #endif // Note, this should match PLATFORM_* values in <mach-o/loader.h> enum Platform { unknown = 0, macOS = 1, // PLATFORM_MACOS iOS = 2, // PLATFORM_IOS tvOS = 3, // PLATFORM_TVOS watchOS = 4, // PLATFORM_WATCHOS bridgeOS = 5, // PLATFORM_BRIDGEOS iOSMac = 6, // PLATFORM_MACCATALYST iOS_simulator = 7, // PLATFORM_IOSIMULATOR tvOS_simulator = 8, // PLATFORM_TVOSSIMULATOR watchOS_simulator = 9, // PLATFORM_WATCHOSSIMULATOR driverKit = 10, // PLATFORM_DRIVERKIT macOSExclaveKit = 16, // PLATFORM_MACOS_EXCLAVEKIT iOSExclaveKit = 18, // PLATFORM_IOS_EXCLAVEKIT }; enum Disposition { Unknown = 0, InternalDevelopment = 1, Customer = 2, InternalMinDevelopment = 3, SymbolsCache = 4 }; enum FileFlags { // Note these are for macho inputs NoFlags = 0, MustBeInCache = 1, ShouldBeExcludedFromCacheIfUnusedLeaf = 2, RequiredClosure = 3, // These are for the order files DylibOrderFile = 100, DirtyDataOrderFile = 101, ObjCOptimizationsFile = 102, SwiftGenericMetadataFile = 103, // This replaces all the magic JSON files and order files, ie, 100..103 above // The path (or some field in the file if its JSON) will be used later to work // out which file it is OptimizationFile = 1000, }; struct BuildOptions_v1 { uint64_t version; // Future proofing, set to 1 const char * updateName; // BuildTrain+UpdateNumber const char * deviceName; enum Disposition disposition; // Internal, Customer, etc. enum Platform platform; // Enum: unknown, macOS, iOS, ... const char ** archs; uint64_t numArchs; bool verboseDiagnostics; bool isLocallyBuiltCache; }; // This is available when getVersion() returns 1.2 or higher struct BuildOptions_v2 { uint64_t version; // Future proofing, set to 2 const char * updateName; // BuildTrain+UpdateNumber const char * deviceName; enum Disposition disposition; // Internal, Customer, etc. enum Platform platform; // Enum: unknown, macOS, iOS, ... const char ** archs; uint64_t numArchs; bool verboseDiagnostics; bool isLocallyBuiltCache; // Added in v2 bool optimizeForSize; }; // This is available when getVersion() returns 1.3 or higher struct BuildOptions_v3 { uint64_t version; // Future proofing, set to 2 const char * updateName; // BuildTrain+UpdateNumber const char * deviceName; enum Disposition disposition; // Internal, Customer, etc. enum Platform platform; // Enum: unknown, macOS, iOS, ... const char ** archs; uint64_t numArchs; bool verboseDiagnostics; bool isLocallyBuiltCache; // Added in v2 bool optimizeForSize; // Added in v3 bool filesRemovedFromDisk; bool timePasses; bool printStats; // Added in v3.1 (still just v3 as there's no clients of it yet) bool verboseIMPCaches; bool verboseCacheLayout; }; enum FileBehavior { AddFile = 0, // New file: uid, gid, mode, data, cdhash fields must be set ChangeFile = 1, // Change the data of file: data, size, and cdhash fields must be set }; struct FileResult { uint64_t version; }; struct FileResult_v1 { uint64_t version; // Future proofing, set to 1 const char* path; enum FileBehavior behavior; const uint8_t* data; // Owned by the cache builder. Destroyed by destroySharedCacheBuilder uint64_t size; // CDHash, must be set for new or modified files const char* hashArch; const char* hashType; const char* hash; }; struct CacheResult { uint64_t version; // Future proofing, set to 1 const char* loggingPrefix; // needed? const char* deviceConfiguration; const char ** warnings; // should this be per-result? uint64_t numWarnings; const char ** errors; // should this be per-result? uint64_t numErrors; const char* uuidString; const char* mapJSON; }; struct MRMSharedCacheBuilder; __API_AVAILABLE(macos(10.12)) void getVersion(uint32_t *major, uint32_t *minor); __API_AVAILABLE(macos(10.12)) struct MRMSharedCacheBuilder* createSharedCacheBuilder(const struct BuildOptions_v1* options); // Add a file. Returns true on success. __API_AVAILABLE(macos(10.12)) bool addFile(struct MRMSharedCacheBuilder* builder, const char* path, uint8_t* data, uint64_t size, enum FileFlags fileFlags); // Add a file. Returns true on success. // Available in API version 1.6 and later __API_AVAILABLE(macos(10.12)) bool addFile_v2(struct MRMSharedCacheBuilder* builder, const char* path, uint8_t* data, uint64_t size, enum FileFlags fileFlags, const char* projectName); // Add an on-disk file (ie, a file which won't be removed by MRM). Returns true on success. __API_AVAILABLE(macos(10.12)) bool addOnDiskFile(struct MRMSharedCacheBuilder* builder, const char* path, uint8_t* data, uint64_t size, enum FileFlags fileFlags, uint64_t inode, uint64_t modTime); __API_AVAILABLE(macos(10.12)) bool addSymlink(struct MRMSharedCacheBuilder* builder, const char* fromPath, const char* toPath); __API_AVAILABLE(macos(10.12)) bool runSharedCacheBuilder(struct MRMSharedCacheBuilder* builder); __API_AVAILABLE(macos(10.12)) const char* const* getErrors(const struct MRMSharedCacheBuilder* builder, uint64_t* errorCount); __API_AVAILABLE(macos(10.12)) const struct FileResult* const* getFileResults(struct MRMSharedCacheBuilder* builder, uint64_t* resultCount); __API_AVAILABLE(macos(10.12)) const struct CacheResult* const* getCacheResults(struct MRMSharedCacheBuilder* builder, uint64_t* resultCount); __API_AVAILABLE(macos(10.12)) const char* const* getFilesToRemove(const struct MRMSharedCacheBuilder* builder, uint64_t* fileCount); __API_AVAILABLE(macos(10.12)) const char* const* getCacheStats(const struct MRMSharedCacheBuilder* builder, uint64_t* resultCount); __API_AVAILABLE(macos(10.12)) void destroySharedCacheBuilder(struct MRMSharedCacheBuilder* builder); #ifdef __cplusplus } #endif #endif /* mrm_shared_cache_builder_h */ |