swift README

The project's README from github.com/swiftlang/swift. As one markdown file: README.md.

Swift logo

Swift Programming Language

Welcome to Swift

Swift is a high-performance system programming language. It has a clean and modern syntax, offers seamless access to existing C and Objective-C code and frameworks, and is memory-safe by default.

Although inspired by Objective-C and many other languages, Swift is not itself a C-derived language. As a complete and independent language, Swift packages core features like flow control, data structures, and functions, with high-level constructs like objects, protocols, closures, and generics. Swift embraces modules, eliminating the need for headers and the code duplication they entail.

To learn more about using the language, visit swift.org. To learn more about the compiler's internal design, see the documentation index.

Contributing to Swift

Contributions to Swift are welcomed and encouraged! Please see the Contributing to Swift guide.

Before submitting the pull request, please make sure you have tested your changes and that they follow the Swift project guidelines for contributing code.

To be a truly great community, Swift.org needs to welcome developers from all walks of life, with different backgrounds, and with a wide range of experience. A diverse and friendly community will have more great ideas, more unique perspectives, and produce more great code. We will work diligently to make the Swift community welcoming to everyone.

To give clarity of what is expected of our members, Swift has adopted the code of conduct defined by the Contributor Covenant. This document is used across many open source communities, and we think it articulates our values well. For more, see the Code of Conduct.

Getting Started

If you are interested in:

We also have an FAQ that answers common questions.

Swift Toolchains

Building

Swift toolchains are created using the script build-toolchain. This script is used by swift.org's CI to produce snapshots and can allow for one to locally reproduce such builds for development or distribution purposes. A typical invocation looks like the following:

  $ ./swift/utils/build-toolchain $BUNDLE_PREFIX

where $BUNDLE_PREFIX is a string that will be prepended to the build date to give the bundle identifier of the toolchain's Info.plist. For instance, if $BUNDLE_PREFIX was com.example, the toolchain produced will have the bundle identifier com.example.YYYYMMDD. It will be created in the directory you run the script with a filename of the form: swift-LOCAL-YYYY-MM-DD-a-osx.tar.gz.

Beyond building the toolchain, build-toolchain also supports the following (non-exhaustive) set of useful options:

More options may be added over time. Please pass --help to build-toolchain to see the full set of options.

Installing into Xcode

On macOS if one wants to install such a toolchain into Xcode:

  1. Untar and copy the toolchain to one of /Library/Developer/Toolchains/ or ~/Library/Developer/Toolchains/. E.g.:
  $ sudo tar -xzf swift-LOCAL-YYYY-MM-DD-a-osx.tar.gz -C /
  $ tar -xzf swift-LOCAL-YYYY-MM-DD-a-osx.tar.gz -C ~/

The script also generates an archive containing debug symbols which can be installed over the main archive allowing symbolication of any compiler crashes.

  $ sudo tar -xzf swift-LOCAL-YYYY-MM-DD-a-osx-symbols.tar.gz -C /
  $ tar -xzf swift-LOCAL-YYYY-MM-DD-a-osx-symbols.tar.gz -C ~/
  1. Specify the local toolchain for Xcode's use via Xcode->Toolchains.

Build Failures

Try the suggestions in Troubleshooting build issues.

Make sure you are using the correct release of Xcode.

If you have changed Xcode versions but still encounter errors that appear to be related to the Xcode version, try passing --clean to build-script.

When a new version of Xcode is released, you can update your build without recompiling the entire project by passing --reconfigure to build-script.

swift (swiftlang/swift)

Searching Database…

70.5K ·GitHub
这是什么?这是 Swift 的源代码仓库。Swift 是一种高性能的系统编程语言,语法简洁现代,可以直接调用现有的 C 和 Objective-C 代码,并且默认具备内存安全性。
Swift 编译器是在这里开发的吗?还是说我可以从这里下载这门语言?这里是编译器的源代码,不是安装程序。要写 Swift 的话,用 swift.org 或 Xcode 提供的现成工具链就行;这个仓库是用来开发编译器本身的。
我想动手改编译器,该从哪里入手?如果想提交修复,请按照 How to Submit Your First Pull Request 指南操作;如果只是想临时构建一次编译器,用 Getting Started 指南即可。
构建它需要特定版本的 Xcode 吗?文档里写明在 macOS 上的构建要求是 Xcode,而且必须是与你检出的代码版本相匹配的版本——构建失败指南也是从这里开始排查的。
我更新了 Xcode 之后构建就挂了,有什么快速解决办法吗?有:如果更换 Xcode 版本后错误仍然存在,可以给 build-script 加上 --clean 参数;另外,新 Xcode 发布后,用 --reconfigure 可以更新构建配置,而不用把整个项目重新编译一遍。
构建编译器只能在 macOS 上进行吗?这个 README 里的实操说明只针对 macOS:本地构建出的工具链会解压到 /Library/Developer/Toolchains 或 ~/Library/Developer/Toolchains,然后在 Xcode 的 Toolchains 设置里选用。
Swift 是从 C 派生出来的语言吗?不是——虽然 Swift 受到 Objective-C 和许多其他语言的启发,但它并不是从 C 派生的。它是一门完整、独立的语言,支持对象、协议、闭包和泛型,并且用模块(modules)取代了头文件。
我可以在本地构建自己的 Swift 工具链吗?可以——build-toolchain 脚本构建工具链的方式和 swift.org 的 CI 生成快照完全一样,会产出类似 swift-LOCAL-YYYY-MM-DD-a-osx.tar.gz 这样的压缩包。
有没有什么参数可以测试或加快工具链的构建?有:--test 会在编译完成后运行测试套件,--distcc 把构建中 C++ 的部分分发出去,--sccache 缓存 C++ 编译产物,--dry-run 则只做一次试构建。
Creator
swiftlang
Size
1.3 GB
Stars
70.5K
Age
10y
Commits · 90 Days