Swift.Org, the Open Source Project

Swift.Org, the Open Source Project

CHAPTER 1 Swift.org, the Open Source Project n December 3, 2015, Apple made version 2.2 of the Swift programming language open source Osoftware by creating Swift.org and contributing a key set of source code repositories covering the compilers, debuggers, libraries, and more. The Swift.org site ( https://swift.org ) was set up to serve as a central hub for this new community. The site contains documentation, binary downloads, links to the open source repositories on GitHub, mailing lists, and bug reporting mechanisms, as well as continuous integration support to maintain stability across the projects. In this chapter, I will cover what is included on the site as well as some pointers about how to get involved in this exciting community. What’s Included The Swift.org website is the focal point for the Swift language development community. Because the community supporting Swift is composed of people with diverse skill levels and different interests, the site is designed to be a single entry point from which visitors can access the information relevant to their needs. The navigation categories listed on the left-hand side of the Swift.org home page represent major topic areas into which visitors can dive, depending on whether they are developers who want to look at the source code, testers wanting to report a bug, people with general interest who want to sub- scribe to a mailing list, or any of the dozens of possible reasons why they are involved with the language. There are roughly a dozen of these major navigation categories on the Swift.org home page. Visitors can learn general informationCOPYRIGHTED about the language by following MATERIAL the About Swift link. They can access public blogs and documentation by clicking on those same named links. They can learn about the rules of the community and how to contribute through the Community and Contributing links. You will learn more information about community involvement later in this chapter. For developers, one of the most important Swift.org categories is the Source Code link. All of the source code for the Swift language and related utilities is stored in GitHub repositories (a separate website from Swift.org). The SOURCE CODE navigation link from the Swift.org home page takes you to a web page where the organization of the source code is explained and links are provided to the various GitHub repos containing code for different Swift libraries. 2 Swift in the Cloud Source Code Repositories The open source Swift language is managed by the community as a collection of projects, each with its own source code repositories. These repositories are the core of Swift.org. Anyone can freely access the source repositories to get the code for the Swift language, build it, and run their own local version; they can even make enhancements or fi x defects as long as the community rules for contributions are followed. These source code repositories include the following: ■ Swift compiler and standard library ■ https://github.com/apple/swift ■ Core libraries (Foundation, libdispatch , and XCTest ) ■ https://github.com/apple/swift-corelibs-foundation ■ https://github.com/apple/swift-corelibs-libdispatch ■ https://github.com/apple/swift-corelibs-xctest ■ LLDB debugger and REPL ■ https://github.com/apple/swift-lldb ■ Swift Package Manager ■ https://github.com/apple/swift-package-manager ■ Xcode Playground Support ■ https://github.com/apple/swift-xcode-playground-support ■ A variety of repositories that include support for compiler tools, tests, code samples, protobuf support, and much more These projects are published under an Apache 2 license with a runtime library extension. The importance of this kind of license is that it solves the potential problem of a schism between the compiler and runtime library by allowing both to be covered uniformly under the same license. Figure 1-1 shows the GitHub web page for a typical Swift.org repository—in this case, for the Swift compiler and standard library project. Swift Compiler and Standard Library The Swift compiler and standard library provide basic language and type system support across the platforms. This support is completely equivalent for macOS and Linux, but no other operating systems are supported as of this writing. All the language features described in this chapter are delivered by the compiler and standard library. The Swift standard library supplies a programmer with the fundamental data types such as Int , Double , and String , as well as more complex data structures including Set , Array , Dictionary , and many more. It is within this library that many common protocols are defi ned for the language features. Many language features have a corresponding protocol, and any type that conforms to the protocol can be used with that feature. For example, a for-in loop can iterate over the elements of any value whose type conforms to the Sequence protocol. c01.indd 07/25/17 Page 2 Chapter 1 Swift.org, the Open Source Project 3 Figure 1-1: One of the Swift.org source repositories Foundation The Foundation library provides many core capabilities that Swift developers are accustomed to, such as URLSession , JSONSerialization , and more. On Apple platforms, this library is implemented in Objective-C. The Swift.org version of this library is being implemented in Swift. As such, there are several APIs in Foundation that are being rewritten to make Foundation support on Linux more mature. To view the latest status of Foundation, you can check the status page at https://github .com/apple/swift-corelibs-foundation/blob/master/Docs/Status.md . Libdispatch (Grand Central Dispatch) Swift developers are accustomed to using Grand Central Dispatch to leverage concurrency support in their applications running on client operating systems such as iOS. Grand Central Dispatch support is provided within the libdispatch core library. This library is provided as part of the Swift runtime. When Swift was fi rst made open source, the libdispatch core library was included as part of Swift.org. At that time, the library had not been ported to Linux. IBM agreed that it was important to provide this same consistent concurrency support on Linux, and set about porting libdispatch to Linux. The ported version of libdispatch was included in the Swift 3.0 release in September 2016. This was an important milestone because many Foundation APIs (like OperationQueue and URLSession ) also depend upon libdispatch. c01.indd 07/25/17 Page 3 4 Swift in the Cloud Debugger and REPL Tight integration of the Swift compiler and debugger enables accurate inspection of data types in the debugger, as well as full-featured expression evaluation in the context of this rapidly evolving language. However, because of this tight integration, developers must be sure to use a matched pair of a compiler and debugger built using the same sources. Debugging using a mismatched compiler- debugger set will lead to unpredictable behavior and programming problems. The s wift-lldb repository contains the source code that can be used to build the Swift debug- ger. The debugger includes an interactive version of the Swift language, known as the REPL (read- eval-print loop). You can use this interactive command environment to experiment with Swift and quickly see the results of arbitrary Swift code snippets that you write and execute. You can try the Swift REPL environment on your macOS computer by simply typing swift on the Terminal command line: Leighs-MacBook-Pro:~ leighwilliamson$ s wift Welcome to Apple Swift version 3.0.1 (swiftlang-800.0.58.6 clang-800.0.42.1). Type:help for assistance. 1> All you need to do is type Swift statements, and the REPL immediately executes your code. Expression results are automatically formatted and displayed along with their type, as are the results of both variable and constant declarations. 1> var whoami = "Leigh Williamson" whoami: String = "Leigh Williamson" 2> print("Hello") Hello 3> print("Hello, \(whoami)") Hello, Leigh Williamson 4> The swift-lldb project wraps enhancements around the core LLDB (Low Level Debugger) open- source debugger project developed under the broader LLVM (Low Level Virtual Machine) project, located at llvm.org. Therefore, any code modifi cations that are contributed to swift-lldb will undergo extra scrutiny because of the potential impact outside of the Swift language ecosystem. Swift Package Manager Swift Package Manager is a new feature that was introduced with Swift 3.0. Although it is not yet used for building applications on other Swift platforms, it is used extensively for building applications on Linux. Projects that are compatible with Swift Package Manager are built around a Package.swift fi le that specifi es build targets as well as other packages that the project is dependent upon. Chapter 6 is devoted to Swift Package Manager and all of its details. c01.indd 07/25/17 Page 4 Chapter 1 Swift.org, the Open Source Project 5 Xcode Playground Support The “playground” feature in Xcode has long been used by developers to experiment with a language, explore its standard library types, and learn high-level concepts using visualizations and practical examples. Within Xcode there are several “playgrounds” supported for different languages. For instance, a programmer can use the Xcode Swift Playground to learn how the Swift language uses protocols and generics to express powerful constraints. The playground feature is valuable for developers who are new to the language, but also very handy for those who are well versed in the behavior of the language. The Xcode Playground Support project enables the Swift language to be integrated with the Xcode playground feature so that developers can take advantage of the playground to learn and explore the language. This same project code is used outside of Xcode for similar language learning “playground” systems such as the Bluemix Swift Sandbox (see Chapter 2 ).

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    18 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us