GithubHelp home page GithubHelp logo

narlei / buckstartersample Goto Github PK

View Code? Open in Web Editor NEW
7.0 4.0 0.0 4.63 MB

Buck starter sample is a project to you understand the steps to change your iOS build system

License: MIT License

Swift 77.37% Starlark 16.74% Makefile 5.89%

buckstartersample's Introduction

Buck starter sample

This project will help you to start a project using Buck build system.

Mindset

The first think is change your mindset, buck is NOT a Xcode project generator, it IS a build system! Of course, buck generates Xcode project, but, if is only what you want, use other tools.

Setup

What you’ll install:

  • Command line tools;
  • Java 8;
  • Buck;

I recommend you use HomeBrew.

To install The command line tools: xcode-select —install

Buck is written in Java, then you will need to install Java in your machine. Not, let’s install Java using AdoptOpenJDK:

brew tap AdoptOpenJDK/openjdk
brew install --cask adoptopenjdk8

Let’s install buck now:

brew tap facebook/fb
brew install buck

If you receive a error like Error: /usr/local/Cellar/buck/2021.01.12.01 is not a directory Run brew link buck

For the last step, run: brew install watchman

You can see the complete guide here.

Let’s buck!

Before use Buck, I recommend you read this article. Will help you to understand how a .app or .ipa is generated.

Understanding the structure

The most benefit of Buck is modularization. Then, stop to think in your app as a BIG code, start to think in a LOT of small parts of code. Each module need to work “alone”, with dependencies of course, but you need to can use the module in other app without bring all other modules.

Each module need a BUCK file. It’s a file without extension named BUCK. In this file you will teach buck how build the module.

Config

To use buck, some default configs are needed. See the file .buckconfig . This file contains the default configs and some paths needed.

App module

To generate a .app, or using the correct term, a Bundle, you need a Binary. A Binary is an executable file with your code. And pay attention here, a saw your CODE. Assets, xibs and storyboards aren’t code!

Go to VeryCoolApp/BUCK. You’ll see a code like this:

apple_binary(
    name = “VeryCoolAppBinary”,
    visibility = [“PUBLIC”],
    srcs = glob([‘**/*.swift’]),
    ...
    is_main_run_destination = True,
)

The command apple_binary will generate a binary (oh a Sherlock Holmes here…). This binary by self don’t do anything, you will need to put it inside a Bundle.

apple_bundle(
    name = “VeryCoolApp”,
    visibility = [“PUBLIC”],
    extension = “app”,
    binary = “:VeryCoolAppBinary”,
    product_name = “VeryCoolApp”,
    info_plist = “Info.plist”,
    ... 
)

Finally, the Bundle is the app! A Bundle is in resume a folder that contains all compiled sources.

All of parameters you can find at buck documentation.

“Ok, but my app have assets and xibs and storyboards, where I put it?”

As I saw before, BUCK file is how we teach buck to build our files. Let’s see how compile assets:

apple_asset_catalog(
    name = “VeryCoolAppAssets”,
    visibility = [“PUBLIC”],
    dirs = [“Media.xcassets”],
)

After added the apple_asset_catalog to your buck file, you need use it as dependency in your app:

apple_binary(
    name = “VeryCoolAppBinary”,
    visibility = [“PUBLIC”],
    srcs = glob([‘**/*.swift’]),
    deps = [“:VeryCoolAppAssets”],
)

Ok, next step is compile de xibs and storyboards, the resources:

apple_resource(
    name = “VeryCoolAppResources”,
    visibility = [“PUBLIC”],
    files = glob([
        “**/*.xib”
    ]),
)

If you need to compile storyboards too, just add to files . Now, let’s use it as dependency:

apple_binary(
    name = “VeryCoolAppBinary”,
    visibility = [“PUBLIC”],
    srcs = glob([‘**/*.swift’]),
    deps = [“:VeryCoolAppResources”,
            “:VeryCoolAppAssets”],
)

Congratulations!!! Now, buck can build your app! Try make: buck build VeryCoolApp

Library

Yeah, finally we will create a Module! An independent module. Please, go to VeryCoolLibrary/BUCK.

Here is more simple, it’s a apple_library :

apple_library(
    name = “VeryCoolLibrary”,
    visibility = [“PUBLIC”],
    srcs = glob([‘*.swift’]),
    tests = [“:VeryCoolLibraryTests”],
)

It’s and independent library. This library have a tests module inside:

apple_test(
    name =  “VeryCoolLibraryTests”,
    ...
    deps = [
        “//VeryCoolLibrary:VeryCoolLibrary”,
    ],
    srcs = glob([
        “Tests/Sources/*.swift”,
    ]),
)

Using the library

Now, to use the library is too easy, do you remember de deps ?

apple_binary(
    name = “VeryCoolAppBinary”,
    visibility = [“PUBLIC”],
    srcs = glob([‘**/*.swift’]),
    deps = [“:VeryCoolAppResources”,
            “:VeryCoolAppAssets”,
            “//VeryCoolLibrary:VeryCoolLibrary”],
)

Congratulations!!! Now, buck can test your library! Try make: buck test //VeryCoolLibrary -n “iPhone 12

Makefile

The make file is only to help you with the commands. Just run make build for example. Open the makefile to see all options.

Xcode

Yes, Buck can create a Xcode project to you use to develop. Using the makefile, just run make xcode .

DONE! Now you are building a iOS Project without Xcode!

For questions/suggestions please Create an issue!

I hope this help you!

buckstartersample's People

Contributors

narlei avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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