├── .bazelrc ├── .bazelversion ├── .github └── workflows │ └── build.yml ├── .gitignore ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── Makefile ├── README.md ├── WORKSPACE ├── apple ├── BUILD ├── apple_library.bzl ├── apple_linker_inputs.bzl ├── apple_preprocessed_plist.bzl ├── apple_resource_bundle.bzl ├── common.bzl ├── defines.bzl ├── headermap_support.bzl ├── metal_library.bzl ├── mixed_static_framework.bzl ├── module_map.bzl ├── objc_library.bzl ├── objc_module_map_config.bzl ├── objc_static_framework.bzl ├── pkg_dsym.bzl ├── repositories.bzl ├── string_dict_select_values.bzl ├── swift_library.bzl ├── swift_static_framework.bzl ├── swiftgen.bzl ├── unique_symbol_file.bzl ├── utils.bzl └── zipper_support.bzl ├── docs ├── BUILD ├── README.md └── doc_hub.bzl ├── examples └── ios │ ├── App │ ├── BUILD │ ├── Configuration │ │ └── BUILD │ ├── README.md │ ├── ShareExtension │ │ ├── BUILD │ │ ├── Base.lproj │ │ │ └── MainInterface.storyboard │ │ ├── Info.plist │ │ └── ShareViewController.swift │ ├── Sources │ │ ├── AppDelegate.swift │ │ ├── Assets.xcassets │ │ │ ├── AppIcon.appiconset │ │ │ │ └── Contents.json │ │ │ └── Contents.json │ │ ├── BUILD │ │ ├── Base.lproj │ │ │ ├── LaunchScreen.storyboard │ │ │ └── Main.storyboard │ │ ├── Info.plist │ │ ├── ViewController.swift │ │ └── constants.bzl │ ├── WatchKitApp │ │ ├── Assets.xcassets │ │ │ ├── AppIcon.appiconset │ │ │ │ └── Contents.json │ │ │ └── Contents.json │ │ ├── BUILD │ │ ├── Base.lproj │ │ │ └── Interface.storyboard │ │ └── Info.plist │ └── WatchKitExtension │ │ ├── Assets.xcassets │ │ ├── Complication.complicationset │ │ │ ├── Circular.imageset │ │ │ │ └── Contents.json │ │ │ ├── Contents.json │ │ │ ├── Extra Large.imageset │ │ │ │ └── Contents.json │ │ │ ├── Graphic Bezel.imageset │ │ │ │ └── Contents.json │ │ │ ├── Graphic Circular.imageset │ │ │ │ └── Contents.json │ │ │ ├── Graphic Corner.imageset │ │ │ │ └── Contents.json │ │ │ ├── Graphic Large Rectangular.imageset │ │ │ │ └── Contents.json │ │ │ ├── Modular.imageset │ │ │ │ └── Contents.json │ │ │ └── Utilitarian.imageset │ │ │ │ └── Contents.json │ │ └── Contents.json │ │ ├── BUILD │ │ ├── ContentView.swift │ │ ├── ExtensionsDelegate.swift │ │ ├── HostingController.swift │ │ ├── Info.plist │ │ └── Preview Content │ │ └── Preview Assets.xcassets │ │ └── Contents.json │ ├── Mixed │ ├── BUILD │ ├── MXDObjcGreeter.h │ ├── MXDObjcGreeter.m │ └── SwiftGreeter.swift │ ├── MixedWithPrivateSubmodule │ ├── BUILD │ ├── MXDObjcGreeter.h │ ├── MXDObjcGreeter.m │ ├── SwiftGreeter.swift │ └── submodule │ │ ├── BUILD │ │ └── SubModuleSwiftGreeter.swift │ ├── PureObjC │ ├── BUILD │ ├── ObjcGreeter.h │ └── ObjcGreeter.m │ └── PureSwift │ ├── BUILD │ └── SwiftGreeter.swift ├── test └── BUILD ├── third_party ├── BUILD ├── CardIO.BUILD ├── Commander.BUILD ├── FLEX.BUILD ├── GoogleAnalytics.BUILD ├── Kanna.BUILD ├── OHHTTPStubs.BUILD ├── PathKit.BUILD ├── Stencil.BUILD ├── StencilSwiftKit.BUILD ├── SwiftGen.BUILD ├── Yams.BUILD ├── facebook-ios-sdk.BUILD ├── lld.BUILD └── rules_ios.patch └── tools ├── buildifier └── BUILD └── plist_merger ├── BUILD ├── README.md └── plist_merger.py /.bazelrc: -------------------------------------------------------------------------------- 1 | # Copyright 2020 LINE Corporation 2 | # 3 | # LINE Corporation licenses this file to you under the Apache License, 4 | # version 2.0 (the "License"); you may not use this file except in compliance 5 | # with the License. You may obtain a copy of the License at: 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | build --subcommands 16 | build --strategy=Stardoc=local 17 | build --incompatible_strict_action_env 18 | 19 | # Disable the Swift compilation worker 20 | build --define=RULES_SWIFT_BUILD_DUMMY_WORKER=1 21 | build --strategy=SwiftCompile=sandboxed 22 | 23 | build --watchos_cpus=x86_64 24 | -------------------------------------------------------------------------------- /.bazelversion: -------------------------------------------------------------------------------- 1 | 5.3.1 2 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: build 2 | 3 | on: 4 | pull_request: 5 | push: 6 | branches: 7 | - main 8 | 9 | jobs: 10 | build: 11 | name: Build 12 | runs-on: macOS-11 13 | steps: 14 | - uses: actions/checkout@v2 15 | - name: Test 16 | run: bazelisk test //test/... 17 | - name: Test Package dSYM 18 | run: bazelisk test --apple_generate_dsym --output_groups=+dsyms //test:pkg_dsym_build_test 19 | buildifier: 20 | name: Run Buildifier and Verify Documentation Generation 21 | runs-on: macOS-latest 22 | steps: 23 | - uses: actions/checkout@v2 24 | - run: make buildifier 25 | - run: make docs 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.swp 3 | /bazel-* 4 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | 2 | # Contributor Covenant Code of Conduct 3 | 4 | ## Our Pledge 5 | 6 | We as members, contributors, and leaders pledge to make participation in our 7 | community a harassment-free experience for everyone, regardless of age, body 8 | size, visible or invisible disability, ethnicity, sex characteristics, gender 9 | identity and expression, level of experience, education, socio-economic status, 10 | nationality, personal appearance, race, religion, or sexual identity 11 | and orientation. 12 | 13 | We pledge to act and interact in ways that contribute to an open, welcoming, 14 | diverse, inclusive, and healthy community. 15 | 16 | ## Our Standards 17 | 18 | Examples of behavior that contributes to a positive environment for our 19 | community include: 20 | 21 | * Demonstrating empathy and kindness toward other people 22 | * Being respectful of differing opinions, viewpoints, and experiences 23 | * Giving and gracefully accepting constructive feedback 24 | * Accepting responsibility and apologizing to those affected by our mistakes, 25 | and learning from the experience 26 | * Focusing on what is best not just for us as individuals, but for the 27 | overall community 28 | 29 | Examples of unacceptable behavior include: 30 | 31 | * The use of sexualized language or imagery, and sexual attention or 32 | advances of any kind 33 | * Trolling, insulting or derogatory comments, and personal or political attacks 34 | * Public or private harassment 35 | * Publishing others' private information, such as a physical or email 36 | address, without their explicit permission 37 | * Other conduct which could reasonably be considered inappropriate in a 38 | professional setting 39 | 40 | ## Enforcement Responsibilities 41 | 42 | Community leaders are responsible for clarifying and enforcing our standards of 43 | acceptable behavior and will take appropriate and fair corrective action in 44 | response to any behavior that they deem inappropriate, threatening, offensive, 45 | or harmful. 46 | 47 | Community leaders have the right and responsibility to remove, edit, or reject 48 | comments, commits, code, wiki edits, issues, and other contributions that are 49 | not aligned to this Code of Conduct, and will communicate reasons for moderation 50 | decisions when appropriate. 51 | 52 | ## Scope 53 | 54 | This Code of Conduct applies within all community spaces, and also applies when 55 | an individual is officially representing the community in public spaces. 56 | Examples of representing our community include using an official e-mail address, 57 | posting via an official social media account, or acting as an appointed 58 | representative at an online or offline event. 59 | 60 | ## Enforcement 61 | 62 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 63 | reported to the community leaders responsible for enforcement at 64 | [dl_oss_dev@linecorp.com](mailto:dl_oss_dev@linecorp.com). 65 | All complaints will be reviewed and investigated promptly and fairly. 66 | 67 | All community leaders are obligated to respect the privacy and security of the 68 | reporter of any incident. 69 | 70 | ## Enforcement Guidelines 71 | 72 | Community leaders will follow these Community Impact Guidelines in determining 73 | the consequences for any action they deem in violation of this Code of Conduct: 74 | 75 | ### 1. Correction 76 | 77 | **Community Impact**: Use of inappropriate language or other behavior deemed 78 | unprofessional or unwelcome in the community. 79 | 80 | **Consequence**: A private, written warning from community leaders, providing 81 | clarity around the nature of the violation and an explanation of why the 82 | behavior was inappropriate. A public apology may be requested. 83 | 84 | ### 2. Warning 85 | 86 | **Community Impact**: A violation through a single incident or series 87 | of actions. 88 | 89 | **Consequence**: A warning with consequences for continued behavior. No 90 | interaction with the people involved, including unsolicited interaction with 91 | those enforcing the Code of Conduct, for a specified period of time. This 92 | includes avoiding interactions in community spaces as well as external channels 93 | like social media. Violating these terms may lead to a temporary or 94 | permanent ban. 95 | 96 | ### 3. Temporary Ban 97 | 98 | **Community Impact**: A serious violation of community standards, including 99 | sustained inappropriate behavior. 100 | 101 | **Consequence**: A temporary ban from any sort of interaction or public 102 | communication with the community for a specified period of time. No public or 103 | private interaction with the people involved, including unsolicited interaction 104 | with those enforcing the Code of Conduct, is allowed during this period. 105 | Violating these terms may lead to a permanent ban. 106 | 107 | ### 4. Permanent Ban 108 | 109 | **Community Impact**: Demonstrating a pattern of violation of community 110 | standards, including sustained inappropriate behavior, harassment of an 111 | individual, or aggression toward or disparagement of classes of individuals. 112 | 113 | **Consequence**: A permanent ban from any sort of public interaction within 114 | the community. 115 | 116 | ## Attribution 117 | 118 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 119 | version 2.0, available at 120 | https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 121 | 122 | Community Impact Guidelines were inspired by [Mozilla's code of conduct 123 | enforcement ladder](https://github.com/mozilla/diversity). 124 | 125 | [homepage]: https://www.contributor-covenant.org 126 | 127 | For answers to common questions about this code of conduct, see the FAQ at 128 | https://www.contributor-covenant.org/faq. Translations are available at 129 | https://www.contributor-covenant.org/translations. 130 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## How to contribute to bazel_rules_apple project 2 | First of all, thank you so much for taking your time to contribute! bazel_rules_apple is not very different from any other open 3 | source projects you are aware of. It will be amazing if you could help us by doing any of the following: 4 | 5 | - File an issue in [the issue tracker](https://github.com/line/bazel_rules_apple/issues) to report bugs or suggest an idea. 6 | - Ask a question using [the issue tracker](https://github.com/line/bazel_rules_apple/issues). 7 | - Contribute your work by sending [a pull request](https://github.com/line/bazel_rules_apple/pulls). 8 | 9 | ### Contributor license agreement 10 | 11 | When you are sending a pull request and it's a non-trivial change beyond fixing typos, please sign 12 | [the ICLA (individual contributor license agreement)](https://cla-assistant.io/line/bazel_rules_apple). Please 13 | [contact us](mailto:dl_oss_dev@linecorp.com) if you need the CCLA (corporate contributor license agreement). 14 | 15 | ### Code of conduct 16 | 17 | We expect contributors to follow [our code of conduct](https://github.com/line/bazel_rules_apple/blob/master/CODE_OF_CONDUCT.md). -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | https://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | https://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Copyright 2020 LINE Corporation 2 | # 3 | # LINE Corporation licenses this file to you under the Apache License, 4 | # version 2.0 (the "License"); you may not use this file except in compliance 5 | # with the License. You may obtain a copy of the License at: 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | .PHONY: docs 16 | docs: 17 | @bazelisk build //docs --nocheck_visibility 18 | @cp -f bazel-bin/docs/README.md docs 19 | 20 | .PHONY: buildifier 21 | buildifier: 22 | @bazelisk run //tools/buildifier 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LINE's Apple rules for Bazel ![](https://github.com/line/bazel_rules_apple/workflows/build/badge.svg) 2 | 3 | This repository contains additional rules for Bazel that can be used to bundle 4 | applications and frameworks for Apple platforms. 5 | 6 | ## Overview 7 | 8 | These are open references of what are used to build the LINE iOS app, which 9 | solve some of our specific use-cases, for instance, mixed Objective-C and Swift 10 | modules. They can be used as drop-in replacements for the official Apple rules 11 | when needed, with the goal of being easy to switch back to the official ones 12 | when we longer need them. 13 | 14 | They may not work with certain revisions of `rules_apple` or 15 | `rules_swift` due to their breaking changes. If they don't work out-of-the-box 16 | for you, use them as references for your custom rule's implementation. 17 | 18 | ## Build Definitions 19 | 20 | ### Library Rules 21 | 22 | * [apple_library](docs/README.md#apple_library) 23 | * [metal_library](docs/README.md#metal_library) 24 | * [objc_library](docs/README.md#objc_library) 25 | * [swift_library](docs/README.md#swift_library) 26 | 27 | ### Bundling Rules 28 | 29 | * [mixed_static_framework](docs/README.md#mixed_static_framework) 30 | * [objc_static_framework](docs/README.md#objc_static_framework) 31 | * [swift_static_framework](docs/README.md#swift_static_framework) 32 | 33 | ### Other Rules 34 | 35 | * [apple_linker_inputs](docs/README.md#apple_linker_inputs) 36 | * [apple_preprocessed_plist](docs/README.md#apple_preprocessed_plist) 37 | * [apple_resource_bundle](docs/README.md#apple_resource_bundle) 38 | * [pkg_dsym](docs/README.md#pkg_dsym) 39 | * [swiftgen](docs/README.md#swiftgen) 40 | 41 | ## Requirements 42 | 43 | Bazel 4.0+ 44 | 45 | ## Setup 46 | 47 | - Setup [rules_apple](https://github.com/bazelbuild/rules_apple#quick-setup). 48 | 49 | - Add the following to your `WORKSPACE` file, replacing `` with the 50 | commit you wish to depend on and `` with the expected SHA-256 of the 51 | zip file. 52 | 53 | ```starlark 54 | RULES_APPLE_LINE_COMMIT = "" 55 | 56 | http_archive( 57 | name = "rules_apple_line", 58 | sha256 = "", 59 | strip_prefix = "rules_apple_line-%s" % RULES_APPLE_LINE_COMMIT, 60 | url = "https://github.com/line/rules_apple_line/archive/%s.zip" % RULES_APPLE_LINE_COMMIT, 61 | ) 62 | 63 | load( 64 | "@rules_apple_line//apple:repositories.bzl", 65 | "rules_apple_line_dependencies", 66 | ) 67 | 68 | rules_apple_line_dependencies() 69 | ``` 70 | 71 | ## Examples 72 | 73 | See the [examples](examples) directory. 74 | 75 | ## License 76 | 77 | ``` 78 | Copyright 2020 LINE Corporation 79 | 80 | LINE Corporation licenses this file to you under the Apache License, 81 | version 2.0 (the "License"); you may not use this file except in compliance 82 | with the License. You may obtain a copy of the License at: 83 | 84 | https://www.apache.org/licenses/LICENSE-2.0 85 | 86 | Unless required by applicable law or agreed to in writing, software 87 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 88 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 89 | License for the specific language governing permissions and limitations 90 | under the License. 91 | ``` 92 | 93 | See [LICENSE](LICENSE) for more detail. 94 | -------------------------------------------------------------------------------- /WORKSPACE: -------------------------------------------------------------------------------- 1 | # Copyright 2020 LINE Corporation 2 | # 3 | # LINE Corporation licenses this file to you under the Apache License, 4 | # version 2.0 (the "License"); you may not use this file except in compliance 5 | # with the License. You may obtain a copy of the License at: 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | workspace(name = "rules_apple_line") 16 | 17 | load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") 18 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 19 | load("//apple:repositories.bzl", "rules_apple_line_dependencies") 20 | 21 | rules_apple_line_dependencies() 22 | 23 | load( 24 | "@build_bazel_rules_apple//apple:repositories.bzl", 25 | "apple_rules_dependencies", 26 | ) 27 | 28 | apple_rules_dependencies() 29 | 30 | load( 31 | "@build_bazel_rules_swift//swift:repositories.bzl", 32 | "swift_rules_dependencies", 33 | ) 34 | 35 | swift_rules_dependencies() 36 | 37 | load( 38 | "@build_bazel_rules_swift//swift:extras.bzl", 39 | "swift_rules_extra_dependencies", 40 | ) 41 | 42 | swift_rules_extra_dependencies() 43 | 44 | load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") 45 | 46 | bazel_skylib_workspace() 47 | 48 | http_archive( 49 | name = "io_bazel_stardoc", 50 | sha256 = "05fb57bb4ad68a360470420a3b6f5317e4f722839abc5b17ec4ef8ed465aaa47", 51 | urls = [ 52 | "https://mirror.bazel.build/github.com/bazelbuild/stardoc/releases/download/0.5.2/stardoc-0.5.2.tar.gz", 53 | "https://github.com/bazelbuild/stardoc/releases/download/0.5.2/stardoc-0.5.2.tar.gz", 54 | ], 55 | ) 56 | 57 | load("@io_bazel_stardoc//:setup.bzl", "stardoc_repositories") 58 | 59 | stardoc_repositories() 60 | 61 | http_archive( 62 | name = "io_bazel_rules_go", 63 | sha256 = "b9aa86ec08a292b97ec4591cf578e020b35f98e12173bbd4a921f84f583aebd9", 64 | url = "https://github.com/bazelbuild/rules_go/releases/download/v0.20.2/rules_go-v0.20.2.tar.gz", 65 | ) 66 | 67 | load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") 68 | 69 | go_rules_dependencies() 70 | 71 | go_register_toolchains() 72 | 73 | http_archive( 74 | name = "com_github_bazelbuild_buildtools", 75 | sha256 = "66e047cd1804e3115447fcb64870a9e721ced8c0e500a906824e3ae8af912e78", 76 | strip_prefix = "buildtools-3.2.0", 77 | urls = ["https://github.com/bazelbuild/buildtools/archive/3.2.0.tar.gz"], 78 | ) 79 | 80 | http_archive( 81 | name = "lld", 82 | build_file = "//third_party:lld.BUILD", 83 | sha256 = "28566b943082349269b6460a5c23a305a73460bac54f5cd21eb490ff7d84fed7", 84 | url = "https://github.com/keith/ld64.lld/releases/download/10-14-22/ld64.tar.xz", 85 | ) 86 | 87 | load("//apple:repositories.bzl", "rules_apple_line_test_dependencies") 88 | 89 | rules_apple_line_test_dependencies() 90 | -------------------------------------------------------------------------------- /apple/BUILD: -------------------------------------------------------------------------------- 1 | load( 2 | "@bazel_skylib//:bzl_library.bzl", 3 | "bzl_library", 4 | ) 5 | 6 | bzl_library( 7 | name = "rules", 8 | srcs = [ 9 | "@bazel_skylib//lib:paths.bzl", 10 | "@bazel_skylib//lib:sets.bzl", 11 | "@bazel_skylib//lib:types.bzl", 12 | "@bazel_tools//tools/build_defs/repo:http.bzl", 13 | "@build_bazel_apple_support//lib:apple_support.bzl", 14 | "@build_bazel_rules_apple//apple:ios.bzl", 15 | "@build_bazel_rules_apple//apple:providers.bzl", 16 | "@build_bazel_rules_swift//swift:swift.bzl", 17 | "@com_github_ob_rules_ios//rules:hmap.bzl", 18 | "@rules_proto//proto:defs.bzl", 19 | ] + glob(["*.bzl"]), 20 | visibility = ["//visibility:public"], 21 | ) 22 | -------------------------------------------------------------------------------- /apple/apple_library.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2020 LINE Corporation 2 | # 3 | # LINE Corporation licenses this file to you under the Apache License, 4 | # version 2.0 (the "License"); you may not use this file except in compliance 5 | # with the License. You may obtain a copy of the License at: 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | load(":mixed_static_framework.bzl", "mixed_static_framework") 16 | 17 | def apple_library(**kwargs): 18 | """Compiles and links Objective-C and Swift code into a static library. 19 | 20 | To use this rule in your BUILD files, load it with: 21 | 22 | ```starlark 23 | load("@rules_apple_line//apple:apple_library.bzl", "apple_library") 24 | ``` 25 | 26 | See [mixed_static_framework](#mixed_static_framework) for the documentation 27 | of each attribute. 28 | """ 29 | mixed_static_framework(**kwargs) 30 | -------------------------------------------------------------------------------- /apple/apple_linker_inputs.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2020 LINE Corporation 2 | # 3 | # LINE Corporation licenses this file to you under the Apache License, 4 | # version 2.0 (the "License"); you may not use this file except in compliance 5 | # with the License. You may obtain a copy of the License at: 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | def _apple_linker_inputs_impl(ctx): 16 | linkopts = [] 17 | for opt in ctx.attr.linkopts: 18 | expanded_opt = ctx.expand_location( 19 | opt, 20 | targets = ctx.attr.linker_inputs, 21 | ) 22 | expanded_opt = ctx.expand_make_variables( 23 | "linkopts", 24 | expanded_opt, 25 | {}, 26 | ) 27 | linkopts.append(expanded_opt) 28 | 29 | linkopts_depset = depset(direct = linkopts, order = "topological") 30 | linker_inputs_depset = depset(ctx.files.linker_inputs) 31 | 32 | objc_provider = apple_common.new_objc_provider( 33 | link_inputs = linker_inputs_depset, 34 | linkopt = linkopts_depset, 35 | ) 36 | 37 | return [ 38 | objc_provider, 39 | ] 40 | 41 | apple_linker_inputs = rule( 42 | attrs = { 43 | "linkopts": attr.string_list( 44 | doc = """ 45 | Extra flags to be passed to Clang's linker command. Subject to ["Make" 46 | variable](https://docs.bazel.build/versions/master/be/make-variables.html) 47 | substitution and [label 48 | expansion](https://docs.bazel.build/versions/master/be/common-definitions.html#label-expansion). 49 | """, 50 | ), 51 | "linker_inputs": attr.label_list( 52 | allow_files = True, 53 | doc = """ 54 | Extra files to be passed to the linker action. 55 | """, 56 | ), 57 | }, 58 | doc = """ 59 | Provides additional inputs to Apple rules' linker action. 60 | 61 | Unlike C++ rules like `cc_binary` and `cc_test`, Apple rules don't have any 62 | mechanism to allow providing additional inputs to the linker action. This 63 | little rule helps mitigate that. 64 | 65 | To use this rule in your BUILD files, load it with: 66 | 67 | ```starlark 68 | load("@rules_apple_line//apple:apple_linker_inputs.bzl", "apple_linker_inputs") 69 | ``` 70 | """, 71 | implementation = _apple_linker_inputs_impl, 72 | ) 73 | -------------------------------------------------------------------------------- /apple/apple_preprocessed_plist.bzl: -------------------------------------------------------------------------------- 1 | load("//apple:string_dict_select_values.bzl", "string_dict_select_values") 2 | 3 | def _impl(ctx): 4 | substitutions = {} 5 | for key, value in zip(ctx.attr.keys, ctx.attr.values): 6 | substitutions["${" + key + "}"] = value 7 | substitutions["$(" + key + ")"] = value 8 | 9 | output = ctx.outputs.out 10 | ctx.actions.expand_template( 11 | template = ctx.file.src, 12 | output = output, 13 | substitutions = substitutions, 14 | ) 15 | 16 | return [ 17 | DefaultInfo(files = depset([output])), 18 | ] 19 | 20 | _apple_preprocessed_plist = rule( 21 | attrs = { 22 | "src": attr.label( 23 | mandatory = True, 24 | allow_single_file = True, 25 | doc = "The property list file that should be processed.", 26 | ), 27 | "out": attr.output( 28 | mandatory = True, 29 | doc = "The file reference for the output plist.", 30 | ), 31 | "keys": attr.string_list( 32 | allow_empty = True, 33 | mandatory = False, 34 | default = [], 35 | doc = "The attribute names to be expanded.", 36 | ), 37 | "values": attr.string_list( 38 | allow_empty = True, 39 | mandatory = False, 40 | default = [], 41 | doc = "The attribute values. The order should match the order of keys.", 42 | ), 43 | }, 44 | doc = """ 45 | Generates the plist given the provided keys and values to be used for the 46 | substitution. By default, Bazel only supports a limited set of variable 47 | substitutions when handling Info.plists --- use this rule to preprocess them 48 | before passing them to the official rules. See [rules_apple's Variable 49 | Substitution](https://github.com/bazelbuild/rules_apple/blob/d77d5b96293344a96176c1f93da5af5dee23d0f5/doc/common_info.md#variable-substitution) 50 | for more details. Note that this does not compile your plist into the binary 51 | format. 52 | 53 | To use this rule in your BUILD files, load it with: 54 | 55 | ```starlark 56 | load("@rules_apple_line//apple:apple_preprocessed_plist.bzl", "apple_preprocessed_plist") 57 | ``` 58 | """, 59 | fragments = ["apple"], 60 | implementation = _impl, 61 | ) 62 | 63 | def apple_preprocessed_plist(name, src, out, substitutions, **kwargs): 64 | _apple_preprocessed_plist( 65 | name = name, 66 | src = src, 67 | out = out, 68 | keys = substitutions.keys(), 69 | values = string_dict_select_values(substitutions.values()), 70 | **kwargs 71 | ) 72 | -------------------------------------------------------------------------------- /apple/apple_resource_bundle.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2020 LINE Corporation 2 | # 3 | # LINE Corporation licenses this file to you under the Apache License, 4 | # version 2.0 (the "License"); you may not use this file except in compliance 5 | # with the License. You may obtain a copy of the License at: 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | load("@bazel_skylib//lib:paths.bzl", "paths") 16 | load( 17 | "@build_bazel_rules_apple//apple:resources.bzl", 18 | _apple_resource_bundle = "apple_resource_bundle", 19 | ) 20 | 21 | def apple_resource_bundle( 22 | name, 23 | infoplists, 24 | bundle_id = None, 25 | **kwargs): 26 | """ 27 | To use this rule in your BUILD files, load it with: 28 | 29 | ```starlark 30 | load("@rules_apple_line//apple:apple_resource_bundle.bzl", "apple_resource_bundle") 31 | ``` 32 | """ 33 | 34 | # Replace PRODUCT_BUNDLE_IDENTIFIER with the provided bundle_id. For the 35 | # simplicity of this patch, we only use a single Info.plist for each 36 | # resource bundle target now. 37 | if len(infoplists) > 1: 38 | fail("There should be only a single Info.plist") 39 | infoplist = infoplists[0] 40 | 41 | modified_infoplists = [ 42 | name + "-" + paths.basename(infoplist) + "-modified", 43 | ] 44 | 45 | bundle_id = bundle_id or name 46 | 47 | native.genrule( 48 | name = name + "_info_plist_modified", 49 | srcs = [infoplist], 50 | outs = modified_infoplists, 51 | message = "Substitute variables in {}".format(infoplist), 52 | cmd = """ 53 | plutil -replace CFBundleIdentifier -string {} -o "$@" "$<" 54 | """.format(bundle_id), 55 | ) 56 | 57 | _apple_resource_bundle( 58 | name = name, 59 | infoplists = modified_infoplists, 60 | **kwargs 61 | ) 62 | -------------------------------------------------------------------------------- /apple/common.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2020 LINE Corporation 2 | # 3 | # LINE Corporation licenses this file to you under the Apache License, 4 | # version 2.0 (the "License"); you may not use this file except in compliance 5 | # with the License. You may obtain a copy of the License at: 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | # Default attributes 16 | 17 | DEFAULT_MINIMUM_OS_VERSION = "11.0" 18 | 19 | DEFAULT_VISIBILITY = ["//visibility:public"] 20 | 21 | # Shared compiler options 22 | 23 | SHARED_COMPILER_OPTIONS = ["-DBAZEL"] 24 | 25 | SHARED_OBJC_COMPILER_OPTIONS = SHARED_COMPILER_OPTIONS 26 | 27 | SHARED_SWIFT_COMPILER_OPTIONS = SHARED_COMPILER_OPTIONS 28 | 29 | # File types 30 | 31 | CPP_FILE_TYPES = [".cc", ".cpp", ".mm", ".cxx", ".C"] 32 | 33 | NON_CPP_FILE_TYPES = [".m", ".c"] 34 | 35 | ASSEMBLY_FILE_TYPES = [".s", ".S", ".asm"] 36 | 37 | OBJECT_FILE_FILE_TYPES = [".o"] 38 | 39 | HEADERS_FILE_TYPES = [ 40 | ".h", 41 | ".hh", 42 | ".hpp", 43 | ".ipp", 44 | ".hxx", 45 | ".h++", 46 | ".inc", 47 | ".inl", 48 | ".tlh", 49 | ".tli", 50 | ".H", 51 | ".hmap", 52 | ] 53 | 54 | OBJC_FILE_TYPES = CPP_FILE_TYPES + \ 55 | NON_CPP_FILE_TYPES + \ 56 | ASSEMBLY_FILE_TYPES + \ 57 | OBJECT_FILE_FILE_TYPES + \ 58 | HEADERS_FILE_TYPES 59 | 60 | SWIFT_FILE_TYPES = [".swift"] 61 | 62 | METAL_FILE_TYPES = [".metal"] 63 | -------------------------------------------------------------------------------- /apple/defines.bzl: -------------------------------------------------------------------------------- 1 | # In the open-source version, these are all just empty lists 2 | 3 | DEFINES = [] 4 | 5 | SWIFT_DEFINES = DEFINES + [] 6 | 7 | OBJC_DEFINES = DEFINES + [] 8 | -------------------------------------------------------------------------------- /apple/headermap_support.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2020 LINE Corporation 2 | # 3 | # LINE Corporation licenses this file to you under the Apache License, 4 | # version 2.0 (the "License"); you may not use this file except in compliance 5 | # with the License. You may obtain a copy of the License at: 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | load( 16 | "@com_github_ob_rules_ios//rules:hmap.bzl", 17 | "headermap", 18 | ) 19 | 20 | def headermap_support(name, module_name, hdrs, private_hdrs, deps): 21 | # Don't rename this. The 'headermap' rule relies on the filename to 22 | # determine which one is a public header map, in order to merge it with 23 | # transitve public header maps. 24 | public_hmap = name + "_public_hmap" 25 | public_hdrs_filegroup = name + "_public_hdrs" 26 | private_hmap = name + "_private_hmap" 27 | private_angled_hmap = name + "_private_angled_hmap" 28 | private_hdrs_filegroup = name + "_private_hdrs" 29 | private_angled_hdrs_filegroup = name + "_private_angled_hdrs" 30 | 31 | native.filegroup( 32 | name = public_hdrs_filegroup, 33 | srcs = hdrs, 34 | ) 35 | native.filegroup( 36 | name = private_hdrs_filegroup, 37 | srcs = private_hdrs + hdrs, 38 | ) 39 | native.filegroup( 40 | name = private_angled_hdrs_filegroup, 41 | srcs = private_hdrs, 42 | ) 43 | 44 | headermap( 45 | name = public_hmap, 46 | namespace = module_name, 47 | hdrs = [public_hdrs_filegroup], 48 | hdr_providers = deps, 49 | flatten_headers = True, 50 | ) 51 | headermap( 52 | name = private_hmap, 53 | namespace = module_name, 54 | hdrs = [private_hdrs_filegroup], 55 | flatten_headers = False, 56 | ) 57 | headermap( 58 | name = private_angled_hmap, 59 | namespace = module_name, 60 | hdrs = [private_angled_hdrs_filegroup], 61 | flatten_headers = True, 62 | ) 63 | 64 | headermap_copts = [ 65 | "-I$(execpath :{})".format(private_hmap), 66 | "-I$(execpath :{})".format(public_hmap), 67 | "-I$(execpath :{})".format(private_angled_hmap), 68 | "-I.", 69 | "-iquote", 70 | "$(execpath :{})".format(private_hmap), 71 | ] 72 | 73 | return { 74 | "public_hmap": public_hmap, 75 | "private_hmap": private_hmap, 76 | "private_angled_hmap": private_angled_hmap, 77 | "headermap_copts": headermap_copts, 78 | } 79 | -------------------------------------------------------------------------------- /apple/metal_library.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2020 LINE Corporation 2 | # 3 | # LINE Corporation licenses this file to you under the Apache License, 4 | # version 2.0 (the "License"); you may not use this file except in compliance 5 | # with the License. You may obtain a copy of the License at: 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | """Metal library implementation.""" 16 | 17 | load("@build_bazel_apple_support//lib:apple_support.bzl", "apple_support") 18 | load( 19 | "@build_bazel_rules_apple//apple/internal:platform_support.bzl", 20 | "platform_support", 21 | ) 22 | load("@bazel_skylib//lib:dicts.bzl", "dicts") 23 | load("@bazel_skylib//lib:paths.bzl", "paths") 24 | load(":common.bzl", "METAL_FILE_TYPES") 25 | load("@build_bazel_rules_apple//apple/internal:resources.bzl", "resources") 26 | 27 | def _metal_apple_target_triple(platform_prerequisites): 28 | """Returns a Metal target triple string for an Apple platform. 29 | Args: 30 | ctx: The compilation context. 31 | Returns: 32 | A target triple string describing the platform. 33 | """ 34 | target_os_version = platform_prerequisites.minimum_os 35 | 36 | platform = platform_prerequisites.platform 37 | platform_string = platform_prerequisites.platform_type 38 | if platform_string == "macos": 39 | platform_string = "macosx" 40 | 41 | environment = "" if platform.is_device else "-simulator" 42 | 43 | return "air64-apple-{platform}{version}{environment}".format( 44 | environment = environment, 45 | platform = platform_string, 46 | version = target_os_version, 47 | ) 48 | 49 | def _metal_library_impl(ctx): 50 | air_files = [] 51 | includes_input = [] 52 | 53 | # Compile each .metal file into a single .air file 54 | platform_prerequisites = platform_support.platform_prerequisites( 55 | apple_fragment = ctx.fragments.apple, 56 | config_vars = ctx.var, 57 | device_families = None, 58 | disabled_features = ctx.disabled_features, 59 | explicit_minimum_os = None, 60 | features = ctx.features, 61 | objc_fragment = None, 62 | platform_type_string = str(ctx.fragments.apple.single_arch_platform.platform_type), 63 | uses_swift = False, 64 | xcode_path_wrapper = ctx.executable._xcode_path_wrapper, 65 | xcode_version_config = ctx.attr._xcode_config[apple_common.XcodeVersionConfig], 66 | ) 67 | target = _metal_apple_target_triple(platform_prerequisites) 68 | 69 | for include_path in ctx.attr.includes: 70 | includes_input.append("-I{}".format(include_path)) 71 | 72 | for input_metal in ctx.files.srcs: 73 | air_file = ctx.actions.declare_file( 74 | paths.replace_extension(input_metal.basename, ".air"), 75 | ) 76 | air_files.append(air_file) 77 | 78 | args = [ 79 | "metal", 80 | "-c", 81 | "-target", 82 | target, 83 | "-ffast-math", 84 | ] 85 | 86 | args = args + includes_input 87 | args = args + [ 88 | "-o", 89 | air_file.path, 90 | input_metal.path, 91 | ] 92 | 93 | apple_support.run( 94 | ctx, 95 | executable = "/usr/bin/xcrun", 96 | inputs = [input_metal] + ctx.files.hdrs, 97 | outputs = [air_file], 98 | arguments = args, 99 | mnemonic = "MetalCompile", 100 | ) 101 | 102 | # Compile .air files into a single .metallib file, which stores the Metal library. 103 | output_metallib = ctx.outputs.out 104 | 105 | args = [ 106 | "metallib", 107 | "-o", 108 | output_metallib.path, 109 | ] + [ 110 | air_file.path 111 | for air_file in air_files 112 | ] 113 | 114 | apple_support.run( 115 | ctx, 116 | executable = "/usr/bin/xcrun", 117 | inputs = air_files, 118 | outputs = [output_metallib], 119 | arguments = args, 120 | mnemonic = "MetallibCompile", 121 | ) 122 | 123 | # Return the provider for the new bundling logic of rules_apple. 124 | return [ 125 | DefaultInfo( 126 | files = depset([output_metallib]), 127 | ), 128 | resources.bucketize_typed([output_metallib], "unprocessed"), 129 | ] 130 | 131 | metal_library = rule( 132 | attrs = dicts.add(apple_support.action_required_attrs(), { 133 | "srcs": attr.label_list( 134 | mandatory = True, 135 | allow_files = METAL_FILE_TYPES, 136 | doc = """\ 137 | A list of `.metal` source files that will be compiled into the library. 138 | """, 139 | ), 140 | "hdrs": attr.label_list( 141 | allow_files = [".h"], 142 | doc = """\ 143 | A list of headers that you need import to metal source. 144 | """, 145 | ), 146 | "out": attr.string( 147 | default = "default.metallib", 148 | doc = """\ 149 | An output `.metallib` filename. Defaults to `default.metallib` if unspecified. 150 | """, 151 | ), 152 | "includes": attr.string_list( 153 | doc = """\ 154 | A list of header search paths. 155 | """, 156 | ), 157 | }), 158 | doc = """\ 159 | Compiles Metal Shading Language source code into a Metal library. 160 | To use this rule in your BUILD files, load it with: 161 | ```starlark 162 | load("@rules_apple_line//apple:metal_library.bzl", "metal_library") 163 | ``` 164 | """, 165 | fragments = ["apple"], 166 | implementation = _metal_library_impl, 167 | outputs = { 168 | "out": "%{out}", 169 | }, 170 | ) 171 | -------------------------------------------------------------------------------- /apple/mixed_static_framework.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2020 LINE Corporation 2 | # 3 | # LINE Corporation licenses this file to you under the Apache License, 4 | # version 2.0 (the "License"); you may not use this file except in compliance 5 | # with the License. You may obtain a copy of the License at: 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | """Rule for creating a multi-architecture static framework for a mixed 16 | Objective-C and Swift module.""" 17 | 18 | load( 19 | "@build_bazel_rules_swift//swift:swift.bzl", 20 | "SwiftInfo", 21 | "swift_library", 22 | ) 23 | load( 24 | "@build_bazel_rules_apple//apple:ios.bzl", 25 | "ios_static_framework", 26 | ) 27 | load( 28 | "@build_bazel_rules_apple//apple:providers.bzl", 29 | "AppleBundleInfo", 30 | ) 31 | load("@bazel_skylib//lib:paths.bzl", "paths") 32 | load(":defines.bzl", "OBJC_DEFINES", "SWIFT_DEFINES") 33 | load(":headermap_support.bzl", "headermap_support") 34 | load(":module_map.bzl", "module_map") 35 | load(":objc_module_map_config.bzl", "objc_module_map_config") 36 | load( 37 | ":common.bzl", 38 | "DEFAULT_MINIMUM_OS_VERSION", 39 | "DEFAULT_VISIBILITY", 40 | "HEADERS_FILE_TYPES", 41 | "OBJC_FILE_TYPES", 42 | "SHARED_COMPILER_OPTIONS", 43 | "SHARED_OBJC_COMPILER_OPTIONS", 44 | "SHARED_SWIFT_COMPILER_OPTIONS", 45 | "SWIFT_FILE_TYPES", 46 | ) 47 | load(":zipper_support.bzl", "swiftmodule_zipper_arg_format") 48 | 49 | _PLATFORM_TO_SWIFTMODULE = { 50 | "ios_armv7": "arm", 51 | "ios_arm64": "arm64", 52 | "ios_i386": "i386", 53 | "ios_sim_arm64": "arm64", 54 | "ios_x86_64": "x86_64", 55 | } 56 | 57 | def _objc_headers_impl(ctx): 58 | # Get all the Obj-C headers 59 | headers = [] 60 | for dep in ctx.attr.deps: 61 | objc_headers = dep[CcInfo].compilation_context.headers.to_list() 62 | for hdr in objc_headers: 63 | if hdr.owner == dep.label: 64 | headers.append(hdr) 65 | return [ 66 | DefaultInfo( 67 | files = depset(headers), 68 | ), 69 | ] 70 | 71 | _objc_headers = rule( 72 | _objc_headers_impl, 73 | attrs = { 74 | "deps": attr.label_list( 75 | providers = [SwiftInfo], 76 | ), 77 | }, 78 | ) 79 | 80 | def _mixed_static_framework_impl(ctx): 81 | bundle_info = ctx.attr.framework[AppleBundleInfo] 82 | framework_name = bundle_info.bundle_name + bundle_info.bundle_extension 83 | new_framework = ctx.actions.declare_file(ctx.label.name + ".zip") 84 | inputs = [ 85 | ctx.file.framework, 86 | ] 87 | zipper_args = ctx.actions.args() 88 | 89 | # Get the `swiftdoc` and `swiftmodule` files for each architecture. 90 | for arch, target in ctx.split_attr.swift_partial_target.items(): 91 | cpu = _PLATFORM_TO_SWIFTMODULE[arch] 92 | if not cpu: 93 | continue 94 | 95 | direct_module = target[SwiftInfo].direct_modules[0] 96 | swiftdoc = direct_module.swift.swiftdoc 97 | swiftmodule = direct_module.swift.swiftmodule 98 | inputs.extend([swiftmodule, swiftdoc]) 99 | module_name = direct_module.name 100 | 101 | # There is a bit of hardcoding here, but this would avoid the file 102 | # from needing to be evaluated at analysis phase. 103 | zipper_args.add( 104 | swiftdoc, 105 | format = swiftmodule_zipper_arg_format( 106 | framework = framework_name, 107 | module_name = module_name, 108 | cpu = cpu, 109 | extension = "swiftdoc", 110 | ), 111 | ) 112 | zipper_args.add( 113 | swiftmodule, 114 | format = swiftmodule_zipper_arg_format( 115 | framework = framework_name, 116 | module_name = module_name, 117 | cpu = cpu, 118 | extension = "swiftmodule", 119 | ), 120 | ) 121 | 122 | ctx.actions.run_shell( 123 | inputs = inputs, 124 | outputs = [new_framework], 125 | mnemonic = "SwiftFrameworkPostProcess", 126 | progress_message = "Postprocessing %s for Swift support" % framework_name, 127 | command = """ 128 | {zipper} x {framework} 129 | {zipper} c {new_framework} $(find {framework_name} -type f) $@ 130 | rm -rf {framework} 131 | """.format( 132 | framework = ctx.file.framework.path, 133 | framework_name = framework_name, 134 | new_framework = new_framework.path, 135 | zipper = ctx.executable._zipper.path, 136 | ), 137 | arguments = [zipper_args], 138 | tools = [ 139 | ctx.executable._zipper, 140 | ], 141 | ) 142 | 143 | return [ 144 | DefaultInfo( 145 | files = depset([new_framework]), 146 | ), 147 | ] 148 | 149 | _mixed_static_framework = rule( 150 | implementation = _mixed_static_framework_impl, 151 | attrs = dict( 152 | framework = attr.label( 153 | providers = [AppleBundleInfo], 154 | allow_single_file = True, 155 | ), 156 | swift_partial_target = attr.label( 157 | mandatory = True, 158 | providers = [SwiftInfo], 159 | cfg = apple_common.multi_arch_split, 160 | ), 161 | minimum_os_version = attr.string( 162 | mandatory = True, 163 | ), 164 | platform_type = attr.string( 165 | default = str(apple_common.platform_type.ios), 166 | ), 167 | _zipper = attr.label( 168 | default = "@bazel_tools//tools/zip:zipper", 169 | cfg = "exec", 170 | executable = True, 171 | ), 172 | ), 173 | fragments = ["apple"], 174 | outputs = { 175 | "output_file": "%{name}.zip", 176 | }, 177 | ) 178 | 179 | def mixed_static_framework( 180 | name, 181 | srcs, 182 | non_arc_srcs = [], 183 | hdrs = [], 184 | textual_hdrs = [], 185 | enable_modules = True, 186 | includes = [], 187 | copts = [], 188 | objc_copts = [], 189 | swift_copts = [], 190 | use_defines = None, 191 | swiftc_inputs = [], 192 | objc_deps = [], 193 | swift_deps = [], 194 | avoid_deps = None, 195 | deps = [], 196 | data = [], 197 | umbrella_header = None, 198 | visibility = DEFAULT_VISIBILITY, 199 | minimum_os_version = DEFAULT_MINIMUM_OS_VERSION, 200 | features = [], 201 | **kwargs): 202 | """Builds and bundles a static framework for Xcode consumption or third-party distribution. 203 | 204 | This supports Swift only targets and mixed language targets. If your target 205 | only contains Objective-C source code, use `objc_static_framework` rule 206 | instead. 207 | 208 | This rule in general is very similar to `build_bazel_rules_apple`'s 209 | `ios_static_framework` rule, with some differences: 210 | 211 | * It supports Swift as well as mixed Objective-C and Swift targets. 212 | * It supports bundling a swift_library target that depend transitively on 213 | any other swift_library targets. By default, it will not link any of 214 | its dependencies into the final framework binary - the same way Xcode 215 | does when it builds frameworks - which means you can prebuild your 216 | dependencies as static frameworks for Xcode consumption. 217 | * It supports header maps out of the box--you don't need to change your 218 | imports to make your code build with Bazel. 219 | * It always collects the Swift generated header and bundles a 220 | `module.modulemap` file. For a mixed language target, the module map 221 | file is an extended module map. 222 | * It bundles `swiftmodule` and `swiftdoc` files (`ios_static_framework` 223 | rule bundles `swiftinterface` instead of `swiftmodule` file). 224 | 225 | This rule uses the native `objc_library` rule and `rules_swift`'s 226 | `swift_library` in its implementation. Even if you're not building a static 227 | framework for Xcode consumption or third-party distribution, this can still 228 | be used as a convenient way to declare a library target that compiles mixed 229 | Objective-C and Swift source code. 230 | 231 | The macro contains 3 underlying rules--given `name` is `Greet`: 232 | 233 | * `Greet_swift`: a `swift_library` target. This target has private 234 | visibility by default, hence it can't be a dependency of any other 235 | target. It should not be used directly. 236 | * `GreetModule`: a `module_map` target. This has the same visibility as 237 | `Greet`. The common use-case is using it in an `objc_library`'s 238 | `copts` attribute to import the generated module map file (e.g. 239 | `-fmodule-map-file=$(execpath //path/to/package:GreetModule)`). This 240 | will be done automatically if the dependent target is also a 241 | `mixed_static_framework` target. 242 | * `Greet`: an `objc_library` target. This is the wrapper library target. 243 | This can be depended on any `objc_library` or `swift_library` target. 244 | 245 | ### Examples 246 | 247 | ```starlark 248 | load("@rules_apple_line//apple:mixed_static_framework.bzl", "mixed_static_framework") 249 | 250 | mixed_static_framework( 251 | name = "Mixed", 252 | srcs = glob([ 253 | "*.m", 254 | "*.swift", 255 | ]), 256 | hdrs = glob(["*.h"]), 257 | ) 258 | ``` 259 | 260 | Args: 261 | name: A unique name for this target. This will be the name of the 262 | library target that the framework depends on. The framework target 263 | will be named `${name}Framework`. 264 | srcs: The list of Objective-C and Swift source files to compile. 265 | non_arc_srcs: The Objective-C source files to compile that do not use 266 | ARC. Provide both `srcs` and `non_arc_srcs` explicitly if both kinds 267 | of source files should be included. 268 | hdrs: The list of C, C++, Objective-C, and Objective-C++ header files 269 | published by this library to be included by sources in dependent 270 | rules. These headers describe the public interface for the library 271 | and will be made available for inclusion by sources in this rule or 272 | in dependent rules. Headers not meant to be included by a client of 273 | this library should be listed in the `srcs` attribute instead. These 274 | will be compiled separately from the source if modules are enabled. 275 | textual_hdrs: The list of C, C++, Objective-C, and Objective-C++ files 276 | that are included as headers by source files in this rule or by users 277 | of this library. Unlike `hdrs`, these will not be compiled separately 278 | from the sources. 279 | enable_modules: Enables clang module support (via `-fmodules`). 280 | 281 | Note: This is `True` by default. Changing this to `False` might no 282 | longer work. This attribute is here because there are still targets 283 | which are referencing to it. 284 | includes: List of header search paths to add to this target and all 285 | depending targets. Unlike `copts`, these flags are added for this 286 | rule and every rule that depends on it. (Note: not the rules it 287 | depends upon!) Be very careful, since this may have far-reaching 288 | effects. When in doubt, add "-iquote" flags to `copts` instead. 289 | 290 | Usage of this is rarely necessary because all headers will be visible 291 | to their depended targets with the help of header maps. 292 | copts: Additional compiler options that should be passed to `clang` and 293 | `swiftc`. 294 | objc_copts: Additional compiler options that should be passed to `clang`. 295 | swift_copts: Additional compiler options that should be passed to `swiftc`. 296 | swiftc_inputs: Additional files that are referenced using `$(rootpath 297 | ...)` and `$(execpath ...)` in attributes that support location 298 | expansion (e.g. `copts`). 299 | objc_deps: Dependencies of the underlying `objc_library` target. 300 | swift_deps: Dependencies of the underlying `swift_library` target. 301 | deps: Dependencies of the both `objc_library` and `swift_library` targets. 302 | avoid_deps: A list of `objc_library` and `swift_library` targets on which 303 | this framework depends in order to compile, but the transitive 304 | closure of which will not be linked into the framework's binary. By 305 | default this is the same as `deps`, that is none of the 306 | depependencies will be linked into the framework's binary. For 307 | example, providing an empty list (`[]`) here will result in a fully 308 | static link binary. 309 | data: The list of files needed by this rule at runtime. These will be 310 | bundled to the top level directory of the bundling target (`.app` or 311 | `.framework`). 312 | umbrella_header: An optional single `.h` file to use as the umbrella 313 | header for this framework. Usually, this header will have the same name 314 | as this target, so that clients can load the header using the #import 315 | `` format. If this attribute is not specified 316 | (the common use case), an umbrella header will be generated under the 317 | same name as this target. 318 | visibility: The visibility specifications for this target. 319 | features: Features of the underlying `swift_library` target. 320 | minimum_os_version: Minimum os version. 321 | **kwargs: Additional arguments being passed through. 322 | """ 323 | swift_srcs = [] 324 | objc_srcs = [] 325 | private_hdrs = [] 326 | for x in srcs: 327 | _, extension = paths.split_extension(x) 328 | if extension in SWIFT_FILE_TYPES: 329 | swift_srcs.append(x) 330 | elif extension in OBJC_FILE_TYPES: 331 | objc_srcs.append(x) 332 | if extension in HEADERS_FILE_TYPES: 333 | private_hdrs.append(x) 334 | 335 | module_name = kwargs.get("module_name", name) 336 | 337 | objc_library_name = name 338 | swift_library_name = name + "_swift" 339 | 340 | objc_deps = objc_deps + deps 341 | swift_deps = swift_deps + deps 342 | 343 | headermaps = headermap_support( 344 | name = name, 345 | module_name = module_name, 346 | hdrs = hdrs, 347 | private_hdrs = private_hdrs, 348 | deps = deps, 349 | ) 350 | headermap_deps = [ 351 | headermaps["public_hmap"], 352 | headermaps["private_hmap"], 353 | headermaps["private_angled_hmap"], 354 | ] 355 | objc_deps += headermap_deps 356 | swift_deps += headermap_deps 357 | 358 | headermap_copts = headermaps["headermap_copts"] 359 | 360 | if use_defines == None: 361 | use_defines = native.repository_name() == "@" 362 | 363 | if use_defines: 364 | swift_defines = SWIFT_DEFINES 365 | objc_defines = OBJC_DEFINES 366 | else: 367 | swift_defines = [] 368 | objc_defines = [] 369 | 370 | swift_copts = SHARED_COMPILER_OPTIONS + swift_defines + SHARED_SWIFT_COMPILER_OPTIONS + swift_copts + [ 371 | "-Xfrontend", 372 | "-enable-objc-interop", 373 | "-import-underlying-module", 374 | ] 375 | for copt in headermap_copts: 376 | swift_copts += [ 377 | "-Xcc", 378 | copt, 379 | ] 380 | 381 | objc_deps = objc_deps + [":" + swift_library_name] 382 | 383 | # Add Obj-C includes to Swift header search paths 384 | repository_name = native.repository_name() 385 | for x in includes: 386 | include = x if repository_name == "@" else "external/" + repository_name.lstrip("@") + "/" + x 387 | swift_copts += [ 388 | "-Xcc", 389 | "-I{}".format(include), 390 | ] 391 | 392 | # Generate module map for the underlying module 393 | module_map( 394 | name = name + "_objc_module", 395 | hdrs = hdrs, 396 | textual_hdrs = textual_hdrs, 397 | module_name = module_name, 398 | ) 399 | 400 | objc_module_map = ":" + name + "_objc_module" 401 | swiftc_inputs = swiftc_inputs + hdrs + textual_hdrs + private_hdrs + [objc_module_map] + headermap_deps 402 | 403 | swift_copts += [ 404 | "-Xcc", 405 | "-fmodule-map-file=$(execpath {})".format(objc_module_map), 406 | ] 407 | 408 | swift_features = features + ["swift.no_generated_module_map"] 409 | 410 | swift_library( 411 | name = swift_library_name, 412 | srcs = swift_srcs, 413 | swiftc_inputs = swiftc_inputs, 414 | copts = swift_copts, 415 | module_name = module_name, 416 | visibility = ["//visibility:private"], 417 | features = swift_features, 418 | deps = swift_deps, 419 | generates_header = True, 420 | generated_header_name = module_name + "-Swift.h", 421 | ) 422 | 423 | objc_copts = SHARED_COMPILER_OPTIONS + objc_defines + SHARED_OBJC_COMPILER_OPTIONS + objc_copts + headermap_copts 424 | 425 | # Modules is not enabled if a custom module map is present even with 426 | # `enable_modules` set to `True`. This forcibly enables it. 427 | # See https://github.com/bazelbuild/bazel/blob/18d01e7f6d8a3f5b4b4487e9d61a6d4d0f74f33a/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java#L1280 428 | if enable_modules: 429 | objc_copts += ["-fmodules"] 430 | 431 | # The extended module map for mixed language modules can't have the name 432 | # "module.modulemap", otherwise it would cause duplicate definition errors. 433 | module_map( 434 | name = name + "Module", 435 | hdrs = hdrs, 436 | deps = [":" + swift_library_name], 437 | module_name = module_name, 438 | visibility = visibility, 439 | ) 440 | umbrella_module_map = name + "Module" 441 | objc_deps += [name + "Module"] 442 | 443 | objc_module_map_config_name = name + "_module_maps" 444 | objc_module_map_config( 445 | name = objc_module_map_config_name, 446 | deps = deps, 447 | out = name + "_module_map_config.cfg", 448 | ) 449 | objc_deps += [":" + objc_module_map_config_name] 450 | if deps: 451 | objc_copts += [ 452 | "--config", 453 | "$(execpath {})".format(":" + objc_module_map_config_name), 454 | ] 455 | 456 | native.objc_library( 457 | name = objc_library_name, 458 | module_map = umbrella_module_map, 459 | enable_modules = enable_modules, 460 | includes = includes, 461 | srcs = objc_srcs, 462 | non_arc_srcs = non_arc_srcs, 463 | hdrs = hdrs + [ 464 | # These aren't headers but here is the only place to declare these 465 | # files as the inputs because objc_library doesn't have an attribute 466 | # to declare custom inputs. 467 | ":" + objc_module_map_config_name, 468 | ":" + umbrella_module_map, 469 | ], 470 | textual_hdrs = textual_hdrs, 471 | copts = objc_copts, 472 | deps = objc_deps, 473 | data = data, 474 | pch = kwargs.get("pch", None), 475 | sdk_frameworks = kwargs.get("sdk_frameworks", []), 476 | visibility = visibility, 477 | ) 478 | 479 | _objc_headers( 480 | name = name + ".hdrs", 481 | deps = [ 482 | ":" + swift_library_name, 483 | ], 484 | ) 485 | 486 | if avoid_deps == None: 487 | avoid_deps = deps 488 | 489 | ios_static_framework( 490 | name = name + ".intermediate", 491 | hdrs = hdrs + textual_hdrs + [ 492 | ":" + name + ".hdrs", 493 | ], 494 | deps = [ 495 | ":" + objc_library_name, 496 | ], 497 | avoid_deps = avoid_deps, 498 | bundle_name = module_name, 499 | minimum_os_version = minimum_os_version, 500 | umbrella_header = umbrella_header, 501 | ) 502 | 503 | _mixed_static_framework( 504 | name = name + "Framework", 505 | framework = name + ".intermediate", 506 | swift_partial_target = ":" + swift_library_name, 507 | minimum_os_version = minimum_os_version, 508 | visibility = visibility, 509 | ) 510 | -------------------------------------------------------------------------------- /apple/module_map.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2020 LINE Corporation 2 | # 3 | # LINE Corporation licenses this file to you under the Apache License, 4 | # version 2.0 (the "License"); you may not use this file except in compliance 5 | # with the License. You may obtain a copy of the License at: 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | load("@build_bazel_rules_swift//swift:swift.bzl", "SwiftInfo") 16 | load(":common.bzl", "HEADERS_FILE_TYPES") 17 | 18 | def _module_map_content( 19 | module_name, 20 | hdrs, 21 | textual_hdrs, 22 | swift_generated_header, 23 | module_map_path): 24 | # Up to the execution root 25 | # bazel-out//bin//.modulemaps/ 26 | slashes_count = module_map_path.count("/") 27 | relative_path = "".join(["../"] * slashes_count) 28 | 29 | content = "module " + module_name + " {\n" 30 | 31 | for hdr in hdrs: 32 | content += " header \"%s%s\"\n" % (relative_path, hdr.path) 33 | for hdr in textual_hdrs: 34 | content += " textual header \"%s%s\"\n" % (relative_path, hdr.path) 35 | 36 | content += "\n" 37 | content += " export *\n" 38 | content += "}\n" 39 | 40 | # Add a Swift submodule if a Swift generated header exists 41 | if swift_generated_header: 42 | content += "\n" 43 | content += "module " + module_name + ".Swift {\n" 44 | content += " header \"%s\"\n" % swift_generated_header.basename 45 | content += " requires objc\n" 46 | content += "}\n" 47 | 48 | return content 49 | 50 | def _umbrella_header_content(module_name, hdrs): 51 | # If the platform is iOS, add an import call to `UIKit/UIKit.h` to the top 52 | # of the umbrella header. This allows implicit import of UIKit from Swift. 53 | content = """\ 54 | #ifdef __OBJC__ 55 | #import 56 | #if __has_include() 57 | #import 58 | #endif 59 | #endif 60 | 61 | """ 62 | for hdr in hdrs: 63 | content += "#import \"%s\"\n" % (hdr.path) 64 | 65 | return content 66 | 67 | def _impl(ctx): 68 | outputs = [] 69 | 70 | hdrs = ctx.files.hdrs 71 | textual_hdrs = ctx.files.textual_hdrs 72 | outputs.extend(hdrs) 73 | outputs.extend(textual_hdrs) 74 | 75 | # Find Swift generated header 76 | swift_generated_header = None 77 | for dep in ctx.attr.deps: 78 | if CcInfo in dep: 79 | objc_headers = dep[CcInfo].compilation_context.headers.to_list() 80 | else: 81 | objc_headers = [] 82 | for hdr in objc_headers: 83 | if hdr.owner == dep.label: 84 | swift_generated_header = hdr 85 | outputs.append(swift_generated_header) 86 | 87 | # Write the module map content 88 | if swift_generated_header: 89 | umbrella_header_path = ctx.attr.module_name + ".h" 90 | umbrella_header = ctx.actions.declare_file(umbrella_header_path) 91 | outputs.append(umbrella_header) 92 | ctx.actions.write( 93 | content = _umbrella_header_content(ctx.attr.module_name, hdrs), 94 | output = umbrella_header, 95 | ) 96 | outputs.append(umbrella_header) 97 | 98 | module_map = ctx.outputs.out 99 | outputs.append(module_map) 100 | 101 | ctx.actions.write( 102 | content = _module_map_content( 103 | module_name = ctx.attr.module_name, 104 | hdrs = hdrs, 105 | textual_hdrs = textual_hdrs, 106 | swift_generated_header = swift_generated_header, 107 | module_map_path = module_map.path, 108 | ), 109 | output = module_map, 110 | ) 111 | 112 | module_map_to_provide = [] 113 | if ctx.attr.add_to_provider: 114 | module_map_to_provide = [module_map] 115 | 116 | objc_provider = apple_common.new_objc_provider( 117 | module_map = depset(module_map_to_provide), 118 | header = depset(outputs), 119 | ) 120 | 121 | compilation_context = cc_common.create_compilation_context( 122 | headers = depset(outputs), 123 | ) 124 | cc_info = CcInfo( 125 | compilation_context = compilation_context, 126 | ) 127 | 128 | return struct( 129 | providers = [ 130 | DefaultInfo( 131 | files = depset([module_map]), 132 | ), 133 | objc_provider, 134 | cc_info, 135 | ], 136 | ) 137 | 138 | _module_map = rule( 139 | implementation = _impl, 140 | attrs = { 141 | "module_name": attr.string( 142 | mandatory = True, 143 | doc = "The name of the module.", 144 | ), 145 | "hdrs": attr.label_list( 146 | allow_files = HEADERS_FILE_TYPES, 147 | doc = """\ 148 | The list of C, C++, Objective-C, and Objective-C++ header files used to 149 | construct the module map. 150 | """, 151 | ), 152 | "textual_hdrs": attr.label_list( 153 | allow_files = HEADERS_FILE_TYPES, 154 | doc = """\ 155 | The list of C, C++, Objective-C, and Objective-C++ header files used to 156 | construct the module map. Unlike hdrs, these will be declared as 'textual 157 | header' in the module map. 158 | """, 159 | ), 160 | "deps": attr.label_list( 161 | providers = [SwiftInfo], 162 | doc = """\ 163 | The list of swift_library targets. A `${module_name}.Swift` submodule will be 164 | generated if non-empty. 165 | """, 166 | ), 167 | "add_to_provider": attr.bool( 168 | default = True, 169 | doc = """\ 170 | Whether to add the generated module map to the returning provider. Targets 171 | imported via `apple_static_framework_import` or 172 | `apple_dynamic_framework_import` already have their module maps provided to 173 | swift_library targets depending on them. Set this to `False` in that case to 174 | avoid duplicate modules. 175 | """, 176 | ), 177 | "out": attr.output( 178 | doc = "The name of the output module map file.", 179 | ), 180 | }, 181 | doc = "Generates a module map given a list of header files.", 182 | ) 183 | 184 | # TODO: Revisit. Stardoc generation of this. Stardoc will look at this macro 185 | # instead of the rule above, so it is generating empty documentation for this. 186 | def module_map(name, **kwargs): 187 | _module_map( 188 | name = name, 189 | out = name + "-module.modulemap", 190 | **kwargs 191 | ) 192 | -------------------------------------------------------------------------------- /apple/objc_library.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2020 LINE Corporation 2 | # 3 | # LINE Corporation licenses this file to you under the Apache License, 4 | # version 2.0 (the "License"); you may not use this file except in compliance 5 | # with the License. You may obtain a copy of the License at: 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | load(":objc_static_framework.bzl", "objc_static_framework") 16 | 17 | def objc_library(**kwargs): 18 | """Produces a static library from the given Objective-C source files. 19 | 20 | A drop-in replacement of the native 21 | [objc_library](https://docs.bazel.build/versions/3.2.0/be/objective-c.html#objc_library) 22 | rule, with added supports for header maps and modules. 23 | 24 | To use this rule in your BUILD files, load it with: 25 | 26 | ```starlark 27 | load("@rules_apple_line//apple:objc_library.bzl", "objc_library") 28 | ``` 29 | 30 | See [objc_static_framework](#objc_static_framework) for the documentation 31 | of each attribute. 32 | """ 33 | objc_static_framework(**kwargs) 34 | -------------------------------------------------------------------------------- /apple/objc_module_map_config.bzl: -------------------------------------------------------------------------------- 1 | def _clang_config_file_content(module_maps): 2 | """Returns the contents of a Clang configuration file given a depset of module maps.""" 3 | 4 | content = "" 5 | for map in module_maps.to_list(): 6 | path = map.path 7 | 8 | # Ignore module maps from the prebuilt frameworks. These are redundant 9 | # because those frameworks are already being imported via the framework 10 | # search paths flag (`-F`). 11 | if ".framework" in path: 12 | continue 13 | 14 | # Ignore the auto-generated module maps by Bazel. We use our 15 | # `module_map` rule to generate module maps instead of relying on 16 | # Bazel's autogerated ones (they are only generated when being directly 17 | # depended on a `swift_library` target, which is uncontrollable). 18 | # Bazel's auto-generated module maps follow the naming convention 19 | # `target_name.modulemaps/module.modulemap`. 20 | if ".modulemaps" in path: 21 | continue 22 | 23 | content += "-fmodule-map-file=" 24 | content += path 25 | content += "\n" 26 | return content 27 | 28 | def _get_transitive_module_maps(deps): 29 | """Returns a [depset](https://docs.bazel.build/versions/3.1.0/skylark/depsets.html) of transitive module maps given a depset of transitive dependencies. 30 | 31 | Args: 32 | deps: The cc_library, objc_library and swift_library dependencies. 33 | Returns: 34 | A depset of transitive module maps. 35 | """ 36 | return depset( 37 | transitive = [ 38 | dep[apple_common.Objc].module_map 39 | for dep in deps 40 | if apple_common.Objc in dep 41 | ], 42 | ) 43 | 44 | def _objc_module_map_config_impl(ctx): 45 | all_module_maps = _get_transitive_module_maps(ctx.attr.deps) 46 | output = ctx.outputs.out 47 | ctx.actions.write( 48 | content = _clang_config_file_content(all_module_maps), 49 | output = output, 50 | ) 51 | 52 | return struct( 53 | providers = [ 54 | DefaultInfo( 55 | files = depset([output]), 56 | ), 57 | apple_common.new_objc_provider( 58 | module_map = all_module_maps, 59 | ), 60 | ], 61 | ) 62 | 63 | objc_module_map_config = rule( 64 | attrs = { 65 | "deps": attr.label_list( 66 | doc = "The dependencies from which to retrieve the list of module maps.", 67 | mandatory = True, 68 | providers = [CcInfo], 69 | ), 70 | "out": attr.output( 71 | doc = "The output filename of the Clang configuration file.", 72 | mandatory = True, 73 | ), 74 | }, 75 | doc = """ 76 | Generates a Clang configuration file with all the `-fmodule-map-file` flags 77 | for all direct and transitive module maps from dependencies. 78 | """, 79 | implementation = _objc_module_map_config_impl, 80 | ) 81 | -------------------------------------------------------------------------------- /apple/objc_static_framework.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2020 LINE Corporation 2 | # 3 | # LINE Corporation licenses this file to you under the Apache License, 4 | # version 2.0 (the "License"); you may not use this file except in compliance 5 | # with the License. You may obtain a copy of the License at: 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | """Bazel rule for creating a multi-architecture static framework for an Objective-C module.""" 16 | 17 | load("@build_bazel_rules_apple//apple:ios.bzl", "ios_static_framework") 18 | load("@bazel_skylib//lib:paths.bzl", "paths") 19 | load(":defines.bzl", "OBJC_DEFINES") 20 | load(":headermap_support.bzl", "headermap_support") 21 | load(":module_map.bzl", "module_map") 22 | load(":objc_module_map_config.bzl", "objc_module_map_config") 23 | load(":unique_symbol_file.bzl", "unique_symbol_file") 24 | load( 25 | ":common.bzl", 26 | "DEFAULT_MINIMUM_OS_VERSION", 27 | "DEFAULT_VISIBILITY", 28 | "HEADERS_FILE_TYPES", 29 | "SHARED_COMPILER_OPTIONS", 30 | "SHARED_OBJC_COMPILER_OPTIONS", 31 | ) 32 | 33 | def objc_static_framework( 34 | name, 35 | srcs = [], 36 | non_arc_srcs = [], 37 | hdrs = [], 38 | archives = [], 39 | deps = [], 40 | avoid_deps = None, 41 | data = [], 42 | use_defines = None, 43 | module_name = None, 44 | textual_hdrs = [], 45 | includes = [], 46 | testonly = False, 47 | enable_modules = False, 48 | minimum_os_version = DEFAULT_MINIMUM_OS_VERSION, 49 | pch = None, 50 | visibility = DEFAULT_VISIBILITY, 51 | umbrella_header = None, 52 | **kwargs): 53 | """Builds and bundles a Objective-C static framework for Xcode consumption or third-party distribution. 54 | 55 | This rule in general is very similar to `build_bazel_rules_apple`'s 56 | `ios_static_framework` rule, with support for modules and header maps out 57 | of the box--which means you don't need to change your imports to make your 58 | code build with Bazel. Note that, unlike `build_bazel_rules_apple`'s 59 | `ios_static_framework`, by default, it will not link any of its 60 | dependencies into the final framework binary - the same way Xcode does when 61 | it builds frameworks. 62 | 63 | Args: 64 | name: A unique name for this target. This will be the name of the 65 | `objc_library` target that the framework depends on. The framework 66 | target will be named `${name}Framework`. 67 | srcs: The Objective-C source files to compile. 68 | hdrs: The list of C, C++, Objective-C, and Objective-C++ header files 69 | published by this library to be included by sources in dependent 70 | rules. These headers describe the public interface for the library 71 | and will be made available for inclusion by sources in this rule or 72 | in dependent rules. Headers not meant to be included by a client of 73 | this library should be listed in the `srcs` attribute instead. These 74 | will be compiled separately from the source if modules are enabled. 75 | non_arc_srcs: The Objective-C source files to compile that do not use 76 | ARC. Provide both `srcs` and `non_arc_srcs` explicitly if both kinds 77 | of source files should be included. 78 | pch: Header file to prepend to every source file being compiled (both arc 79 | and non-arc). Use of pch files is actively discouraged in BUILD files, 80 | and this should be considered deprecated. Since pch files are not 81 | actually precompiled this is not a build-speed enhancement, and instead 82 | is just a global dependency. From a build efficiency point of view you 83 | are actually better including what you need directly in your sources 84 | where you need it. 85 | textual_hdrs: The list of C, C++, Objective-C, and Objective-C++ files 86 | that are included as headers by source files in this rule or by users 87 | of this library. Unlike `hdrs`, these will not be compiled separately 88 | from the sources. 89 | includes: List of header search paths to add to this target and all 90 | depending targets. Unlike `copts`, these flags are added for this 91 | rule and every rule that depends on it. (Note: not the rules it 92 | depends upon!) Be very careful, since this may have far-reaching 93 | effects. When in doubt, add "-iquote" flags to `copts` instead. 94 | archives: The list of `.a` files provided to Objective-C targets that 95 | depend on this target. 96 | enable_modules: Enables clang module support (via `-fmodules`). Setting 97 | this to `True` will allow you to @import system headers and other 98 | targets). 99 | umbrella_header: An optional single `.h` file to use as the umbrella 100 | header for this framework. Usually, this header will have the same name 101 | as this target, so that clients can load the header using the #import 102 | format. If this attribute is not specified 103 | (the common use case), an umbrella header will be generated under the 104 | same name as this target. 105 | deps: Dependencies of the `objc_library` target being compiled. 106 | avoid_deps: A list of `objc_library` and `swift_library` targets on which 107 | this framework depends in order to compile, but you don't want to link to 108 | the framework binary. Defaults to `deps` if not specified. 109 | data: The list of files needed by this rule at runtime. These will be 110 | bundled to the top level directory of the bundling target (`.app` or 111 | `.framework`). 112 | copts: Additional compiler options that should be passed to `clang`. 113 | module_name: The name of the module being built. If not 114 | provided, the `name` is used. 115 | minimum_os_version: The minimum OS version supported by the framework. 116 | testonly: If `True`, only testonly targets (such as tests) can depend 117 | on the `objc_library` target. The default is `False`. 118 | visibility: The visibility specifications for this target. 119 | **kwargs: Additional arguments being passed through to the underlying 120 | `objc_library` rule. 121 | """ 122 | 123 | module_name = module_name or name 124 | 125 | if avoid_deps == None: 126 | avoid_deps = deps 127 | 128 | private_hdrs = [] 129 | for x in srcs: 130 | _, extension = paths.split_extension(x) 131 | if extension in HEADERS_FILE_TYPES: 132 | private_hdrs.append(x) 133 | 134 | module_map_name = name + "Module" 135 | module_map( 136 | name = module_map_name, 137 | hdrs = hdrs, 138 | module_name = module_name, 139 | visibility = visibility, 140 | ) 141 | 142 | if use_defines == None: 143 | use_defines = native.repository_name() == "@" 144 | 145 | if use_defines: 146 | defines = OBJC_DEFINES 147 | else: 148 | defines = [] 149 | 150 | copts = SHARED_COMPILER_OPTIONS + defines + SHARED_OBJC_COMPILER_OPTIONS + kwargs.get("copts", []) 151 | 152 | # Modules is not enabled if a custom module map is present even with 153 | # `enable_modules` set to `True`. This forcibly enables it. 154 | # See https://github.com/bazelbuild/bazel/blob/18d01e7f6d8a3f5b4b4487e9d61a6d4d0f74f33a/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java#L1280 155 | if enable_modules: 156 | copts += ["-fmodules"] 157 | 158 | headermaps = headermap_support( 159 | name = name, 160 | module_name = module_name, 161 | hdrs = hdrs + textual_hdrs, 162 | private_hdrs = private_hdrs, 163 | deps = deps, 164 | ) 165 | headermap_deps = [ 166 | headermaps["public_hmap"], 167 | headermaps["private_hmap"], 168 | headermaps["private_angled_hmap"], 169 | ] 170 | objc_deps = deps + headermap_deps 171 | copts += headermaps["headermap_copts"] 172 | 173 | if archives: 174 | native.objc_import( 175 | name = name + "Import", 176 | hdrs = hdrs, 177 | archives = archives, 178 | sdk_dylibs = kwargs.get("sdk_dylibs", []), 179 | sdk_frameworks = kwargs.get("sdk_frameworks", []), 180 | includes = includes, 181 | testonly = testonly, 182 | ) 183 | objc_deps += [":" + name + "Import"] 184 | avoid_deps = [] 185 | 186 | # objc_library needs at least a source file 187 | if not srcs: 188 | unique_symbol_name = name + "UniqueSymbol" 189 | unique_symbol_file( 190 | name = unique_symbol_name, 191 | out = name + "UniqueSymbol.m", 192 | ) 193 | srcs = [":{}".format(unique_symbol_name)] 194 | 195 | objc_module_map_config_name = name + "_module_maps" 196 | objc_module_map_config( 197 | name = objc_module_map_config_name, 198 | deps = deps, 199 | out = name + "_module_map_config.cfg", 200 | ) 201 | objc_deps += [":" + objc_module_map_config_name] 202 | if deps: 203 | copts += [ 204 | "--config", 205 | "$(execpath {})".format(":" + objc_module_map_config_name), 206 | ] 207 | 208 | native.objc_library( 209 | name = name, 210 | module_map = module_map_name, 211 | hdrs = hdrs + [ 212 | # These aren't headers but here is the only place to declare these 213 | # files as the inputs because objc_library doesn't have an attribute 214 | # to declare custom inputs. 215 | ":" + objc_module_map_config_name, 216 | ":" + module_map_name, 217 | ], 218 | srcs = srcs, 219 | non_arc_srcs = non_arc_srcs, 220 | pch = pch, 221 | includes = includes, 222 | enable_modules = enable_modules, 223 | testonly = testonly, 224 | copts = copts, 225 | defines = kwargs.get("defines", []), 226 | visibility = visibility, 227 | deps = objc_deps, 228 | data = data, 229 | sdk_dylibs = kwargs.get("sdk_dylibs", []), 230 | sdk_frameworks = kwargs.get("sdk_frameworks", []), 231 | textual_hdrs = kwargs.get("textual_hdrs", []), 232 | ) 233 | 234 | ios_static_framework( 235 | name = name + "Framework", 236 | avoid_deps = avoid_deps, 237 | bundle_name = module_name, 238 | hdrs = hdrs + textual_hdrs, 239 | testonly = testonly, 240 | minimum_os_version = minimum_os_version, 241 | visibility = visibility, 242 | deps = [":" + name], 243 | umbrella_header = umbrella_header, 244 | ) 245 | -------------------------------------------------------------------------------- /apple/pkg_dsym.bzl: -------------------------------------------------------------------------------- 1 | """Rule for packaging .dSYM.zip. Originally imported from 2 | https://github.com/bazelbuild/rules_pkg/blob/cd2fd762be23a6cc672e6390f7b6ef3c1c7bfd4b/pkg/pkg.bzl 3 | with modifications for dSYM specifics.""" 4 | 5 | def _quote(filename, protect = "="): 6 | """Quote the filename, by escaping = by \\= and \\ by \\\\""" 7 | return filename.replace("\\", "\\\\").replace(protect, "\\" + protect) 8 | 9 | def _dest_path(path): 10 | """Returns the path, stripped of parent directories of .dSYM.""" 11 | components = path.split("/") 12 | res_components = [] 13 | found = False 14 | for c in components: 15 | # Find .dSYM directory and make it be at the root path 16 | if c.endswith(".dSYM"): 17 | found = True 18 | if found: 19 | res_components.append(c) 20 | return "/".join(res_components) 21 | 22 | def _dsym_files(files): 23 | """Remove files that aren't dSYM files.""" 24 | return [ 25 | f 26 | for f in files 27 | if f.path.find(".dSYM") != -1 28 | ] 29 | 30 | def _pkg_dsym_impl(ctx): 31 | args = ctx.actions.args() 32 | 33 | args.add("-o", ctx.outputs.out) 34 | args.add("-d", ctx.attr._package_dir) 35 | args.add("-t", ctx.attr.timestamp) 36 | args.add("-m", ctx.attr.mode) 37 | 38 | srcs = _dsym_files(ctx.files.srcs) 39 | for f in srcs: 40 | path = f.path 41 | arg = "%s=%s" % ( 42 | _quote(path), 43 | _dest_path(path), 44 | ) 45 | args.add(arg) 46 | 47 | args.set_param_file_format("multiline") 48 | args.use_param_file("@%s") 49 | 50 | ctx.actions.run( 51 | mnemonic = "PackageDsym", 52 | inputs = srcs, 53 | executable = ctx.executable._build_zip, 54 | arguments = [args], 55 | outputs = [ctx.outputs.out], 56 | env = { 57 | "LANG": "en_US.UTF-8", 58 | "LC_CTYPE": "UTF-8", 59 | "PYTHONIOENCODING": "UTF-8", 60 | "PYTHONUTF8": "1", 61 | }, 62 | use_default_shell_env = True, 63 | ) 64 | return OutputGroupInfo(out = [ctx.outputs.out]) 65 | 66 | pkg_dsym = rule( 67 | implementation = _pkg_dsym_impl, 68 | attrs = { 69 | "srcs": attr.label_list( 70 | allow_files = True, 71 | doc = """ 72 | A list of executable targets that produce dSYM, and/or a list of imported dSYMs 73 | if they're prebuilt. 74 | """, 75 | ), 76 | "timestamp": attr.int( 77 | default = 315532800, 78 | doc = """ 79 | The time to use for every file in the zip, expressed as seconds since Unix 80 | Epoch, RFC 3339. 81 | 82 | Due to limitations in the format of zip files, values before Jan 1, 1980 will 83 | be rounded up and the precision in the zip file is limited to a granularity of 84 | 2 seconds. 85 | """, 86 | ), 87 | "mode": attr.string( 88 | default = "0555", 89 | doc = "Set the mode of files added by the `srcs` attribute.", 90 | ), 91 | "out": attr.output( 92 | doc = "The output filename.", 93 | ), 94 | # Implicit dependencies. 95 | "_build_zip": attr.label( 96 | default = Label("@rules_pkg//:build_zip"), 97 | cfg = "exec", 98 | executable = True, 99 | allow_files = True, 100 | ), 101 | "_package_dir": attr.string(default = "/"), 102 | }, 103 | doc = "Creates a `.dSYM.zip` file given targets that produce dSYMs.", 104 | ) 105 | -------------------------------------------------------------------------------- /apple/repositories.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2020 LINE Corporation 2 | # 3 | # LINE Corporation licenses this file to you under the Apache License, 4 | # version 2.0 (the "License"); you may not use this file except in compliance 5 | # with the License. You may obtain a copy of the License at: 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | """Definitions for handling Bazel repositories used by the LINE Apple rules.""" 16 | 17 | load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") 18 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 19 | load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") 20 | 21 | def rules_apple_line_dependencies(): 22 | """Fetches repositories that are dependencies of the `rules_apple_line` workspace. 23 | 24 | Users should call this macro in their `WORKSPACE` to ensure that all of the 25 | dependencies of the Apple rules are downloaded and that they are isolated from 26 | changes to those dependencies. 27 | """ 28 | maybe( 29 | http_archive, 30 | name = "bazel_skylib", 31 | urls = [ 32 | "https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz", 33 | ], 34 | sha256 = "97e70364e9249702246c0e9444bccdc4b847bed1eb03c5a3ece4f83dfe6abc44", 35 | ) 36 | 37 | maybe( 38 | http_archive, 39 | name = "rules_pkg", 40 | urls = [ 41 | "https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.3.0/rules_pkg-0.3.0.tar.gz", 42 | "https://github.com/bazelbuild/rules_pkg/releases/download/0.3.0/rules_pkg-0.3.0.tar.gz", 43 | ], 44 | sha256 = "6b5969a7acd7b60c02f816773b06fcf32fbe8ba0c7919ccdc2df4f8fb923804a", 45 | ) 46 | 47 | maybe( 48 | http_archive, 49 | name = "build_bazel_rules_apple", 50 | sha256 = "90e3b5e8ff942be134e64a83499974203ea64797fd620eddeb71b3a8e1bff681", 51 | url = "https://github.com/bazelbuild/rules_apple/releases/download/1.1.2/rules_apple.1.1.2.tar.gz", 52 | ) 53 | 54 | maybe( 55 | git_repository, 56 | name = "com_github_ob_rules_ios", 57 | commit = "7c0759d784a3f66032038a51c1c144e528c5d7a8", 58 | remote = "https://github.com/ob/rules_ios.git", 59 | # TODO: Update hmap rule 60 | patch_args = ["-p1"], 61 | patches = ["@rules_apple_line//third_party:rules_ios.patch"], 62 | ) 63 | 64 | maybe( 65 | http_archive, 66 | name = "Commander", 67 | build_file = "@rules_apple_line//third_party:Commander.BUILD", 68 | sha256 = "4243b0227e51b8ea60345eac3ec4a3ff4385435e86011f2b60273e16806af9a8", 69 | strip_prefix = "Commander-0.9.1", 70 | url = "https://github.com/kylef/Commander/archive/0.9.1.tar.gz", 71 | ) 72 | 73 | # SwiftGen dependencies 74 | maybe( 75 | http_archive, 76 | name = "Kanna", 77 | build_file = "@rules_apple_line//third_party:Kanna.BUILD", 78 | sha256 = "9aad278e9ec7069a4c06d638c8b21580587e93a67e93f488dabf0a51cd275265", 79 | strip_prefix = "Kanna-5.2.3", 80 | url = "https://github.com/tid-kijyun/Kanna/archive/5.2.3.tar.gz", 81 | ) 82 | 83 | maybe( 84 | http_archive, 85 | name = "PathKit", 86 | build_file = "@rules_apple_line//third_party:PathKit.BUILD", 87 | sha256 = "6d45fb8153b047d21568b607ba7da851a52f59817f35441a4656490b37680c64", 88 | strip_prefix = "PathKit-1.0.0", 89 | url = "https://github.com/kylef/PathKit/archive/1.0.0.tar.gz", 90 | ) 91 | 92 | maybe( 93 | http_archive, 94 | name = "Stencil", 95 | build_file = "@rules_apple_line//third_party:Stencil.BUILD", 96 | sha256 = "1f20c356f9dd454517e1362df7ec5355aee9fa3c59b8d48cadc62019f905d8ec", 97 | strip_prefix = "Stencil-0.14.0", 98 | url = "https://github.com/stencilproject/Stencil/archive/0.14.0.tar.gz", 99 | ) 100 | 101 | maybe( 102 | http_archive, 103 | name = "StencilSwiftKit", 104 | build_file = "@rules_apple_line//third_party:StencilSwiftKit.BUILD", 105 | sha256 = "225f5c03051805d6bdb8f25f980bed83b03bb3c840278e9d7171d016c8b33fbd", 106 | strip_prefix = "StencilSwiftKit-fad4415a4c904a9845134b02fd66bd8464741427", 107 | url = "https://github.com/SwiftGen/StencilSwiftKit/archive/fad4415a4c904a9845134b02fd66bd8464741427.tar.gz", 108 | ) 109 | 110 | maybe( 111 | http_archive, 112 | name = "SwiftGen", 113 | build_file = "@rules_apple_line//third_party:SwiftGen.BUILD", 114 | sha256 = "fa9377ebea5c0bea55d67671eb2f20491a49f3a3d90b086d75743bffc99507f0", 115 | strip_prefix = "SwiftGen-6.4.0", 116 | url = "https://github.com/SwiftGen/SwiftGen/archive/6.4.0.tar.gz", 117 | ) 118 | 119 | maybe( 120 | http_archive, 121 | name = "Yams", 122 | build_file = "@rules_apple_line//third_party:Yams.BUILD", 123 | sha256 = "1653e729419565b9a34b327e3a70f514254c9d73c46c18be2599cd271105079f", 124 | strip_prefix = "Yams-4.0.0", 125 | url = "https://github.com/jpsim/Yams/archive/4.0.0.tar.gz", 126 | ) 127 | 128 | def rules_apple_line_test_dependencies(): 129 | """Fetches repositories that are dependencies for tests of the `rules_apple_line` workspace. 130 | """ 131 | maybe( 132 | http_archive, 133 | name = "CardIO", 134 | build_file = "@rules_apple_line//third_party:CardIO.BUILD", 135 | url = "https://github.com/card-io/card.io-iOS-SDK/archive/5.4.1.tar.gz", 136 | sha256 = "ff3e1ddf3cb111b7dec15cb62811a9cfc22c33c9de9d6a0fb8e64ee9c64c5a04", 137 | strip_prefix = "card.io-iOS-SDK-5.4.1", 138 | ) 139 | 140 | maybe( 141 | http_archive, 142 | name = "GoogleAnalytics", 143 | build_file = "@rules_apple_line//third_party:GoogleAnalytics.BUILD", 144 | sha256 = "5731a649759c1bd676a378e5caeb9e8ffb466a0c5aeab344ddd3800c9917e9ca", 145 | url = "https://www.gstatic.com/cpdc/5cd71dd2f756bb01/GoogleAnalytics-3.17.0.tar.gz", 146 | ) 147 | 148 | maybe( 149 | http_archive, 150 | name = "OHHTTPStubs", 151 | build_file = "@rules_apple_line//third_party:OHHTTPStubs.BUILD", 152 | sha256 = "6a5689f8b857d16f89e89ca0462b71c9b2c46eaf28d66f9e105b6f859d888cfb", 153 | strip_prefix = "OHHTTPStubs-9.0.0", 154 | url = "https://github.com/AliSoftware/OHHTTPStubs/archive/9.0.0.tar.gz", 155 | ) 156 | 157 | maybe( 158 | http_archive, 159 | name = "facebook_ios_sdk", 160 | build_file = "@rules_apple_line//third_party:facebook-ios-sdk.BUILD", 161 | sha256 = "2039e0c197e0cbda9824e7fda97904e88171ed3a5ced1f03f78408a624afdac8", 162 | strip_prefix = "facebook-ios-sdk-5.7.0", 163 | url = "https://github.com/facebook/facebook-ios-sdk/archive/v5.7.0.tar.gz", 164 | ) 165 | 166 | maybe( 167 | http_archive, 168 | name = "FLEX", 169 | build_file = "@rules_apple_line//third_party:FLEX.BUILD", 170 | sha256 = "b91fc261697fa1f3233aa2ede9dfe2b5fcffb9dafdbcdaddb1edfc94df40275a", 171 | strip_prefix = "FLEX-4.1.1", 172 | url = "https://github.com/FLEXTool/FLEX/archive/4.1.1.tar.gz", 173 | ) 174 | -------------------------------------------------------------------------------- /apple/string_dict_select_values.bzl: -------------------------------------------------------------------------------- 1 | def string_dict_select_values(values): 2 | select_values = [] 3 | 4 | for value in values: 5 | if type(value) == type(""): 6 | select_values += [value] 7 | else: 8 | select_values += select(_wrap_dict_values_in_array(value)) 9 | 10 | return select_values 11 | 12 | def _wrap_dict_values_in_array(d): 13 | retval = {} 14 | for key, value in d.items(): 15 | retval[key] = [value] 16 | return retval 17 | -------------------------------------------------------------------------------- /apple/swift_library.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2020 LINE Corporation 2 | # 3 | # LINE Corporation licenses this file to you under the Apache License, 4 | # version 2.0 (the "License"); you may not use this file except in compliance 5 | # with the License. You may obtain a copy of the License at: 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | load(":swift_static_framework.bzl", "swift_static_framework") 16 | 17 | def swift_library(**kwargs): 18 | """Compiles and links Swift code into a static library and Swift module. 19 | 20 | A drop-in replacement of the official 21 | [swift_library](https://github.com/bazelbuild/rules_swift/blob/master/doc/rules.md#swift_library) 22 | rule, with added supports for header maps, and better integration with other 23 | rules in this repository. 24 | 25 | To use this rule in your BUILD files, load it with: 26 | 27 | ```starlark 28 | load("@rules_apple_line//apple:objc_library.bzl", "objc_library") 29 | ``` 30 | 31 | See [swift_static_framework](#swift_static_framework) for the documentation 32 | of each attribute. 33 | """ 34 | swift_static_framework(**kwargs) 35 | -------------------------------------------------------------------------------- /apple/swift_static_framework.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2020 LINE Corporation 2 | # 3 | # LINE Corporation licenses this file to you under the Apache License, 4 | # version 2.0 (the "License"); you may not use this file except in compliance 5 | # with the License. You may obtain a copy of the License at: 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | """Rule for creating a multi-architecture static framework for a 16 | Swift module.""" 17 | 18 | load( 19 | "@build_bazel_rules_swift//swift:swift.bzl", 20 | "swift_library", 21 | ) 22 | load( 23 | "@build_bazel_rules_apple//apple:ios.bzl", 24 | "ios_static_framework", 25 | ) 26 | load(":defines.bzl", "SWIFT_DEFINES") 27 | load(":headermap_support.bzl", "headermap_support") 28 | load( 29 | ":common.bzl", 30 | "DEFAULT_MINIMUM_OS_VERSION", 31 | "DEFAULT_VISIBILITY", 32 | "SHARED_COMPILER_OPTIONS", 33 | "SHARED_SWIFT_COMPILER_OPTIONS", 34 | ) 35 | 36 | def swift_static_framework( 37 | name, 38 | srcs, 39 | copts = [], 40 | use_defines = None, 41 | swiftc_inputs = [], 42 | deps = [], 43 | avoid_deps = None, 44 | data = [], 45 | visibility = DEFAULT_VISIBILITY, 46 | minimum_os_version = DEFAULT_MINIMUM_OS_VERSION, 47 | features = [], 48 | **kwargs): 49 | """Builds and bundles a Swift static framework for Xcode consumption or third-party distribution. 50 | 51 | This rule in general is very similar to `build_bazel_rules_apple`'s 52 | `ios_static_framework` rule, with some differences: 53 | 54 | * It supports bundling a swift_library target that depend transitively on 55 | any other swift_library targets. By default, it will not link any of 56 | its dependencies into the final framework binary - the same way Xcode 57 | does when it builds frameworks - which means you can prebuild your 58 | dependencies as static frameworks for Xcode consumption. 59 | * It supports header maps out of the box--you don't need to change your 60 | imports to make your code build with Bazel. 61 | * It always collects the Swift generated header and bundles a 62 | `module.modulemap` file. 63 | * It bundles `swiftmodule` and `swiftdoc` files (`ios_static_framework` 64 | rule bundles `swiftinterface` instead of `swiftmodule` file). 65 | 66 | Under the hood, this uses an `objc_library` target to wrap a 67 | `swift_library` target -- so by a sense, it's still a mixed Obj-C and Swift 68 | target - to make use of `objc_library`'s configuration transition. 69 | 70 | ### Examples 71 | 72 | ```starlark 73 | load("@rules_apple_line//apple:swift_static_framework.bzl", "swift_static_framework") 74 | 75 | swift_static_framework( 76 | name = "MyLibrary", 77 | srcs = glob(["**/*.swift"]), 78 | ) 79 | ``` 80 | 81 | Args: 82 | name: A unique name for this target. This will be the name of the 83 | library target that the framework depends on. The framework target 84 | will be named `${name}Framework`. 85 | srcs: The list of Swift source files to compile. 86 | copts: Additional compiler options that should be passed to `swiftc`. 87 | swiftc_inputs: Additional files that are referenced using `$(rootpath 88 | ...)` and `$(execpath ...)` in attributes that support location 89 | expansion (e.g. `copts`). 90 | swift_deps: Dependencies of the underlying `swift_library` target. 91 | deps: A list of targets that are dependencies of the target being built. 92 | Note that, by default, none of these and all of their transitive 93 | dependencies will be linked into the final binary when building the 94 | `${name}Framework` target. 95 | avoid_deps: A list of `objc_library` and `swift_library` targets on which 96 | this framework depends in order to compile, but the transitive 97 | closure of which will not be linked into the framework's binary. By 98 | default this is the same as `deps`, that is none of the 99 | depependencies will be linked into the framework's binary. For 100 | example, providing an empty list (`[]`) here will result in a fully 101 | static link binary. 102 | data: The list of files needed by this rule at runtime. These will be 103 | bundled to the top level directory of the bundling target (`.app` or 104 | `.framework`). 105 | visibility: The visibility specifications for this target. 106 | features: Features of the underlying `swift_library` target. 107 | **kwargs: Additional arguments being passed through. 108 | """ 109 | swift_srcs = srcs 110 | 111 | module_name = kwargs.pop("module_name", name) 112 | 113 | swift_library_name = name 114 | 115 | swift_deps = [] + deps 116 | 117 | headermaps = headermap_support( 118 | name = name, 119 | module_name = module_name, 120 | hdrs = [], 121 | private_hdrs = [], 122 | deps = deps, 123 | ) 124 | headermap_deps = [ 125 | headermaps["public_hmap"], 126 | headermaps["private_hmap"], 127 | headermaps["private_angled_hmap"], 128 | ] 129 | swift_deps += headermap_deps 130 | 131 | headermap_copts = headermaps["headermap_copts"] 132 | 133 | if use_defines == None: 134 | use_defines = native.repository_name() == "@" 135 | 136 | if use_defines: 137 | swift_defines = SWIFT_DEFINES 138 | else: 139 | swift_defines = [] 140 | 141 | swift_copts = SHARED_COMPILER_OPTIONS + swift_defines + SHARED_SWIFT_COMPILER_OPTIONS + copts 142 | for copt in headermap_copts: 143 | swift_copts += [ 144 | "-Xcc", 145 | copt, 146 | ] 147 | 148 | swift_library( 149 | name = swift_library_name, 150 | srcs = swift_srcs, 151 | swiftc_inputs = swiftc_inputs, 152 | copts = swift_copts, 153 | features = features, 154 | module_name = module_name, 155 | visibility = visibility, 156 | deps = swift_deps, 157 | generates_header = True, 158 | generated_header_name = module_name + "-Swift.h", 159 | data = data, 160 | ) 161 | 162 | if avoid_deps == None: 163 | avoid_deps = deps 164 | 165 | ios_static_framework( 166 | name = name + "Framework", 167 | deps = [":" + swift_library_name], 168 | avoid_deps = avoid_deps, 169 | bundle_name = module_name, 170 | minimum_os_version = minimum_os_version, 171 | visibility = visibility, 172 | ) 173 | -------------------------------------------------------------------------------- /apple/swiftgen.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2021 LINE Corporation 2 | # 3 | # LINE Corporation licenses this file to you under the Apache License, 4 | # version 2.0 (the "License"); you may not use this file except in compliance 5 | # with the License. You may obtain a copy of the License at: 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | load( 16 | "@build_bazel_rules_apple//apple:utils.bzl", 17 | "group_files_by_directory", 18 | ) 19 | 20 | def _swiftgen_impl(ctx): 21 | srcs = ctx.files.srcs 22 | 23 | inputs = [] 24 | inputs.extend(srcs) 25 | inputs.append(ctx.file.template_file) 26 | output = ctx.outputs.out 27 | 28 | # Figure out the source type from the input files 29 | src_type = "" 30 | for f in srcs: 31 | if ".xcassets/" in f.path: 32 | src_type = "xcassets" 33 | break 34 | if f.path.endswith(".strings") or f.path.endswith(".stringsdict"): 35 | src_type = "strings" 36 | break 37 | 38 | args = ctx.actions.args() 39 | args.add("run") 40 | args.add(src_type) 41 | args.add("--output", output) 42 | args.add("--templatePath", ctx.file.template_file) 43 | 44 | for (key, value) in ctx.attr.template_params.items(): 45 | args.add_joined( 46 | "--param", 47 | (key, value), 48 | join_with = "=", 49 | ) 50 | 51 | # Figure out the last argument that will be passed to the swiftgen command 52 | if src_type == "xcassets": 53 | xcassets_dirs = group_files_by_directory( 54 | srcs, 55 | ["xcassets"], 56 | attr = "srcs", 57 | ).keys() 58 | if len(xcassets_dirs) != 1: 59 | fail("The xcassets_swift's srcs should contain exactly one" + 60 | " directory named *.xcassets.") 61 | args.add(xcassets_dirs[0]) 62 | 63 | elif src_type == "strings": 64 | for f in srcs: 65 | if f.path.endswith(".strings"): 66 | args.add(f) 67 | if f.path.endswith(".stringsdict"): 68 | args.add(f) 69 | 70 | else: 71 | fail("Failed to figure out the resource type from the input files, " + 72 | "or support for it has not been implemented: {}".format(src_type)) 73 | 74 | ctx.actions.run( 75 | inputs = inputs, 76 | outputs = [output], 77 | executable = ctx.executable._swiftgen, 78 | arguments = [args], 79 | mnemonic = "SwiftGen", 80 | ) 81 | 82 | swiftgen = rule( 83 | attrs = { 84 | "srcs": attr.label_list( 85 | allow_files = True, 86 | doc = "The list of input resource files.", 87 | mandatory = True, 88 | ), 89 | "out": attr.output( 90 | doc = "The output Swift filename.", 91 | mandatory = True, 92 | ), 93 | "template_file": attr.label( 94 | allow_single_file = [".stencil"], 95 | doc = "The template file which will be used to generate Swift code.", 96 | mandatory = True, 97 | ), 98 | "template_params": attr.string_dict( 99 | doc = """An optional dictionary of parameters that you want to pass 100 | to the template.""", 101 | ), 102 | "_swiftgen": attr.label( 103 | default = "@SwiftGen//:swiftgen", 104 | allow_files = True, 105 | cfg = "exec", 106 | executable = True, 107 | ), 108 | }, 109 | doc = "Generates Swift code from the given resource files.", 110 | implementation = _swiftgen_impl, 111 | ) 112 | -------------------------------------------------------------------------------- /apple/unique_symbol_file.bzl: -------------------------------------------------------------------------------- 1 | """Implementation of unique_symbol_file rule.""" 2 | 3 | def _string_to_c_symbol(string): 4 | """Converts a string to a valid C symbol 5 | 6 | Args: 7 | string: The string to convert 8 | 9 | Returns: 10 | The converted string 11 | """ 12 | out = "" 13 | for character in string.elems(): 14 | if character.isalnum(): 15 | out += character 16 | else: 17 | out += "_" 18 | return out 19 | 20 | def _label_to_c_symbol(label): 21 | """Converts a label to a valid C symbol 22 | 23 | Args: 24 | label: The label to convert 25 | 26 | Returns: 27 | The converted string 28 | """ 29 | workspace = _string_to_c_symbol(label.workspace_root) 30 | package = _string_to_c_symbol(label.package) 31 | name = _string_to_c_symbol(label.name) 32 | 33 | return "{workspace}{package}_{name}".format( 34 | workspace = workspace, 35 | package = package, 36 | name = name, 37 | ) 38 | 39 | def _unique_symbol_file_impl(ctx): 40 | output = ctx.outputs.out 41 | label = _label_to_c_symbol(ctx.label) 42 | 43 | content = """\ 44 | __attribute__((visibility("default"))) char k{}ExportToSuppressLibToolWarning = 0; 45 | """.format(label) 46 | 47 | ctx.actions.write( 48 | output = output, 49 | content = content, 50 | ) 51 | 52 | unique_symbol_file = rule( 53 | implementation = _unique_symbol_file_impl, 54 | attrs = { 55 | "out": attr.output( 56 | doc = "The name of the generated file.", 57 | mandatory = True, 58 | ), 59 | }, 60 | doc = """ 61 | Creates a source file with a unique symbol in it so that the linker does not 62 | generate warnings at link time for static libraries with no symbols in them. 63 | """, 64 | ) 65 | -------------------------------------------------------------------------------- /apple/utils.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2020 LINE Corporation 2 | # 3 | # LINE Corporation licenses this file to you under the Apache License, 4 | # version 2.0 (the "License"); you may not use this file except in compliance 5 | # with the License. You may obtain a copy of the License at: 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | """Utility functions for rules_apple_line.""" 16 | 17 | def build_file_dirname(repository_name, package_name): 18 | """Returns path to the directory containing BUILD file for this rule, 19 | relative to the source root.""" 20 | dirs = [] 21 | if repository_name != "@": 22 | dirs.append("external") 23 | dirs.append(repository_name.lstrip("@")) 24 | if package_name: 25 | dirs.append(package_name) 26 | return "/".join(dirs) 27 | -------------------------------------------------------------------------------- /apple/zipper_support.bzl: -------------------------------------------------------------------------------- 1 | def swiftmodule_zipper_arg_format(framework, module_name, cpu, extension): 2 | return "{framework}/Modules/{module_name}.swiftmodule/{cpu}.{extension}=%s".format( 3 | framework = framework, 4 | module_name = module_name, 5 | cpu = cpu, 6 | extension = extension, 7 | ) 8 | -------------------------------------------------------------------------------- /docs/BUILD: -------------------------------------------------------------------------------- 1 | load( 2 | "@io_bazel_stardoc//stardoc:stardoc.bzl", 3 | "stardoc", 4 | ) 5 | 6 | stardoc( 7 | name = "docs", 8 | out = "README.md", 9 | input = "doc_hub.bzl", 10 | deps = ["//apple:rules"], 11 | ) 12 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | ## apple_linker_inputs 8 | 9 |
 10 | apple_linker_inputs(name, linker_inputs, linkopts)
 11 | 
12 | 13 | 14 | Provides additional inputs to Apple rules' linker action. 15 | 16 | Unlike C++ rules like `cc_binary` and `cc_test`, Apple rules don't have any 17 | mechanism to allow providing additional inputs to the linker action. This 18 | little rule helps mitigate that. 19 | 20 | To use this rule in your BUILD files, load it with: 21 | 22 | ```starlark 23 | load("@rules_apple_line//apple:apple_linker_inputs.bzl", "apple_linker_inputs") 24 | ``` 25 | 26 | 27 | **ATTRIBUTES** 28 | 29 | 30 | | Name | Description | Type | Mandatory | Default | 31 | | :------------- | :------------- | :------------- | :------------- | :------------- | 32 | | name | A unique name for this target. | Name | required | | 33 | | linker_inputs | Extra files to be passed to the linker action. | List of labels | optional | [] | 34 | | linkopts | Extra flags to be passed to Clang's linker command. Subject to ["Make" variable](https://docs.bazel.build/versions/master/be/make-variables.html) substitution and [label expansion](https://docs.bazel.build/versions/master/be/common-definitions.html#label-expansion). | List of strings | optional | [] | 35 | 36 | 37 | 38 | 39 | ## metal_library 40 | 41 |
 42 | metal_library(name, hdrs, includes, out, srcs)
 43 | 
44 | 45 | Compiles Metal Shading Language source code into a Metal library. 46 | To use this rule in your BUILD files, load it with: 47 | ```starlark 48 | load("@rules_apple_line//apple:metal_library.bzl", "metal_library") 49 | ``` 50 | 51 | 52 | **ATTRIBUTES** 53 | 54 | 55 | | Name | Description | Type | Mandatory | Default | 56 | | :------------- | :------------- | :------------- | :------------- | :------------- | 57 | | name | A unique name for this target. | Name | required | | 58 | | hdrs | A list of headers that you need import to metal source. | List of labels | optional | [] | 59 | | includes | A list of header search paths. | List of strings | optional | [] | 60 | | out | An output .metallib filename. Defaults to default.metallib if unspecified. | String | optional | "default.metallib" | 61 | | srcs | A list of .metal source files that will be compiled into the library. | List of labels | required | | 62 | 63 | 64 | 65 | 66 | ## pkg_dsym 67 | 68 |
 69 | pkg_dsym(name, mode, out, srcs, timestamp)
 70 | 
71 | 72 | Creates a `.dSYM.zip` file given targets that produce dSYMs. 73 | 74 | **ATTRIBUTES** 75 | 76 | 77 | | Name | Description | Type | Mandatory | Default | 78 | | :------------- | :------------- | :------------- | :------------- | :------------- | 79 | | name | A unique name for this target. | Name | required | | 80 | | mode | Set the mode of files added by the srcs attribute. | String | optional | "0555" | 81 | | out | The output filename. | Label | optional | | 82 | | srcs | A list of executable targets that produce dSYM, and/or a list of imported dSYMs if they're prebuilt. | List of labels | optional | [] | 83 | | timestamp | The time to use for every file in the zip, expressed as seconds since Unix Epoch, RFC 3339.

Due to limitations in the format of zip files, values before Jan 1, 1980 will be rounded up and the precision in the zip file is limited to a granularity of 2 seconds. | Integer | optional | 315532800 | 84 | 85 | 86 | 87 | 88 | ## swiftgen 89 | 90 |
 91 | swiftgen(name, out, srcs, template_file, template_params)
 92 | 
93 | 94 | Generates Swift code from the given resource files. 95 | 96 | **ATTRIBUTES** 97 | 98 | 99 | | Name | Description | Type | Mandatory | Default | 100 | | :------------- | :------------- | :------------- | :------------- | :------------- | 101 | | name | A unique name for this target. | Name | required | | 102 | | out | The output Swift filename. | Label | required | | 103 | | srcs | The list of input resource files. | List of labels | required | | 104 | | template_file | The template file which will be used to generate Swift code. | Label | required | | 105 | | template_params | An optional dictionary of parameters that you want to pass to the template. | Dictionary: String -> String | optional | {} | 106 | 107 | 108 | 109 | 110 | ## apple_library 111 | 112 |
113 | apple_library(kwargs)
114 | 
115 | 116 | Compiles and links Objective-C and Swift code into a static library. 117 | 118 | To use this rule in your BUILD files, load it with: 119 | 120 | ```starlark 121 | load("@rules_apple_line//apple:apple_library.bzl", "apple_library") 122 | ``` 123 | 124 | See [mixed_static_framework](#mixed_static_framework) for the documentation 125 | of each attribute. 126 | 127 | **PARAMETERS** 128 | 129 | 130 | | Name | Description | Default Value | 131 | | :------------- | :------------- | :------------- | 132 | | kwargs |

-

| none | 133 | 134 | 135 | 136 | 137 | ## apple_preprocessed_plist 138 | 139 |
140 | apple_preprocessed_plist(name, src, out, substitutions, kwargs)
141 | 
142 | 143 | 144 | 145 | **PARAMETERS** 146 | 147 | 148 | | Name | Description | Default Value | 149 | | :------------- | :------------- | :------------- | 150 | | name |

-

| none | 151 | | src |

-

| none | 152 | | out |

-

| none | 153 | | substitutions |

-

| none | 154 | | kwargs |

-

| none | 155 | 156 | 157 | 158 | 159 | ## mixed_static_framework 160 | 161 |
162 | mixed_static_framework(name, srcs, non_arc_srcs, hdrs, textual_hdrs, enable_modules, includes,
163 |                        copts, objc_copts, swift_copts, use_defines, swiftc_inputs, objc_deps,
164 |                        swift_deps, avoid_deps, deps, data, umbrella_header, visibility,
165 |                        minimum_os_version, features, kwargs)
166 | 
167 | 168 | Builds and bundles a static framework for Xcode consumption or third-party distribution. 169 | 170 | This supports Swift only targets and mixed language targets. If your target 171 | only contains Objective-C source code, use `objc_static_framework` rule 172 | instead. 173 | 174 | This rule in general is very similar to `build_bazel_rules_apple`'s 175 | `ios_static_framework` rule, with some differences: 176 | 177 | * It supports Swift as well as mixed Objective-C and Swift targets. 178 | * It supports bundling a swift_library target that depend transitively on 179 | any other swift_library targets. By default, it will not link any of 180 | its dependencies into the final framework binary - the same way Xcode 181 | does when it builds frameworks - which means you can prebuild your 182 | dependencies as static frameworks for Xcode consumption. 183 | * It supports header maps out of the box--you don't need to change your 184 | imports to make your code build with Bazel. 185 | * It always collects the Swift generated header and bundles a 186 | `module.modulemap` file. For a mixed language target, the module map 187 | file is an extended module map. 188 | * It bundles `swiftmodule` and `swiftdoc` files (`ios_static_framework` 189 | rule bundles `swiftinterface` instead of `swiftmodule` file). 190 | 191 | This rule uses the native `objc_library` rule and `rules_swift`'s 192 | `swift_library` in its implementation. Even if you're not building a static 193 | framework for Xcode consumption or third-party distribution, this can still 194 | be used as a convenient way to declare a library target that compiles mixed 195 | Objective-C and Swift source code. 196 | 197 | The macro contains 3 underlying rules--given `name` is `Greet`: 198 | 199 | * `Greet_swift`: a `swift_library` target. This target has private 200 | visibility by default, hence it can't be a dependency of any other 201 | target. It should not be used directly. 202 | * `GreetModule`: a `module_map` target. This has the same visibility as 203 | `Greet`. The common use-case is using it in an `objc_library`'s 204 | `copts` attribute to import the generated module map file (e.g. 205 | `-fmodule-map-file=$(execpath //path/to/package:GreetModule)`). This 206 | will be done automatically if the dependent target is also a 207 | `mixed_static_framework` target. 208 | * `Greet`: an `objc_library` target. This is the wrapper library target. 209 | This can be depended on any `objc_library` or `swift_library` target. 210 | 211 | ### Examples 212 | 213 | ```starlark 214 | load("@rules_apple_line//apple:mixed_static_framework.bzl", "mixed_static_framework") 215 | 216 | mixed_static_framework( 217 | name = "Mixed", 218 | srcs = glob([ 219 | "*.m", 220 | "*.swift", 221 | ]), 222 | hdrs = glob(["*.h"]), 223 | ) 224 | ``` 225 | 226 | 227 | **PARAMETERS** 228 | 229 | 230 | | Name | Description | Default Value | 231 | | :------------- | :------------- | :------------- | 232 | | name | A unique name for this target. This will be the name of the library target that the framework depends on. The framework target will be named ${name}Framework. | none | 233 | | srcs | The list of Objective-C and Swift source files to compile. | none | 234 | | non_arc_srcs | The Objective-C source files to compile that do not use ARC. Provide both srcs and non_arc_srcs explicitly if both kinds of source files should be included. | [] | 235 | | hdrs | The list of C, C++, Objective-C, and Objective-C++ header files published by this library to be included by sources in dependent rules. These headers describe the public interface for the library and will be made available for inclusion by sources in this rule or in dependent rules. Headers not meant to be included by a client of this library should be listed in the srcs attribute instead. These will be compiled separately from the source if modules are enabled. | [] | 236 | | textual_hdrs | The list of C, C++, Objective-C, and Objective-C++ files that are included as headers by source files in this rule or by users of this library. Unlike hdrs, these will not be compiled separately from the sources. | [] | 237 | | enable_modules | Enables clang module support (via -fmodules).

Note: This is True by default. Changing this to False might no longer work. This attribute is here because there are still targets which are referencing to it. | True | 238 | | includes | List of header search paths to add to this target and all depending targets. Unlike copts, these flags are added for this rule and every rule that depends on it. (Note: not the rules it depends upon!) Be very careful, since this may have far-reaching effects. When in doubt, add "-iquote" flags to copts instead.

Usage of this is rarely necessary because all headers will be visible to their depended targets with the help of header maps. | [] | 239 | | copts | Additional compiler options that should be passed to clang and swiftc. | [] | 240 | | objc_copts | Additional compiler options that should be passed to clang. | [] | 241 | | swift_copts | Additional compiler options that should be passed to swiftc. | [] | 242 | | use_defines |

-

| None | 243 | | swiftc_inputs | Additional files that are referenced using $(rootpath ...) and $(execpath ...) in attributes that support location expansion (e.g. copts). | [] | 244 | | objc_deps | Dependencies of the underlying objc_library target. | [] | 245 | | swift_deps | Dependencies of the underlying swift_library target. | [] | 246 | | avoid_deps | A list of objc_library and swift_library targets on which this framework depends in order to compile, but the transitive closure of which will not be linked into the framework's binary. By default this is the same as deps, that is none of the depependencies will be linked into the framework's binary. For example, providing an empty list ([]) here will result in a fully static link binary. | None | 247 | | deps | Dependencies of the both objc_library and swift_library targets. | [] | 248 | | data | The list of files needed by this rule at runtime. These will be bundled to the top level directory of the bundling target (.app or .framework). | [] | 249 | | umbrella_header | An optional single .h file to use as the umbrella header for this framework. Usually, this header will have the same name as this target, so that clients can load the header using the #import <MyFramework/MyFramework.h> format. If this attribute is not specified (the common use case), an umbrella header will be generated under the same name as this target. | None | 250 | | visibility | The visibility specifications for this target. | ["//visibility:public"] | 251 | | minimum_os_version | Minimum os version. | "11.0" | 252 | | features | Features of the underlying swift_library target. | [] | 253 | | kwargs | Additional arguments being passed through. | none | 254 | 255 | 256 | 257 | 258 | ## objc_library 259 | 260 |
261 | objc_library(kwargs)
262 | 
263 | 264 | Produces a static library from the given Objective-C source files. 265 | 266 | A drop-in replacement of the native 267 | [objc_library](https://docs.bazel.build/versions/3.2.0/be/objective-c.html#objc_library) 268 | rule, with added supports for header maps and modules. 269 | 270 | To use this rule in your BUILD files, load it with: 271 | 272 | ```starlark 273 | load("@rules_apple_line//apple:objc_library.bzl", "objc_library") 274 | ``` 275 | 276 | See [objc_static_framework](#objc_static_framework) for the documentation 277 | of each attribute. 278 | 279 | **PARAMETERS** 280 | 281 | 282 | | Name | Description | Default Value | 283 | | :------------- | :------------- | :------------- | 284 | | kwargs |

-

| none | 285 | 286 | 287 | 288 | 289 | ## objc_static_framework 290 | 291 |
292 | objc_static_framework(name, srcs, non_arc_srcs, hdrs, archives, deps, avoid_deps, data, use_defines,
293 |                       module_name, textual_hdrs, includes, testonly, enable_modules,
294 |                       minimum_os_version, pch, visibility, umbrella_header, kwargs)
295 | 
296 | 297 | Builds and bundles a Objective-C static framework for Xcode consumption or third-party distribution. 298 | 299 | This rule in general is very similar to `build_bazel_rules_apple`'s 300 | `ios_static_framework` rule, with support for modules and header maps out 301 | of the box--which means you don't need to change your imports to make your 302 | code build with Bazel. Note that, unlike `build_bazel_rules_apple`'s 303 | `ios_static_framework`, by default, it will not link any of its 304 | dependencies into the final framework binary - the same way Xcode does when 305 | it builds frameworks. 306 | 307 | 308 | **PARAMETERS** 309 | 310 | 311 | | Name | Description | Default Value | 312 | | :------------- | :------------- | :------------- | 313 | | name | A unique name for this target. This will be the name of the objc_library target that the framework depends on. The framework target will be named ${name}Framework. | none | 314 | | srcs | The Objective-C source files to compile. | [] | 315 | | non_arc_srcs | The Objective-C source files to compile that do not use ARC. Provide both srcs and non_arc_srcs explicitly if both kinds of source files should be included. | [] | 316 | | hdrs | The list of C, C++, Objective-C, and Objective-C++ header files published by this library to be included by sources in dependent rules. These headers describe the public interface for the library and will be made available for inclusion by sources in this rule or in dependent rules. Headers not meant to be included by a client of this library should be listed in the srcs attribute instead. These will be compiled separately from the source if modules are enabled. | [] | 317 | | archives | The list of .a files provided to Objective-C targets that depend on this target. | [] | 318 | | deps | Dependencies of the objc_library target being compiled. | [] | 319 | | avoid_deps | A list of objc_library and swift_library targets on which this framework depends in order to compile, but you don't want to link to the framework binary. Defaults to deps if not specified. | None | 320 | | data | The list of files needed by this rule at runtime. These will be bundled to the top level directory of the bundling target (.app or .framework). | [] | 321 | | use_defines |

-

| None | 322 | | module_name | The name of the module being built. If not provided, the name is used. | None | 323 | | textual_hdrs | The list of C, C++, Objective-C, and Objective-C++ files that are included as headers by source files in this rule or by users of this library. Unlike hdrs, these will not be compiled separately from the sources. | [] | 324 | | includes | List of header search paths to add to this target and all depending targets. Unlike copts, these flags are added for this rule and every rule that depends on it. (Note: not the rules it depends upon!) Be very careful, since this may have far-reaching effects. When in doubt, add "-iquote" flags to copts instead. | [] | 325 | | testonly | If True, only testonly targets (such as tests) can depend on the objc_library target. The default is False. | False | 326 | | enable_modules | Enables clang module support (via -fmodules). Setting this to True will allow you to @import system headers and other targets). | False | 327 | | minimum_os_version | The minimum OS version supported by the framework. | "11.0" | 328 | | pch | Header file to prepend to every source file being compiled (both arc and non-arc). Use of pch files is actively discouraged in BUILD files, and this should be considered deprecated. Since pch files are not actually precompiled this is not a build-speed enhancement, and instead is just a global dependency. From a build efficiency point of view you are actually better including what you need directly in your sources where you need it. | None | 329 | | visibility | The visibility specifications for this target. | ["//visibility:public"] | 330 | | umbrella_header | An optional single .h file to use as the umbrella header for this framework. Usually, this header will have the same name as this target, so that clients can load the header using the #import <MyFramework/MyFramework.h> format. If this attribute is not specified (the common use case), an umbrella header will be generated under the same name as this target. | None | 331 | | kwargs | Additional arguments being passed through to the underlying objc_library rule. | none | 332 | 333 | 334 | 335 | 336 | ## swift_library 337 | 338 |
339 | swift_library(kwargs)
340 | 
341 | 342 | Compiles and links Swift code into a static library and Swift module. 343 | 344 | A drop-in replacement of the official 345 | [swift_library](https://github.com/bazelbuild/rules_swift/blob/master/doc/rules.md#swift_library) 346 | rule, with added supports for header maps, and better integration with other 347 | rules in this repository. 348 | 349 | To use this rule in your BUILD files, load it with: 350 | 351 | ```starlark 352 | load("@rules_apple_line//apple:objc_library.bzl", "objc_library") 353 | ``` 354 | 355 | See [swift_static_framework](#swift_static_framework) for the documentation 356 | of each attribute. 357 | 358 | **PARAMETERS** 359 | 360 | 361 | | Name | Description | Default Value | 362 | | :------------- | :------------- | :------------- | 363 | | kwargs |

-

| none | 364 | 365 | 366 | 367 | 368 | ## swift_static_framework 369 | 370 |
371 | swift_static_framework(name, srcs, copts, use_defines, swiftc_inputs, deps, avoid_deps, data,
372 |                        visibility, minimum_os_version, features, kwargs)
373 | 
374 | 375 | Builds and bundles a Swift static framework for Xcode consumption or third-party distribution. 376 | 377 | This rule in general is very similar to `build_bazel_rules_apple`'s 378 | `ios_static_framework` rule, with some differences: 379 | 380 | * It supports bundling a swift_library target that depend transitively on 381 | any other swift_library targets. By default, it will not link any of 382 | its dependencies into the final framework binary - the same way Xcode 383 | does when it builds frameworks - which means you can prebuild your 384 | dependencies as static frameworks for Xcode consumption. 385 | * It supports header maps out of the box--you don't need to change your 386 | imports to make your code build with Bazel. 387 | * It always collects the Swift generated header and bundles a 388 | `module.modulemap` file. 389 | * It bundles `swiftmodule` and `swiftdoc` files (`ios_static_framework` 390 | rule bundles `swiftinterface` instead of `swiftmodule` file). 391 | 392 | Under the hood, this uses an `objc_library` target to wrap a 393 | `swift_library` target -- so by a sense, it's still a mixed Obj-C and Swift 394 | target - to make use of `objc_library`'s configuration transition. 395 | 396 | ### Examples 397 | 398 | ```starlark 399 | load("@rules_apple_line//apple:swift_static_framework.bzl", "swift_static_framework") 400 | 401 | swift_static_framework( 402 | name = "MyLibrary", 403 | srcs = glob(["**/*.swift"]), 404 | ) 405 | ``` 406 | 407 | 408 | **PARAMETERS** 409 | 410 | 411 | | Name | Description | Default Value | 412 | | :------------- | :------------- | :------------- | 413 | | name | A unique name for this target. This will be the name of the library target that the framework depends on. The framework target will be named ${name}Framework. | none | 414 | | srcs | The list of Swift source files to compile. | none | 415 | | copts | Additional compiler options that should be passed to swiftc. | [] | 416 | | use_defines |

-

| None | 417 | | swiftc_inputs | Additional files that are referenced using $(rootpath ...) and $(execpath ...) in attributes that support location expansion (e.g. copts). | [] | 418 | | deps | A list of targets that are dependencies of the target being built. Note that, by default, none of these and all of their transitive dependencies will be linked into the final binary when building the ${name}Framework target. | [] | 419 | | avoid_deps | A list of objc_library and swift_library targets on which this framework depends in order to compile, but the transitive closure of which will not be linked into the framework's binary. By default this is the same as deps, that is none of the depependencies will be linked into the framework's binary. For example, providing an empty list ([]) here will result in a fully static link binary. | None | 420 | | data | The list of files needed by this rule at runtime. These will be bundled to the top level directory of the bundling target (.app or .framework). | [] | 421 | | visibility | The visibility specifications for this target. | ["//visibility:public"] | 422 | | minimum_os_version |

-

| "11.0" | 423 | | features | Features of the underlying swift_library target. | [] | 424 | | kwargs | Additional arguments being passed through. | none | 425 | 426 | 427 | -------------------------------------------------------------------------------- /docs/doc_hub.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2020 LINE Corporation 2 | # 3 | # LINE Corporation licenses this file to you under the Apache License, 4 | # version 2.0 (the "License"); you may not use this file except in compliance 5 | # with the License. You may obtain a copy of the License at: 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | load("//apple:apple_library.bzl", _apple_library = "apple_library") 16 | load("//apple:apple_linker_inputs.bzl", _apple_linker_inputs = "apple_linker_inputs") 17 | load("//apple:apple_preprocessed_plist.bzl", _apple_preprocessed_plist = "apple_preprocessed_plist") 18 | load("//apple:metal_library.bzl", _metal_library = "metal_library") 19 | load("//apple:mixed_static_framework.bzl", _mixed_static_framework = "mixed_static_framework") 20 | load("//apple:objc_library.bzl", _objc_library = "objc_library") 21 | load("//apple:objc_static_framework.bzl", _objc_static_framework = "objc_static_framework") 22 | load("//apple:pkg_dsym.bzl", _pkg_dsym = "pkg_dsym") 23 | load("//apple:swift_library.bzl", _swift_library = "swift_library") 24 | load("//apple:swift_static_framework.bzl", _swift_static_framework = "swift_static_framework") 25 | load("//apple:swiftgen.bzl", _swiftgen = "swiftgen") 26 | 27 | # No need for any implementation here. The rules need only be loaded for the 28 | # documentation generation purpose. 29 | 30 | # This aliasing isn't mentioned in the documentation, but the `stardoc` rule is 31 | # broken without it. 32 | apple_library = _apple_library 33 | apple_linker_inputs = _apple_linker_inputs 34 | apple_preprocessed_plist = _apple_preprocessed_plist 35 | metal_library = _metal_library 36 | mixed_static_framework = _mixed_static_framework 37 | objc_library = _objc_library 38 | objc_static_framework = _objc_static_framework 39 | pkg_dsym = _pkg_dsym 40 | swift_library = _swift_library 41 | swift_static_framework = _swift_static_framework 42 | swiftgen = _swiftgen 43 | -------------------------------------------------------------------------------- /examples/ios/App/BUILD: -------------------------------------------------------------------------------- 1 | load("@build_bazel_rules_apple//apple:ios.bzl", "ios_application") 2 | load("@build_bazel_rules_apple//apple:versioning.bzl", "apple_bundle_version") 3 | load( 4 | "//examples/ios/App/Sources:constants.bzl", 5 | "APP_EXECUTABLE_NAME", 6 | "APP_IDENTIFIER", 7 | "APP_VERSION", 8 | "DEFAULT_MINIMUM_OS_VERSION", 9 | ) 10 | load("//apple:pkg_dsym.bzl", "pkg_dsym") 11 | 12 | ios_application( 13 | name = "App", 14 | app_icons = ["//examples/ios/App/Sources:AppIcon"], 15 | bundle_id = select(APP_IDENTIFIER), 16 | executable_name = select(APP_EXECUTABLE_NAME), 17 | extensions = [ 18 | "//examples/ios/App/ShareExtension:ShareExtension_appex", 19 | ], 20 | families = [ 21 | "iphone", 22 | "ipad", 23 | ], 24 | infoplists = ["//examples/ios/App/Sources:PreprocessedInfoPlist"], 25 | linkopts = select({ 26 | "//examples/ios/App/Configuration:Debug": [], 27 | # Speed up link time of the app. The exported symbol list is only 28 | # needed for an app if you're using that app as the bundle loader in tests. 29 | "//conditions:default": [ 30 | "-exported_symbols_list", 31 | "/dev/null", 32 | ], 33 | }), 34 | minimum_os_version = DEFAULT_MINIMUM_OS_VERSION, 35 | version = ":version", 36 | visibility = ["//visibility:public"], 37 | watch_application = "//examples/ios/App/WatchKitApp", 38 | deps = [ 39 | "//examples/ios/App/Sources:Main", 40 | "@lld//:lld_linkopts", 41 | ], 42 | ) 43 | 44 | apple_bundle_version( 45 | name = "version", 46 | build_label_pattern = "{timestamp_version}", 47 | build_version = "{timestamp_version}", 48 | capture_groups = { 49 | "timestamp_version": ".*", 50 | }, 51 | fallback_build_label = "1980.0101.000000", # Low number so we can't accidentally upload it. 52 | visibility = ["//visibility:public"], 53 | ) 54 | 55 | pkg_dsym( 56 | name = "App_dSYM", 57 | srcs = [ 58 | ":App", 59 | "//examples/ios/App/ShareExtension:ShareExtension_appex", 60 | "//examples/ios/App/WatchKitExtension", 61 | ], 62 | out = "App.dSYM.zip", 63 | visibility = ["//visibility:public"], 64 | ) 65 | -------------------------------------------------------------------------------- /examples/ios/App/Configuration/BUILD: -------------------------------------------------------------------------------- 1 | config_setting( 2 | name = "Debug", 3 | values = {"compilation_mode": "dbg"}, 4 | ) 5 | 6 | config_setting( 7 | name = "Release", 8 | values = {"compilation_mode": "opt"}, 9 | ) 10 | -------------------------------------------------------------------------------- /examples/ios/App/README.md: -------------------------------------------------------------------------------- 1 | # Example iOS App 2 | 3 | This example demonstrates how to use the rules in this repository to build a 4 | fully functional mixed source iOS app. 5 | 6 | To build this example, run: 7 | 8 | ``` 9 | bazel build //examples/ios/App 10 | ``` 11 | 12 | To build and run this example on a simulator, run: 13 | 14 | ``` 15 | bazel run //examples/ios/App 16 | ``` 17 | -------------------------------------------------------------------------------- /examples/ios/App/ShareExtension/BUILD: -------------------------------------------------------------------------------- 1 | load("//apple:swift_library.bzl", "swift_library") 2 | load("//apple:apple_preprocessed_plist.bzl", "apple_preprocessed_plist") 3 | load("@build_bazel_rules_apple//apple:ios.bzl", "ios_extension") 4 | load( 5 | "//examples/ios/App/Sources:constants.bzl", 6 | "APP_IDENTIFIER", 7 | "DEFAULT_MINIMUM_OS_VERSION", 8 | "EXTENSION_INFO_PLIST_DICT", 9 | ) 10 | 11 | swift_library( 12 | name = "ShareExtension", 13 | srcs = glob(["**/*.swift"]), 14 | data = glob(["**/*.storyboard"]), 15 | ) 16 | 17 | apple_preprocessed_plist( 18 | name = "PreprocessedInfoPlist", 19 | src = "Info.plist", 20 | out = "Info-Preprocessed.plist", 21 | substitutions = EXTENSION_INFO_PLIST_DICT, 22 | ) 23 | 24 | ios_extension( 25 | name = "ShareExtension_appex", 26 | bundle_id = select(APP_IDENTIFIER) + ".ShareExtension", 27 | bundle_name = "ShareExtension", 28 | families = [ 29 | "iphone", 30 | "ipad", 31 | ], 32 | infoplists = [":PreprocessedInfoPlist"], 33 | minimum_os_version = DEFAULT_MINIMUM_OS_VERSION, 34 | version = "//examples/ios/App:version", 35 | visibility = ["//examples/ios/App:__pkg__"], 36 | deps = [ 37 | ":ShareExtension", 38 | "@lld//:lld_linkopts", 39 | ], 40 | ) 41 | -------------------------------------------------------------------------------- /examples/ios/App/ShareExtension/Base.lproj/MainInterface.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /examples/ios/App/ShareExtension/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleDisplayName 8 | ShareExtension 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleVersion 22 | 1 23 | NSExtension 24 | 25 | NSExtensionAttributes 26 | 27 | NSExtensionActivationRule 28 | TRUEPREDICATE 29 | 30 | NSExtensionMainStoryboard 31 | MainInterface 32 | NSExtensionPointIdentifier 33 | com.apple.share-services 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /examples/ios/App/ShareExtension/ShareViewController.swift: -------------------------------------------------------------------------------- 1 | // Copyright 2020 LINE Corporation 2 | // 3 | // LINE Corporation licenses this file to you under the Apache License, 4 | // version 2.0 (the "License"); you may not use this file except in compliance 5 | // with the License. You may obtain a copy of the License at: 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | // License for the specific language governing permissions and limitations 13 | // under the License. 14 | 15 | import UIKit 16 | import Social 17 | 18 | class ShareViewController: SLComposeServiceViewController { 19 | 20 | override func isContentValid() -> Bool { 21 | return true 22 | } 23 | 24 | override func didSelectPost() { 25 | self.extensionContext!.completeRequest(returningItems: [], completionHandler: nil) 26 | } 27 | 28 | override func configurationItems() -> [Any]! { 29 | return [] 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /examples/ios/App/Sources/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // Copyright 2020 LINE Corporation 2 | // 3 | // LINE Corporation licenses this file to you under the Apache License, 4 | // version 2.0 (the "License"); you may not use this file except in compliance 5 | // with the License. You may obtain a copy of the License at: 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | // License for the specific language governing permissions and limitations 13 | // under the License. 14 | 15 | import UIKit 16 | 17 | @UIApplicationMain 18 | class AppDelegate: UIResponder, UIApplicationDelegate { 19 | var window: UIWindow? 20 | 21 | func application( 22 | _ application: UIApplication, 23 | didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? 24 | ) -> Bool { 25 | window = UIWindow(frame: UIScreen.main.bounds) 26 | window?.rootViewController = ViewController() 27 | window?.makeKeyAndVisible() 28 | 29 | return true 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /examples/ios/App/Sources/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "scale" : "2x", 6 | "size" : "20x20" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "scale" : "3x", 11 | "size" : "20x20" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "scale" : "2x", 16 | "size" : "29x29" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "scale" : "3x", 21 | "size" : "29x29" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "scale" : "2x", 26 | "size" : "40x40" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "scale" : "3x", 31 | "size" : "40x40" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "scale" : "2x", 36 | "size" : "60x60" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "scale" : "3x", 41 | "size" : "60x60" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "scale" : "1x", 46 | "size" : "20x20" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "scale" : "2x", 51 | "size" : "20x20" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "scale" : "1x", 56 | "size" : "29x29" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "scale" : "2x", 61 | "size" : "29x29" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "scale" : "1x", 66 | "size" : "40x40" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "scale" : "2x", 71 | "size" : "40x40" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "scale" : "1x", 76 | "size" : "76x76" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "scale" : "2x", 81 | "size" : "76x76" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "scale" : "2x", 86 | "size" : "83.5x83.5" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "scale" : "1x", 91 | "size" : "1024x1024" 92 | } 93 | ], 94 | "info" : { 95 | "author" : "xcode", 96 | "version" : 1 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /examples/ios/App/Sources/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /examples/ios/App/Sources/BUILD: -------------------------------------------------------------------------------- 1 | load("//apple:apple_preprocessed_plist.bzl", "apple_preprocessed_plist") 2 | load("//apple:apple_library.bzl", "apple_library") 3 | load( 4 | "//examples/ios/App/Sources:constants.bzl", 5 | "INFO_PLIST_DICT", 6 | ) 7 | 8 | apple_library( 9 | name = "Main", 10 | srcs = glob([ 11 | "**/*.swift", 12 | ]), 13 | data = glob([ 14 | "**/*.storyboard", 15 | ]), 16 | deps = [ 17 | "//examples/ios/Mixed", 18 | "//examples/ios/PureObjC", 19 | "//examples/ios/PureSwift", 20 | ], 21 | ) 22 | 23 | apple_preprocessed_plist( 24 | name = "PreprocessedInfoPlist", 25 | src = "Info.plist", 26 | out = "Info-Preprocessed.plist", 27 | substitutions = INFO_PLIST_DICT, 28 | visibility = ["//examples/ios/App:__pkg__"], 29 | ) 30 | 31 | filegroup( 32 | name = "AppIcon", 33 | srcs = glob([":Assets.xcassets/AppIcon.appiconset/**"]), 34 | visibility = ["//visibility:public"], 35 | ) 36 | -------------------------------------------------------------------------------- /examples/ios/App/Sources/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /examples/ios/App/Sources/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /examples/ios/App/Sources/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /examples/ios/App/Sources/ViewController.swift: -------------------------------------------------------------------------------- 1 | // Copyright 2020 LINE Corporation 2 | // 3 | // LINE Corporation licenses this file to you under the Apache License, 4 | // version 2.0 (the "License"); you may not use this file except in compliance 5 | // with the License. You may obtain a copy of the License at: 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | // License for the specific language governing permissions and limitations 13 | // under the License. 14 | 15 | import Mixed 16 | import PureObjC 17 | import PureSwift 18 | import UIKit 19 | 20 | class ViewController: UIViewController { 21 | override func viewDidLoad() { 22 | super.viewDidLoad() 23 | view.backgroundColor = .white 24 | } 25 | 26 | override func viewDidAppear(_ animated: Bool) { 27 | super.viewDidAppear(animated) 28 | 29 | let name = "LINE" 30 | PureObjC.ObjcGreeter.sayHi(name) 31 | PureSwift.SwiftGreeter.sayHi(name: name) 32 | Mixed.MXDObjcGreeter.sayHi(name) 33 | Mixed.SwiftGreeter.sayHi(name: name) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /examples/ios/App/Sources/constants.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2020 LINE Corporation 2 | # 3 | # LINE Corporation licenses this file to you under the Apache License, 4 | # version 2.0 (the "License"); you may not use this file except in compliance 5 | # with the License. You may obtain a copy of the License at: 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | APP_VERSION = "1.0" 16 | 17 | APP_EXECUTABLE_NAME = { 18 | "//conditions:default": "BazelSamples-Beta", 19 | "//examples/ios/App/Configuration:Debug": "BazelSamples-Beta", 20 | "//examples/ios/App/Configuration:Release": "BazelSamples", 21 | } 22 | 23 | APP_IDENTIFIER = { 24 | "//conditions:default": "com.linecorp.BazelSamples.beta", 25 | "//examples/ios/App/Configuration:Debug": "com.linecorp.BazelSamples.beta", 26 | "//examples/ios/App/Configuration:Release": "com.linecorp.BazelSamples", 27 | } 28 | 29 | DEFAULT_MINIMUM_OS_VERSION = "11.0" 30 | 31 | DEFAULT_MINIMUM_WATCHOS_VERSION = "6.0" 32 | 33 | EXTENSION_INFO_PLIST_DICT = { 34 | "APP_IDENTIFIER": APP_IDENTIFIER, 35 | "PRODUCT_BUNDLE_PACKAGE_TYPE": "XPC!", 36 | } 37 | 38 | INFO_PLIST_DICT = { 39 | "APP_IDENTIFIER": APP_IDENTIFIER, 40 | "PRODUCT_BUNDLE_PACKAGE_TYPE": "AAPL", 41 | } 42 | -------------------------------------------------------------------------------- /examples/ios/App/WatchKitApp/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "watch", 5 | "role" : "notificationCenter", 6 | "scale" : "2x", 7 | "size" : "24x24", 8 | "subtype" : "38mm" 9 | }, 10 | { 11 | "idiom" : "watch", 12 | "role" : "notificationCenter", 13 | "scale" : "2x", 14 | "size" : "27.5x27.5", 15 | "subtype" : "42mm" 16 | }, 17 | { 18 | "idiom" : "watch", 19 | "role" : "companionSettings", 20 | "scale" : "2x", 21 | "size" : "29x29" 22 | }, 23 | { 24 | "idiom" : "watch", 25 | "role" : "companionSettings", 26 | "scale" : "3x", 27 | "size" : "29x29" 28 | }, 29 | { 30 | "idiom" : "watch", 31 | "role" : "appLauncher", 32 | "scale" : "2x", 33 | "size" : "40x40", 34 | "subtype" : "38mm" 35 | }, 36 | { 37 | "idiom" : "watch", 38 | "role" : "appLauncher", 39 | "scale" : "2x", 40 | "size" : "44x44", 41 | "subtype" : "40mm" 42 | }, 43 | { 44 | "idiom" : "watch", 45 | "role" : "appLauncher", 46 | "scale" : "2x", 47 | "size" : "50x50", 48 | "subtype" : "44mm" 49 | }, 50 | { 51 | "idiom" : "watch", 52 | "role" : "quickLook", 53 | "scale" : "2x", 54 | "size" : "86x86", 55 | "subtype" : "38mm" 56 | }, 57 | { 58 | "idiom" : "watch", 59 | "role" : "quickLook", 60 | "scale" : "2x", 61 | "size" : "98x98", 62 | "subtype" : "42mm" 63 | }, 64 | { 65 | "idiom" : "watch", 66 | "role" : "quickLook", 67 | "scale" : "2x", 68 | "size" : "108x108", 69 | "subtype" : "44mm" 70 | }, 71 | { 72 | "idiom" : "watch-marketing", 73 | "scale" : "1x", 74 | "size" : "1024x1024" 75 | } 76 | ], 77 | "info" : { 78 | "author" : "xcode", 79 | "version" : 1 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /examples/ios/App/WatchKitApp/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /examples/ios/App/WatchKitApp/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2020 LINE Corporation 2 | # 3 | # LINE Corporation licenses this file to you under the Apache License, 4 | # version 2.0 (the "License"); you may not use this file except in compliance 5 | # with the License. You may obtain a copy of the License at: 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | # License for the specific language governing permissions and limitations 13 | # under the License. 14 | 15 | load("@build_bazel_rules_apple//apple:watchos.bzl", "watchos_application") 16 | load("//apple:apple_preprocessed_plist.bzl", "apple_preprocessed_plist") 17 | load( 18 | "//examples/ios/App/Sources:constants.bzl", 19 | "APP_EXECUTABLE_NAME", 20 | "APP_IDENTIFIER", 21 | "DEFAULT_MINIMUM_OS_VERSION", 22 | "DEFAULT_MINIMUM_WATCHOS_VERSION", 23 | "INFO_PLIST_DICT", 24 | ) 25 | 26 | watchos_application( 27 | name = "WatchKitApp", 28 | app_icons = [":AppIcon"], 29 | bundle_id = select(APP_IDENTIFIER) + ".WatchKitApp", 30 | extension = "//examples/ios/App/WatchKitExtension", 31 | infoplists = [":PreprocessedInfoPlist"], 32 | minimum_os_version = DEFAULT_MINIMUM_WATCHOS_VERSION, 33 | resources = [ 34 | "Base.lproj/Interface.storyboard", 35 | ], 36 | version = "//examples/ios/App:version", 37 | visibility = ["//visibility:public"], 38 | ) 39 | 40 | filegroup( 41 | name = "AppIcon", 42 | srcs = glob(["Assets.xcassets/AppIcon.appiconset/**"]), 43 | ) 44 | 45 | apple_preprocessed_plist( 46 | name = "PreprocessedInfoPlist", 47 | src = "Info.plist", 48 | out = "Info-Preprocessed.plist", 49 | substitutions = INFO_PLIST_DICT, 50 | ) 51 | -------------------------------------------------------------------------------- /examples/ios/App/WatchKitApp/Base.lproj/Interface.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/ios/App/WatchKitApp/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleDisplayName 8 | WatchApp WatchKit App 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleVersion 22 | 1 23 | UISupportedInterfaceOrientations 24 | 25 | UIInterfaceOrientationPortrait 26 | UIInterfaceOrientationPortraitUpsideDown 27 | 28 | WKCompanionAppBundleIdentifier 29 | $(APP_IDENTIFIER) 30 | WKWatchKitApp 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /examples/ios/App/WatchKitExtension/Assets.xcassets/Complication.complicationset/Circular.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "watch", 5 | "scale" : "2x", 6 | "screen-width" : "<=145" 7 | }, 8 | { 9 | "idiom" : "watch", 10 | "scale" : "2x", 11 | "screen-width" : ">161" 12 | }, 13 | { 14 | "idiom" : "watch", 15 | "scale" : "2x", 16 | "screen-width" : ">145" 17 | }, 18 | { 19 | "idiom" : "watch", 20 | "scale" : "2x", 21 | "screen-width" : ">183" 22 | } 23 | ], 24 | "info" : { 25 | "author" : "xcode", 26 | "version" : 1 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /examples/ios/App/WatchKitExtension/Assets.xcassets/Complication.complicationset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "assets" : [ 3 | { 4 | "filename" : "Circular.imageset", 5 | "idiom" : "watch", 6 | "role" : "circular" 7 | }, 8 | { 9 | "filename" : "Extra Large.imageset", 10 | "idiom" : "watch", 11 | "role" : "extra-large" 12 | }, 13 | { 14 | "filename" : "Graphic Bezel.imageset", 15 | "idiom" : "watch", 16 | "role" : "graphic-bezel" 17 | }, 18 | { 19 | "filename" : "Graphic Circular.imageset", 20 | "idiom" : "watch", 21 | "role" : "graphic-circular" 22 | }, 23 | { 24 | "filename" : "Graphic Corner.imageset", 25 | "idiom" : "watch", 26 | "role" : "graphic-corner" 27 | }, 28 | { 29 | "filename" : "Graphic Large Rectangular.imageset", 30 | "idiom" : "watch", 31 | "role" : "graphic-large-rectangular" 32 | }, 33 | { 34 | "filename" : "Modular.imageset", 35 | "idiom" : "watch", 36 | "role" : "modular" 37 | }, 38 | { 39 | "filename" : "Utilitarian.imageset", 40 | "idiom" : "watch", 41 | "role" : "utilitarian" 42 | } 43 | ], 44 | "info" : { 45 | "author" : "xcode", 46 | "version" : 1 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /examples/ios/App/WatchKitExtension/Assets.xcassets/Complication.complicationset/Extra Large.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "watch", 5 | "scale" : "2x", 6 | "screen-width" : "<=145" 7 | }, 8 | { 9 | "idiom" : "watch", 10 | "scale" : "2x", 11 | "screen-width" : ">161" 12 | }, 13 | { 14 | "idiom" : "watch", 15 | "scale" : "2x", 16 | "screen-width" : ">145" 17 | }, 18 | { 19 | "idiom" : "watch", 20 | "scale" : "2x", 21 | "screen-width" : ">183" 22 | } 23 | ], 24 | "info" : { 25 | "author" : "xcode", 26 | "version" : 1 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /examples/ios/App/WatchKitExtension/Assets.xcassets/Complication.complicationset/Graphic Bezel.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "watch", 5 | "scale" : "2x", 6 | "screen-width" : "<=145" 7 | }, 8 | { 9 | "idiom" : "watch", 10 | "scale" : "2x", 11 | "screen-width" : ">161" 12 | }, 13 | { 14 | "idiom" : "watch", 15 | "scale" : "2x", 16 | "screen-width" : ">145" 17 | }, 18 | { 19 | "idiom" : "watch", 20 | "scale" : "2x", 21 | "screen-width" : ">183" 22 | } 23 | ], 24 | "info" : { 25 | "author" : "xcode", 26 | "version" : 1 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /examples/ios/App/WatchKitExtension/Assets.xcassets/Complication.complicationset/Graphic Circular.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "watch", 5 | "scale" : "2x", 6 | "screen-width" : "<=145" 7 | }, 8 | { 9 | "idiom" : "watch", 10 | "scale" : "2x", 11 | "screen-width" : ">161" 12 | }, 13 | { 14 | "idiom" : "watch", 15 | "scale" : "2x", 16 | "screen-width" : ">145" 17 | }, 18 | { 19 | "idiom" : "watch", 20 | "scale" : "2x", 21 | "screen-width" : ">183" 22 | } 23 | ], 24 | "info" : { 25 | "author" : "xcode", 26 | "version" : 1 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /examples/ios/App/WatchKitExtension/Assets.xcassets/Complication.complicationset/Graphic Corner.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "watch", 5 | "scale" : "2x", 6 | "screen-width" : "<=145" 7 | }, 8 | { 9 | "idiom" : "watch", 10 | "scale" : "2x", 11 | "screen-width" : ">161" 12 | }, 13 | { 14 | "idiom" : "watch", 15 | "scale" : "2x", 16 | "screen-width" : ">145" 17 | }, 18 | { 19 | "idiom" : "watch", 20 | "scale" : "2x", 21 | "screen-width" : ">183" 22 | } 23 | ], 24 | "info" : { 25 | "author" : "xcode", 26 | "version" : 1 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /examples/ios/App/WatchKitExtension/Assets.xcassets/Complication.complicationset/Graphic Large Rectangular.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "watch", 5 | "scale" : "2x", 6 | "screen-width" : "<=145" 7 | }, 8 | { 9 | "idiom" : "watch", 10 | "scale" : "2x", 11 | "screen-width" : ">161" 12 | }, 13 | { 14 | "idiom" : "watch", 15 | "scale" : "2x", 16 | "screen-width" : ">145" 17 | }, 18 | { 19 | "idiom" : "watch", 20 | "scale" : "2x", 21 | "screen-width" : ">183" 22 | } 23 | ], 24 | "info" : { 25 | "author" : "xcode", 26 | "version" : 1 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /examples/ios/App/WatchKitExtension/Assets.xcassets/Complication.complicationset/Modular.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "watch", 5 | "scale" : "2x", 6 | "screen-width" : "<=145" 7 | }, 8 | { 9 | "idiom" : "watch", 10 | "scale" : "2x", 11 | "screen-width" : ">161" 12 | }, 13 | { 14 | "idiom" : "watch", 15 | "scale" : "2x", 16 | "screen-width" : ">145" 17 | }, 18 | { 19 | "idiom" : "watch", 20 | "scale" : "2x", 21 | "screen-width" : ">183" 22 | } 23 | ], 24 | "info" : { 25 | "author" : "xcode", 26 | "version" : 1 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /examples/ios/App/WatchKitExtension/Assets.xcassets/Complication.complicationset/Utilitarian.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "watch", 5 | "scale" : "2x", 6 | "screen-width" : "<=145" 7 | }, 8 | { 9 | "idiom" : "watch", 10 | "scale" : "2x", 11 | "screen-width" : ">161" 12 | }, 13 | { 14 | "idiom" : "watch", 15 | "scale" : "2x", 16 | "screen-width" : ">145" 17 | }, 18 | { 19 | "idiom" : "watch", 20 | "scale" : "2x", 21 | "screen-width" : ">183" 22 | } 23 | ], 24 | "info" : { 25 | "author" : "xcode", 26 | "version" : 1 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /examples/ios/App/WatchKitExtension/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /examples/ios/App/WatchKitExtension/BUILD: -------------------------------------------------------------------------------- 1 | load("@build_bazel_rules_apple//apple:watchos.bzl", "watchos_extension") 2 | load("//apple:apple_preprocessed_plist.bzl", "apple_preprocessed_plist") 3 | load("//apple:swift_library.bzl", "swift_library") 4 | load( 5 | "//examples/ios/App/Sources:constants.bzl", 6 | "APP_IDENTIFIER", 7 | "DEFAULT_MINIMUM_WATCHOS_VERSION", 8 | "EXTENSION_INFO_PLIST_DICT", 9 | ) 10 | 11 | watchos_extension( 12 | name = "WatchKitExtension", 13 | bundle_id = select(APP_IDENTIFIER) + ".WatchKitApp.WatchKitExtension", 14 | infoplists = [":PreprocessedInfoPlist"], 15 | minimum_os_version = DEFAULT_MINIMUM_WATCHOS_VERSION, 16 | resources = glob([ 17 | "Assets.xcassets/**", 18 | ]), 19 | version = "//examples/ios/App:version", 20 | visibility = ["//visibility:public"], 21 | deps = [ 22 | ":WatchKitExtensionLib", 23 | "@lld//:lld_linkopts", 24 | ], 25 | ) 26 | 27 | swift_library( 28 | name = "WatchKitExtensionLib", 29 | srcs = glob(["**/*.swift"]), 30 | module_name = "WatchKitExtension", 31 | ) 32 | 33 | apple_preprocessed_plist( 34 | name = "PreprocessedInfoPlist", 35 | src = "Info.plist", 36 | out = "Info-Preprocessed.plist", 37 | substitutions = EXTENSION_INFO_PLIST_DICT, 38 | ) 39 | -------------------------------------------------------------------------------- /examples/ios/App/WatchKitExtension/ContentView.swift: -------------------------------------------------------------------------------- 1 | // Copyright 2020 LINE Corporation 2 | // 3 | // LINE Corporation licenses this file to you under the Apache License, 4 | // version 2.0 (the "License"); you may not use this file except in compliance 5 | // with the License. You may obtain a copy of the License at: 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | // License for the specific language governing permissions and limitations 13 | // under the License. 14 | 15 | import SwiftUI 16 | 17 | struct ContentView: View { 18 | var body: some View { 19 | Text("Hello, World!") 20 | } 21 | } 22 | 23 | struct ContentView_Previews: PreviewProvider { 24 | static var previews: some View { 25 | ContentView() 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /examples/ios/App/WatchKitExtension/ExtensionsDelegate.swift: -------------------------------------------------------------------------------- 1 | // Copyright 2020 LINE Corporation 2 | // 3 | // LINE Corporation licenses this file to you under the Apache License, 4 | // version 2.0 (the "License"); you may not use this file except in compliance 5 | // with the License. You may obtain a copy of the License at: 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | // License for the specific language governing permissions and limitations 13 | // under the License. 14 | 15 | import WatchKit 16 | 17 | class ExtensionDelegate: NSObject, WKExtensionDelegate { 18 | func handle(_ backgroundTasks: Set) { 19 | for task in backgroundTasks { 20 | switch task { 21 | case let backgroundTask as WKApplicationRefreshBackgroundTask: 22 | backgroundTask.setTaskCompletedWithSnapshot(false) 23 | case let snapshotTask as WKSnapshotRefreshBackgroundTask: 24 | snapshotTask.setTaskCompleted(restoredDefaultState: true, estimatedSnapshotExpiration: Date.distantFuture, userInfo: nil) 25 | case let connectivityTask as WKWatchConnectivityRefreshBackgroundTask: 26 | connectivityTask.setTaskCompletedWithSnapshot(false) 27 | case let urlSessionTask as WKURLSessionRefreshBackgroundTask: 28 | urlSessionTask.setTaskCompletedWithSnapshot(false) 29 | case let relevantShortcutTask as WKRelevantShortcutRefreshBackgroundTask: 30 | relevantShortcutTask.setTaskCompletedWithSnapshot(false) 31 | case let intentDidRunTask as WKIntentDidRunRefreshBackgroundTask: 32 | intentDidRunTask.setTaskCompletedWithSnapshot(false) 33 | default: 34 | task.setTaskCompletedWithSnapshot(false) 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /examples/ios/App/WatchKitExtension/HostingController.swift: -------------------------------------------------------------------------------- 1 | // Copyright 2020 LINE Corporation 2 | // 3 | // LINE Corporation licenses this file to you under the Apache License, 4 | // version 2.0 (the "License"); you may not use this file except in compliance 5 | // with the License. You may obtain a copy of the License at: 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | // License for the specific language governing permissions and limitations 13 | // under the License. 14 | 15 | import WatchKit 16 | import Foundation 17 | import SwiftUI 18 | 19 | class HostingController: WKHostingController { 20 | override var body: ContentView { 21 | return ContentView() 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /examples/ios/App/WatchKitExtension/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleDisplayName 8 | WatchKitExtension 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleVersion 22 | 1 23 | NSExtension 24 | 25 | NSExtensionAttributes 26 | 27 | WKAppBundleIdentifier 28 | $(APP_IDENTIFIER).WatchKitApp 29 | 30 | NSExtensionPointIdentifier 31 | com.apple.watchkit 32 | 33 | WKExtensionDelegateClassName 34 | $(PRODUCT_NAME).ExtensionDelegate 35 | 36 | 37 | -------------------------------------------------------------------------------- /examples/ios/App/WatchKitExtension/Preview Content/Preview Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /examples/ios/Mixed/BUILD: -------------------------------------------------------------------------------- 1 | load( 2 | "@rules_apple_line//apple:mixed_static_framework.bzl", 3 | "mixed_static_framework", 4 | ) 5 | 6 | mixed_static_framework( 7 | name = "Mixed", 8 | srcs = glob([ 9 | "**/*.m", 10 | "**/*.swift", 11 | ]), 12 | hdrs = glob([ 13 | "**/*.h", 14 | ]), 15 | objc_copts = [ 16 | "-I$(BINDIR)/examples/ios", 17 | ], 18 | ) 19 | -------------------------------------------------------------------------------- /examples/ios/Mixed/MXDObjcGreeter.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 LINE Corporation 2 | // 3 | // LINE Corporation licenses this file to you under the Apache License, 4 | // version 2.0 (the "License"); you may not use this file except in compliance 5 | // with the License. You may obtain a copy of the License at: 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | // License for the specific language governing permissions and limitations 13 | // under the License. 14 | 15 | #import 16 | 17 | @interface MXDObjcGreeter : NSObject 18 | 19 | + (void)sayHi:(NSString *)name; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /examples/ios/Mixed/MXDObjcGreeter.m: -------------------------------------------------------------------------------- 1 | // Copyright 2020 LINE Corporation 2 | // 3 | // LINE Corporation licenses this file to you under the Apache License, 4 | // version 2.0 (the "License"); you may not use this file except in compliance 5 | // with the License. You may obtain a copy of the License at: 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | // License for the specific language governing permissions and limitations 13 | // under the License. 14 | 15 | #import "MXDObjcGreeter.h" 16 | #import 17 | 18 | @implementation MXDObjcGreeter 19 | 20 | + (void)sayHi:(NSString *)name { 21 | printf("Hi %s from ObjC\n", [name UTF8String]); 22 | } 23 | 24 | + (void)callSwift:(NSString *)name { 25 | [SwiftGreeter sayHiWithName:name]; 26 | } 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /examples/ios/Mixed/SwiftGreeter.swift: -------------------------------------------------------------------------------- 1 | // Copyright 2020 LINE Corporation 2 | // 3 | // LINE Corporation licenses this file to you under the Apache License, 4 | // version 2.0 (the "License"); you may not use this file except in compliance 5 | // with the License. You may obtain a copy of the License at: 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | // License for the specific language governing permissions and limitations 13 | // under the License. 14 | 15 | import Foundation 16 | 17 | public class SwiftGreeter: NSObject { 18 | @objc public class func sayHi(name: String) { 19 | print("Hi \(name) from Swift") 20 | } 21 | 22 | @objc public class func callObjC(name: String) { 23 | MXDObjcGreeter.sayHi(name) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /examples/ios/MixedWithPrivateSubmodule/BUILD: -------------------------------------------------------------------------------- 1 | load( 2 | "@rules_apple_line//apple:mixed_static_framework.bzl", 3 | "mixed_static_framework", 4 | ) 5 | load( 6 | "@rules_apple_line//apple:objc_library.bzl", 7 | "objc_library", 8 | ) 9 | 10 | mixed_static_framework( 11 | name = "MixedWithPrivateSubmodule", 12 | srcs = [ 13 | "MXDObjcGreeter.m", 14 | "SwiftGreeter.swift", 15 | ], 16 | hdrs = [ 17 | "MXDObjcGreeter.h", 18 | ], 19 | avoid_deps = [], 20 | objc_copts = [ 21 | "-I$(BINDIR)/examples/ios", 22 | ], 23 | deps = [ 24 | "//examples/ios/MixedWithPrivateSubmodule/submodule", 25 | ], 26 | ) 27 | -------------------------------------------------------------------------------- /examples/ios/MixedWithPrivateSubmodule/MXDObjcGreeter.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 LINE Corporation 2 | // 3 | // LINE Corporation licenses this file to you under the Apache License, 4 | // version 2.0 (the "License"); you may not use this file except in compliance 5 | // with the License. You may obtain a copy of the License at: 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | // License for the specific language governing permissions and limitations 13 | // under the License. 14 | 15 | #import 16 | 17 | @interface MXDObjcGreeter : NSObject 18 | 19 | + (void)sayHi:(NSString *)name; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /examples/ios/MixedWithPrivateSubmodule/MXDObjcGreeter.m: -------------------------------------------------------------------------------- 1 | // Copyright 2020 LINE Corporation 2 | // 3 | // LINE Corporation licenses this file to you under the Apache License, 4 | // version 2.0 (the "License"); you may not use this file except in compliance 5 | // with the License. You may obtain a copy of the License at: 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | // License for the specific language governing permissions and limitations 13 | // under the License. 14 | 15 | #import "MXDObjcGreeter.h" 16 | #import 17 | 18 | @implementation MXDObjcGreeter 19 | 20 | + (void)sayHi:(NSString *)name { 21 | printf("Hi %s from ObjC\n", [name UTF8String]); 22 | } 23 | 24 | + (void)callSwift:(NSString *)name { 25 | [SwiftGreeter sayHiWithName:name]; 26 | } 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /examples/ios/MixedWithPrivateSubmodule/SwiftGreeter.swift: -------------------------------------------------------------------------------- 1 | // Copyright 2020 LINE Corporation 2 | // 3 | // LINE Corporation licenses this file to you under the Apache License, 4 | // version 2.0 (the "License"); you may not use this file except in compliance 5 | // with the License. You may obtain a copy of the License at: 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | // License for the specific language governing permissions and limitations 13 | // under the License. 14 | 15 | import Foundation 16 | @_implementationOnly import submodule 17 | 18 | public class SwiftGreeter: NSObject { 19 | 20 | public var submodule_greeter: submodule.SubModuleSwiftGreeter? = nil 21 | 22 | @objc public class func sayHi(name: String) { 23 | print("Hi \(name) from Swift") 24 | } 25 | 26 | @objc public class func callObjC(name: String) { 27 | MXDObjcGreeter.sayHi(name) 28 | } 29 | @objc public class func callSubModule(name: String) { 30 | submodule.SubModuleSwiftGreeter.sayHi(name: name) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /examples/ios/MixedWithPrivateSubmodule/submodule/BUILD: -------------------------------------------------------------------------------- 1 | load( 2 | "@rules_apple_line//apple:swift_library.bzl", 3 | "swift_library", 4 | ) 5 | 6 | swift_library( 7 | name = "submodule", 8 | srcs = [ 9 | "SubModuleSwiftGreeter.swift", 10 | ], 11 | ) 12 | -------------------------------------------------------------------------------- /examples/ios/MixedWithPrivateSubmodule/submodule/SubModuleSwiftGreeter.swift: -------------------------------------------------------------------------------- 1 | // Copyright 2020 LINE Corporation 2 | // 3 | // LINE Corporation licenses this file to you under the Apache License, 4 | // version 2.0 (the "License"); you may not use this file except in compliance 5 | // with the License. You may obtain a copy of the License at: 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | // License for the specific language governing permissions and limitations 13 | // under the License. 14 | 15 | import Foundation 16 | 17 | public class SubModuleSwiftGreeter: NSObject { 18 | @objc public class func sayHi(name: String) { 19 | print("Hi \(name) from a Swift SubModule") 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /examples/ios/PureObjC/BUILD: -------------------------------------------------------------------------------- 1 | load( 2 | "@rules_apple_line//apple:objc_static_framework.bzl", 3 | "objc_static_framework", 4 | ) 5 | 6 | objc_static_framework( 7 | name = "PureObjC", 8 | srcs = glob([ 9 | "**/*.m", 10 | ]), 11 | hdrs = glob([ 12 | "**/*.h", 13 | ]), 14 | ) 15 | -------------------------------------------------------------------------------- /examples/ios/PureObjC/ObjcGreeter.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 LINE Corporation 2 | // 3 | // LINE Corporation licenses this file to you under the Apache License, 4 | // version 2.0 (the "License"); you may not use this file except in compliance 5 | // with the License. You may obtain a copy of the License at: 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | // License for the specific language governing permissions and limitations 13 | // under the License. 14 | 15 | #import 16 | 17 | @interface ObjcGreeter : NSObject 18 | 19 | + (void)sayHi:(NSString *)name; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /examples/ios/PureObjC/ObjcGreeter.m: -------------------------------------------------------------------------------- 1 | // Copyright 2020 LINE Corporation 2 | // 3 | // LINE Corporation licenses this file to you under the Apache License, 4 | // version 2.0 (the "License"); you may not use this file except in compliance 5 | // with the License. You may obtain a copy of the License at: 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | // License for the specific language governing permissions and limitations 13 | // under the License. 14 | 15 | #import "ObjcGreeter.h" 16 | 17 | @implementation ObjcGreeter 18 | 19 | + (void)sayHi:(NSString *)name { 20 | printf("Hi %s from ObjC\n", [name UTF8String]); 21 | } 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /examples/ios/PureSwift/BUILD: -------------------------------------------------------------------------------- 1 | load( 2 | "@rules_apple_line//apple:swift_static_framework.bzl", 3 | "swift_static_framework", 4 | ) 5 | 6 | swift_static_framework( 7 | name = "PureSwift", 8 | srcs = glob([ 9 | "**/*.swift", 10 | ]), 11 | ) 12 | -------------------------------------------------------------------------------- /examples/ios/PureSwift/SwiftGreeter.swift: -------------------------------------------------------------------------------- 1 | // Copyright 2020 LINE Corporation 2 | // 3 | // LINE Corporation licenses this file to you under the Apache License, 4 | // version 2.0 (the "License"); you may not use this file except in compliance 5 | // with the License. You may obtain a copy of the License at: 6 | // 7 | // https://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | // License for the specific language governing permissions and limitations 13 | // under the License. 14 | 15 | public struct SwiftGreeter { 16 | public static func sayHi(name: String) { 17 | print("Hi \(name) from Swift") 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /test/BUILD: -------------------------------------------------------------------------------- 1 | load("@bazel_skylib//rules:build_test.bzl", "build_test") 2 | 3 | build_test( 4 | name = "examples_build_test", 5 | targets = [ 6 | "//examples/ios/App", 7 | "//examples/ios/Mixed:MixedFramework", 8 | "//examples/ios/PureObjC:PureObjCFramework", 9 | "//examples/ios/PureSwift:PureSwiftFramework", 10 | ], 11 | ) 12 | 13 | build_test( 14 | name = "pkg_dsym_build_test", 15 | tags = ["manual"], 16 | targets = [ 17 | "//examples/ios/App:App_dSYM", 18 | ], 19 | ) 20 | 21 | build_test( 22 | name = "third_party_build_test", 23 | targets = [ 24 | "@CardIO//:CardIOFramework", 25 | "@GoogleAnalytics//:GoogleAnalyticsFramework", 26 | "@OHHTTPStubs//:OHHTTPStubsFramework", 27 | "@facebook_ios_sdk//:FBSDKCoreKitFramework", 28 | "@facebook_ios_sdk//:FBSDKLoginKitFramework", 29 | "@FLEX//:FLEXFramework", 30 | ], 31 | ) 32 | -------------------------------------------------------------------------------- /third_party/BUILD: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/line/rules_apple_line/63f50b29616e7a439c47a140cadd59c3ccf4066f/third_party/BUILD -------------------------------------------------------------------------------- /third_party/CardIO.BUILD: -------------------------------------------------------------------------------- 1 | load( 2 | "@rules_apple_line//apple:objc_static_framework.bzl", 3 | "objc_static_framework", 4 | ) 5 | 6 | objc_static_framework( 7 | name = "CardIO", 8 | hdrs = glob(["CardIO/*.h"]), 9 | archives = glob(["CardIO/*.a"]), 10 | umbrella_header = "CardIO/CardIO.h", 11 | ) 12 | -------------------------------------------------------------------------------- /third_party/Commander.BUILD: -------------------------------------------------------------------------------- 1 | load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library") 2 | 3 | swift_library( 4 | name = "Commander", 5 | srcs = glob(["Sources/Commander/*.swift"]), 6 | copts = ["-suppress-warnings"], 7 | visibility = ["//visibility:public"], 8 | ) 9 | -------------------------------------------------------------------------------- /third_party/FLEX.BUILD: -------------------------------------------------------------------------------- 1 | load( 2 | "@rules_apple_line//apple:objc_static_framework.bzl", 3 | "objc_static_framework", 4 | ) 5 | 6 | _PUBLIC_HEADERS = glob( 7 | [ 8 | "Classes/*.h", 9 | "Classes/Manager/*.h", 10 | "Classes/Toolbar/*.h", 11 | "Classes/GlobalStateExplorers/Globals/FLEXGlobalsEntry.h", 12 | "Classes/Core/**/*.h", 13 | "Classes/Utility/Runtime/Objc/**/*.h", 14 | "Classes/ObjectExplorers/**/*.h", 15 | "Classes/Editing/**/*.h", 16 | "Classes/Utility/FLEXMacros.h", 17 | "Classes/Utility/Categories/*.h", 18 | "Classes/Utility/FLEXAlert.h", 19 | "Classes/Utility/FLEXResources.h", 20 | ], 21 | exclude = ["Classes/FLEX.h"], 22 | ) 23 | 24 | objc_static_framework( 25 | name = "FLEX", 26 | srcs = glob( 27 | [ 28 | "Classes/**/*.c", 29 | "Classes/**/*.h", 30 | "Classes/**/*.m", 31 | "Classes/**/*.mm", 32 | ], 33 | exclude = _PUBLIC_HEADERS, 34 | ), 35 | hdrs = _PUBLIC_HEADERS, 36 | umbrella_header = "Classes/FLEX.h", 37 | ) 38 | -------------------------------------------------------------------------------- /third_party/GoogleAnalytics.BUILD: -------------------------------------------------------------------------------- 1 | load( 2 | "@rules_apple_line//apple:objc_static_framework.bzl", 3 | "objc_static_framework", 4 | ) 5 | 6 | objc_static_framework( 7 | name = "GoogleAnalytics", 8 | hdrs = glob(["Sources/*.h"]), 9 | archives = glob(["Libraries/*.a"]), 10 | sdk_dylibs = [ 11 | "libsqlite3", 12 | "libz", 13 | ], 14 | ) 15 | -------------------------------------------------------------------------------- /third_party/Kanna.BUILD: -------------------------------------------------------------------------------- 1 | load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library") 2 | 3 | swift_library( 4 | name = "Kanna", 5 | srcs = glob(["Sources/Kanna/**/*.swift"]), 6 | visibility = ["//visibility:public"], 7 | ) 8 | -------------------------------------------------------------------------------- /third_party/OHHTTPStubs.BUILD: -------------------------------------------------------------------------------- 1 | load( 2 | "@rules_apple_line//apple:mixed_static_framework.bzl", 3 | "mixed_static_framework", 4 | ) 5 | 6 | _PUBLIC_HEADERS = glob(["Sources/OHHTTPStubs/include/*.h"]) 7 | 8 | mixed_static_framework( 9 | name = "OHHTTPStubs", 10 | srcs = glob( 11 | [ 12 | "Sources/**/*.h", 13 | "Sources/**/*.m", 14 | "Sources/**/*.swift", 15 | ], 16 | exclude = _PUBLIC_HEADERS, 17 | ), 18 | hdrs = _PUBLIC_HEADERS, 19 | umbrella_header = "Sources/OHHTTPStubs/include/HTTPStubs.h", 20 | ) 21 | -------------------------------------------------------------------------------- /third_party/PathKit.BUILD: -------------------------------------------------------------------------------- 1 | load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library") 2 | 3 | swift_library( 4 | name = "PathKit", 5 | srcs = glob(["Sources/**/*.swift"]), 6 | visibility = ["//visibility:public"], 7 | ) 8 | -------------------------------------------------------------------------------- /third_party/Stencil.BUILD: -------------------------------------------------------------------------------- 1 | load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library") 2 | 3 | swift_library( 4 | name = "Stencil", 5 | srcs = glob(["Sources/**/*.swift"]), 6 | visibility = ["//visibility:public"], 7 | deps = ["@PathKit"], 8 | ) 9 | -------------------------------------------------------------------------------- /third_party/StencilSwiftKit.BUILD: -------------------------------------------------------------------------------- 1 | load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library") 2 | 3 | swift_library( 4 | name = "StencilSwiftKit", 5 | srcs = glob(["Sources/StencilSwiftKit/**/*.swift"]), 6 | visibility = ["//visibility:public"], 7 | deps = ["@Stencil"], 8 | ) 9 | -------------------------------------------------------------------------------- /third_party/SwiftGen.BUILD: -------------------------------------------------------------------------------- 1 | load("@build_bazel_rules_swift//swift:swift.bzl", "swift_binary", "swift_library") 2 | 3 | swift_library( 4 | name = "SwiftGenKit", 5 | srcs = glob(["Sources/SwiftGenKit/**/*.swift"]), 6 | deps = [ 7 | "@Kanna", 8 | "@PathKit", 9 | "@Yams", 10 | ], 11 | ) 12 | 13 | swift_binary( 14 | name = "swiftgen", 15 | srcs = glob(["Sources/SwiftGen/**/*.swift"]), 16 | visibility = ["//visibility:public"], 17 | deps = [ 18 | ":SwiftGenKit", 19 | "@Commander", 20 | "@StencilSwiftKit", 21 | ], 22 | ) 23 | -------------------------------------------------------------------------------- /third_party/Yams.BUILD: -------------------------------------------------------------------------------- 1 | load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library") 2 | 3 | swift_library( 4 | name = "Yams", 5 | srcs = glob(["Sources/Yams/**/*.swift"]), 6 | copts = [ 7 | "-suppress-warnings", 8 | "-DSWIFT_PACKAGE", 9 | ], 10 | visibility = ["//visibility:public"], 11 | deps = [":CYams"], 12 | ) 13 | 14 | objc_library( 15 | name = "CYams", 16 | srcs = glob(["Sources/CYaml/src/*"]), 17 | hdrs = glob(["Sources/CYaml/include/*"]), 18 | copts = [ 19 | "-iquote", 20 | "external/Yams/Sources/CYaml/include", 21 | ], 22 | module_map = "Sources/CYaml/include/module.modulemap", 23 | ) 24 | -------------------------------------------------------------------------------- /third_party/facebook-ios-sdk.BUILD: -------------------------------------------------------------------------------- 1 | load( 2 | "@rules_apple_line//apple:objc_static_framework.bzl", 3 | "objc_static_framework", 4 | ) 5 | 6 | objc_static_framework( 7 | name = "FBSDKCoreKit", 8 | srcs = glob( 9 | [ 10 | "FBSDKCoreKit/FBSDKCoreKit/**/*.m", 11 | "FBSDKCoreKit/FBSDKCoreKit/AppLink/Internal/**/*.h", 12 | ], 13 | exclude = glob([ 14 | # From the podspec 15 | "FBSDKCoreKit/FBSDKCoreKit/FBSDKDeviceButton.*", 16 | "FBSDKCoreKit/FBSDKCoreKit/FBSDKDeviceViewControllerBase.*", 17 | "FBSDKCoreKit/FBSDKCoreKit/Internal/Device/**/*", 18 | # Non ARC code 19 | "FBSDKCoreKit/FBSDKCoreKit/Internal_NoARC/FBSDKDynamicFrameworkLoader.m", 20 | ]), 21 | ), 22 | hdrs = glob([ 23 | "FBSDKCoreKit/FBSDKCoreKit/*.h", 24 | "FBSDKCoreKit/FBSDKCoreKit/AppEvents/**/*.h", 25 | "FBSDKCoreKit/FBSDKCoreKit/AppLink/*.h", 26 | "FBSDKCoreKit/FBSDKCoreKit/Basics/**/*.h", 27 | "FBSDKCoreKit/FBSDKCoreKit/Internal/**/*.h", 28 | ]), 29 | non_arc_srcs = [ 30 | "FBSDKCoreKit/FBSDKCoreKit/Internal_NoARC/FBSDKDynamicFrameworkLoader.m", 31 | ], 32 | umbrella_header = "FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit.h", 33 | ) 34 | 35 | objc_static_framework( 36 | name = "FBSDKLoginKit", 37 | srcs = glob([ 38 | "FBSDKLoginKit/FBSDKLoginKit/**/*.m", 39 | "FBSDKLoginKit/FBSDKLoginKit/Internal/**/*.h", 40 | ]), 41 | hdrs = glob([ 42 | "FBSDKLoginKit/FBSDKLoginKit/*.h", 43 | ]), 44 | copts = ["-w"], 45 | umbrella_header = "FBSDKLoginKit/FBSDKLoginKit/FBSDKLoginKit.h", 46 | deps = [ 47 | ":FBSDKCoreKit", 48 | ], 49 | ) 50 | -------------------------------------------------------------------------------- /third_party/lld.BUILD: -------------------------------------------------------------------------------- 1 | load("@rules_apple_line//apple:apple_linker_inputs.bzl", "apple_linker_inputs") 2 | 3 | apple_linker_inputs( 4 | name = "lld_linkopts", 5 | linker_inputs = ["ld64.lld"], 6 | linkopts = [ 7 | "--ld-path=$(execpath ld64.lld)", 8 | ], 9 | visibility = ["//visibility:public"], 10 | ) 11 | -------------------------------------------------------------------------------- /third_party/rules_ios.patch: -------------------------------------------------------------------------------- 1 | diff --git i/rules/hmap.bzl w/rules/hmap.bzl 2 | index 640b833..7aa6440 100644 3 | --- i/rules/hmap.bzl 4 | +++ w/rules/hmap.bzl 5 | @@ -60,12 +60,10 @@ def _make_headermap_impl(ctx): 6 | # Extract propagated headermaps 7 | for hdr_provider in ctx.attr.hdr_providers: 8 | hdrs = [] 9 | - if apple_common.Objc in hdr_provider: 10 | - hdrs.extend(hdr_provider[apple_common.Objc].header.to_list()) 11 | - elif CcInfo in hdr_provider: 12 | + if CcInfo in hdr_provider: 13 | hdrs.extend(hdr_provider[CcInfo].compilation_context.headers.to_list()) 14 | else: 15 | - fail("hdr_provider must contain either 'CcInfo' or 'objc' provider") 16 | + fail("hdr_provider must contain 'CcInfo' provider") 17 | 18 | for hdr in hdrs: 19 | if SwiftInfo in hdr_provider and hdr.path.endswith("-Swift.h"): 20 | @@ -121,9 +119,15 @@ def _make_headermap_impl(ctx): 21 | objc_provider = apple_common.new_objc_provider( 22 | header = depset([ctx.outputs.headermap]), 23 | ) 24 | + compilation_context = cc_common.create_compilation_context( 25 | + headers = depset([ctx.outputs.headermap]), 26 | + ) 27 | + cc_info = CcInfo( 28 | + compilation_context = compilation_context, 29 | + ) 30 | return struct( 31 | files = depset([ctx.outputs.headermap]), 32 | - providers = [objc_provider], 33 | + providers = [objc_provider, cc_info], 34 | objc = objc_provider, 35 | headers = depset([ctx.outputs.headermap]), 36 | ) 37 | -------------------------------------------------------------------------------- /tools/buildifier/BUILD: -------------------------------------------------------------------------------- 1 | load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier") 2 | 3 | buildifier( 4 | name = "buildifier", 5 | ) 6 | -------------------------------------------------------------------------------- /tools/plist_merger/BUILD: -------------------------------------------------------------------------------- 1 | py_binary( 2 | name = "plist_merger", 3 | srcs = ["plist_merger.py"], 4 | srcs_version = "PY3", 5 | # Used by the rule implementations, so it needs to be public; but 6 | # should be considered an implementation detail of the rules and 7 | # not used by other things. 8 | visibility = ["//visibility:public"], 9 | deps = ["@build_bazel_rules_apple//tools/wrapper_common:execute"], 10 | ) 11 | -------------------------------------------------------------------------------- /tools/plist_merger/README.md: -------------------------------------------------------------------------------- 1 | `plist_merger` merges multiple plist files into a single one. 2 | 3 | This tool takes multiple `--input` arguments that point to each input plist 4 | file. When key duplication occurs, the value from the first file wins. 5 | 6 | `plist_merger` only runs on Darwin. 7 | -------------------------------------------------------------------------------- /tools/plist_merger/plist_merger.py: -------------------------------------------------------------------------------- 1 | # Lint as: python3 2 | # Copyright 2020 LINE Corporation 3 | # 4 | # LINE Corporation licenses this file to you under the Apache License, 5 | # version 2.0 (the "License"); you may not use this file except in compliance 6 | # with the License. You may obtain a copy of the License at: 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | # License for the specific language governing permissions and limitations 14 | # under the License. 15 | 16 | """Merges multiple plist files into a single one""" 17 | 18 | import argparse 19 | import sys 20 | from build_bazel_rules_apple.tools.wrapper_common import execute 21 | 22 | 23 | def main(): 24 | parser = argparse.ArgumentParser( 25 | prog="Merges multiple plist files into a single one", 26 | description="""This script takes multiple `--input` arguments that 27 | point to each input plist file. When key duplication 28 | occurs, the value from the first input file wins.""") 29 | parser.add_argument( 30 | "--input", 31 | required=True, 32 | action="append", 33 | help="Path to an input plist, may be used multiple times." 34 | ) 35 | parser.add_argument( 36 | "--output", 37 | required=True, 38 | help="Path to the output plist." 39 | ) 40 | parser.add_argument( 41 | "--output_format", 42 | required=False, 43 | default="xml1", 44 | help="The output plist format, can be one of 'xml1', 'binary1', " 45 | "'json', 'swift', and 'objc'." 46 | ) 47 | 48 | args = parser.parse_args() 49 | 50 | # Merge each plist to the output file 51 | for input in args.input: 52 | cmd = [ 53 | "/usr/libexec/PlistBuddy", 54 | "-c", 55 | "Merge {}".format(input), 56 | args.output] 57 | 58 | _, _, stderr = execute.execute_and_filter_output( 59 | cmd, raise_on_failure=True) 60 | 61 | if stderr: 62 | print(stderr) 63 | 64 | # Convert to a non-XML format if requested 65 | if args.output_format != "xml1": 66 | cmd = [ 67 | "/usr/bin/plutil", 68 | "-convert", 69 | args.output_format, 70 | args.output] 71 | 72 | _, stdout, stderr = execute.execute_and_filter_output( 73 | cmd, raise_on_failure=True) 74 | 75 | if stdout: 76 | print(stdout) 77 | if stderr: 78 | print(stderr) 79 | 80 | 81 | if __name__ == "__main__": 82 | sys.exit(main()) 83 | --------------------------------------------------------------------------------