All Projects → bazelbuild → Rules_swift

bazelbuild / Rules_swift

Licence: apache-2.0
Bazel rules to build Swift on Apple and Linux platforms

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Rules swift

Rules typescript
MOVED to https://github.com/bazelbuild/rules_nodejs/tree/3.x/third_party/github.com/bazelbuild/rules_typescript
Stars: ✭ 280 (+85.43%)
Mutual labels:  bazel, bazel-rules
Rules apple line
LINE's Apple rules for Bazel
Stars: ✭ 151 (+0%)
Mutual labels:  bazel, bazel-rules
Rules nodejs
JavaScript and NodeJS rules for Bazel
Stars: ✭ 488 (+223.18%)
Mutual labels:  bazel, bazel-rules
Bazel Tools
Reusable bits for Bazel
Stars: ✭ 109 (-27.81%)
Mutual labels:  bazel, bazel-rules
Platforms
Constraint values for specifying platforms and toolchains
Stars: ✭ 34 (-77.48%)
Mutual labels:  bazel, bazel-rules
Rules scala
Scala rules for Bazel
Stars: ✭ 269 (+78.15%)
Mutual labels:  bazel, bazel-rules
Rules docker
Rules for building and handling Docker images with Bazel
Stars: ✭ 744 (+392.72%)
Mutual labels:  bazel, bazel-rules
ios-bazel-users
Resources for using bazel for iOS development
Stars: ✭ 80 (-47.02%)
Mutual labels:  bazel, bazel-rules
Rules codeowners
Bazel rules for generating CODEOWNERS from a workspace.
Stars: ✭ 31 (-79.47%)
Mutual labels:  bazel, bazel-rules
Rules go
Go rules for Bazel
Stars: ✭ 852 (+464.24%)
Mutual labels:  bazel, bazel-rules
rules clojure
Clojure rules for Bazel
Stars: ✭ 27 (-82.12%)
Mutual labels:  bazel, bazel-rules
Dbx build tools
Dropbox's Bazel rules and tools
Stars: ✭ 119 (-21.19%)
Mutual labels:  bazel, bazel-rules
svelte-ts
[WIP] Tools for building Svelte apps with TS
Stars: ✭ 89 (-41.06%)
Mutual labels:  bazel, bazel-rules
Bazel Linting System
🌿💚 Experimental system for registering, configuring, and invoking source-code linters in Bazel.
Stars: ✭ 63 (-58.28%)
Mutual labels:  bazel, bazel-rules
rules poetry
Bazel rules that use Poetry for Python package management
Stars: ✭ 40 (-73.51%)
Mutual labels:  bazel, bazel-rules
Awesome Bazel
A curated list of Bazel rules, tooling and resources.
Stars: ✭ 640 (+323.84%)
Mutual labels:  bazel, bazel-rules
grab-bazel-common
Common rules and macros for Grab's Android projects built with Bazel.
Stars: ✭ 20 (-86.75%)
Mutual labels:  bazel, bazel-rules
rules gwt
Bazel rules for GWT
Stars: ✭ 20 (-86.75%)
Mutual labels:  bazel, bazel-rules
Rules terraform
Bazel rules for using Hashicorp's Terraform in your Bazel builds.
Stars: ✭ 26 (-82.78%)
Mutual labels:  bazel, bazel-rules
Rules grafana
Bazel rules for building Grafana dashboards
Stars: ✭ 46 (-69.54%)
Mutual labels:  bazel, bazel-rules

Swift Rules for Bazel

Build status

This repository contains rules for Bazel that can be used to build Swift libraries, tests, and executables for macOS and Linux.

To build applications for all of Apple's platforms (macOS, iOS, tvOS, and watchOS), they can be combined with the Apple Rules.

If you run into any problems with these rules, please file an issue!

Reference Documentation

Click here for the reference documentation for the rules and other definitions in this repository.

Compatibility

Please refer to the release notes for a given release to see which version of Bazel it is compatible with.

Quick Setup

1. Install Swift

Before getting started, make sure that you have a Swift toolchain installed.

Apple users: Install Xcode. If this is your first time installing it, make sure to open it once after installing so that the command line tools are correctly configured.

Linux users: Follow the instructions on the Swift download page to download and install the appropriate Swift toolchain for your platform. Take care to ensure that you have all of Swift's dependencies installed (such as ICU, Clang, and so forth), and also ensure that the Swift compiler is available on your system path.

2. Configure your workspace

Add the following to your WORKSPACE file to add the external repositories, replacing the urls and sha256 attributes with the values from the release you wish to depend on:

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "build_bazel_rules_swift",
    sha256 = "be80375680b2553a8b318ffd02ce916a7e1d9060ccad3e7c50f543caafb86fed",
    url = "https://github.com/bazelbuild/rules_swift/releases/download/0.19.0/rules_swift.0.19.0.tar.gz",
)

load(
    "@build_bazel_rules_swift//swift:repositories.bzl",
    "swift_rules_dependencies",
)

swift_rules_dependencies()

load(
    "@build_bazel_rules_swift//swift:extras.bzl",
    "swift_rules_extra_dependencies",
)

swift_rules_extra_dependencies()

The swift_rules_dependencies macro creates a toolchain appropriate for your platform (either by locating an installation of Xcode on macOS, or looking for swiftc on the system path on Linux).

3. Additional configuration (Linux only)

The swift_binary and swift_test rules expect to use clang as the driver for linking, and they query the Bazel C++ API and CROSSTOOL to determine which arguments should be passed to the linker. By default, the C++ toolchain used by Bazel is gcc, so Swift users on Linux need to override this by setting the environment variable CC=clang when invoking Bazel.

This step is not necessary for macOS users because the Xcode toolchain always uses clang.

Building with Custom Toolchains

macOS hosts: You can build with a custom toolchain installed in /Library/Developer/Toolchains instead of Xcode's default. To do so, pass the following flag to Bazel:

--define=SWIFT_CUSTOM_TOOLCHAIN=toolchain.id

where toolchain.id is the value of the CFBundleIdentifier key in the toolchain'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 whichever swift executable is encountered first on your PATH.

Supporting remote builds

To make remote builds work correctly with debugging and general reproducibility see this doc

Future Work

  • Support for building and linking to shared libraries (.dylib/.so) written in Swift.
  • Interoperability with Swift Package Manager.
  • Migration to the Bazel platforms/toolchains APIs.
  • Support for multiple toolchains, and support for non-Xcode toolchains on macOS.
  • Automatically download a Linux toolchain from swift.org if one is not already installed.

Acknowledgments

We gratefully acknowledge the following external packages that rules_swift depends on:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].