Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Bazel rules to build Swift on Apple and Linux platforms

License

NotificationsYou must be signed in to change notification settings

bazelbuild/rules_swift

 
 

Repository files navigation

Build status

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!

Basic Examples

Create a simple CLI that can run on macOS, Linux, or Windows:

load("@build_bazel_rules_swift//swift:swift_binary.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_library.bzl","swift_library")swift_library(name="MyLibrary",srcs= ["MyLibrary.swift"],tags= ["manual"],)

Reference Documentation

Click herefor the reference documentation for the rules and other definitions in thisrepository.

Quick Setup

1. Install Swift

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.

2. Configure your workspace

Copy theWORKSPACE snippet fromthe releasespage.

3. Additional configuration (Linux only)

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.

Building with Custom Toolchains

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.id

Wheretoolchain.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.

Supporting debugging

To make cacheable builds work correctly with debugging seethis doc.

Swift Package Manager Support

To download, build, and reference external Swift packages as Bazeltargets, check outrules_swift_package_manager.

Supported bazel versions

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 releaseMinimum supported rules versionFinal supported rules version
8.x (most recent rolling)0.27.0current
7.x0.27.0current
6.x0.27.02.2.0
5.x0.25.01.14.0
4.x0.19.00.24.0
3.x0.14.00.18.0

About

Bazel rules to build Swift on Apple and Linux platforms

Topics

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors74


[8]ページ先頭

©2009-2025 Movatter.jp