Skip to content

Commit

Permalink
Merge pull request #39 from sergeykhliustin/prerelease
Browse files Browse the repository at this point in the history
Pre release updates
  • Loading branch information
sergeykhliustin authored Feb 20, 2023
2 parents 4256826 + 7550b10 commit c3bc62b
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 45 deletions.
86 changes: 50 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,12 @@ Now you can add first level dependencies to your app as `//Pods/<pod_name>`
Note: if you have multiplatform setup (`--platform` with more than 1 option), use `//Pods/<pod_name>:<pod_name>_<platform>`
Enjoy :)

### 🤔 History and motivation
There are two existing wonderful alternatives to this project: [cocoapods-bazel](https://github.com/bazel-ios/cocoapods-bazel) and [PodToBUILD](https://github.com/pinterest/PodToBUILD).

`cocoapods-bazel` generates BUILD files based on targets from `Pods.xcodeproj`.
As a result of this, we will have some aggregated targets needed for Xcode but redundant for Bazel.
These targets cause issues with resources and module name resolving.
For example, currently, it's not working out of the box for a custom Firebase setup.

`PodToBUILD`'s main idea is to generate BUILD files directly from .podspec info and **it's great!**
Unfortunately, out of the box, it cannot resolve the whole dependency tree with private pods as Cocoapods do.
We can solve it by letting Cocoapods do its work and vendorise pods after. (something like [this](https://github.com/pinterest/PodToBUILD/pull/216/files))
Another problem is "mixed code" (Swift + Objective-C). It's still [`in development`](https://github.com/pinterest/PodToBUILD#does-it-work-with-swift), so you cannot resolve it with reasonable effort.
Meanwhile, [`rules_ios`](https://github.com/bazel-ios/rules_ios) already supports it.

`BazelPods` uses best of all worlds.
Let Cocoapods download, resolve and setup everything for us. After that, BazelPods will generate `BUILD` files from .podspecs with only needed subspecs with rules from [`rules_ios`](https://github.com/bazel-ios/rules_ios). Written in Swift, so it will do it really fast.
#### Patches
You can specify patches to use in order you want. Also you can use same patch several times.
- `bundle_deduplicate` checks if final bundle will contain bundles with same name and avoids them.
For example, [GoogleMaps](https://github.com/CocoaPods/Specs/blob/master/Specs/a/d/d/GoogleMaps/7.3.0/GoogleMaps.podspec.json) contains `GoogleMaps.bundle` in `resources` and vendored `GoogleMaps.xcframework` also contains same bundle.
- `arm64_to_sim` patches legacy frameworks and libraries to support arm64 simulator. Read more [arm64-to-sim](https://github.com/bogo/arm64-to-sim)
- `user_options` applies options from `--user-options`. If not specified but `--user-options` not empty will be applied in the end.

### ⌨️ Command line options
Generator
Expand All @@ -93,19 +83,12 @@ OPTIONS:
--src <src> Sources root where Pods directory located (or renamed by podsRoot)
--pods-json <pods-json> Pods.json (default: Pods/Pods.json)
--platforms <platforms> Space separated platforms.
Valid values are: ios, osx, tvos, watchos.
Currently ignored, only 'ios' supported (default: ios)
Valid values are: ios, osx, tvos, watchos. (default: ios)
--min-ios <min-ios> Minimum iOS version (default: 13.0)
--deps-prefix <deps-prefix>
Dependencies prefix (default: //Pods)
--pods-root <pods-root> Pods root relative to workspace. Used for headers search paths (default: Pods)
-f, --frameworks Packaging pods in dynamic frameworks if possible (same as `use_frameworks!`)
-c, --concurrent Concurrent mode for generating files faster
--print-output Print BUILD files contents to terminal output
--dry-run Dry run. Files will not be written
-a, --add-podspec Will add podspec.json to the pod directory. Just for debugging purposes.
--color <color> Logs color (auto|yes|no) (default: auto)
--log-level <log-level> Log level (debug|info|warning|error|none) (default: 1)
--patches <patches> Patches. It will be applied in the order listed here.
Available options: bundle_deduplicate, arm64_to_sim, user_options.
user_options requires --user-options configured.
If 'user_options' not specified, but --user_options exist, user_options patch are applied automatically.
--user-options <user-options>
User extra options.
Supported fields: 'sdk_frameworks', 'sdk_dylibs', 'weak_sdk_frameworks', 'vendored_libraries', 'vendored_frameworks', 'vendored_xcframeworks', 'testonly', 'link_dynamic'.
Expand All @@ -115,25 +98,33 @@ OPTIONS:
'SomePod.testonly := true'
Platform specific:
'SomePod.platform_ios.sdk_dylibs += something,something'
--deps-prefix <deps-prefix>
Dependencies prefix (default: //Pods)
--pods-root <pods-root> Pods root relative to workspace. Used for headers search paths (default: Pods)
-f, --frameworks Packaging pods in dynamic frameworks if possible (same as `use_frameworks!`)
-c, --concurrent Concurrent mode for generating files faster
--print-output Print BUILD files contents to terminal output
--dry-run Dry run. Files will not be written
-a, --add-podspec Will add podspec.json to the pod directory. Just for debugging purposes.
--color <color> Logs color (auto|yes|no) (default: auto)
--log-level <log-level> Log level (debug|info|warning|error|none) (default: info)
-h, --help Show help information.
```
Compiler
```
USAGE: Compiler --src <src> --podspec <podspec> [--subspecs <subspecs> ...] [--platforms <platforms> ...] [--min-ios <min-ios>] [--deps-prefix <deps-prefix>] [--pods-root <pods-root>] [--frameworks] [--log-level <log-level>] [--user-options <user-options> ...]
USAGE: Compiler --src <src> --podspec <podspec> [--subspecs <subspecs> ...] [--platforms <platforms> ...] [--min-ios <min-ios>] [--patches <patches> ...] [--user-options <user-options> ...] [--deps-prefix <deps-prefix>] [--pods-root <pods-root>] [--frameworks] [--log-level <log-level>]
OPTIONS:
--src <src> Sources root where Pods directory located (or renamed by podsRoot)
--podspec <podspec> podspec.json
--subspecs <subspecs> Subspecs list
--platforms <platforms> Space separated platforms.
Valid values are: ios, osx, tvos, watchos.
Currently ignored, only 'ios' supported (default: ios)
Valid values are: ios, osx, tvos, watchos. (default: ios)
--min-ios <min-ios> Minimum iOS version (default: 13.0)
--deps-prefix <deps-prefix>
Dependencies prefix (default: //Pods)
--pods-root <pods-root> Pods root relative to workspace. Used for headers search paths (default: Pods)
-f, --frameworks Packaging pods in dynamic frameworks if possible (same as `use_frameworks!`)
--log-level <log-level> Log level (debug|info|warning|error|none) (default: 1)
--patches <patches> Patches. It will be applied in the order listed here.
Available options: bundle_deduplicate, arm64_to_sim, user_options.
user_options requires --user-options configured.
If 'user_options' not specified, but --user_options exist, user_options patch are applied automatically.
--user-options <user-options>
User extra options.
Supported fields: 'sdk_frameworks', 'sdk_dylibs', 'weak_sdk_frameworks', 'vendored_libraries', 'vendored_frameworks', 'vendored_xcframeworks', 'testonly', 'link_dynamic'.
Expand All @@ -143,8 +134,31 @@ OPTIONS:
'SomePod.testonly := true'
Platform specific:
'SomePod.platform_ios.sdk_dylibs += something,something'
--deps-prefix <deps-prefix>
Dependencies prefix (default: //Pods)
--pods-root <pods-root> Pods root relative to workspace. Used for headers search paths (default: Pods)
-f, --frameworks Packaging pods in dynamic frameworks if possible (same as `use_frameworks!`)
--log-level <log-level> Log level (debug|info|warning|error|none) (default: info)
-h, --help Show help information.
```

### 🤔 History and motivation
There are two existing wonderful alternatives to this project: [cocoapods-bazel](https://github.com/bazel-ios/cocoapods-bazel) and [PodToBUILD](https://github.com/pinterest/PodToBUILD).

`cocoapods-bazel` generates BUILD files based on targets from `Pods.xcodeproj`.
As a result of this, we will have some aggregated targets needed for Xcode but redundant for Bazel.
These targets cause issues with resources and module name resolving.
For example, currently, it's not working out of the box for a custom Firebase setup.

`PodToBUILD`'s main idea is to generate BUILD files directly from .podspec info and **it's great!**
Unfortunately, out of the box, it cannot resolve the whole dependency tree with private pods as Cocoapods do.
We can solve it by letting Cocoapods do its work and vendorise pods after. (something like [this](https://github.com/pinterest/PodToBUILD/pull/216/files))
Another problem is "mixed code" (Swift + Objective-C). It's still [`in development`](https://github.com/pinterest/PodToBUILD#does-it-work-with-swift), so you cannot resolve it with reasonable effort.
Meanwhile, [`rules_ios`](https://github.com/bazel-ios/rules_ios) already supports it.

`BazelPods` uses best of all worlds.
Let Cocoapods download, resolve and setup everything for us. After that, BazelPods will generate `BUILD` files from .podspecs with only needed subspecs with rules from [`rules_ios`](https://github.com/bazel-ios/rules_ios). Written in Swift, so it will do it really fast.

## Contributing and issues
`make xcodeproj`
Just contribute and report your issues
Expand Down
3 changes: 1 addition & 2 deletions Sources/Compiler/RootCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ struct RootCommand: ParsableCommand {
help: """
Space separated platforms.
Valid values are: ios, osx, tvos, watchos.
Currently ignored, only 'ios' supported
""")
var platforms: [Platform] = [.ios]

Expand All @@ -42,7 +41,7 @@ struct RootCommand: ParsableCommand {
Patches. It will be applied in the order listed here.
Available options: \(PatchType.allValueStrings.joined(separator: ", ")).
\(PatchType.user_options.rawValue) requires --user-options configured.
If no patches are specified, but --user_options exist, user_options patch are applied automatically.
If 'user_options' not specified, but --user_options exist, user_options patch are applied automatically.
"""
)
var patches: [PatchType] = []
Expand Down
8 changes: 4 additions & 4 deletions Sources/CompilerCore/BuildFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,6 @@ public struct PodBuildFile: StarlarkConvertible {
continue
}

if options.patches.isEmpty && !options.userOptions.isEmpty {
analyzer.patch(UserOptionsPatch(options.userOptions, platform: platform))
}

for patch in options.patches {
switch patch {
case .bundle_deduplicate:
Expand All @@ -157,6 +153,10 @@ public struct PodBuildFile: StarlarkConvertible {
}
}

if !options.patches.contains(.user_options) && !options.userOptions.isEmpty {
analyzer.patch(UserOptionsPatch(options.userOptions, platform: platform))
}

let (resourceTargets, resourceInfoplists) = makeResourceBundles(analyzer: analyzer)
let (vendoredTargets, conditions) = makeVendoredTargets(analyzer: analyzer)

Expand Down
2 changes: 1 addition & 1 deletion Sources/CompilerCore/Patches/BundlesDeduplicate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct BundlesDeduplicate: Patch {
resources.precompiledBundles = resources.precompiledBundles
.reduce(into: [String](), { result, bundle in
if let path = frameworksPaths.first(where: { bundle.contains($0) }) {
log_debug("Removed bundle \"\(bundle.lastPath)\" since conflicts with \"\(path.lastPath)\"")
log_info("Removing bundle \(bundle.lastPath) since \(path.lastPath) alredy includes it")
} else {
result.append(bundle)
}
Expand Down
3 changes: 1 addition & 2 deletions Sources/Generator/RootCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ struct RootCommand: ParsableCommand {
help: """
Space separated platforms.
Valid values are: ios, osx, tvos, watchos.
Currently ignored, only 'ios' supported
""")
var platforms: [Platform] = [.ios]

Expand All @@ -52,7 +51,7 @@ struct RootCommand: ParsableCommand {
Patches. It will be applied in the order listed here.
Available options: \(PatchType.allValueStrings.joined(separator: ", ")).
\(PatchType.user_options.rawValue) requires --user-options configured.
If no patches are specified, but --user_options exist, user_options patch are applied automatically.
If 'user_options' not specified, but --user_options exist, user_options patch are applied automatically.
"""
)
var patches: [PatchType] = []
Expand Down

0 comments on commit c3bc62b

Please sign in to comment.