Skip to content

Commit

Permalink
Merge pull request #71 from cashapp/entin/bazel
Browse files Browse the repository at this point in the history
Add support for installing via Bazel
  • Loading branch information
NickEntin authored Jan 20, 2024
2 parents fcbc40f + 3c4fafc commit d4cc5b5
Show file tree
Hide file tree
Showing 14 changed files with 206 additions and 0 deletions.
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 @@ -59,3 +59,11 @@ jobs:
run: Scripts/github/prepare-simulators.sh ${{ matrix.platform }}
- name: Build
run: Scripts/build.swift spm ${{ matrix.platform }}
bazel:
name: Bazel
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 @@ -35,3 +35,6 @@ timeline.xctimeline
generated/
.build/
.swiftpm/

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

swift_library(
name = "Stagehand.lib",
srcs = glob(["Sources/Stagehand/**/*.swift"]),
module_name = "Stagehand",
tags = ["manual"],
visibility = ["//visibility:public"],
deps = [],
)

swift_library(
name = "StagehandTestingCore.lib",
testonly = True,
srcs = glob(["Sources/StagehandTesting/Core/**/*.swift"]),
defines = ["BAZEL_PACKAGE"],
module_name = "StagehandTestingCore",
tags = ["manual"],
visibility = ["//visibility:public"],
deps = [":Stagehand.lib"],
)

swift_library(
name = "StagehandTesting_iOSSnapshotTestCase.lib",
testonly = True,
srcs = glob(["Sources/StagehandTesting/iOSSnapshotTestCase/**/*.swift"]),
defines = ["BAZEL_PACKAGE"],
module_name = "StagehandTesting_iOSSnapshotTestCase",
tags = ["manual"],
visibility = ["//visibility:public"],
deps = [
":Stagehand.lib",
":StagehandTestingCore.lib",
"@ios_snapshot_test_case//:iOSSnapshotTestCase",
],
)

ios_framework(
name = "Stagehand",
bundle_id = "com.squareup.Stagehand",
families = [
"iphone",
"ipad",
],
infoplists = ["Sources/Info.plist"],
minimum_os_version = "12.0",
visibility = ["//visibility:public"],
deps = [":Stagehand.lib"],
)

ios_framework(
name = "StagehandTesting_iOSSnapshotTestCase",
testonly = True,
bundle_id = "com.squareup.StagehandTesting",
families = [
"iphone",
"ipad",
],
infoplists = ["Sources/Info.plist"],
minimum_os_version = "12.0",
visibility = ["//visibility:public"],
deps = [":StagehandTesting_iOSSnapshotTestCase.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,
)
29 changes: 29 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module(
name = "stagehand",
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",
)
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")
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>
2 changes: 2 additions & 0 deletions Sources/StagehandTesting/Core/AnimationSnapshotting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
// limitations under the License.
//

import Foundation
import MobileCoreServices
import UIKit

@testable import Stagehand

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
// limitations under the License.
//

#if BAZEL_PACKAGE
@testable import StagehandTestingCore
import iOSSnapshotTestCase
#else
import FBSnapshotTestCase
#endif

@testable import Stagehand

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@
// limitations under the License.
//

#if BAZEL_PACKAGE
@testable import StagehandTestingCore
import iOSSnapshotTestCase
#else
import FBSnapshotTestCase
#endif

import ImageIO

@testable import Stagehand
Expand Down
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"""

0 comments on commit d4cc5b5

Please sign in to comment.