Introduce basic Bazel build support for gtm-session-fetcher (#447)

This introduces basic Bazel build support for the `gtm-session-fetcher` library. It includes a `BUILD.bazel` file defining several build targets that can be consumed externally. Most tests also have been migrated, with the exception of `objc-import-test`, which is currently not working with Bazel.

Fixes #446

* Add basic Bazel build support for gtm-session-fetcher

* Add comment regarding ObjCImportTest build failure in Bazel

* Add bazel module version value

* Add MODULE.bazel.lock to .gitignore

* Add Bazel CI workflow configuration
This commit is contained in:
Byoungchan Lee authored and GitHub committed 2025-04-21 12:45:08 -04:00
1 parent 252948d863
commit 609f567078
6 files changed
+188

No files matched your search

+1
View File
@@ -0,0 +1 @@
common --enable_bzlmod
+1
View File
@@ -0,0 +1 @@
8.2.0
+37
View File
@@ -0,0 +1,37 @@
name: Bazel
on:
push:
branches: [ main ]
paths:
- 'Sources/**'
- 'UnitTests/**'
- '.github/workflows/bazel.yml'
pull_request:
branches: [ main ]
paths:
- 'Sources/**'
- 'UnitTests/**'
- '.github/workflows/bazel.yml'
schedule:
# Run the first and fifteenth of every month at 5:12 UTC
- cron: '12 5 1,15 * *'
# Also allow manual triggering from the github UX to revalidate things.
workflow_dispatch:
jobs:
bazel:
runs-on: macos-14
strategy:
fail-fast: false
matrix:
MODE: ["dbg", "opt"]
steps:
- uses: actions/checkout@v4
- uses: bazel-contrib/setup-bazel@0.14.0
with:
bazelisk-cache: true
repository-cache: true
- name: bazel test
run: |
bazelisk test --build_tests_only -c "${{ matrix.MODE }}" --test_output=all --verbose_failures --flaky_test_attempts=3 //...
+4
View File
@@ -33,3 +33,7 @@ Podfile.lock
# CocoaPods generate
gen/
# Bazel
bazel-*
MODULE.bazel.lock
+133
View File
@@ -0,0 +1,133 @@
load("@rules_apple//apple:ios.bzl", "ios_unit_test")
load("@rules_apple//apple:macos.bzl", "macos_unit_test")
load("@rules_cc//cc:defs.bzl", "objc_library")
load("@rules_swift//swift:swift.bzl", "swift_test")
package(default_visibility = ["//visibility:public"])
core_hdrs_internal = glob(
["Sources/Core/**/*.h"],
exclude = ["Sources/Core/Public/**/*.h"],
)
objc_library(
name = "GTMSessionFetcherCore",
srcs = glob(["Sources/Core/**/*.m"]) + core_hdrs_internal,
hdrs = glob(["Sources/Core/Public/**/*.h"]),
enable_modules = True,
includes = [
"Sources/Core/Public",
"Sources/Core/Public/GTMSessionFetcher",
],
module_name = "GTMSessionFetcherCore",
sdk_frameworks = ["Foundation"],
)
objc_library(
name = "GTMSessionFetcherFull",
srcs = glob(["Sources/Full/**/*.m"]),
hdrs = glob(["Sources/Full/Public/**/*.h"]),
enable_modules = True,
includes = [
"Sources/Full/Public",
"Sources/Full/Public/GTMSessionFetcher",
],
module_name = "GTMSessionFetcherFull",
deps = [":GTMSessionFetcherCore"],
)
objc_library(
name = "GTMSessionFetcherLogView",
srcs = glob([
"Sources/LogView/**/*.m",
"Sources/LogView/**/*.h",
]),
hdrs = glob(["Sources/LogView/Public/**/*.h"]),
enable_modules = True,
includes = [
"Sources/LogView/Public",
"Sources/LogView/Public/GTMSessionFetcher",
],
module_name = "GTMSessionFetcherLogView",
sdk_frameworks = [
"WebKit",
"Security",
],
deps = [":GTMSessionFetcherCore"],
)
core_tests = glob(
[
"UnitTests/**/*.m",
"UnitTests/**/*.h",
],
exclude = ["GTMSessionFetcherUserAgentTest.m"],
)
objc_library(
name = "GTMSessionFetcherCoreTestsLib",
srcs = core_tests + core_hdrs_internal,
includes = [
"Sources/Core",
"UnitTests",
],
sdk_frameworks = [
"CFNetwork",
"Security",
],
deps = [
":GTMSessionFetcherCore",
":GTMSessionFetcherFull",
],
)
macos_unit_test(
name = "GTMSessionFetcherCoreTests",
minimum_os_version = "10.15",
deps = [":GTMSessionFetcherCoreTestsLib"],
)
ios_unit_test(
name = "GTMSessionFetcherCoreTests_iOS",
minimum_os_version = "12.0",
runner = "@rules_apple//apple/testing/default_runner:ios_xctestrun_ordered_runner",
deps = [":GTMSessionFetcherCoreTestsLib"],
)
objc_library(
name = "GTMSessionFetcherUserAgentTestsLib",
srcs = ["UnitTests/GTMSessionFetcherUserAgentTest.m"],
includes = ["UnitTests"],
sdk_frameworks = [
"Security",
],
deps = [":GTMSessionFetcherCore"],
)
macos_unit_test(
name = "GTMSessionFetcherUserAgentTests",
minimum_os_version = "10.15",
target_compatible_with = ["@platforms//os:osx"],
deps = [":GTMSessionFetcherUserAgentTestsLib"],
)
ios_unit_test(
name = "GTMSessionFetcherUserAgentTests_iOS",
minimum_os_version = "12.0",
runner = "@rules_apple//apple/testing/default_runner:ios_xctestrun_ordered_runner",
target_compatible_with = ["@platforms//os:ios"],
deps = [":GTMSessionFetcherUserAgentTestsLib"],
)
swift_test(
name = "GTMSessionFetcherSwiftTestsLib",
srcs = ["SwiftPMTests/SwiftImportTest/ImportTests.swift"],
deps = [
":GTMSessionFetcherCore",
":GTMSessionFetcherFull",
":GTMSessionFetcherLogView",
],
)
# ObjCImportTest is omitted from bazel build because it currently fails to build.
# See https://github.com/bazelbuild/rules_apple/issues/2690 for details.
+12
View File
@@ -0,0 +1,12 @@
module(name = "gtm_session_fetcher", version = "4.4.0")
bazel_dep(name = "rules_cc", version = "0.1.1")
bazel_dep(name = "rules_apple", version = "3.20.1")
bazel_dep(name = "rules_swift", version = "2.7.0")
bazel_dep(name = "platforms", version = "0.0.11")
bazel_dep(name = "apple_support", version = "1.20.0")
apple_cc_configure = use_extension("@apple_support//crosstool:setup.bzl", "apple_cc_configure_extension")
use_repo(apple_cc_configure, "local_config_apple_cc", "local_config_apple_cc_toolchains")
register_toolchains("@local_config_apple_cc_toolchains//:all")