415 wwdc 2018 behind the scenes of the xcode build process

285
#WWDC18 © 2018 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple. Behind the Scenes of the Xcode Build Process Session 415 Jake Petroules, Xcode Build System Team Jürgen Ributzka, Clang Frontend Team Devin Coughlin, Program Analysis Team Louis Gerbarg, Linker Team

Upload: others

Post on 20-Jul-2022

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

#WWDC18

© 2018 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple.

•Behind the Scenes of the •Xcode Build Process •Session 415

Jake Petroules, Xcode Build System Team Jürgen Ributzka, Clang Frontend Team Devin Coughlin, Program Analysis Team Louis Gerbarg, Linker Team

Page 2: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Exploring the Xcode Build Process

Page 3: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Exploring the Xcode Build Process: Build System

Page 4: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Exploring the Xcode Build Process: Clang and Swift

Page 5: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Exploring the Xcode Build Process: Linker

Page 6: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process
Page 7: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process
Page 8: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Build Process: Execution of a Collection of Tasks

Compile PetViewController.m

Compile PetController.swift

Compile PetView.swift

Generate PetWall-Swift.hCompile Main.storyboard

Link PetWall

Process Info.plist

CodeSign PetWall.app

Run GenerateDocs.shCompile Assets.xcassets

Page 9: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Generate PetWall-Swift.hCompile Main.storyboard

Process Info.plist

CodeSign PetWall.app

Run GenerateDocs.shCompile Assets.xcassets

Build Process: Execution of a Collection of Tasks

Link PetWall

Compile PetViewController.m

Compile PetController.swift

Compile PetView.swift

Page 10: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Build Process: Execution of a Collection of Tasks

CodeSign PetWall.app

Run GenerateDocs.sh

Link PetWall

Compile PetViewController.m

Compile PetController.swift

Compile PetView.swift

Process Info.plistCompile Assets.xcassets

Compile Main.storyboardGenerate PetWall-Swift.h

Page 11: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Build Process: Execution of a Collection of Tasks

Generate PetWall-Swift.h

Link PetWall

Compile PetViewController.m

Compile PetController.swift

Compile PetView.swift

Process Info.plistCompile Assets.xcassets

Compile Main.storyboard

CodeSign PetWall.app

Run GenerateDocs.sh

Page 12: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Build Process: Execution of a Collection of Tasks

$ swiftc -module-name PetWall -target arm64-apple-ios12.0 -swift-version 4.2 ... $ clang -x objective-c -arch arm64 ... PetViewController.m -o PetViewController.o $ ld -o PetWall -framework PetKit PetViewController.o ... $ actool --app-icon AppIcon ... Assets.xcassets $ ... $ [thousands more]

Page 13: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

The build process automates a series of tasks

Page 14: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process
Page 15: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process
Page 16: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process
Page 17: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

1. Compile PetView.swift

2. Compile PetController.swift

3. Compile PetViewController.m

6. Process Info.plist

4. Compile Main.storyboard

5. Compile Assets.xcassets

7. Link PetWall

PetWall.app

Build Task Execution Order

Page 18: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

1. Compile PetView.swift

2. Compile PetController.swift

3. Compile PetViewController.m

6. Process Info.plist

4. Compile Main.storyboard

5. Compile Assets.xcassets

7. Link PetWall

PetWall.app

Build Task Execution Order

PetViewController.m PetViewController.o

Page 19: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

1. Compile PetView.swift

2. Compile PetController.swift

3. Compile PetViewController.m

6. Process Info.plist

4. Compile Main.storyboard

5. Compile Assets.xcassets

7. Link PetWall

PetWall.app

Build Task Execution Order

PetWall

PetController.o

PetView.o

PetViewController.o

Page 20: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Build Task Dependency Order

PetController.o

PetView.o

PetViewController.o

Compile PetController.m

Compile PetView.m

Compile PetViewController.m

PetController.m

PetView.m

PetViewController.m

Link PetWall

Page 21: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Build Task Dependency Order

PetController.o

PetView.o

PetViewController.o

Compile PetController.m

Compile PetView.m

Compile PetViewController.m

PetController.m

PetView.m

PetViewController.m

Link PetWall

Page 22: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Build tasks are executed independency order

Page 23: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

What Happens When You Press Build?

Page 24: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

What Happens When You Press Build?

Page 25: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Build Process Represented as a Directed Graph

PetKit.framework

Process Info.plist Compile Assets.xcassets

Compile Main.storyboard

Compile PetView.swift

PetWall.app

Compile PetController.swift

Compile PetViewController.m

Generate PetWall-Swift.h

Link PetWall

Page 26: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Execution of the Build Graph

Process Info.plist

Compile Assets.xcassets

Compile Main.storyboard

Compile PetView.swift

PetWall.app

Compile PetController.swift

Compile PetViewController.m

Generate PetWall-Swift.h Link PetWall

Page 27: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Execution of the Build Graph

Process Info.plist

Compile Assets.xcassets

Compile Main.storyboard

Compile PetView.swift

PetWall.app

Compile PetController.swift

Compile PetViewController.m

Generate PetWall-Swift.h Link PetWall

Time

Page 28: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

llbuild Execution Engine: Open Source

Page 29: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Discovered Dependencies

PetController.oPetController.m

PetController.h

Compile PetController.m

Page 30: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Discovered Dependencies

PetController.oPetController.m

Compile PetController.m

PetController.h

Page 31: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Discovered Dependencies

PetController.d

PetController.oPetController.m

Compile PetController.m

PetController.h

Page 32: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Discovered Dependencies

PetController.d

PetController.oPetController.m

Compile PetController.m

PetController.h

Page 33: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Discovered Dependencies

PetController.d

PetController.oPetController.m

Compile PetController.m

PetController.h

Page 34: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Discovered Dependencies

PetController.d

PetController.oPetController.m

Compile PetController.m

PetController.h

Page 35: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

PetKit.framework

Process Info.plist Compile Assets.xcassets

Compile Main.storyboard

Compile PetView.swift

Compile PetController.swift

Generate PetWall-Swift.h

Incremental Builds

Compile PetViewController.m

Link PetWall

PetWall.app

Page 36: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

PetKit.framework

Process Info.plist Compile Assets.xcassets

Compile Main.storyboard

Compile PetView.swift

Compile PetController.swift

Generate PetWall-Swift.h

Incremental Builds

Compile PetViewController.m

Link PetWall

PetWall.app

File modified

Page 37: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Change Detection and Task Signatures

Page 38: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Change Detection and Task Signatures

•Each task in the build graph has a signature

Page 39: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Change Detection and Task Signatures

•Each task in the build graph has a signature •Computed from stat info of inputs and other task metadata

Page 40: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Change Detection and Task Signatures

•Each task in the build graph has a signature •Computed from stat info of inputs and other task metadata •Build system tracks task signatures of current and previous build •

Page 41: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Change Detection and Task Signatures

•Each task in the build graph has a signature •Computed from stat info of inputs and other task metadata •Build system tracks task signatures of current and previous build •Compared to determine whether a task should be run

Page 42: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

How can you help the build system?

Page 43: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

1. Compile PetView.swift

2. Compile PetController.swift

3. Compile PetViewController.m

4. Process Info.plist

5. Compile Main.storyboard

6. Compile Assets.xcassets

...

PetWall.app

Page 44: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Don't Think About the Order of Task Execution!

1. Compile PetView.swift

2. Compile PetController.swift

3. Compile PetViewController.m

4. Process Info.plist

5. Compile Main.storyboard

6. Compile Assets.xcassets

...

PetWall.app

Page 45: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

PetKit.framework

Process Info.plist Compile Assets.xcassets

Compile Main.storyboard

Compile PetView.swift

PetWall.app

Compile PetController.swift

Generate PetWall-Swift.h

Think in Terms of Task Dependencies

Compile PetViewController.m

Link PetWall

Page 46: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

PetKit.framework

Process Info.plist Compile Assets.xcassets

Compile Main.storyboard

Compile PetView.swift

PetWall.app

Compile PetController.swift

Generate PetWall-Swift.h

Think in Terms of Task Dependencies

Compile PetViewController.m

Link PetWall

Page 47: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Where Do Dependencies Come From?

•Built in •Target dependencies •Implicit dependencies •Build phase dependencies •Scheme order dependencies

Page 48: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Where Do Dependencies Come From?

•Built in •Target dependencies •Implicit dependencies •Build phase dependencies •Scheme order dependencies

Page 49: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Where Do Dependencies Come From?

•Built in •Target dependencies •Implicit dependencies •Build phase dependencies •Scheme order dependencies

Page 50: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Where Do Dependencies Come From?

•Built in •Target dependencies •Implicit dependencies •Build phase dependencies •Scheme order dependencies

Page 51: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Where Do Dependencies Come From?

•Built in •Target dependencies •Implicit dependencies •Build phase dependencies •Scheme order dependencies

Page 52: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Where Do Dependencies Come From?

•Built in •Target dependencies •Implicit dependencies •Build phase dependencies •Scheme order dependencies

Page 53: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

You!

Page 54: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Declare Inputs and Outputs!

Page 55: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Declare Inputs and Outputs!

Page 56: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Avoid Auto-Link for Project Dependencies

Page 57: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Add Explicit Dependencies

Page 58: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Create Workspaces and Project References

Page 59: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process
Page 60: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Building Faster in Xcode WWDC 2018

Page 61: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Jürgen Ributzka, Clang Frontend Team

•Behind the Scenes of the Xcode •Build Process: Clang Builds

Page 62: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process
Page 63: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

What Is Clang?

Page 64: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

What Is Clang?

Apple’s official compiler for the C language family

• C

• C++

• Objective-C

• Objective-C++

Page 65: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Traditional C Language Compilation

Clang Compiler

m .o

Page 66: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Traditional C Language Compilation

Clang Compiler

m

h

.o

Page 67: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Traditional C Language Compilation

h m

Page 68: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Traditional C Language Compilation

h m

Page 69: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Traditional C Language Compilation

h m

Page 70: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Traditional C Language Compilation

Clang Compiler

m

h

h

.o

Page 71: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Traditional C Language Compilation

Clang CompilermhhClang CompilermhhClang CompilermhhClang Compilermhh

.o

.o

.o

.o

Page 72: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process
Page 73: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process
Page 74: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

PetWall Example

Page 75: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

PetWall Example

Page 76: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

PetWall Example

Page 77: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

PetWall Example

Page 78: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

PetWall Example

Page 79: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

PetWall Example

Page 80: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

PetWall Example

// // Cat.mm // PetKit // #import <PetKit/Cat.h> #import “PetSupport.h”

// // NorwegianCat.h // PetKit // #import <PetKit/Cat.h>

Page 81: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

How do we find your headers?

Page 82: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

// // Cat.mm // PetKit // #import <PetKit/Cat.h>

@implementation Cat

- (NSInteger)_sizeOfCat { return 10; } - (void)meow { theCatsMeow((int)self._sizeOfCat);

How Do We Find Our Cat?

Page 83: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

How Do We Find Our Cat?

Page 84: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

How Do We Find Our Cat?

Page 85: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

On the Search for Our Cat

$ clang <list of arguments> -c Cat.mm -o Cat.o -v

Page 86: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

On the Search for Our Cat

#include "..." search starts here:#include <...> search starts here:

Page 87: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

On the Search for Our Cat

#include "..." search starts here:PetKit-generated-files.hmap (headermap)PetKit-project-headers.hmap (headermap)#include <...> search starts here:PetKit-own-target-headers.hmap (headermap)PetKit-all-target-headers.hmap (headermap)DerivedSourcesBuild/Products/Debug (framework directory)Header and Framework Locations in the SDK

Page 88: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

What Are Header Maps?

PetKit.h PetKit/PetKit.h

Cat.h PetKit/Cat.h

CatLogic_Private.h /x/src/PetKit/PetKit/CatLogic_Private.h

PetKit/Cat.h /x/src/PetKit/PetKit/Cat/Cat.h

PetKit/PetKit.h /x/src/PetKit/PetKit/PetKit.h

PetKit-own-target-headers.hmap:

PetKit-project-headers.hmap:

Page 89: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

What Are Header Maps?

PetKit.h PetKit/PetKit.h

Cat.h PetKit/Cat.h

CatLogic_Private.h /x/src/PetKit/PetKit/CatLogic_Private.h

PetKit/Cat.h /x/src/PetKit/PetKit/Cat/Cat.h

PetKit/PetKit.h /x/src/PetKit/PetKit/PetKit.h

PetKit-own-target-headers.hmap:

PetKit-project-headers.hmap:

Page 90: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

What Are Header Maps?

PetKit.h PetKit/PetKit.h

Cat.h PetKit/Cat.h

CatLogic_Private.h /x/src/PetKit/PetKit/CatLogic_Private.h

PetKit/Cat.h /x/src/PetKit/PetKit/Cat/Cat.h

PetKit/PetKit.h /x/src/PetKit/PetKit/PetKit.h

PetKit-own-target-headers.hmap:

PetKit-project-headers.hmap:

Page 91: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

What Are Header Maps?

PetKit.h PetKit/PetKit.h

Cat.h PetKit/Cat.h

CatLogic_Private.h /x/src/PetKit/PetKit/CatLogic_Private.h

PetKit/Cat.h /x/src/PetKit/PetKit/Cat/Cat.h

PetKit/PetKit.h /x/src/PetKit/PetKit/PetKit.h

PetKit-own-target-headers.hmap:

PetKit-project-headers.hmap:

Page 92: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Common Project Issues with Header Maps

Header is not part of the project

Headers with the same name shadow each other

Page 93: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

How do we find system headers?

Page 94: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

// // Pet.h // PetKit //

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN @interface Pet : NSObject - (instancetype)initWithName:(NSString *)name; @property (readonly) NSString *name; @property (readonly) BOOL isHungry; - (void)eat;

How Do We Find Foundation.h?

Page 95: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

On the Search for Foundation.h

#include "..." search starts here:PetKit-generated-files.hmap (headermap)PetKit-project-headers.hmap (headermap)#include <...> search starts here:PetKit-own-target-headers.hmap (headermap)PetKit-all-target-headers.hmap (headermap)DerivedSourcesBuild/Products/Debug (framework directory)$(SDKROOT)/usr/include$(SDKROOT)/System/Library/Frameworks.(framework directory)

Page 96: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

#include.<...> search starts here:.

A$(SDKROOT)/usr/include $(SDKROOT)/System/Library/Frameworks.(framework directory).

On the Search for Foundation.h

Page 97: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

A$(SDKROOT)/usr/include $(SDKROOT)/System/Library/Frameworks.(framework directory).

#include.<...> search starts here:.

On the Search for Foundation.h

Page 98: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

On the Search for Foundation.h

A$(SDKROOT)/usr/include $(SDKROOT)/System/Library/Frameworks.(framework directory).

#include.<...> search starts here:.

Page 99: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

On the Search for Foundation.h

$(SDKROOT)/usr/include/Foundation/Foundation.h

Page 100: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

On the Search for Foundation.h

$(SDKROOT)/usr/include/Foundation/Foundation.h

Page 101: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

On the Search for Foundation.h

A$(SDKROOT)/usr/include $(SDKROOT)/System/Library/Frameworks.(framework directory).

#include.<...> search starts here:.

Page 102: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

On the Search for Foundation.h

$SDKROOT/System/Library/Frameworks/Foundation.framework

Page 103: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

On the Search for Foundation.h

$SDKROOT/System/Library/Frameworks/Foundation.framework

Page 104: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

On the Search for Foundation.h

$SDKROOT/System/Library/Frameworks/Foundation.framework

$SDKROOT/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h

Page 105: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

On the Search for Foundation.h

$SDKROOT/System/Library/Frameworks/Foundation.framework

$SDKROOT/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h

Page 106: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

On the Search for Bogus.h

$SDKROOT/System/Library/Frameworks/Foundation.framework

$SDKROOT/System/Library/Frameworks/Foundation.framework/Headers/Bogus.h

Page 107: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

On the Search for Bogus.h

$SDKROOT/System/Library/Frameworks/Foundation.framework

$SDKROOT/System/Library/Frameworks/Foundation.framework/Headers/Bogus.h

Page 108: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

On the Search for Bogus.h

$SDKROOT/System/Library/Frameworks/Foundation.framework

$SDKROOT/System/Library/Frameworks/Foundation.framework/Headers/Bogus.h

$SDKROOT/System/Library/Frameworks/Foundation.framework/PrivateHeaders/Bogus.h

Page 109: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

On the Search for Bogus.h

$SDKROOT/System/Library/Frameworks/Foundation.framework

$SDKROOT/System/Library/Frameworks/Foundation.framework/Headers/Bogus.h

$SDKROOT/System/Library/Frameworks/Foundation.framework/PrivateHeaders/Bogus.h

Page 110: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process
Page 111: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process
Page 112: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

!89

Page 113: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

#import <Foundation/Foundation.h>

Page 114: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

headers included

>800

Page 115: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

of source code

>9MB

Page 116: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

How can we do better?

Page 117: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Clang Modules

On-disk cached header representation

Reusable

Faster build times

Page 118: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Module Properties

Page 119: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Module Properties

Context-free:

Page 120: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Module Properties

#define ENABLE_CHINCHILLA 1 // ignored#import <PetKit/PetKit.h>

#define ENABLE_DOG 1 // ignored#import <PetKit/PetKit.h>

Context-free:

Page 121: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Module Properties

#define ENABLE_CHINCHILLA 1 // ignored#import <PetKit/PetKit.h>

#define ENABLE_DOG 1 // ignored#import <PetKit/PetKit.h>

Context-free:

Self-contained:

Page 122: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Module Properties

#define ENABLE_CHINCHILLA 1 // ignored#import <PetKit/PetKit.h>

#define ENABLE_DOG 1 // ignored#import <PetKit/PetKit.h>

#import <Foundation/Foundation.h> // import not required before PetKit module#import <PetKit/Cat.h>

Context-free:

Self-contained:

Page 123: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

#import <Foundation/NSString.h>

Page 124: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Foundation Framework

Foundation.framework/ Headers/ Foundation.h NSString.h ... Modules/ module.modulemap

Page 125: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Foundation Framework

Foundation.framework/ Headers/ Foundation.h NSString.h ... Modules/ module.modulemap

Page 126: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Foundation Framework

Foundation.framework/ Headers/ Foundation.h NSString.h ... Modules/ module.modulemap

Page 127: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

// Module Map - Foundation.framework/Modules/module.modulemap

framework module Foundation [extern_c] [system] { umbrella header "Foundation.h"

export * module * { export * }

explicit module NSDebug { header "NSDebug.h" export * } }

Page 128: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

// Module Map - Foundation.framework/Modules/module.modulemap

framework module Foundation [extern_c] [system] { umbrella header "Foundation.h"

export * module * { export * }

explicit module NSDebug { header "NSDebug.h" export * } }

Page 129: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

// Module Map - Foundation.framework/Modules/module.modulemap

framework module Foundation [extern_c] [system] { umbrella header "Foundation.h"

export * module * { export * }

explicit module NSDebug { header "NSDebug.h" export * } }

Page 130: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

// Module Map - Foundation.framework/Modules/module.modulemap

framework module Foundation [extern_c] [system] { umbrella header "Foundation.h"

export * module * { export * }

explicit module NSDebug { header "NSDebug.h" export * } }

Page 131: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

// Foundation.h

… #import <Foundation/NSScanner.h> #import <Foundation/NSSet.h> #import <Foundation/NSSortDescriptor.h> #import <Foundation/NSStream.h> #import <Foundation/NSString.h> #import <Foundation/NSTextCheckingResult.h> #import <Foundation/NSThread.h> #import <Foundation/NSTimeZone.h> …

Page 132: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

// Foundation.h

… #import <Foundation/NSScanner.h> #import <Foundation/NSSet.h> #import <Foundation/NSSortDescriptor.h> #import <Foundation/NSStream.h> #import <Foundation/NSString.h> #import <Foundation/NSTextCheckingResult.h> #import <Foundation/NSThread.h> #import <Foundation/NSTimeZone.h> …

Page 133: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Building the Module

Foundation

Page 134: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Building the Module

CoreFoundation Security ObjectiveC Darwin …

Foundation

Page 135: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Building the Module

Foundation

ObjectiveC Darwin

…SecurityCoreFoundation

Page 136: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Building the Module

Foundation

ObjectiveC Darwin

…SecurityCoreFoundation

Page 137: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Module Cache

$ clang -fmodules —DENABLE_CHINCHILLA=1 …

Page 138: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Module Cache

$ clang -fmodules —DENABLE_CHINCHILLA=1 …

98XN8P5QH5OQ/ CoreFoundation-2A5I5R2968COJ.pcm Security-1A229VWPAK67R.pcm Foundation-1RDF848B47PF4.pcm

Page 139: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Module Cache

$ clang -fmodules —DENABLE_CHINCHILLA=1 …

98XN8P5QH5OQ/ CoreFoundation-2A5I5R2968COJ.pcm Security-1A229VWPAK67R.pcm Foundation-1RDF848B47PF4.pcm

$ clang -fmodules —DENABLE_CAT=1 …

Page 140: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Module Cache

$ clang -fmodules —DENABLE_CHINCHILLA=1 …

98XN8P5QH5OQ/ CoreFoundation-2A5I5R2968COJ.pcm Security-1A229VWPAK67R.pcm Foundation-1RDF848B47PF4.pcm

1GYDULU5XJRF/ CoreFoundation-2A5I5R2968COJ.pcm Security-1A229VWPAK67R.pcm Foundation-1RDF848B47PF4.pcm

$ clang -fmodules —DENABLE_CAT=1 …

Page 141: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

// // NorwegianCat.h // PetKit //

#import <PetKit/Cat.h>

NS_ASSUME_NONNULL_BEGIN @interface NorwegianCat: Cat ... @end NS_ASSUME_NONNULL_END

How Do We Find Our Cat… Again? This time with Clang Modules

Page 142: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

PetWall/ PetKit/ Cat/ Cat.h Cat.mm ... Info.plist Pet.h Pet.m PetKit.h

PetWall Project Directory

Page 143: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

PetWall/ PetKit/ Cat/ Cat.h Cat.mm ... Info.plist Pet.h Pet.m PetKit.h

PetKit.framework/ Headers/ Cat.h PetKit.h ... Modules/ module.modulemap

Clang’s Virtual File System (VFS)

Page 144: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

PetWall/ PetKit/ Cat/ Cat.h Cat.mm ... Info.plist Pet.h Pet.m PetKit.h

PetKit.framework/ Headers/ Cat.h PetKit.h ... Modules/ module.modulemap

Clang’s Virtual File System (VFS)

Page 145: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Potential Modules Pitfalls

#import <PetKit/PetKit.h>#import “Cat.h”

Page 146: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Potential Modules Pitfalls

#import <PetKit/PetKit.h>#import “Cat.h”

#define ENABLE_CUTE_KITTENS 1

Page 147: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Potential Modules Pitfalls

#import <PetKit/PetKit.h>#import <PetKit/Cat.h>

#define ENABLE_CUTE_KITTENS 1

Page 148: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Devin Coughlin, Program Analysis Team

•Behind the Scenes of the Xcode •Build Process: Swift Builds •

Page 149: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process
Page 150: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Recap: Clang Uses Headers to Find Declarations

.o

.m

.h

clang.m

.o

linker

clang

Page 151: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Recap: Clang Uses Headers to Find Declarations

.o

.m

.h

clang.m

.o

linker

clang

Page 152: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Swift Does Not Have Headers

Easier for beginners to get started

Avoids repeating declarations in separate file

Compiler does book-keeping to find declarations

Page 153: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

import UIKit class PetViewController: UIViewController { var view = PetView(name: "Fido", frame: frame) … }

Page 154: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

import UIKit class PetViewController: UIViewController { var view = PetView(name: "Fido", frame: frame) … }

#import "PetWall-Swift.h" @implementation AppDelegate … @end

Page 155: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

import UIKit class PetViewController: UIViewController { var view = PetView(name: "Fido", frame: frame) … }

@testable import PetWall class TestPetViewController: XCTestCase { }

#import "PetWall-Swift.h" @implementation AppDelegate … @end

Page 156: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

import UIKit class PetViewController: UIViewController { var view = PetView(name: "Fido", frame: frame) … }

@testable import PetWall class TestPetViewController: XCTestCase { }

#import "PetWall-Swift.h" @implementation AppDelegate … @end

Finding declarations

Page 157: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

import UIKit class PetViewController: UIViewController { var view = PetView(name: "Fido", frame: frame) … }

@testable import PetWall class TestPetViewController: XCTestCase { }

#import "PetWall-Swift.h" @implementation AppDelegate … @end

Finding declarations• Within a Swift target

Page 158: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

import UIKit class PetViewController: UIViewController { var view = PetView(name: "Fido", frame: frame) … }

@testable import PetWall class TestPetViewController: XCTestCase { }

#import "PetWall-Swift.h" @implementation AppDelegate … @end

Finding declarations• Within a Swift target• From Objective-C

Page 159: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

import UIKit class PetViewController: UIViewController { var view = PetView(name: "Fido", frame: frame) … }

@testable import PetWall class TestPetViewController: XCTestCase { }

#import "PetWall-Swift.h" @implementation AppDelegate … @end

Finding declarations• Within a Swift target• From Objective-C

Generating interfaces

Page 160: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

import UIKit class PetViewController: UIViewController { var view = PetView(name: "Fido", frame: frame) … }

@testable import PetWall class TestPetViewController: XCTestCase { }

#import "PetWall-Swift.h" @implementation AppDelegate … @end

Finding declarations• Within a Swift target• From Objective-C

Generating interfaces• To use in Objective-C

Page 161: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

import UIKit class PetViewController: UIViewController { var view = PetView(name: "Fido", frame: frame) … }

@testable import PetWall class TestPetViewController: XCTestCase { }

#import "PetWall-Swift.h" @implementation AppDelegate … @end

Finding declarations• Within a Swift target• From Objective-C

Generating interfaces• To use in Objective-C• To use in other Swift targets

Page 162: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

import UIKit class PetViewController: UIViewController { var view = PetView(name: "Fido", frame: frame) … }

@testable import PetWall class TestPetViewController: XCTestCase { }

#import "PetWall-Swift.h" @implementation AppDelegate … @end

Finding declarations• Within a Swift target• From Objective-C

Generating interfaces• To use in Objective-C• To use in other Swift targets

Page 163: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

import UIKit class PetViewController: UIViewController { var view = PetView(name: "Fido", frame: frame) … }

Finding Declarations Within a Swift Target

Page 164: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Finding Declarations Within a Swift Target

import UIKit class PetViewController: UIViewController { var view = PetView(name: "Fido", frame: frame) … }

Page 165: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Finding Declarations Within a Swift Target

import UIKit class PetViewController: UIViewController { var view = PetView(name: "Fido", frame: frame) … }

PetViewController.swift

Page 166: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Finding Declarations Within a Swift Target

import UIKit class PetViewController: UIViewController { var view = PetView(name: "Fido", frame: frame) … }

PetViewController.swift

Page 167: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Finding Declarations Within a Swift Target

import UIKit class PetViewController: UIViewController { var view = PetView(name: "Fido", frame: frame) … }

PetViewController.swift

class PetView: UIView { init(name: String, frame: CGRect) { self.name = name super.init(frame: frame) } }

PetView.swiftLoad and parse file

Page 168: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Finding Declarations Within a Swift Target

import UIKit class PetViewController: UIViewController { var view = PetView(name: "Fido", frame: frame) … }

PetViewController.swift

class PetView: UIView { init(name: String, frame: CGRect) { self.name = name super.init(frame: frame) } }

PetView.swiftLoad and parse file

Does not check types in bodies

Page 169: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Compiler Looks at All Files Within Target

swiftc.swift .o

Page 170: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Compiler Looks at All Files Within Target

swiftc

.swift

.swift

.swift

.o

Page 171: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Xcode 9: Repeated Work in Debug Builds

Compiled each file separately

Enabled parallel, incremental compilation

Compiler had to repeatedly parse all files to find declarations

swiftc.swift .o

swiftc.swift .o

swiftc.swift .o

Page 172: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Xcode 9: Repeated Work in Debug Builds

Compiled each file separately

Enabled parallel, incremental compilation

Compiler had to repeatedly parse all files to find declarations

swiftc.swift .o

swiftc.swift .o

swiftc.swift .o

Page 173: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Xcode 10: More Sharing in Debug Builds

Group multiple files into common compilation process per core

Shares work of parsing within a process

Only repeat parsing across processes

NEW

swiftc.swift .o

.swift

swiftc.swift .o

Group 1

Group 2

Page 174: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Xcode 10: More Sharing in Debug Builds

Group multiple files into common compilation process per core

Shares work of parsing within a process

Only repeat parsing across processes

NEW

swiftc.swift .o

.swift

swiftc.swift .o

Group 1

Group 2

Page 175: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

import UIKit class PetViewController: UIViewController { var view = PetView(name: "Fido", frame: frame) … }

@testable import PetWall class TestPetViewController: XCTestCase { }

#import "PetWall-Swift.h" @implementation AppDelegate … @end

Generating interfaces • To use in Objective-C • To use in other Swift targets

Finding declarations• Within a Swift target• From Objective-C

Page 176: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

import UIKit class PetViewController: UIViewController { var view = PetView(name: "Fido", frame: frame) … }

Finding Declarations from Objective-C

Page 177: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Compiler Uses Clang as a Library to Import Objective-C

Avoids messiness of a foreign-function interface

Can import clang frameworks directly

swiftc

clang

Page 178: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Objective-C Declarations Come from Headers

Page 179: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Objective-C Declarations Come from Headers

Imported Objective-C frameworks: • From headers exposed in Clang module map

Page 180: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Objective-C Declarations Come from Headers

Imported Objective-C frameworks: • From headers exposed in Clang module map

Within frameworks that mix Swift and Objective-C: • From the umbrella header

Page 181: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Objective-C Declarations Come from Headers

Imported Objective-C frameworks: • From headers exposed in Clang module map

Within frameworks that mix Swift and Objective-C: • From the umbrella header

Within applications and unit test bundles: • From target’s bridging header

Page 182: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Clang Importer Makes Methods More “Swifty”

- (BOOL)validateCuteness:(nonnull Pet *)pet error:(NSError **)err;

do { try validateCuteness(fluffy) } catch let e { … }

Objective-C Swift

Page 183: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Clang Importer Makes Methods More “Swifty”

- (BOOL)validateCuteness:(nonnull Pet *)pet error:(NSError **)err;

do { try validateCuteness(fluffy) } catch let e { … }

Objective-C Swift

Page 184: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Rename Methods Based on Part of Speech

Objective-C Swift

- (void)drawPet:(nonnull Pet *)pet atPoint:(CGPoint)point;

draw(fluffy, at: origin)

Drops parameter type names following verbs and prepositions

Page 185: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Rename Methods Based on Part of Speech

Objective-C Swift

- (void)drawPet:(nonnull Pet *)pet atPoint:(CGPoint)point;

draw(fluffy, at: origin)

Drops parameter type names following verbs and prepositions

Page 186: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Rename Methods Based on Part of Speech

Objective-C Swift

- (void)drawPet:(nonnull Pet *)pet atPoint:(CGPoint)point;

draw(fluffy, at: origin)

Drops parameter type names following verbs and prepositions

Page 187: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Rename Methods Based on Part of Speech

Objective-C Swift

- (void)drawPet:(nonnull Pet *)pet atPoint:(CGPoint)point;

draw(fluffy, at: origin)

Drops parameter type names following verbs and prepositions

Page 188: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

// https://github.com/apple/swift/blob/master/lib/Basic/PartsOfSpeech.def ... VERB(extend) VERB(face) VERB(fade) VERB(fail) VERB(fancy) VERB(fasten) VERB(fax) VERB(fear) VERB(feel) VERB(fence) VERB(fetch) VERB(fight) VERB(fill) VERB(film) ...

Page 189: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

… But It Is Just a List

- (void)feedPet:(nonnull Pet *)petfeedPet(fluffy)

Objective-C Swift

Not renamed because ‘feed’ not in list

Use NS_SWIFT_NAME to change imported name explicitly

;

Page 190: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

… But It Is Just a List

- (void)feedPet:(nonnull Pet *)petfeed(fluffy)

Objective-C Swift

Not renamed because ‘feed’ not in list

Use NS_SWIFT_NAME to change imported name explicitly

NS_SWIFT_NAME(feed(_:));

Page 191: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Xcode Shows Imported Swift Interface

Page 192: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

import UIKit class PetViewController: UIViewController { var view = PetView(name: "Fido", frame: frame) … }

@testable import PetWall class TestPetViewController: XCTestCase { }

#import "PetWall-Swift.h"

Finding declarations• Within a Swift target• From Objective-C

@implementation AppDelegate … @end

Generating interfaces• To use in Objective-C• To use in other Swift targets

Page 193: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

#import "PetWall-Swift.h"

Generating Interfaces to Use in Objective-C

Page 194: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Generating Interfaces to Use in Objective-C

#import "PetWall-Swift.h"

Page 195: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Generating Interfaces to Use in Objective-C

class PetCollar: NSObject { @objc var color: UIColor = .blue var name: String = "Fido" }

Write in Swift:

#import "PetWall-Swift.h"

Page 196: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Generating Interfaces to Use in Objective-C

class PetCollar: NSObject { @objc var color: UIColor = .blue var name: String = "Fido" }

Write in Swift:

Use from Objective-C:

#import "PetWall-Swift.h"

- (void)resetCollarColor { self.collar.color = [UIColor redColor]; }

Page 197: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Compiler Generates Objective-C Header

class PetCollar: NSObject { @objc var color: UIColor = .blue var name: String = "Fido" }

Swift

Page 198: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Compiler Generates Objective-C Header

SWIFT_CLASS("_TtC7PetWall9PetCollar") @interface PetCollar: NSObject @property (nonatomic, strong) UIColor * _Nonnull color; - (nonnull instancetype)init; @end

class PetCollar: NSObject { @objc var color: UIColor = .blue var name: String = "Fido" }

Swift Generated Objective-C Header

For classes extending NSObject and methods/properties marked @objc

Page 199: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Compiler Generates Objective-C Header

SWIFT_CLASS("_TtC7PetWall9PetCollar") @interface PetCollar: NSObject @property (nonatomic, strong) UIColor * _Nonnull color; - (nonnull instancetype)init; @end

class PetCollar: NSObject { @objc var color: UIColor = .blue var name: String = "Fido" }

Swift Generated Objective-C Header

For classes extending NSObject and methods/properties marked @objc

Apps and unit tests: both public and internal declarations

Page 200: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Compiler Generates Objective-C Header

SWIFT_CLASS("_TtC7PetWall9PetCollar") @interface PetCollar: NSObject @property (nonatomic, strong) UIColor * _Nonnull color; - (nonnull instancetype)init; @end

class PetCollar: NSObject { @objc var color: UIColor = .blue var name: String = "Fido" }

Swift Generated Objective-C Header

For classes extending NSObject and methods/properties marked @objc

Apps and unit tests: both public and internal declarations

Frameworks: Only public declarations

Page 201: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Changing the Class Name in Objective-C

Compiler ties Objective-C class to mangled Swift class name

Prevents conflict when two modules define class with same name

class PetCollar: NSObject { @objc var color: UIColor = .blue var name: String = "Fido" }

Swift

@interface @property (nonatomic, strong) UIColor * _Nonnull color; - (nonnull instancetype)init; @end

Generated Objective-C Header

SWIFT_CLASS("_TtC7PetWall9PetCollar")PetCollar : NSObject

Page 202: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Changing the Class Name in Objective-C

Compiler ties Objective-C class to mangled Swift class name

Prevents conflict when two modules define class with same name

class PetCollar: NSObject { @objc var color: UIColor = .blue var name: String = "Fido" }

Swift

@interface @property (nonatomic, strong) UIColor * _Nonnull color; - (nonnull instancetype)init; @end

Generated Objective-C Header

SWIFT_CLASS("_TtC7PetWall9PetCollar")PetCollar : NSObject

Page 203: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Changing the Class Name in Objective-C

Compiler ties Objective-C class to mangled Swift class name

Prevents conflict when two modules define class with same name

class PetCollar: NSObject { @objc var color: UIColor = .blue var name: String = "Fido" }

Swift

Use @objc(Name) to provide custom name — but must not conflict!

@interface @property (nonatomic, strong) UIColor * _Nonnull color; - (nonnull instancetype)init; @end

Generated Objective-C Header

SWIFT_CLASS("_TtC7PetWall9PetCollar")PetCollar : NSObject

Page 204: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Changing the Class Name in Objective-C

Compiler ties Objective-C class to mangled Swift class name

Prevents conflict when two modules define class with same name

class PetCollar: NSObject { @objc var color: UIColor = .blue var name: String = "Fido" }

Swift

@objc(PWLPetCollar)

Use @objc(Name) to provide custom name — but must not conflict!

@interface @property (nonatomic, strong) UIColor * _Nonnull color; - (nonnull instancetype)init; @end

Generated Objective-C Header

PWLPetCollar : NSObject SWIFT_CLASS_NAMED(“PetCollar")

Page 205: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

A

UNITIDENTIFIER

import UIKit class PetViewController: UIViewController { var view = PetView(name: "Fido", frame: frame) … }

@testable import PetWall

#import "PetWall-Swift.h"

Finding declarations• Within a Swift target• From Objective-C

@implementation AppDelegate … @end

Generating interfaces• To use in Objective-C• To use in other Swift targets

class TestPetViewController: XCTestCase {

}

Page 206: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

A

UNITIDENTIFIER

Must first import other modules to see their declarations

Can import Clang modules

In Xcode each Swift target produces a separate module

@testable import PetWallclass TestPetViewController: XCTestCase {

Module: A Distributable Unit of Declarations

}

Page 207: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

A

UNITIDENTIFIER

Must first import other modules to see their declarations

Can import Clang modules

In Xcode each Swift target produces a separate module

import XCTest

func testInitialPet() { let controller = PetViewController() XCTAssertEqual(controller.view.name, "Fido") }

@testable import PetWallclass TestPetViewController: XCTestCase {

Module: A Distributable Unit of Declarations

}

Page 208: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

A

UNITIDENTIFIER

Must first import other modules to see their declarations

Can import Clang modules

In Xcode each Swift target produces a separate module

import XCTest

func testInitialPet() { let controller = PetViewController() XCTAssertEqual(controller.view.name, "Fido") }

@testable import PetWallclass TestPetViewController: XCTestCase {

Module: A Distributable Unit of Declarations

}

Page 209: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

A

UNITIDENTIFIER

Must first import other modules to see their declarations

Can import Clang modules

In Xcode each Swift target produces a separate module

import XCTest

func testInitialPet() { let controller = PetViewController() XCTAssertEqual(controller.view.name, "Fido") }

@testable import PetWallclass TestPetViewController: XCTestCase {

Module: A Distributable Unit of Declarations

}

Page 210: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

A

UNITIDENTIFIER

Importing Swift Declarations from Other Modules

import XCTest @testable import PetWall class TestPetViewController: XCTestCase { func testInitialPet() { let controller = PetViewController() XCTAssertEqual(controller.view.name, "Fido") } }

Page 211: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

A

UNITIDENTIFIER

Importing Swift Declarations from Other Modules

import XCTest @testable import PetWall class TestPetViewController: XCTestCase { func testInitialPet() { let controller = PetViewController() XCTAssertEqual(controller.view.name, "Fido") } }

Deserialize to check typesPetWall.swiftmodule

PetViewController:

view: PetView

init() rename: () -> Void = { … } printDescription: () -> Void

Page 212: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Expose Declarations to Other Modules via .swiftmodule

Serialized, binary representation of module’s declarations

Includes bodies of inlinable functions

Includes private declarations for debugging

public class PetViewController { public let view = PetView()

@inlinable public func rename() { view.name = "Fido" } private func printDescription() { … } }

PetWall.swiftmodule PetViewController:

view: PetView

init() rename: () -> Void = { … } printDescription: () -> Void

Serialize

Page 213: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Produced During Compilation and Merged

.swift

.swift

swiftc

swiftc

.o

.o

Page 214: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Produced During Compilation and Merged

.swift

.swift

swiftc

swiftc

.o

.o

.swift module

.swift module

Page 215: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Produced During Compilation and Merged

.swift

.swift

swiftc

swiftc

.o

.o

.swift module

.swift module

swiftc .swift module

Page 216: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Produced During Compilation and Merged

Generated Objective-C

Header

.swift

.swift

swiftc

swiftc

.o

.o

.swift module

.swift module

swiftc .swift module

.h

Page 217: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Louis Gerbarg, Linker Team

•Behind the Scenes of the Xcode •Build Process: Linking

Page 218: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process
Page 219: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

•What does the linker actually do? •What are symbols? •What are object files? •What are libraries?

Page 220: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

The Linker

Page 221: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

The Linker

Final task in building an executable Mach-O

Page 222: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

The Linker

Final task in building an executable Mach-O

Combines the output of all compiler invocations into a single file

Page 223: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

The Linker

Final task in building an executable Mach-O

Combines the output of all compiler invocations into a single file• Moves and patches code generated by the compilers

Page 224: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

The Linker

Final task in building an executable Mach-O

Combines the output of all compiler invocations into a single file• Moves and patches code generated by the compilers

Takes two kinds of input files

Page 225: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

The Linker

Final task in building an executable Mach-O

Combines the output of all compiler invocations into a single file• Moves and patches code generated by the compilers

Takes two kinds of input files• Object files (.o)

Page 226: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

The Linker

Final task in building an executable Mach-O

Combines the output of all compiler invocations into a single file• Moves and patches code generated by the compilers

Takes two kinds of input files• Object files (.o)• Libraries (.dylib, .tbd, .a)

Page 227: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Symbols

Page 228: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Symbols

A symbol is a name for a fragment of code or data

Page 229: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Symbols

A symbol is a name for a fragment of code or data

Fragments of code may reference other symbols

Page 230: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Symbols

A symbol is a name for a fragment of code or data

Fragments of code may reference other symbols

Symbols can have attributes on them that alter the linker’s behavior

Page 231: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Symbols

A symbol is a name for a fragment of code or data

Fragments of code may reference other symbols

Symbols can have attributes on them that alter the linker’s behavior• Weak symbols

Page 232: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Symbols

A symbol is a name for a fragment of code or data

Fragments of code may reference other symbols

Symbols can have attributes on them that alter the linker’s behavior• Weak symbols

Languages often encode data into a symbol “mangling” the symbol

Page 233: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Object Files

Page 234: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Object Files

Output of individual compiler actions

Page 235: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Object Files

Output of individual compiler actions

A non-executable Mach-O file containing code and data fragments

Page 236: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Object Files

Output of individual compiler actions

A non-executable Mach-O file containing code and data fragments• Each fragment is represented by a symbol

Page 237: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Object Files

Output of individual compiler actions

A non-executable Mach-O file containing code and data fragments• Each fragment is represented by a symbol• Fragments may reference “undefined” symbols

Page 238: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Libraries

Page 239: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Libraries

Libraries define symbols that are not built as part of your target

Page 240: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Libraries

Libraries define symbols that are not built as part of your target• Dylibs: Dynamic libraries

Page 241: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Libraries

Libraries define symbols that are not built as part of your target• Dylibs: Dynamic libraries- Mach-O file that exposes code and data fragments executables can use

Page 242: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Libraries

Libraries define symbols that are not built as part of your target• Dylibs: Dynamic libraries- Mach-O file that exposes code and data fragments executables can use

• TBDs: Text Based Dylib Stubs

Page 243: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Libraries

Libraries define symbols that are not built as part of your target• Dylibs: Dynamic libraries- Mach-O file that exposes code and data fragments executables can use

• TBDs: Text Based Dylib Stubs- Only contains symbols

Page 244: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Libraries

Libraries define symbols that are not built as part of your target• Dylibs: Dynamic libraries- Mach-O file that exposes code and data fragments executables can use

• TBDs: Text Based Dylib Stubs- Only contains symbols

• Static archives

Page 245: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Libraries

Libraries define symbols that are not built as part of your target• Dylibs: Dynamic libraries- Mach-O file that exposes code and data fragments executables can use

• TBDs: Text Based Dylib Stubs- Only contains symbols

• Static archives- An archive of multiple .o files built with the “ar” tool

Page 246: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Libraries

Libraries define symbols that are not built as part of your target• Dylibs: Dynamic libraries- Mach-O file that exposes code and data fragments executables can use

• TBDs: Text Based Dylib Stubs- Only contains symbols

• Static archives- An archive of multiple .o files built with the “ar” tool- Only the .o files with symbols you reference are included in your app

Page 247: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Example

Page 248: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

// Cat.mm

extern void playSound(const char * file);

static const char * purrFile = “purr.aac”; @implementation Cat - (void) purr { playSound(purrFile); } @end

Example

Page 249: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

// Cat.mm

extern void playSound(const char * file);

static const char * purrFile = “purr.aac”; @implementation Cat - (void) purr { playSound(purrFile); } @end

Example

Cat.o l_.str: .asciz "purr.aac" "-[Cat purr]": adrp x0, l_.str@PAGE add x0, x0, l_.str@PAGEOFF b __Z9playSoundPKc

Page 250: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

// Cat.mm

extern void playSound(const char * file);

static const char * purrFile = “purr.aac”; @implementation Cat - (void) purr { playSound(purrFile); } @end

Example

Cat.o l_.str: .asciz "purr.aac" "-[Cat purr]": adrp x0, l_.str@PAGE add x0, x0, l_.str@PAGEOFF b __Z9playSoundPKc

Page 251: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Example

// Cat.mm

extern void playSound(const char * file);

static const char * purrFile = “purr.aac”; @implementation Cat - (void) purr { playSound(purrFile); } @end

Cat.o l_.str: .asciz "purr.aac" "-[Cat purr]": adrp x0, l_.str@PAGE add x0, x0, l_.str@PAGEOFF b __Z9playSoundPKc

Page 252: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Example

// Cat.mm

extern void playSound(const char * file);

static const char * purrFile = “purr.aac”; @implementation Cat - (void) purr { playSound(purrFile); } @end

Cat.o l_.str: .asciz "purr.aac" "-[Cat purr]": adrp x0, l_.str@PAGE add x0, x0, l_.str@PAGEOFF b __Z9playSoundPKc

Page 253: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Example

// Cat.mm

extern void playSound(const char * file);

static const char * purrFile = “purr.aac”; @implementation Cat - (void) purr { playSound(purrFile); } @end

Cat.o l_.str: .asciz "purr.aac" "-[Cat purr]": adrp x0, l_.str@PAGE add x0, x0, l_.str@PAGEOFF b __Z9playSoundPKc

Page 254: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Example

// Cat.mm

extern void playSound(const char * file);

static const char * purrFile = “purr.aac”; @implementation Cat - (void) purr { playSound(purrFile); } @end

Cat.o l_.str: .asciz "purr.aac" "-[Cat purr]": adrp x0, l_.str@PAGE add x0, x0, l_.str@PAGEOFF b __Z9playSoundPKc

Page 255: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Example

Cat.o l_.str: .asciz "purr.aac" -[Cat purr]: adrp x0, l_.str@PAGE add x0, x0, l_.str@PAGEOFF b __Z9playSoundPKc

Page 256: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Example

Cat.o l_.str: .asciz "purr.aac" -[Cat purr]: adrp x0, l_.str@PAGE add x0, x0, l_.str@PAGEOFF b __Z9playSoundPKc

PetKit

Page 257: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Example

Cat.o l_.str: .asciz "purr.aac" -[Cat purr]: adrp x0, l_.str@PAGE add x0, x0, l_.str@PAGEOFF b __Z9playSoundPKc

PetKit __TEXT

Page 258: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Example

Cat.o l_.str: .asciz "purr.aac" -[Cat purr]: adrp x0, l_.str@PAGE add x0, x0, l_.str@PAGEOFF b __Z9playSoundPKc

PetKit __TEXT

__cstring: .asciz "purr.aac"

-[Cat purr]: adrp x0, l_.str@PAGE add x0, x0, l_.str@PAGEOFF b __Z9playSoundPKc

Page 259: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Example

Cat.o l_.str: .asciz "purr.aac" -[Cat purr]: adrp x0, l_.str@PAGE add x0, x0, l_.str@PAGEOFF b __Z9playSoundPKc

PetKit __TEXT

__cstring: .asciz "purr.aac"

-[Cat purr]: adr x0, #0x6f4 nop b __Z9playSoundPKc

Page 260: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Example

Cat.o l_.str: .asciz "purr.aac" -[Cat purr]: adrp x0, l_.str@PAGE add x0, x0, l_.str@PAGEOFF b __Z9playSoundPKc

PetKit __TEXT

__cstring: .asciz "purr.aac"

-[Cat purr]: adr x0, #0x6f4 nop b __Z9playSoundPKc

Page 261: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Example

Cat.o l_.str: .asciz "purr.aac" -[Cat purr]: adrp x0, l_.str@PAGE add x0, x0, l_.str@PAGEOFF b __Z9playSoundPKc

PetKit __TEXT

__cstring: .asciz "purr.aac"

-[Cat purr]: adr x0, #0x6f4 nop b __Z9playSoundPKc

Page 262: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Example

PetSupport.a

Cat.o l_.str: .asciz "purr.aac" -[Cat purr]: adrp x0, l_.str@PAGE add x0, x0, l_.str@PAGEOFF b __Z9playSoundPKc

PetKit __TEXT

__cstring: .asciz "purr.aac"

-[Cat purr]: adr x0, #0x6f4 nop b __Z9playSoundPKc

Page 263: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Example

PetSupport.aPetSounds.o

__Z9playSoundPKc: … bl _open

Cat.o l_.str: .asciz "purr.aac" -[Cat purr]: adrp x0, l_.str@PAGE add x0, x0, l_.str@PAGEOFF b __Z9playSoundPKc

PetCare.o _callVet: …

PetKit __TEXT

__cstring: .asciz "purr.aac"

-[Cat purr]: adr x0, #0x6f4 nop b __Z9playSoundPKc

Page 264: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Example

PetSupport.aPetSounds.o

__Z9playSoundPKc: … bl _open

Cat.o l_.str: .asciz "purr.aac" -[Cat purr]: adrp x0, l_.str@PAGE add x0, x0, l_.str@PAGEOFF b __Z9playSoundPKc

PetCare.o _callVet: …

PetKit __TEXT

__cstring: .asciz "purr.aac"

-[Cat purr]: adr x0, #0x6f4 nop b __Z9playSoundPKc

Page 265: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Example

PetSupport.aPetSounds.o

__Z9playSoundPKc: … bl _open

Cat.o l_.str: .asciz "purr.aac" -[Cat purr]: adrp x0, l_.str@PAGE add x0, x0, l_.str@PAGEOFF b __Z9playSoundPKc

PetCare.o _callVet: …

PetKit __TEXT

__Z9playSoundPKc: … bl _open$stub

__cstring: .asciz "purr.aac"

-[Cat purr]: adr x0, #0x6f4 nop b __Z9playSoundPKc

Page 266: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Example

PetSupport.aPetSounds.o

__Z9playSoundPKc: … bl _open

Cat.o l_.str: .asciz "purr.aac" -[Cat purr]: adrp x0, l_.str@PAGE add x0, x0, l_.str@PAGEOFF b __Z9playSoundPKc

PetCare.o _callVet: …

PetKit __TEXT

__Z9playSoundPKc: … bl _open$stub

__cstring: .asciz "purr.aac"

-[Cat purr]: adr x0, #0x6f4 nop b __Z9playSoundPKc

Page 267: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Example

PetSupport.aPetSounds.o

__Z9playSoundPKc: … bl _open

Cat.o l_.str: .asciz "purr.aac" -[Cat purr]: adrp x0, l_.str@PAGE add x0, x0, l_.str@PAGEOFF b __Z9playSoundPKc

PetCare.o _callVet: …

PetKit __TEXT

__Z9playSoundPKc: … bl _open$stub

__cstring: .asciz "purr.aac"

-[Cat purr]: adr x0, #0x6f4 nop b __Z9playSoundPKc

Page 268: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Example

PetSupport.aPetSounds.o

__Z9playSoundPKc: … bl _open

Cat.o l_.str: .asciz "purr.aac" -[Cat purr]: adrp x0, l_.str@PAGE add x0, x0, l_.str@PAGEOFF b __Z9playSoundPKc

PetCare.o _callVet: …

PetKit __TEXT

__Z9playSoundPKc: … bl _open$stub

__cstring: .asciz "purr.aac"

-[Cat purr]: adr x0, #0x6f4 nop b __Z9playSoundPKc

Page 269: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Example

PetSupport.aPetSounds.o

__Z9playSoundPKc: … bl _open

Cat.o l_.str: .asciz "purr.aac" -[Cat purr]: adrp x0, l_.str@PAGE add x0, x0, l_.str@PAGEOFF b __Z9playSoundPKc

PetCare.o _callVet: …

libSystem.tbd --- archs: [ arm64 ] platform: ios install-name: libSystem.B.dylib exports: - archs: [ arm64 ] - symbols: [ ___open ] ...

PetKit __TEXT

__Z9playSoundPKc: … bl _open$stub

__cstring: .asciz "purr.aac"

-[Cat purr]: adr x0, #0x6f4 nop b __Z9playSoundPKc

Page 270: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Example

PetSupport.aPetSounds.o

__Z9playSoundPKc: … bl _open

Cat.o l_.str: .asciz "purr.aac" -[Cat purr]: adrp x0, l_.str@PAGE add x0, x0, l_.str@PAGEOFF b __Z9playSoundPKc

PetCare.o _callVet: …

libSystem.tbd --- archs: [ arm64 ] platform: ios install-name: libSystem.B.dylib exports: - archs: [ arm64 ] - symbols: [ ___open ] ...

PetKit __TEXT

__Z9playSoundPKc: … bl _open$stub

_open$stub: ldr x16, _open$ptr br x16

__cstring: .asciz "purr.aac"

-[Cat purr]: adr x0, #0x6f4 nop b __Z9playSoundPKc

Page 271: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Example

PetSupport.aPetSounds.o

__Z9playSoundPKc: … bl _open

Cat.o l_.str: .asciz "purr.aac" -[Cat purr]: adrp x0, l_.str@PAGE add x0, x0, l_.str@PAGEOFF b __Z9playSoundPKc

PetCare.o _callVet: …

libSystem.tbd --- archs: [ arm64 ] platform: ios install-name: libSystem.B.dylib exports: - archs: [ arm64 ] - symbols: [ ___open ] ...

PetKit __TEXT

__Z9playSoundPKc: … bl _open$stub

_open$stub: ldr x16, _open$ptr br x16

__cstring: .asciz "purr.aac"

-[Cat purr]: adr x0, #0x6f4 nop b __Z9playSoundPKc

Page 272: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Example

PetSupport.aPetSounds.o

__Z9playSoundPKc: … bl _open

Cat.o l_.str: .asciz "purr.aac" -[Cat purr]: adrp x0, l_.str@PAGE add x0, x0, l_.str@PAGEOFF b __Z9playSoundPKc

PetCare.o _callVet: …

libSystem.tbd --- archs: [ arm64 ] platform: ios install-name: libSystem.B.dylib exports: - archs: [ arm64 ] - symbols: [ ___open ] ...

PetKit __TEXT

__Z9playSoundPKc: … bl _open$stub

_open$stub: ldr x16, _open$ptr br x16

__cstring: .asciz "purr.aac"

-[Cat purr]: adr x0, #0x6f4 nop b __Z9playSoundPKc

Page 273: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Example

PetSupport.aPetSounds.o

__Z9playSoundPKc: … bl _open

Cat.o l_.str: .asciz "purr.aac" -[Cat purr]: adrp x0, l_.str@PAGE add x0, x0, l_.str@PAGEOFF b __Z9playSoundPKc

PetCare.o _callVet: …

libSystem.tbd --- archs: [ arm64 ] platform: ios install-name: libSystem.B.dylib exports: - archs: [ arm64 ] - symbols: [ ___open ] ...

PetKit __TEXT

__Z9playSoundPKc: … bl _open$stub

_open$stub: ldr x16, _open$ptr br x16

__DATA Pointers

_open$ptr: .long 0x0

__cstring: .asciz "purr.aac"

-[Cat purr]: adr x0, #0x6f4 nop b __Z9playSoundPKc

Page 274: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Example

PetSupport.aPetSounds.o

__Z9playSoundPKc: … bl _open

Cat.o l_.str: .asciz "purr.aac" -[Cat purr]: adrp x0, l_.str@PAGE add x0, x0, l_.str@PAGEOFF b __Z9playSoundPKc

PetCare.o _callVet: …

libSystem.tbd --- archs: [ arm64 ] platform: ios install-name: libSystem.B.dylib exports: - archs: [ arm64 ] - symbols: [ ___open ] ...

PetKit __TEXT

__Z9playSoundPKc: … bl _open$stub

_open$stub: ldr x16, _open$ptr br x16

__DATA Pointers

_open$ptr: .long 0x0

__cstring: .asciz "purr.aac"

-[Cat purr]: adr x0, #0x6f4 nop b __Z9playSoundPKc

Page 275: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Example

PetSupport.aPetSounds.o

__Z9playSoundPKc: … bl _open

Cat.o l_.str: .asciz "purr.aac" -[Cat purr]: adrp x0, l_.str@PAGE add x0, x0, l_.str@PAGEOFF b __Z9playSoundPKc

PetCare.o _callVet: …

libSystem.tbd --- archs: [ arm64 ] platform: ios install-name: libSystem.B.dylib exports: - archs: [ arm64 ] - symbols: [ ___open ] ...

PetKit __TEXT

__Z9playSoundPKc: … bl _open$stub

_open$stub: ldr x16, _open$ptr br x16

__DATA Pointers

_open$ptr: .long 0x0

__LINKEDIT Bind _open$ptr -> libSystem`_open

__cstring: .asciz "purr.aac"

-[Cat purr]: adr x0, #0x6f4 nop b __Z9playSoundPKc

Page 276: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Example

PetSupport.aPetSounds.o

__Z9playSoundPKc: … bl _open

Cat.o l_.str: .asciz "purr.aac" -[Cat purr]: adrp x0, l_.str@PAGE add x0, x0, l_.str@PAGEOFF b __Z9playSoundPKc

PetCare.o _callVet: …

libSystem.tbd --- archs: [ arm64 ] platform: ios install-name: libSystem.B.dylib exports: - archs: [ arm64 ] - symbols: [ ___open ] ...

PetKit __TEXT

__Z9playSoundPKc: … bl _open$stub

_open$stub: ldr x16, _open$ptr br x16

__DATA Pointers

_open$ptr: .long 0x0

__LINKEDIT Bind _open$ptr -> libSystem`_open

__cstring: .asciz "purr.aac"

-[Cat purr]: adr x0, #0x6f4 nop b __Z9playSoundPKc

Page 277: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Example

PetSupport.aPetSounds.o

__Z9playSoundPKc: … bl _open

Cat.o l_.str: .asciz "purr.aac" -[Cat purr]: adrp x0, l_.str@PAGE add x0, x0, l_.str@PAGEOFF b __Z9playSoundPKc

PetCare.o _callVet: …

libSystem.tbd --- archs: [ arm64 ] platform: ios install-name: libSystem.B.dylib exports: - archs: [ arm64 ] - symbols: [ ___open ] ...

PetKit __TEXT

__Z9playSoundPKc: … bl _open$stub

_open$stub: ldr x16, _open$ptr br x16

__DATA Pointers

_open$ptr: .long 0x0

__LINKEDIT Bind _open$ptr -> libSystem`_open

__cstring: .asciz "purr.aac"

-[Cat purr]: adr x0, #0x6f4 nop b __Z9playSoundPKc

Optimizing App Startup Time WWDC 2016

Page 278: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process
Page 279: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process
Page 280: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process
Page 281: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process
Page 282: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process
Page 283: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

Open Source

Swift • https://swift.org/

Clang • https://www.llvm.org/

llbuild • https://github.com/apple/swift-llbuild/

Page 284: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process

More Informationhttps://developer.apple.com/wwdc18/415

Page 285: 415 WWDC 2018 Behind the Scenes of the Xcode Build Process