Code Monkey home page Code Monkey logo

rules_swift's Introduction

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

These rules have been verified to work with Bazel 0.19.0.

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.4.0",
)

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

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.

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.

rules_swift's People

Contributors

allevato avatar keith avatar thomasvl avatar kastiglione avatar gwik avatar steeve avatar davidgoldman avatar

Watchers

Laurent Le Brun avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.