Home

Awesome

<p align="center"> <img src="https://user-images.githubusercontent.com/158658/161647598-223361dc-030d-431a-b4fe-d92592ed5530.png" width="255"> </p>

rules_xcodeproj

This repository contains rules for Bazel that can be used to generate Xcode projects from targets in your workspace.

If you run into any problems with these rules, please check our FAQ, check if another issue already exists and comment on it, or file a new issue!

Features

<div align="center"> <a href="https://user-images.githubusercontent.com/158658/216620253-507bbf10-a692-4dcd-bd74-736c9717e53e.png"> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/158658/216620284-6a3cb6ff-f5cd-42f2-8e2b-7ef2a70c8da5.png"> <img alt="Screenshot of a rules_xcodeproj generated project open in Xcode" src="https://user-images.githubusercontent.com/158658/216620253-507bbf10-a692-4dcd-bd74-736c9717e53e.png" width="1245"> </picture> </a> </div>

We’ve also documented the high-level design goals of the ruleset.

Projects using rules_xcodeproj

If you are also using rules_xcodeproj for your project, feel free to open a PR to include it in the list above.

Compatibility

rules_xcodeprojBazelrules_applerules_swiftXcodemacOSSupporting Branch
2.10.0+7.0-9.x3.16.1+1.18.0+13.3–15.x13–14.xmain
1.17.0+6.3-7.x1.0.1–2.x1.x13.3–15.x13–14.x-
1.16.06.3-7.x1.0.1–2.x1.x13.3–15.213–14.x-
1.14.0-1.15.06.1-7.x1.0.1–2.x1.x13.3–15.213–14.x-
1.7.0-1.13.05.3–6.x1.0.1–2.x1.x13.3–15.212–13.x-
1.4.0-1.6.05.3–6.x1.0.1–2.x1.x13.3–14.312–13.x-
1.0-1.3.35.3–6.x1.0.1–2.x1.x13.3–14.212–13.x-

More versions of these tools and rulesets might be supported, but these are the ones we’ve officially tested with.

Installation

From the release you wish to use, copy the Bzlmod or WORKSPACE snippet into your repository. If you want to manually build a release archive, you can use this command: bazel build //distribution:release.

Usage

Please see the documentation in the docs directory and examples in the examples directory.

Simple iOS example

Given a root level BUILD file:

load(
  "@build_bazel_rules_apple//apple:ios.bzl",
  "ios_application",
  "ios_unit_test",
)
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
load(
    "@rules_xcodeproj//xcodeproj:defs.bzl",
    "top_level_target",
    "xcodeproj",
)

xcodeproj(
    name = "xcodeproj",
    project_name = "App",
    tags = ["manual"],
    top_level_targets = [
        top_level_target(":App", target_environments = ["device", "simulator"]),
        ":Tests",
    ],
)

ios_application(
    name = "App",
    bundle_id = "com.example.app",
    families = ["iphone", "ipad"],
    infoplists = [":Info.plist"],
    minimum_os_version = "15.0",
    visibility = ["//visibility:public"],
    deps = [":Lib"],
)

swift_library(
    name = "Lib",
    srcs = glob(["src/*.swift"]),
)

ios_unit_test(
    name = "Tests",
    bundle_id = "com.example.tests",
    minimum_os_version = "15.0",
    test_host = ":App",
    visibility = ["//visibility:public"],
    deps = [":TestLib"],
)

swift_library(
    name = "TestLib",
    srcs = glob(["test/*.swift"]),
)

You can then create the Xcode project with:

bazel run //:xcodeproj

The generated project will be in the workspace next to the BUILD file at App.xcodeproj.

Acknowledgements