text_stub_library/yaml.rs
1// Copyright 2022 Gregory Szorc.
2//
3// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6// option. This file may not be copied, modified, or distributed
7// except according to those terms.
8
9/*! YAML structures in text stub files.
10
11This module defines raw YAML primitives existing in text stub files / `.tbd`
12files.
13
14See https://github.com/llvm/llvm-project/blob/main/llvm/lib/TextAPI/MachO/TextStub.cpp
15for specifications of the YAML files.
16 */
17
18use serde::{Deserialize, Serialize};
19
20/*
21The TBD v1 format only support two level address libraries and is per
22definition application extension safe.
23--- # the tag !tapi-tbd-v1 is optional and
24 # shouldn't be emitted to support older linker.
25archs: [ armv7, armv7s, arm64 ] # the list of architecture slices that are
26 # supported by this file.
27platform: ios # Specifies the platform (macosx, ios, etc)
28install-name: /u/l/libfoo.dylib #
29current-version: 1.2.3 # Optional: defaults to 1.0
30compatibility-version: 1.0 # Optional: defaults to 1.0
31swift-version: 0 # Optional: defaults to 0
32objc-constraint: none # Optional: defaults to none
33exports: # List of export sections
34...
35Each export section is defined as following:
36 - archs: [ arm64 ] # the list of architecture slices
37 allowed-clients: [ client ] # Optional: List of clients
38 re-exports: [ ] # Optional: List of re-exports
39 symbols: [ _sym ] # Optional: List of symbols
40 objc-classes: [] # Optional: List of Objective-C classes
41 objc-ivars: [] # Optional: List of Objective C Instance
42 # Variables
43 weak-def-symbols: [] # Optional: List of weak defined symbols
44 thread-local-symbols: [] # Optional: List of thread local symbols
45*/
46
47/// Version 1 of the TBD structure.
48#[derive(Clone, Debug, Deserialize, Serialize)]
49#[serde(rename_all = "kebab-case")]
50pub struct TbdVersion1 {
51 /// The list of architecture slices that are supported by this file.
52 ///
53 /// armv7, arm64, etc.
54 pub archs: Vec<String>,
55
56 /// Specifies the platform (macosx, ios, etc).
57 pub platform: String,
58
59 /// Path of installed library.
60 pub install_name: String,
61
62 /// Current version of library.
63 ///
64 /// Defaults to `1.0`.
65 pub current_version: Option<String>,
66
67 /// Compatibility version of library.
68 ///
69 /// Defaults to `1.0`.
70 pub compatibility_version: Option<String>,
71
72 /// Swift version of library.
73 ///
74 /// Defaults to `0`.
75 pub swift_version: Option<String>,
76
77 /// Objective-C constraint.
78 ///
79 /// Defaults to `none`.
80 pub objc_constraint: Option<String>,
81
82 /// Export sections.
83 pub exports: Vec<TbdVersion12ExportSection>,
84}
85
86/// Export section in a TBD version 1 or 2 structure.
87#[derive(Clone, Debug, Deserialize, Serialize)]
88#[serde(rename_all = "kebab-case")]
89pub struct TbdVersion12ExportSection {
90 /// List of architecture slices.
91 pub archs: Vec<String>,
92
93 /// List of clients.
94 #[serde(default)]
95 pub allowed_clients: Vec<String>,
96
97 /// List of re-exports.
98 #[serde(default)]
99 pub re_exports: Vec<String>,
100
101 /// List of symbols.
102 #[serde(default)]
103 pub symbols: Vec<String>,
104
105 /// List of Objective-C classes.
106 #[serde(default)]
107 pub objc_classes: Vec<String>,
108
109 /// List of Objective-C instance variables.
110 #[serde(default)]
111 pub objc_ivars: Vec<String>,
112
113 /// List of weak defined symbols.
114 #[serde(default)]
115 pub weak_def_symbols: Vec<String>,
116
117 /// List of thread local symbols.
118 #[serde(default)]
119 pub thread_local_symbols: Vec<String>,
120}
121
122/*
123--- !tapi-tbd-v2
124archs: [ armv7, armv7s, arm64 ] # the list of architecture slices that are
125 # supported by this file.
126uuids: [ armv7:... ] # Optional: List of architecture and UUID pairs.
127platform: ios # Specifies the platform (macosx, ios, etc)
128flags: [] # Optional:
129install-name: /u/l/libfoo.dylib #
130current-version: 1.2.3 # Optional: defaults to 1.0
131compatibility-version: 1.0 # Optional: defaults to 1.0
132swift-version: 0 # Optional: defaults to 0
133objc-constraint: retain_release # Optional: defaults to retain_release
134parent-umbrella: # Optional:
135exports: # List of export sections
136...
137undefineds: # List of undefineds sections
138...
139Each export section is defined as following:
140- archs: [ arm64 ] # the list of architecture slices
141 allowed-clients: [ client ] # Optional: List of clients
142 re-exports: [ ] # Optional: List of re-exports
143 symbols: [ _sym ] # Optional: List of symbols
144 objc-classes: [] # Optional: List of Objective-C classes
145 objc-ivars: [] # Optional: List of Objective C Instance
146 # Variables
147 weak-def-symbols: [] # Optional: List of weak defined symbols
148 thread-local-symbols: [] # Optional: List of thread local symbols
149Each undefineds section is defined as following:
150- archs: [ arm64 ] # the list of architecture slices
151 symbols: [ _sym ] # Optional: List of symbols
152 objc-classes: [] # Optional: List of Objective-C classes
153 objc-ivars: [] # Optional: List of Objective C Instance Variables
154 weak-ref-symbols: [] # Optional: List of weak defined symbols
155*/
156
157/// Version 2 of the TBD data structure.
158#[derive(Clone, Debug, Deserialize, Serialize)]
159#[serde(rename_all = "kebab-case")]
160pub struct TbdVersion2 {
161 /// The list of architecture slices that are supported by this file.
162 pub archs: Vec<String>,
163
164 /// List of architecture and UUID pairs.
165 #[serde(default)]
166 pub uuids: Vec<String>,
167
168 /// Specifies the paltform (macosx, ios, etc).
169 pub platform: String,
170
171 #[serde(default)]
172 pub flags: Vec<String>,
173
174 pub install_name: String,
175
176 /// Current version of library.
177 ///
178 /// Defaults to `1.0`.
179 pub current_version: Option<String>,
180
181 /// Compatibility version of library.
182 ///
183 /// Defaults to `1.0`.
184 pub compatibility_version: Option<String>,
185
186 /// Swift version of library.
187 pub swift_version: Option<String>,
188
189 /// Objective-C constraint.
190 pub objc_constraint: Option<String>,
191
192 pub parent_umbrella: Option<String>,
193
194 /// Export sections.
195 #[serde(default)]
196 pub exports: Vec<TbdVersion12ExportSection>,
197
198 /// Undefineds sections.
199 #[serde(default)]
200 pub undefineds: Vec<TbdVersion2UndefinedsSection>,
201}
202
203/// Undefineds sections in a version 2 TBD structure.
204#[derive(Clone, Debug, Deserialize, Serialize)]
205#[serde(rename_all = "kebab-case")]
206pub struct TbdVersion2UndefinedsSection {
207 /// The list of architecture slices.
208 pub archs: Vec<String>,
209
210 /// List of symbols.
211 #[serde(default)]
212 pub symbols: Vec<String>,
213
214 /// List of Objective-C classes.
215 #[serde(default)]
216 pub objc_classes: Vec<String>,
217
218 /// List of Objective-C instance variables.
219 #[serde(default)]
220 pub objc_ivars: Vec<String>,
221
222 /// List of weak defined symbols.
223 #[serde(default)]
224 pub weak_ref_symbols: Vec<String>,
225}
226
227#[derive(Clone, Debug, Deserialize, Serialize)]
228#[serde(rename_all = "kebab-case")]
229pub struct TbdUmbrellaSection {
230 #[serde(default)]
231 pub targets: Vec<String>,
232
233 pub umbrella: String,
234}
235
236/*
237--- !tapi-tbd-v3
238archs: [ armv7, armv7s, arm64 ] # the list of architecture slices that are
239 # supported by this file.
240uuids: [ armv7:... ] # Optional: List of architecture and UUID pairs.
241platform: ios # Specifies the platform (macosx, ios, etc)
242flags: [] # Optional:
243install-name: /u/l/libfoo.dylib #
244current-version: 1.2.3 # Optional: defaults to 1.0
245compatibility-version: 1.0 # Optional: defaults to 1.0
246swift-abi-version: 0 # Optional: defaults to 0
247objc-constraint: retain_release # Optional: defaults to retain_release
248parent-umbrella: # Optional:
249exports: # List of export sections
250...
251undefineds: # List of undefineds sections
252...
253Each export section is defined as following:
254- archs: [ arm64 ] # the list of architecture slices
255 allowed-clients: [ client ] # Optional: List of clients
256 re-exports: [ ] # Optional: List of re-exports
257 symbols: [ _sym ] # Optional: List of symbols
258 objc-classes: [] # Optional: List of Objective-C classes
259 objc-eh-types: [] # Optional: List of Objective-C classes
260 # with EH
261 objc-ivars: [] # Optional: List of Objective C Instance
262 # Variables
263 weak-def-symbols: [] # Optional: List of weak defined symbols
264 thread-local-symbols: [] # Optional: List of thread local symbols
265Each undefineds section is defined as following:
266- archs: [ arm64 ] # the list of architecture slices
267 symbols: [ _sym ] # Optional: List of symbols
268 objc-classes: [] # Optional: List of Objective-C classes
269 objc-eh-types: [] # Optional: List of Objective-C classes
270 # with EH
271 objc-ivars: [] # Optional: List of Objective C Instance Variables
272 weak-ref-symbols: [] # Optional: List of weak defined symbols
273*/
274
275/// Version 3 of the TBD data structure.
276#[derive(Clone, Debug, Deserialize, Serialize)]
277#[serde(rename_all = "kebab-case")]
278pub struct TbdVersion3 {
279 /// The list of architecture slices that are supported by this file.
280 pub archs: Vec<String>,
281
282 /// List of architecture and UUID pairs.
283 #[serde(default)]
284 pub uuids: Vec<String>,
285
286 /// Specifies the paltform (macosx, ios, etc).
287 pub platform: String,
288
289 #[serde(default)]
290 pub flags: Vec<String>,
291
292 pub install_name: String,
293
294 /// Current version of library.
295 ///
296 /// Defaults to `1.0`.
297 pub current_version: Option<String>,
298
299 /// Compatibility version of library.
300 ///
301 /// Defaults to `1.0`.
302 pub compatibility_version: Option<String>,
303
304 /// Swift version of library.
305 pub swift_abi_version: Option<String>,
306
307 /// Objective-C constraint.
308 ///
309 /// Defaults to `retain_release`.
310 pub objc_constraint: Option<String>,
311
312 pub parent_umbrella: Option<String>,
313
314 /// Export sections.
315 #[serde(default)]
316 pub exports: Vec<TbdVersion3ExportSection>,
317
318 /// Undefineds sections.
319 #[serde(default)]
320 pub undefineds: Vec<TbdVersion3UndefinedsSection>,
321}
322
323/// Export section in a TBD version 3 structure.
324#[derive(Clone, Debug, Deserialize, Serialize)]
325#[serde(rename_all = "kebab-case")]
326pub struct TbdVersion3ExportSection {
327 /// List of architecture slices.
328 pub archs: Vec<String>,
329
330 /// List of clients.
331 #[serde(default)]
332 pub allowed_clients: Vec<String>,
333
334 /// List of re-exports.
335 #[serde(default)]
336 pub re_exports: Vec<String>,
337
338 /// List of symbols.
339 #[serde(default)]
340 pub symbols: Vec<String>,
341
342 /// List of Objective-C classes.
343 #[serde(default)]
344 pub objc_classes: Vec<String>,
345
346 /// List of Objective-C classes with EH.
347 #[serde(default)]
348 pub objc_eh_types: Vec<String>,
349
350 /// List of Objective-C instance variables.
351 #[serde(default)]
352 pub objc_ivars: Vec<String>,
353
354 /// List of weak defined symbols.
355 #[serde(default)]
356 pub weak_def_symbols: Vec<String>,
357
358 /// List of thread local symbols.
359 #[serde(default)]
360 pub thread_local_symbols: Vec<String>,
361}
362
363/// Undefineds section in a version 3 TBD structure.
364#[derive(Clone, Debug, Deserialize, Serialize)]
365#[serde(rename_all = "kebab-case")]
366pub struct TbdVersion3UndefinedsSection {
367 /// The list of architecture slices.
368 pub archs: Vec<String>,
369
370 /// List of symbols.
371 #[serde(default)]
372 pub symbols: Vec<String>,
373
374 /// List of Objective-C classes.
375 #[serde(default)]
376 pub objc_classes: Vec<String>,
377
378 /// List of Objective-C classes with EH.
379 #[serde(default)]
380 pub objc_eh_types: Vec<String>,
381
382 /// List of Objective-C instance variables.
383 #[serde(default)]
384 pub objc_ivars: Vec<String>,
385
386 /// List of weak defined symbols.
387 #[serde(default)]
388 pub weak_ref_symbols: Vec<String>,
389}
390
391/*
392--- !tapi-tbd
393tbd-version: 4 # The tbd version for format
394targets: [ armv7-ios, x86_64-maccatalyst ] # The list of applicable tapi supported target triples
395uuids: # Optional: List of target and UUID pairs.
396 - target: armv7-ios
397 value: ...
398 - target: x86_64-maccatalyst
399 value: ...
400flags: [] # Optional:
401install-name: /u/l/libfoo.dylib #
402current-version: 1.2.3 # Optional: defaults to 1.0
403compatibility-version: 1.0 # Optional: defaults to 1.0
404swift-abi-version: 0 # Optional: defaults to 0
405parent-umbrella: # Optional:
406allowable-clients:
407 - targets: [ armv7-ios ] # Optional:
408 clients: [ clientA ]
409exports: # List of export sections
410...
411re-exports: # List of reexport sections
412...
413undefineds: # List of undefineds sections
414...
415Each export and reexport section is defined as following:
416- targets: [ arm64-macos ] # The list of target triples associated with symbols
417 symbols: [ _symA ] # Optional: List of symbols
418 objc-classes: [] # Optional: List of Objective-C classes
419 objc-eh-types: [] # Optional: List of Objective-C classes
420 # with EH
421 objc-ivars: [] # Optional: List of Objective C Instance
422 # Variables
423 weak-symbols: [] # Optional: List of weak defined symbols
424 thread-local-symbols: [] # Optional: List of thread local symbols
425- targets: [ arm64-macos, x86_64-maccatalyst ] # Optional: Targets for applicable additional symbols
426 symbols: [ _symB ] # Optional: List of symbols
427Each undefineds section is defined as following:
428- targets: [ arm64-macos ] # The list of target triples associated with symbols
429 symbols: [ _symC ] # Optional: List of symbols
430 objc-classes: [] # Optional: List of Objective-C classes
431 objc-eh-types: [] # Optional: List of Objective-C classes
432 # with EH
433 objc-ivars: [] # Optional: List of Objective C Instance Variables
434 weak-symbols: [] # Optional: List of weak defined symbols
435 */
436
437/// Version 4 of the TBD data structure.
438#[derive(Clone, Debug, Deserialize, Serialize)]
439#[serde(rename_all = "kebab-case")]
440pub struct TbdVersion4 {
441 /// The tbd version for format.
442 pub tbd_version: usize,
443
444 /// The list of applicable tapi supported target triples.
445 pub targets: Vec<String>,
446
447 /// List of architecture and UUID pairs.
448 #[serde(default)]
449 pub uuids: Vec<TbdVersion4Uuid>,
450
451 #[serde(default)]
452 pub flags: Vec<String>,
453
454 pub install_name: String,
455
456 /// Current version of library.
457 ///
458 /// Defaults to `1.0`.
459 pub current_version: Option<String>,
460
461 /// Compatibility version of library.
462 ///
463 /// Defaults to `1.0`.
464 pub compatibility_version: Option<String>,
465
466 /// Swift version of library.
467 pub swift_abi_version: Option<String>,
468
469 #[serde(default)]
470 pub parent_umbrella: Vec<TbdUmbrellaSection>,
471
472 #[serde(default)]
473 pub allowable_clients: Vec<TbdVersion4AllowableClient>,
474
475 /// Export sections.
476 #[serde(default)]
477 pub exports: Vec<TbdVersion4ExportSection>,
478
479 /// Reexport sections.
480 ///
481 /// Version 11.0+ of the macOS SDKs renamed the field from `re-exports` to `reexports`.
482 #[serde(default, alias = "reexports")]
483 pub re_exports: Vec<TbdVersion4ExportSection>,
484
485 /// Undefineds sections.
486 #[serde(default)]
487 pub undefineds: Vec<TbdVersion4UndefinedsSection>,
488}
489
490/// A UUID value in a TBD version 4 data structure.
491#[derive(Clone, Debug, Deserialize, Serialize)]
492pub struct TbdVersion4Uuid {
493 pub target: String,
494
495 pub value: String,
496}
497
498/// An allowable client in a TBD version 4 data structure.
499#[derive(Clone, Debug, Deserialize, Serialize)]
500pub struct TbdVersion4AllowableClient {
501 #[serde(default)]
502 targets: Vec<String>,
503 clients: Vec<String>,
504}
505
506/// (Re)export section in a TBD version 4 structure.
507#[derive(Clone, Debug, Deserialize, Serialize)]
508#[serde(rename_all = "kebab-case")]
509pub struct TbdVersion4ExportSection {
510 /// Target triples associated with symbols.
511 pub targets: Vec<String>,
512
513 /// List of symbols.
514 #[serde(default)]
515 pub symbols: Vec<String>,
516
517 /// List of Objective-C classes.
518 #[serde(default)]
519 pub objc_classes: Vec<String>,
520
521 /// List of Objective-C classes with EH.
522 #[serde(default)]
523 pub objc_eh_types: Vec<String>,
524
525 /// List of Objective-C instance variables.
526 #[serde(default)]
527 pub objc_ivars: Vec<String>,
528
529 /// List of weak defined symbols.
530 #[serde(default)]
531 pub weak_symbols: Vec<String>,
532
533 /// List of thread local symbols.
534 #[serde(default)]
535 pub thread_local_symbols: Vec<String>,
536}
537
538/// Undefineds sections in a version 4 TBD structure.
539#[derive(Clone, Debug, Deserialize, Serialize)]
540#[serde(rename_all = "kebab-case")]
541pub struct TbdVersion4UndefinedsSection {
542 /// The list of target triples associated with symbols.
543 pub targets: Vec<String>,
544
545 /// List of symbols.
546 #[serde(default)]
547 pub symbols: Vec<String>,
548
549 /// List of Objective-C classes.
550 #[serde(default)]
551 pub objc_classes: Vec<String>,
552
553 /// List of Objective-C classes with EH.
554 #[serde(default)]
555 pub objc_eh_types: Vec<String>,
556
557 /// List of Objective-C instance variables.
558 #[serde(default)]
559 pub objc_ivars: Vec<String>,
560
561 /// List of weak defined symbols.
562 #[serde(default)]
563 pub weak_symbols: Vec<String>,
564}