GithubHelp home page GithubHelp logo

larryaasen / bazelbuild_examples Goto Github PK

View Code? Open in Web Editor NEW
4.0 3.0 3.0 100 KB

Bazel Build Examples

License: Apache License 2.0

Starlark 33.16% Swift 66.84%
bazel bazel-rules ios ios-swift bazel-examples bazel-build swift bazel-ios

bazelbuild_examples's Introduction

Bazel Build Examples

Build Status

This collection of examples demonstrates how to use Bazel on iOS builds with Xcode 11 and iOS 13.

HelloWorld

The HelloWorld iOS example is a Swift project that was generated by Xcode 11.3.1 and remains in the same structure as when it was generated. The project file was removed and replaced with a Bazel build.

The ios/HelloWorld folder contains a makefile named Makefile.bazel that shows the Bazel commands required to build. It also contains commands to install and launch the build on a simulator.

To build the HelloWorld app in Bazel, install it on the simulator, and then run the app on the simulator, run this command from the Terminal:

$ cd ios/HelloWorld
$ make -f Makefile.bazel build_app

HelloWorld2

The HelloWorld2 iOS example is the same as the HelloWorld example, but with a BUILD file in the subfolder HelloWorld2.

To build the HelloWorld2 app in Bazel, install it on the simulator, and then run the app on the simulator, run this command from the Terminal:

$ cd ios/HelloWorld2
$ make -f Makefile.bazel build_app

HelloWorld3

The HelloWorld3 iOS example is the same as the HelloWorld2 example, but with a second swift_library containing one new Swift file, where SwiftLib depends on library Controllers.

To build the HelloWorld3 app in Bazel, install it on the simulator, and then run the app on the simulator, run this command from the Terminal:

$ cd ios/HelloWorld3
$ make -f Makefile.bazel build_app

Bazel Commands

There are various new commands used when building with Bazel for iOS so I have placed them in a makefile called Makefile.bazel so it is easy to remember how to run bazel.

First, open a Terminal window and navigate to the ios/HelloWorld2 folder.

$ cd ios/HelloWorld2

The bazel build command used for iOS is:

$ bazel build --apple_platform_type=ios HelloWorld2/HelloWorld2

Using make you can just type:

$ make -f Makefile.bazel build_app

To install the app just built with bazel onto the simualator:

$ make -f Makefile.bazel install

To run the app on the simulator:

$ make -f Makefile.bazel launch

To build, install, and launch the app all at once:

$ make -f Makefile.bazel run

After installing Tulsi and configuring the project, you can create the Xcode project file from the command line. It will also launch Xcode.

$ make -f Makefile.bazel generate_xcode_project

Installing Tulsi

Installing Tulsi with Bazel 2.0.0 requires a few modifications to the installation script. The script build_and_run.sh is used to build the Tulsi app and is setup to use Xcode 11.2.1 as of 3/8/2020.

To build Tulsi with Xcode 11.3.1 you need to make two changes:

  • Open the .bazelrc file and find this on line 3: build --xcode_version=11.2.1. Change 11.2.1 to 11.3.1 and save the file.

  • Open the WORKSPACE file and find this on line 3: git_repository(. Replace the entire git_repository function with this one:

git_repository(
    name = "build_bazel_rules_apple",
    remote = "https://github.com/bazelbuild/rules_apple.git",
    tag = "0.19.0",
)

Run the build script:

$ ./build_and_run.sh

If the build succeeded, you should see this:

Target //:tulsi up-to-date:
  bazel-bin/tulsi.zip
INFO: Elapsed time: 35.487s, Critical Path: 29.57s
INFO: 43 processes: 28 darwin-sandbox, 15 local.
INFO: Build completed successfully, 82 total actions

The Tulsi app is automatically launched:

Tulsi App

Contributing

All comments and pull requests are welcome.

Become a Patron!

bazelbuild_examples's People

Contributors

larryaasen avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

bazelbuild_examples's Issues

can not build it in macos catalina version 10.15.7, Bazel 4.0.0 and xcode 12.4

I run your script and get this error throw:

ERROR: /private/var/tmp/_bazel_nguyenphuongthao/6b29721cd13f6b1709dacf15de174f80/external/build_bazel_rules_apple/tools/realpath/BUILD:9:14: in _apple_genrule_inner rule @build_bazel_rules_apple//tools/realpath:realpath_genrule:
Traceback (most recent call last):
	File "/private/var/tmp/_bazel_nguyenphuongthao/6b29721cd13f6b1709dacf15de174f80/external/build_bazel_apple_support/rules/apple_genrule.bzl", line 78, column 28, in _apple_genrule_impl
		apple_support.run_shell(
	File "/private/var/tmp/_bazel_nguyenphuongthao/6b29721cd13f6b1709dacf15de174f80/external/build_bazel_apple_support/lib/apple_support.bzl", line 326, column 26, in _run_shell
		ctx.actions.run_shell(**_kwargs_for_apple_platform(ctx, **kwargs))
Error in run_shell: 'command' must be of type string. passing a sequence of strings as 'command' is deprecated. To temporarily disable this check, set --incompatible_run_shell_command_string=false.
INFO: Repository com_google_protobuf instantiated at:
  /Users/nguyenphuongthao/coding/ios/bazelbuild_examples/ios/HelloWorld/WORKSPACE:54:25: in <toplevel>
  /private/var/tmp/_bazel_nguyenphuongthao/6b29721cd13f6b1709dacf15de174f80/external/build_bazel_rules_swift/swift/repositories.bzl:88:11: in swift_rules_dependencies
  /private/var/tmp/_bazel_nguyenphuongthao/6b29721cd13f6b1709dacf15de174f80/external/build_bazel_rules_swift/swift/repositories.bzl:32:18: in _maybe
Repository rule http_archive defined at:
  /private/var/tmp/_bazel_nguyenphuongthao/6b29721cd13f6b1709dacf15de174f80/external/bazel_tools/tools/build_defs/repo/http.bzl:336:31: in <toplevel>
INFO: Repository com_github_nlohmann_json instantiated at:
  /Users/nguyenphuongthao/coding/ios/bazelbuild_examples/ios/HelloWorld/WORKSPACE:54:25: in <toplevel>
  /private/var/tmp/_bazel_nguyenphuongthao/6b29721cd13f6b1709dacf15de174f80/external/build_bazel_rules_swift/swift/repositories.bzl:79:11: in swift_rules_dependencies
  /private/var/tmp/_bazel_nguyenphuongthao/6b29721cd13f6b1709dacf15de174f80/external/build_bazel_rules_swift/swift/repositories.bzl:32:18: in _maybe
Repository rule http_archive defined at:
  /private/var/tmp/_bazel_nguyenphuongthao/6b29721cd13f6b1709dacf15de174f80/external/bazel_tools/tools/build_defs/repo/http.bzl:336:31: in <toplevel>
ERROR: Analysis of target '//:HelloWorld' failed; build aborted: Analysis of target '@build_bazel_rules_apple//tools/realpath:realpath_genrule' failed
INFO: Elapsed time: 26.856s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (38 packages loaded, 440 targets configured)
make: *** [build_app] Error 1

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.