快速入门指南

配置系统

系统要求

安装 Xcode

mv ~/Downloads/Xcode-beta.app /Applications/
xcode-select -s /Applications/Xcode-beta.app

安装 CMake 和 Ninja

brew install cmake ninja
port install cmake ninja

设置 Swift 代码仓库

git clone [email protected]:swiftlang/swift.git
./swift/utils/update-checkout --clone --scheme main

构建 Swift 编译器


不带额外工具构建 Swift 编译器

./swift/utils/build-script --build-ninja --release-debuginfo

使用 Sccache 构建 Swift 编译器

brew install sccache
export SCCACHE_REDIS=${SCCACHE_REDIS}
sccache  --start-server
./swift/utils/build-script \
    --cmake-c-launcher `which sccache` \
    --cmake-cxx-launcher `which sccache` \
    --preset=buildbot_incremental,tools=RA,stdlib=RD,build
sccache  --stop-server

基于可下载工具链构建 Swift 标准库

mkdir workspace
cd workspace
curl -O https://download.swift.org/development/xcode/swift-DEVELOPMENT-SNAPSHOT-2019-06-06-a/swift-DEVELOPMENT-SNAPSHOT-2019-06-06-a-osx.pkg
mkdir toolchain
xar -C toolchain -x -f swift-DEVELOPMENT-SNAPSHOT-2019-06-06-a-osx.pkg
tar -C toolchain -xzf toolchain/swift-DEVELOPMENT-SNAPSHOT-2019-06-06-a-osx-package.pkg/Payload
TOOLCHAIN_BIN_DIR=$PWD/toolchain/usr/bin
git clone [email protected]:swiftlang/swift.git
./swift/utils/update-checkout --clone --scheme=stdlib_standalone
预设名称 $PRESET_NAME 构建类型 测试 调试信息
stdlib_DA_standalone,build Debug
stdlib_DA_standalone,build,test Debug
stdlib_RA_standalone,build Release
stdlib_RA_standalone,build,test Release
stdlib_RDA_standalone,build Release
stdlib_RDA_standalone,build,test Release

构建 swift-corelibs-foundation


基于可下载工具链构建 swift-corelibs-foundation

git clone [email protected]:swiftlang/swift.git
./swift/utils/update-checkout --clone --scheme main

[1] 手动安装 CMake

mkdir -p $HOME/bin
tar xfz cmake-3.14.4-Darwin-x86_64.tar.gz -C $HOME/bin
export PATH=$HOME/bin/cmake-3.14.4-Darwin-x86_64/CMake.app/Contents/bin:$PATH

[2] 手动安装 Sccache:

mkdir -p $HOME/bin
tar xfz sccache-0.2.8-x86_64-apple-darwin.tar.gz -C $HOME/bin
export PATH=$HOME/bin/sccache-0.2.8-x86_64-apple-darwin:$PATH

适合新手的问题

Swift 项目使用 GitHub Issues 来跟踪 bug、想法和任务。例如,Swift 编译器仓库的问题可以在其 问题面板上找到。适合新手的问题会标记 good first issue 标签,可以通过访问 https://github.com/apple/<repository>/contribute 找到。