Skip to content

Commit

Permalink
Add generated header maps and preserve header map paths to build with…
Browse files Browse the repository at this point in the history
… Bazel

This commit adds headermaps so Bazel can find where headers are located, Incase of XBS Xcode does this for us but for Bazel we need to provide headermap. We have setup example project to generate headermaps
  • Loading branch information
naik-sanju committed Sep 6, 2023
1 parent 51b3bf7 commit a864075
Show file tree
Hide file tree
Showing 12 changed files with 107 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate
.DS_Store
/Example/Pods
Podfile.lock
/Example/Gemfile.lock
/Example/bazel-*
IDEWorkspaceChecks.plist
*.xcworkspace
1 change: 1 addition & 0 deletions Example/.bazeliskrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
USE_BAZEL_VERSION=5.4.1
18 changes: 18 additions & 0 deletions Example/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
build \
--spawn_strategy=local \
--worker_sandboxing=false \
--features=swift.cacheable_swiftmodules \
--apple_platform_type=ios \
--verbose_failures \
--features=swift.use_global_module_cache \
--strategy=SwiftCompile=worker \
--experimental_guard_against_concurrent_changes \
--features=apple.skip_codesign_simulator_bundles \
--features=apple.arm64_simulator_use_device_deps \
--features=swift.index_while_building \
--features=swift.use_global_index_store \
--modify_execution_info=^(BitcodeSymbolsCopy|BundleApp|BundleTreeApp|DsymDwarf|DsymLipo|GenerateAppleSymbolsFile|ObjcBinarySymbolStrip|CppLink|ObjcLink|ProcessAndSign|SignBinary|SwiftArchive|SwiftStdlibCopy)$=+no-remote,^(BundleResources|ImportedDynamicFrameworkProcessor)$=+no-remote-exec \


build:Debug \
--compilation_mode=dbg \
22 changes: 22 additions & 0 deletions Example/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
load("@build_bazel_rules_apple//apple:ios.bzl", "ios_application")
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")


swift_library(
name = "FLEXExampleSources",
srcs = glob(["FLEXample/App/**/*.swift"]) + ["FLEXample/AppDelegate.swift"],
deps = ["//Pods/FLEX"]
)

ios_application(
name = "FLEXExample",
bundle_id = "com.flipboard.flex.FLEXample",
families = ["iphone"],
infoplists = ["FLEXample/Supporting Files/Info.plist"],
minimum_os_version = "12.0",
visibility = ["//visibility:public"],
deps = [
"FLEXExampleSources",
],

)
2 changes: 1 addition & 1 deletion Example/FLEXample/Supporting Files/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<key>UISceneConfigurationName</key>
<string>Default Configuration</string>
<key>UISceneDelegateClassName</key>
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
<string>$(PRODUCT_NAME).SceneDelegate</string>
</dict>
</array>
</dict>
Expand Down
1 change: 1 addition & 0 deletions Example/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gem 'cocoapods-bazel'
10 changes: 9 additions & 1 deletion Example/Podfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
platform :ios, '13.0'

plugin 'cocoapods-bazel', {
rules: {
'apple_framework' => { load: '@build_bazel_rules_ios//rules:framework.bzl', rule: 'apple_framework' }.freeze,
'ios_application' => { load: '@build_bazel_rules_ios//rules:app.bzl', rule: 'ios_application' }.freeze,
'ios_unit_test' => { load: '@build_bazel_rules_ios//rules:test.bzl', rule: 'ios_unit_test' }.freeze
}.freeze,
}

target 'FLEXample' do
project 'FLEXample-Cocoapods'
pod 'FLEX', :path => '../'
pod 'FLEX', :git => 'https://github.com/gojekfarm/Flex.git', :branch => 'remove-private-api-usage-and-add-header-maps', :modular_headers => true , :configurations => ['Debug']
end
43 changes: 43 additions & 0 deletions Example/WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

git_repository(
name = "build_bazel_rules_ios",
remote = "https://github.com/bazel-ios/rules_ios.git",
commit = "3884a206840967cee89c4bf16202bd726c118772",
)

load(
"@build_bazel_rules_ios//rules:repositories.bzl",
"rules_ios_dependencies"
)

rules_ios_dependencies()

load(
"@build_bazel_rules_apple//apple:repositories.bzl",
"apple_rules_dependencies",
)

apple_rules_dependencies()

load(
"@build_bazel_rules_swift//swift:repositories.bzl",
"swift_rules_dependencies",
)

swift_rules_dependencies()

load(
"@build_bazel_rules_swift//swift:extras.bzl",
"swift_rules_extra_dependencies",
)

swift_rules_extra_dependencies()

load(
"@build_bazel_apple_support//lib:repositories.bzl",
"apple_support_dependencies",
)

apple_support_dependencies()
1 change: 1 addition & 0 deletions FLEX.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Pod::Spec.new do |spec|
spec.xcconfig = {
'CLANG_CXX_LANGUAGE_STANDARD' => 'gnu++11',
}
spec.preserve_paths = '*.hmap',
spec.compiler_flags = "-Wno-unsupported-availability-guard", "-Wno-deprecated-declarations"
spec.public_header_files = [ "Classes/*.h", "Classes/Manager/*.h", "Classes/Toolbar/*.h",
"Classes/Core/Controllers/*.h", "Classes/Core/Views/*.h",
Expand Down
Binary file added FLEX_private_hmap.hmap
Binary file not shown.
Binary file added FLEX_public_hmap.hmap
Binary file not shown.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ FLEX (Flipboard Explorer) is a set of in-app debugging and exploration tools for
<img alt="Demo" width=36% height=36% src=https://user-images.githubusercontent.com/8371943/70185687-e842c800-16af-11ea-8ef9-9e071380a462.gif>


## How to generate headermaps?
- Headermaps are required to build with Bazel
- To generate a new set of headermaps, cd into Example folder
- Run `pod install`
- Comment out `xcconfig = {"CLANG_CXX_LANGUAGE_STANDARD": "gnu++11"},` this line from Pods/FLEX/BUILD.bazel file
- Run this command `bazel build --config=Debug --ios_multi_cpus=sim_arm64 --xcode_version=14.3.0 --verbose_failures FLEXExample` , right now the build is failing but it generates headermaps.
- Copy these two generated hmap files - `bazel-out/ios-sim_arm64-min9.0-applebin_ios-ios_sim_arm64-dbg-ST-*/bin/Pods/FLEX/FLEX_private_hmap.hmap` and `bazel-out/ios-sim_arm64-min9.0-applebin_ios-ios_sim_arm64-dbg-ST-*/bin/Pods/FLEX/FLEX_public_hmap.hmap`
- Replace the headermap files are root with these copied headermap files.
- Headermap's are binary files, to inspect its content use this tool - https://github.com/milend/hmap
## Give Yourself Debugging Superpowers
- Inspect and modify views in the hierarchy.
- See the properties and ivars on any object.
Expand Down

0 comments on commit a864075

Please sign in to comment.