From bc02de54fc6bab526373f8eb3c9f5fab4e9bea8d Mon Sep 17 00:00:00 2001 From: Luis Padron Date: Fri, 19 Jan 2024 14:59:04 -0500 Subject: [PATCH] Add support for Bazel --- .bazelrc | 8 ++ .bazelversion | 1 + .github/workflows/ci.yml | 8 ++ .gitignore | 3 + BUILD.bazel | 101 ++++++++++++++++++ Bazel/0001-Patch-testonly-swift_library.patch | 20 ++++ Bazel/BUILD.bazel | 0 Bazel/non_bzlmod_deps.bzl | 28 +++++ MODULE.bazel | 32 ++++++ .../SnapshotTesting+Accessibility.swift | 2 +- .../SnapshotTesting+SwiftUI.swift | 2 +- .../Swift/ErrorMessageFactory.swift | 2 +- .../FBSnapshotTestCase+Accessibility.swift | 2 +- ...pshotTestCase+ImpreciseAccessibility.swift | 2 +- .../FBSnapshotTestCase+ObjCSupport.swift | 2 +- .../Swift/FBSnapshotTestCase+SwiftUI.swift | 2 +- Sources/Info.plist | 24 +++++ WORKSPACE.bzlmod | 1 + 18 files changed, 233 insertions(+), 7 deletions(-) create mode 100644 .bazelrc create mode 100644 .bazelversion create mode 100644 BUILD.bazel create mode 100644 Bazel/0001-Patch-testonly-swift_library.patch create mode 100644 Bazel/BUILD.bazel create mode 100644 Bazel/non_bzlmod_deps.bzl create mode 100644 MODULE.bazel create mode 100644 Sources/Info.plist create mode 100644 WORKSPACE.bzlmod diff --git a/.bazelrc b/.bazelrc new file mode 100644 index 00000000..08658cc6 --- /dev/null +++ b/.bazelrc @@ -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 diff --git a/.bazelversion b/.bazelversion new file mode 100644 index 00000000..19b860c1 --- /dev/null +++ b/.bazelversion @@ -0,0 +1 @@ +6.4.0 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fe7afe6c..146a8785 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 //... diff --git a/.gitignore b/.gitignore index 0ec7ea39..99d86144 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,6 @@ Pods/ generated/ .build/ .swiftpm/ + +# Bazel +bazel-* diff --git a/BUILD.bazel b/BUILD.bazel new file mode 100644 index 00000000..363d26ab --- /dev/null +++ b/BUILD.bazel @@ -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"], +) diff --git a/Bazel/0001-Patch-testonly-swift_library.patch b/Bazel/0001-Patch-testonly-swift_library.patch new file mode 100644 index 00000000..da7fae2f --- /dev/null +++ b/Bazel/0001-Patch-testonly-swift_library.patch @@ -0,0 +1,20 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Luis Padron +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 + diff --git a/Bazel/BUILD.bazel b/Bazel/BUILD.bazel new file mode 100644 index 00000000..e69de29b diff --git a/Bazel/non_bzlmod_deps.bzl b/Bazel/non_bzlmod_deps.bzl new file mode 100644 index 00000000..cde5b2b9 --- /dev/null +++ b/Bazel/non_bzlmod_deps.bzl @@ -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, +) diff --git a/MODULE.bazel b/MODULE.bazel new file mode 100644 index 00000000..4b3db2d8 --- /dev/null +++ b/MODULE.bazel @@ -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") diff --git a/Sources/AccessibilitySnapshot/SnapshotTesting/SnapshotTesting+Accessibility.swift b/Sources/AccessibilitySnapshot/SnapshotTesting/SnapshotTesting+Accessibility.swift index d65c1d9e..39e93de8 100644 --- a/Sources/AccessibilitySnapshot/SnapshotTesting/SnapshotTesting+Accessibility.swift +++ b/Sources/AccessibilitySnapshot/SnapshotTesting/SnapshotTesting+Accessibility.swift @@ -17,7 +17,7 @@ import SnapshotTesting import UIKit -#if SWIFT_PACKAGE +#if SWIFT_PACKAGE || BAZEL_PACKAGE import AccessibilitySnapshotCore import AccessibilitySnapshotCore_ObjC #endif diff --git a/Sources/AccessibilitySnapshot/SnapshotTesting/SnapshotTesting+SwiftUI.swift b/Sources/AccessibilitySnapshot/SnapshotTesting/SnapshotTesting+SwiftUI.swift index 44ac6d53..a3a1caf1 100644 --- a/Sources/AccessibilitySnapshot/SnapshotTesting/SnapshotTesting+SwiftUI.swift +++ b/Sources/AccessibilitySnapshot/SnapshotTesting/SnapshotTesting+SwiftUI.swift @@ -18,7 +18,7 @@ import SnapshotTesting import SwiftUI import UIKit -#if SWIFT_PACKAGE +#if SWIFT_PACKAGE || BAZEL_PACKAGE import AccessibilitySnapshotCore import AccessibilitySnapshotCore_ObjC #endif diff --git a/Sources/AccessibilitySnapshot/iOSSnapshotTestCase/Swift/ErrorMessageFactory.swift b/Sources/AccessibilitySnapshot/iOSSnapshotTestCase/Swift/ErrorMessageFactory.swift index 3777a38a..f0e0e4db 100644 --- a/Sources/AccessibilitySnapshot/iOSSnapshotTestCase/Swift/ErrorMessageFactory.swift +++ b/Sources/AccessibilitySnapshot/iOSSnapshotTestCase/Swift/ErrorMessageFactory.swift @@ -16,7 +16,7 @@ import Foundation -#if SWIFT_PACKAGE +#if SWIFT_PACKAGE || BAZEL_PACKAGE import AccessibilitySnapshotCore #endif diff --git a/Sources/AccessibilitySnapshot/iOSSnapshotTestCase/Swift/FBSnapshotTestCase+Accessibility.swift b/Sources/AccessibilitySnapshot/iOSSnapshotTestCase/Swift/FBSnapshotTestCase+Accessibility.swift index b07868f6..f5dc76c5 100644 --- a/Sources/AccessibilitySnapshot/iOSSnapshotTestCase/Swift/FBSnapshotTestCase+Accessibility.swift +++ b/Sources/AccessibilitySnapshot/iOSSnapshotTestCase/Swift/FBSnapshotTestCase+Accessibility.swift @@ -16,7 +16,7 @@ import XCTest -#if SWIFT_PACKAGE +#if SWIFT_PACKAGE || BAZEL_PACKAGE import AccessibilitySnapshotCore import AccessibilitySnapshotCore_ObjC import iOSSnapshotTestCase diff --git a/Sources/AccessibilitySnapshot/iOSSnapshotTestCase/Swift/FBSnapshotTestCase+ImpreciseAccessibility.swift b/Sources/AccessibilitySnapshot/iOSSnapshotTestCase/Swift/FBSnapshotTestCase+ImpreciseAccessibility.swift index b2bd8d44..973380d8 100644 --- a/Sources/AccessibilitySnapshot/iOSSnapshotTestCase/Swift/FBSnapshotTestCase+ImpreciseAccessibility.swift +++ b/Sources/AccessibilitySnapshot/iOSSnapshotTestCase/Swift/FBSnapshotTestCase+ImpreciseAccessibility.swift @@ -16,7 +16,7 @@ import XCTest -#if SWIFT_PACKAGE +#if SWIFT_PACKAGE || BAZEL_PACKAGE import AccessibilitySnapshotCore import AccessibilitySnapshotCore_ObjC import iOSSnapshotTestCase diff --git a/Sources/AccessibilitySnapshot/iOSSnapshotTestCase/Swift/FBSnapshotTestCase+ObjCSupport.swift b/Sources/AccessibilitySnapshot/iOSSnapshotTestCase/Swift/FBSnapshotTestCase+ObjCSupport.swift index d2e289f1..b21df202 100644 --- a/Sources/AccessibilitySnapshot/iOSSnapshotTestCase/Swift/FBSnapshotTestCase+ObjCSupport.swift +++ b/Sources/AccessibilitySnapshot/iOSSnapshotTestCase/Swift/FBSnapshotTestCase+ObjCSupport.swift @@ -14,7 +14,7 @@ // limitations under the License. // -#if SWIFT_PACKAGE +#if SWIFT_PACKAGE || BAZEL_PACKAGE import AccessibilitySnapshotCore import AccessibilitySnapshotCore_ObjC import iOSSnapshotTestCase diff --git a/Sources/AccessibilitySnapshot/iOSSnapshotTestCase/Swift/FBSnapshotTestCase+SwiftUI.swift b/Sources/AccessibilitySnapshot/iOSSnapshotTestCase/Swift/FBSnapshotTestCase+SwiftUI.swift index 269f04ba..cb831d9c 100644 --- a/Sources/AccessibilitySnapshot/iOSSnapshotTestCase/Swift/FBSnapshotTestCase+SwiftUI.swift +++ b/Sources/AccessibilitySnapshot/iOSSnapshotTestCase/Swift/FBSnapshotTestCase+SwiftUI.swift @@ -16,7 +16,7 @@ import SwiftUI -#if SWIFT_PACKAGE +#if SWIFT_PACKAGE || BAZEL_PACKAGE import AccessibilitySnapshotCore import iOSSnapshotTestCase #else diff --git a/Sources/Info.plist b/Sources/Info.plist new file mode 100644 index 00000000..609619b0 --- /dev/null +++ b/Sources/Info.plist @@ -0,0 +1,24 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1.0 + NSPrincipalClass + + + diff --git a/WORKSPACE.bzlmod b/WORKSPACE.bzlmod new file mode 100644 index 00000000..1fa1775e --- /dev/null +++ b/WORKSPACE.bzlmod @@ -0,0 +1 @@ +"""Defines the WORKSPACE when using bzlmod, this should be empty. Use MODULE.bazel instead"""