- Notifications
You must be signed in to change notification settings - Fork155
Bazel rules to build Swift on Apple and Linux platforms
License
bazelbuild/rules_swift
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Swift Rules forBazel
This repository contains rules forBazel that can beused to build Swift libraries, tests, and executables for macOS and Linux.
To build applications for all of Apple's platforms (macOS, iOS, tvOS,visionOS, and watchOS), they can be combined with theApple Rules.
If you run into any problems with these rules, pleasefile an issue!
Create a simple CLI that can run on macOS, Linux, or Windows:
load("@build_bazel_rules_swift//swift:swift.bzl","swift_binary")swift_binary(name="cli",srcs= ["CLI.swift"],)
Create a single library target that can be used by other targets in yourbuild:
load("@build_bazel_rules_swift//swift:swift.bzl","swift_library")swift_library(name="MyLibrary",srcs= ["MyLibrary.swift"],tags= ["manual"],)
Click herefor the reference documentation for the rules and other definitions in thisrepository.
Before getting started, make sure that you have a Swift toolchain installed.
Apple users: InstallXcode.If this is your first time installing it, make sure to open it once afterinstalling so that the command line tools are correctly configured.
Linux users: Follow the instructions on theSwift download page to download and install theappropriate Swift toolchain for your platform. Take care to ensure that you haveall of Swift's dependencies installed (such as ICU, Clang, and so forth), andalso ensure that the Swift compiler is available on your system path.
Copy theWORKSPACE snippet fromthe releasespage.
Theswift_binary andswift_test rules expect to useclang as the driverfor linking, and they query the Bazel C++ API and CROSSTOOL to determine whicharguments should be passed to the linker. By default, the C++ toolchain used byBazel isgcc, so Swift users on Linux need to override this by setting theenvironment variableCC=clang when invoking Bazel.
This step is not necessary for macOS users because the Xcode toolchain alwaysusesclang.
macOS hosts: You can build with a custom Swift toolchain (downloadedfromhttps://swift.org/download) instead of Xcode's default. To do so,pass the following flag to Bazel:
--action_env=TOOLCHAINS=toolchain.idWheretoolchain.id is the value of theCFBundleIdentifier key in thetoolchain's Info.plist file.
To list the available toolchains and their bundle identifiers, you can run:
bazel run @build_bazel_rules_swift//tools/dump_toolchains
Linux hosts: At this time, Bazel uses whicheverswift executable isencountered first on yourPATH.
To make cacheable builds work correctly with debugging seethis doc.
To download, build, and reference external Swift packages as Bazeltargets, check outrules_swift_package_manager.
rules_apple and rules_swift are often affected by changes in bazelitself. This means you generally need to update these rules as youupdate bazel.
You can also see the supported bazel versions in the notes for eachrelease on thereleasespage.
Besides these constraint this repo followssemveras best as we can since the 1.0.0 release.
| Bazel release | Minimum supported rules version | Final supported rules version |
|---|---|---|
| 8.x (most recent rolling) | 0.27.0 | current |
| 7.x | 0.27.0 | current |
| 6.x | 0.27.0 | current |
| 5.x | 0.25.0 | 1.14.0 |
| 4.x | 0.19.0 | 0.24.0 |
| 3.x | 0.14.0 | 0.18.0 |
About
Bazel rules to build Swift on Apple and Linux platforms
Topics
Resources
License
Contributing
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.