Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Bazel #190

Merged
merged 1 commit into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# TODO: remove when using Bazel 7 where bzlmod is on by default
common --enable_bzlmod

# Use the apple_support macOS toolchains
common --enable_platform_specific_config
common:macos --apple_crosstool_top=@local_config_apple_cc//:toolchain
common:macos --crosstool_top=@local_config_apple_cc//:toolchain
common:macos --host_crosstool_top=@local_config_apple_cc//:toolchain
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6.4.0
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,11 @@ jobs:
uses: actions/checkout@v3
- name: Build
run: carthage build --no-skip-current --platform iOS --use-xcframeworks --verbose
bazel:
name: Bazel Build
runs-on: macOS-13
steps:
- name: Checkout Repo
uses: actions/checkout@v2
- name: Build
run: bazel build //...
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ Pods/
generated/
.build/
.swiftpm/

# Bazel
bazel-*
101 changes: 101 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
load(
"@build_bazel_rules_apple//apple:ios.bzl",
"ios_framework",
)
load(
"@build_bazel_rules_swift//swift:swift.bzl",
"swift_library",
)

objc_library(
name = "AccessibilitySnapshotCoreObjC.lib",
srcs = glob(
["Sources/AccessibilitySnapshot/Core/ObjC/**/*.m"],
allow_empty = False,
),
hdrs = glob(
["Sources/AccessibilitySnapshot/Core/ObjC/include/**/*.h"],
allow_empty = False,
),
defines = ["BAZEL_PACKAGE"],
module_name = "AccessibilitySnapshotCore_ObjC",
tags = ["manual"],
visibility = ["//visibility:public"],
deps = [],
)

swift_library(
name = "AccessibilitySnapshotCoreSwift.lib",
srcs = glob(
["Sources/AccessibilitySnapshot/Core/Swift/**/*.swift"],
allow_empty = False,
),
defines = ["BAZEL_PACKAGE"],
module_name = "AccessibilitySnapshotCore",
tags = ["manual"],
visibility = ["//visibility:public"],
deps = [":AccessibilitySnapshotCoreObjC.lib"],
)

swift_library(
name = "AccessibilitySnapshot_iOSSnapshotTestCase_Swift.lib",
testonly = True,
srcs = glob(["Sources/AccessibilitySnapshot/iOSSnapshotTestCase/Swift/**/*.swift"]),
defines = ["BAZEL_PACKAGE"],
tags = ["manual"],
visibility = ["//visibility:public"],
deps = [
":AccessibilitySnapshotCoreObjC.lib",
":AccessibilitySnapshotCoreSwift.lib",
"@ios_snapshot_test_case//:iOSSnapshotTestCase",
],
)

objc_library(
name = "AccessibilitySnapshot_iOSSnapshotTestCase_ObjC.lib",
testonly = True,
srcs = glob(
["Sources/AccessibilitySnapshot/iOSSnapshotTestCase/ObjC/**/*.m"],
allow_empty = False,
),
hdrs = glob(
["Sources/AccessibilitySnapshot/iOSSnapshotTestCase/ObjC/include/**/*.h"],
allow_empty = False,
),
defines = ["BAZEL_PACKAGE"],
module_name = "AccessibilitySnapshot",
tags = ["manual"],
visibility = ["//visibility:public"],
deps = [":AccessibilitySnapshot_iOSSnapshotTestCase_Swift.lib"],
)

ios_framework(
name = "AccessibilitySnapshotCore",
bundle_id = "com.squareup.AccessibilitySnapshotCore",
families = [
"iphone",
"ipad",
],
infoplists = ["Sources/Info.plist"],
minimum_os_version = "13.0",
resources = glob(
["Sources/AccessibilitySnapshot/Core/Swift/Assets/**/*"],
allow_empty = False,
),
visibility = ["//visibility:public"],
deps = [":AccessibilitySnapshotCoreSwift.lib"],
)

ios_framework(
name = "AccessibilitySnapshot_iOSSnapshotTestCase",
testonly = True,
bundle_id = "com.squareup.AccessibilitySnapshot",
families = [
"iphone",
"ipad",
],
infoplists = ["Sources/Info.plist"],
minimum_os_version = "13.0",
visibility = ["//visibility:public"],
deps = [":AccessibilitySnapshot_iOSSnapshotTestCase_ObjC.lib"],
)
20 changes: 20 additions & 0 deletions Bazel/0001-Patch-testonly-swift_library.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Luis Padron <lpadron@squareup.com>
Date: Fri, 19 Jan 2024 15:17:39 -0500
Subject: Patch testonly swift_library


diff --git a/BUILD.bazel b/BUILD.bazel
index 0ae5406..42e81b5 100644
--- a/BUILD.bazel
+++ b/BUILD.bazel
@@ -25,5 +25,6 @@ swift_library(
deps = [
":iOSSnapshotTestCaseCore"
],
+ testonly = True,
visibility = ["//visibility:public"]
)
--
2.42.1

Empty file added Bazel/BUILD.bazel
Empty file.
28 changes: 28 additions & 0 deletions Bazel/non_bzlmod_deps.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""Defines extensions and macros for MODULE.bazel"""

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# -- Non-bzlmod versions

IOS_SNAPSHOT_TEST_CASE_VERSION = "57b023c8bb3df361e2fae01532cd066ec0b65d2e"

# -- Module extension

def non_bzlmod_repositories():
"""Defines external dependencies which do not support bzlmod"""

http_archive(
name = "ios_snapshot_test_case",
url = "https://github.com/uber/ios-snapshot-test-case/archive/%s.zip" % IOS_SNAPSHOT_TEST_CASE_VERSION,
strip_prefix = "ios-snapshot-test-case-%s" % IOS_SNAPSHOT_TEST_CASE_VERSION,
sha256 = "fae7ec6bfdc35bb026a2e898295c16240eeb001bed188972ddcc0d7dc388cda3",
patches = ["//Bazel:0001-Patch-testonly-swift_library.patch"],
patch_args = ["-p1"],
)

def _non_bzlmod_deps_impl(_):
non_bzlmod_repositories()

non_bzlmod_deps = module_extension(
implementation = _non_bzlmod_deps_impl,
)
32 changes: 32 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""Defines the Bazel module."""

module(
name = "accessibility_snapshot",
version = "0.0.0",
compatibility_level = 1,
)

bazel_dep(
name = "apple_support",
version = "1.11.1",
)
bazel_dep(
name = "rules_apple",
version = "3.1.1",
repo_name = "build_bazel_rules_apple",
)
bazel_dep(
name = "rules_swift",
version = "1.14.0",
repo_name = "build_bazel_rules_swift",
)

# Load non-bzlmod dependencies
non_bzlmod_deps = use_extension("//Bazel:non_bzlmod_deps.bzl", "non_bzlmod_deps")
use_repo(
non_bzlmod_deps,
"ios_snapshot_test_case",
)

apple_cc_configure = use_extension("@apple_support//crosstool:setup.bzl", "apple_cc_configure_extension")
use_repo(apple_cc_configure, "local_config_apple_cc")
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import SnapshotTesting
import UIKit

#if SWIFT_PACKAGE
#if SWIFT_PACKAGE || BAZEL_PACKAGE
import AccessibilitySnapshotCore
import AccessibilitySnapshotCore_ObjC
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import SnapshotTesting
import SwiftUI
import UIKit

#if SWIFT_PACKAGE
#if SWIFT_PACKAGE || BAZEL_PACKAGE
import AccessibilitySnapshotCore
import AccessibilitySnapshotCore_ObjC
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import Foundation

#if SWIFT_PACKAGE
#if SWIFT_PACKAGE || BAZEL_PACKAGE
import AccessibilitySnapshotCore
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import XCTest

#if SWIFT_PACKAGE
#if SWIFT_PACKAGE || BAZEL_PACKAGE
import AccessibilitySnapshotCore
import AccessibilitySnapshotCore_ObjC
import iOSSnapshotTestCase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import XCTest

#if SWIFT_PACKAGE
#if SWIFT_PACKAGE || BAZEL_PACKAGE
import AccessibilitySnapshotCore
import AccessibilitySnapshotCore_ObjC
import iOSSnapshotTestCase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// limitations under the License.
//

#if SWIFT_PACKAGE
#if SWIFT_PACKAGE || BAZEL_PACKAGE
import AccessibilitySnapshotCore
import AccessibilitySnapshotCore_ObjC
import iOSSnapshotTestCase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import SwiftUI

#if SWIFT_PACKAGE
#if SWIFT_PACKAGE || BAZEL_PACKAGE
import AccessibilitySnapshotCore
import iOSSnapshotTestCase
#else
Expand Down
24 changes: 24 additions & 0 deletions Sources/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>
1 change: 1 addition & 0 deletions WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Defines the WORKSPACE when using bzlmod, this should be empty. Use MODULE.bazel instead"""
Loading