gwik / rules_swift

Bazel rules to build Swift on Apple and Linux platforms

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Swift Rules for Bazel

Build Status

⚠️ The rules in this repository are in the beta stage of development. There are many features that still need to be implemented and there may be bugs. If you run into any problems, please file an issue!

This repository contains rules for Bazel that can be used to build Swift libraries and executables for Apple platforms (iOS, macOS, tvOS, and watchOS) and Linux.

NOTE: The build rules in this repository are intended to replace the swift_library rule that is currently housed in bazelbuild/rules_apple.

Reference Documentation

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

Compatibility

These rules have been verified to work with Bazel 0.14.1.

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 version number in the tag attribute with the version of the rules you wish to depend on:

git_repository(
    name = "build_bazel_rules_swift",
    remote = "https://github.com/bazelbuild/rules_swift.git",
    tag = "0.1.1",
)

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

swift_rules_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).

Future Work

  • Support for building and linking to shared libraries (.dylib/.so) written in Swift.
  • Interoperability with Swift Package Manager.
  • Improved C interoperability.
  • 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.

About

Bazel rules to build Swift on Apple and Linux platforms

License:Apache License 2.0


Languages

Language:Python 95.7%Language:Shell 4.3%