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

iOS: Bazel 6 build updates #262

Merged
merged 35 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
25bfe34
touch ups needed to run all tests through query
hborawski Dec 11, 2023
3bf29c1
try running all tests in circle
hborawski Dec 11, 2023
2cba784
fix indent
hborawski Dec 11, 2023
fbc0ca6
check homebrew path
hborawski Dec 11, 2023
0f5bae2
update openjdk version
hborawski Dec 11, 2023
0447c10
fix resource bundle for reference assets icon catalog
hborawski Dec 12, 2023
1e17870
lower to serial test running, builds are getting interuptted with 2
hborawski Dec 12, 2023
51829e2
prebuild test modules before running tests
hborawski Dec 12, 2023
37b4d54
remove print
hborawski Dec 12, 2023
76ae1ac
try large executor
hborawski Dec 12, 2023
f9d4bd1
Merge remote-tracking branch 'origin/bazel-6' into bazel-6-ios-circle…
hborawski Mar 6, 2024
3fd8d57
update swift package deps
hborawski Mar 7, 2024
b97a63b
fix resource class
hborawski Mar 26, 2024
9c66cba
update xcode/macos
hborawski Mar 26, 2024
05af282
update xcode/macos
hborawski Mar 26, 2024
e56db3a
disable cache temporarily to test cold start build time
hborawski Mar 27, 2024
e80ac9a
clean bazel and cache to really test cold start
hborawski Mar 27, 2024
3c568ec
clean bazel and cache to really test cold start
hborawski Mar 27, 2024
0f421ab
log out size of cache before / after clearing
hborawski Mar 27, 2024
33c7417
reenable cache, speed improvements seem fine with no cache
hborawski Mar 28, 2024
275f44b
fix some tests that had deps removed during conversion
hborawski Mar 28, 2024
7a8e99f
update viewinspector to latest
hborawski Mar 29, 2024
4f92efe
remove applitools from UITests
hborawski Mar 29, 2024
49a37c7
fix flaky test
hborawski Mar 29, 2024
a564af2
rewrite assertPublished again
hborawski Mar 29, 2024
82939d7
increase timeout
hborawski Apr 1, 2024
cc98427
tweak input asset so we can still test it all
hborawski Apr 1, 2024
58ee9b1
update iOS contrib docs, remove old docs
hborawski Apr 1, 2024
73e407e
remove Inspectable conformance as it was deprecated
hborawski Apr 1, 2024
e1483c5
change syntax for building all except ios
hborawski Apr 1, 2024
035381c
bump rules_swift
hborawski Apr 2, 2024
9ac29b6
try storing coverage artifacts
hborawski Apr 2, 2024
069906b
fix path
hborawski Apr 2, 2024
6b172c7
install lcov with brew so we have genhtml
hborawski Apr 2, 2024
6f3a4fa
zip up html coverage output
hborawski Apr 2, 2024
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
5 changes: 0 additions & 5 deletions .bazelignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ profile
DerivedData
*.hmap
*.ipa
xcode/Pods/
CoverageData/
bep.json
xcui.json
ios/*/*/Resources/**/*.js

core/make-flow/node_modules
core/types/node_modules
Expand Down
13 changes: 1 addition & 12 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ mobile-install --start=warm

build:ci --build_metadata=ROLE=CI --workspace_status_command=./scripts/workspace-status.sh

# Circle large has 4 CPU cores/8GB mem
# Circle xlarge has 8 CPU cores/16GB mem
build:ci --local_cpu_resources=8
build:ci --local_ram_resources=15000
build:ci --config="release"
Expand All @@ -62,17 +62,6 @@ build:release --stamp --workspace_status_command=./scripts/workspace-status.sh
# Cache action outputs on disk so they persist across output_base and bazel shutdown (eg. changing branches)
# build --disk_cache=~/.cache/bazel-disk-cache

build:skip-ios -- \
-//:PlayerUI \
-//:PlayerUI_Pod \
-//:PlayerUI-Demo \
-//:PlayerUI-Unit-Unit \
-//:PlayerUI-Unit-Unit.__internal__.__test_bundle \
-//:PlayerUI-UI-ViewInspectorTests \
-//:PlayerUI-UI-ViewInspectorTests.__internal__.__test_bundle \
-//:PlayerUI-UI-XCUITests \
-//:PlayerUI-UI-XCUITests.__internal__.__test_bundle

# Support for debugging NodeJS tests
# Add the Bazel option `--config=debug` to enable this
# --test_output=streamed
Expand Down
108 changes: 44 additions & 64 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ executors:
TZ: "/usr/share/zoneinfo/America/Los_Angeles"
ios:
working_directory: ~/player
resource_class: macos.x86.medium.gen2
resource_class: macos.m1.large.gen1
macos:
xcode: 14.3
xcode: 15.3.0
environment:
TZ: "/usr/share/zoneinfo/America/Los_Angeles"
android:
Expand Down Expand Up @@ -93,8 +93,8 @@ jobs:
steps:
- attach_workspace:
at: ~/player

- run: bazel build --config=ci --config=skip-ios -- //...
- run: bazel query '//... except filter("ios|swiftui", //...)'
- run: bazel build --config=ci -- $(bazel query '//... except filter("ios|swiftui", //...)')

- save_cache:
paths:
Expand All @@ -115,70 +115,38 @@ jobs:
- run:
name: Homebrew Dependencies
command: |
HOMEBREW_NO_AUTO_UPDATE=1 brew install bazelisk maven openjdk@8

- run:
name: Set Ruby Version
command: |
rbenv install 2.6.10
rbenv global 2.6.10
rbenv rehash

- restore_cache:
keys:
- android-tools-{{ arch }}-{{ checksum "scripts/install-android-tools.sh" }}

- run: echo 'export ANDROID_HOME=~/android-tools' >> $BASH_ENV

- run:
name: Install Android tools
command: |
sh scripts/install-android-tools.sh
echo 'export ANDROID_SDK_HOME=$ANDROID_HOME' >> $BASH_ENV
echo 'export ANDROID_NDK_HOME=$ANDROID_SDK_HOME/ndk/21.4.7075529' >> $BASH_ENV
echo 'export PATH=$ANDROID_SDK_HOME/tools/bin:$PATH' >> $BASH_ENV
echo 'export PATH=$ANDROID_SDK_HOME/tools:$PATH' >> $BASH_ENV
echo 'export PATH=$ANDROID_SDK_HOME/platform-tools:$PATH' >> $BASH_ENV
echo 'export PATH=$ANDROID_SDK_HOME/emulator:$PATH' >> $BASH_ENV
source $BASH_ENV
environment:
JAVA_HOME: /usr/local/opt/openjdk@8

- save_cache:
key: android-tools-{{ arch }}-{{ checksum "scripts/install-android-tools.sh" }}
paths:
- ~/android-tools

- run: gem install bundler

- restore_cache:
keys:
- gem-v1-{{ arch }}-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
- gem-v1-{{ arch }}-main-{{ checksum "Gemfile.lock" }}

- run: bundle install

- save_cache:
key: gem-v1-{{ arch }}-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
paths:
- ~/.gem/ruby/2.7.5
HOMEBREW_NO_AUTO_UPDATE=1 brew install bazelisk maven openjdk@17 lcov

- macos/preboot-simulator:
version: "15.5"
version: "17.4"
platform: "iOS"
device: "iPhone 13"

- run: bazel sync
device: "iPhone 15"

- run: |
BUNDLE_TARGETS=$(bazel query "attr(name, '^.*_Bundles$', //...)" --output label 2>/dev/null | tr '\n' ' ')
bazel build --config=ci $BUNDLE_TARGETS
- run: bazel build --config=ci -- //ios/demo:PlayerUIDemo

- run: bazel shutdown
- run: cd xcode && bundle exec pod install
- run: bazel build --config=ci -- //:PlayerUI //:PlayerUI-Demo //:PlayerUI_Pod
# TODO: the timeout should be added to the test itself
- run: bazel test --test_env=APPLITOOLS_API_KEY=${APPLITOOLS_API_KEY} --test_env=APPLITOOLS_BATCH_ID=${CIRCLE_SHA1} --test_env=APPLITOOLS_PR_NUMBER=${CIRCLE_PULL_REQUEST##*/} --test_timeout=1200 --jobs=1 --verbose_failures --config=ci -- //:PlayerUI-Unit-Unit //:PlayerUI-UI-ViewInspectorTests //:PlayerUI-UI-XCUITests
- run:
name: Test Prebuild
command: |
bazel build \
--config=ci \
$(bazel query "kind(ios_unit_test, //ios/...)") \
$(bazel query "kind(ios_unit_test, //plugins/...)") \
$(bazel query "kind(ios_ui_test, //ios/...)") \
$(bazel query "kind(ios_ui_test, //plugins/...)")
- run:
name: Tests
command: |
bazel coverage \
--config=ci \
--jobs=2 \
--experimental_use_llvm_covmap \
--combined_report=lcov \
--test_output=all \
--test_timeout=1800 \
$(bazel query "kind(ios_unit_test, //ios/...)") \
$(bazel query "kind(ios_unit_test, //plugins/...)") \
$(bazel query "kind(ios_ui_test, //ios/...)") \
$(bazel query "kind(ios_ui_test, //plugins/...)")

- run:
when: always
Expand All @@ -189,6 +157,18 @@ jobs:
mkdir -p $RESULTS_DIR/$(dirname $line)
cp $line $RESULTS_DIR/$(dirname $line)
done
- run:
when: always
command: |
mkdir -p _coverage/lcov
mkdir -p _coverage/html
cp -r $(bazel info output_path)/_coverage/_coverage_report.dat _coverage/lcov/
genhtml --branch-coverage --output-directory=_coverage/html/ "$(bazel info output_path)/_coverage/_coverage_report.dat"
zip -r _coverage/html.zip _coverage/html/
rm -r _coverage/html/

- store_artifacts:
path: _coverage

- store_test_results:
path: _test_results
Expand All @@ -199,7 +179,7 @@ jobs:
- attach_workspace:
at: ~/player

- run: bazel test --config=skip-ios --config=ci -- //... -//docs/site -//android/demo:android_instrumentation_test
- run: bazel test --config=ci -- $(bazel query '//... except filter("ios|swiftui", //...)') -//docs/site -//android/demo:android_instrumentation_test

- run:
when: always
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ xcui.json
#SPM
.build
.swiftpm
ios/Player.xcodeproj
ios/PlayerUI.xcodeproj

# Bundles used by cocoapods for development
ios/*/*/Resources/**/*.js
Expand Down
10 changes: 1 addition & 9 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# load("@rules_player//cocoapods:cocoapod.bzl", "assemble_pod", "pod_push")
# load("@rules_player//cocoapods:cocoapod.bzl", "pod_push")
# load("@rules_player//internal:stamp.bzl", "stamp")
# load("//:generated.bzl", "PlayerUI", "PlayerUI_Demo", "ui_tests", "unit_tests")
load("//tools/ios:util.bzl", "assemble_pod")

load("@npm//:defs.bzl", "npm_link_all_packages")
Expand Down Expand Up @@ -83,13 +82,6 @@ js_library(
] + glob(["typings/*"]),
visibility = ["//visibility:public"],
)
# PlayerUI(deps = [])

# PlayerUI_Demo(deps = [])

# unit_tests()

# ui_tests()

# # Update the version in the podspec
# stamp(
Expand Down
35 changes: 15 additions & 20 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,6 @@ If the changes are larger (API design, architecture, etc), [opening an issue](ht
* [Android NDK >= 19.2.5345600, <= 21](https://github.com/android/ndk/wiki/Unsupported-Downloads#r19c). Any version > 21 will not work, period. You'll need to add `ANDROID_NDK_HOME` to your environment manually.

## Building and Testing Locally (All platforms)
#### Presetup
For iOS builds, some pre-setup is required for `bazel` to generate BUILD files for dependent CocoaPods.

```bash
bundle install
```
CocoaPods does not directly integrate with `bazel`, when core targets are updated, the output bundles need to be copied to the location described in the `PlayerUI.podspec`, to do so run the script:
```bash
./tools/build_ios_bundles.sh
```
This will query `bazel` for dependent targets, copy their output and regenerate the `.xcworkspace`.
### Player
For speed and consistency, this repo leverages `bazel` as it's main build tool. Check out the [bazel](https://bazel.build/) docs for more info.

Expand All @@ -47,20 +36,26 @@ Tests can also be ran using:
bazel test //...
```

#### Skipping iOS builds
The `.bazelrc` contains a convenience to build everything but the iOS targets, as the toolchain for those is platform specific.

```bash
bazel build --config=skip-ios
```

## For Android Only builds
If you are interested in only contributing for android, follow our [android guide](https://github.com/player-ui/player/android/demo/README.md)
If you are interested in only contributing for android, follow our [android guide](https://github.com/player-ui/player/blob/main/android/demo/README.md)

## For iOS Only builds
If you are interested in only contributing for iOS, follow our [iOS guide](https://github.com/player-ui/player)
### Xcode Project generation
Generate the `.xcodeproj` to open and work in Xcode. Builds and tests will be executed through bazel, to ensure behavioral parity.

```bash
bazel run //ios:xcodeproj
open -a Xcode ios/PlayerUI.xcodeproj/
```
### Demo Application
#### Xcode
The first time the Xcode project is generated, the default selected target is `PlayerUI`, for a runnable target select `PlayerUIDemo` to run the demo application in the simulator.

#### Bazel
The demo app can also be built and launched in a simulator from the command line with bazel:
```bash
bazel run //ios/demo:PlayerUIDemo
```

## Docs Sites
These require the [Android NDK](https://developer.android.com/ndk).
Expand Down
18 changes: 10 additions & 8 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ node = use_extension("@rules_nodejs//nodejs:extensions.bzl", "node")
node.toolchain(node_version = "18.18.0")
#################################

# iOS

bazel_dep(name = "rules_swift", version = "1.13.0", repo_name = "build_bazel_rules_swift")
###### Start iOS ######
## Rule Dependencies
bazel_dep(name = "rules_swift", version = "1.14.0", repo_name = "build_bazel_rules_swift")
bazel_dep(name = "rules_apple", version = "3.1.1", repo_name = "build_bazel_rules_apple")
bazel_dep(name = "rules_ios", version = "3.1.4", repo_name = "build_bazel_rules_ios")
bazel_dep(name = "rules_xcodeproj", version = "1.13.0")

bazel_dep(name = "gazelle", version = "0.34.0", repo_name = "bazel_gazelle")
bazel_dep(name = "rules_swift_package_manager", version = "0.22.0")

# swift_deps START
## This section is handled by rules_swift_package_manager
swift_deps = use_extension(
"@rules_swift_package_manager//:extensions.bzl",
"swift_deps",
Expand All @@ -41,14 +41,16 @@ swift_deps.from_file(
deps_index = "//:swift_deps_index.json",
)

## SPM Dependencies
### need to be listed here to be available as a target in BUILD files
### Add dependency in xcode/Package.swift and then run `bazel run //:update_swift_pkgs`
### before adding it here
use_repo(
swift_deps,
"swiftpkg_swift_hooks",
"swiftpkg_viewinspector",
"swiftpkg_eyes_xcui_swift_package",
"swiftpkg_viewinspector"
)

# end iOS
###### End iOS ######
npm = use_extension("@aspect_rules_js//npm:extensions.bzl", "npm")

npm.npm_translate_lock(
Expand Down
2 changes: 1 addition & 1 deletion ios/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ load(

xcodeproj(
name = "xcodeproj",
project_name = "Player",
project_name = "PlayerUI",
tags = ["manual"],
top_level_targets = [
top_level_target("//ios/demo:PlayerUIDemo", target_environments = ["simulator"]),
Expand Down
6 changes: 4 additions & 2 deletions ios/core/Tests/Types/Generic/AnyTypeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,13 @@ class AnyTypeTests: XCTestCase {
XCTAssertEqual("[\"test\",\"data\"]", doEncode(AnyType.array(data: ["test", "data"])))
XCTAssertEqual("[1,2]", doEncode(AnyType.numberArray(data: [1, 2])))
XCTAssertEqual("[false,true]", doEncode(AnyType.booleanArray(data: [false, true])))
XCTAssertEqual("{\"key\":false,\"key2\":1}", doEncode(AnyType.anyDictionary(data: ["key": false, "key2": 1])))
XCTAssertEqual("{\"a\":false,\"b\":1}", doEncode(AnyType.anyDictionary(data: ["a": false, "b": 1])))
}

func doEncode(_ data: AnyType) -> String? {
let data = try? JSONEncoder().encode(data)
let encoder = JSONEncoder()
encoder.outputFormatting = .sortedKeys
let data = try? encoder.encode(data)
guard let data = data else { return nil }
return String(data: data, encoding: .utf8)
}
Expand Down
2 changes: 1 addition & 1 deletion ios/core/Tests/utilities/ErrorUtilitiesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ErrorUtilitiesTestCase: XCTestCase {
XCTFail("DecodingError expected")
} catch {
let message = error.playerDescription
XCTAssertEqual(message, "Expected to decode Int but found a string/data instead. (coding path bar.bbb)")
XCTAssertEqual(message, "Expected to decode Int but found a string instead. (coding path bar.bbb)")
}

// keyNotFound
Expand Down
Loading