Skip to content

Commit c63f847

Browse files
authored
Allow 'features' customization via 'user_options' (#192)
'features' provides a mechanism for customizing the Bazel toolchain configuration: docs.bazel.build/versions/main/cc-toolchain-config-reference.html It's a useful knob to expose via PodToBUILD for those cases when you want a library to opt-in to features like dead code stripping, dsym generation, or other local toolchain features.
1 parent afd8257 commit c63f847

File tree

7 files changed

+30
-10
lines changed

7 files changed

+30
-10
lines changed

BazelExtensions/workspace.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def new_pod_repository(name,
256256
PlusEquals ( += ). Add an item to an array
257257
258258
Implemented for:
259-
`objc_library` [ `copts`, `deps`, `sdk_frameworks` ]
259+
`objc_library` [ `copts`, `deps`, `features`, `sdk_frameworks` ]
260260
261261
Example usage: add a custom define to the target, Texture's `copts`
262262
field

Examples/React/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,4 +366,4 @@ SPEC CHECKSUMS:
366366

367367
PODFILE CHECKSUM: 2b89daabd5eca2c25b3d551f2e421e69a395664d
368368

369-
COCOAPODS: 1.11.0
369+
COCOAPODS: 1.11.2

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ Supported operators:
216216
PlusEquals ( += ). Add an item to an array
217217

218218
Implemented for:
219-
`objc_library`. Supported fields: `copts`, `deps`, `sdk_frameworks`
219+
`objc_library`. Supported fields: `copts`, `deps`, `features`, `sdk_frameworks`
220220

221221
Example usage: add a custom define to the target, Texture's `copts`
222222
field

Sources/PodToBUILD/EmptyDepPruneTransform.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ struct EmptyDepPruneTransform : SkylarkConvertibleTransform {
9191
lib.prefixHeader, includes: lib.includes,
9292
sdkFrameworks: lib.sdkFrameworks, weakSdkFrameworks:
9393
lib.weakSdkFrameworks, sdkDylibs: lib.sdkDylibs, deps:
94-
prunedDeps, copts: lib.copts, bundles: lib.bundles, resources:
95-
lib.resources, publicHeaders: lib.publicHeaders,
94+
prunedDeps, copts: lib.copts, features: lib.features, bundles:
95+
lib.bundles, resources: lib.resources, publicHeaders: lib.publicHeaders,
9696
nonArcSrcs: lib.nonArcSrcs, requiresArc:
9797
lib.requiresArc, isTopLevelTarget: lib.isTopLevelTarget)
9898

Sources/PodToBUILD/ObjcLibrary.swift

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ public struct ObjcImport: BazelTarget {
147147
public enum ObjcLibraryConfigurableKeys : String {
148148
case copts
149149
case deps
150+
case features
150151
case sdkFrameworks = "sdk_frameworks"
151152
}
152153

@@ -173,6 +174,7 @@ public struct ObjcLibrary: BazelTarget, UserConfigurable, SourceExcludable {
173174
public var sdkFrameworks: AttrSet<[String]>
174175
public var copts: AttrSet<[String]>
175176
public var deps: AttrSet<[String]>
177+
public var features: AttrSet<[String]>
176178

177179
public let isTopLevelTarget: Bool
178180
public let externalName: String
@@ -191,6 +193,7 @@ public struct ObjcLibrary: BazelTarget, UserConfigurable, SourceExcludable {
191193
sdkDylibs: AttrSet<[String]> = AttrSet.empty,
192194
deps: AttrSet<[String]> = AttrSet.empty,
193195
copts: AttrSet<[String]> = AttrSet.empty,
196+
features: AttrSet<[String]> = AttrSet.empty,
194197
bundles: AttrSet<[String]> = AttrSet.empty,
195198
resources: AttrSet<GlobNode> = AttrSet.empty,
196199
publicHeaders: AttrSet<GlobNode> = AttrSet.empty,
@@ -211,6 +214,7 @@ public struct ObjcLibrary: BazelTarget, UserConfigurable, SourceExcludable {
211214
self.sdkDylibs = sdkDylibs
212215
self.deps = deps
213216
self.copts = copts
217+
self.features = features
214218
self.bundles = bundles
215219
self.resources = resources
216220
self.nonArcSrcs = nonArcSrcs
@@ -398,6 +402,8 @@ public struct ObjcLibrary: BazelTarget, UserConfigurable, SourceExcludable {
398402
AttrSet(basic: xcconfigCopts) <>
399403
fallbackSpec.attr(\.compilerFlags)
400404

405+
features = AttrSet.empty
406+
401407
// Select resources that are not prebuilt bundles
402408
let resourceFiles = (spec.attr(\.resources).map { (strArr: [String]) -> [String] in
403409
strArr.filter { (str: String) -> Bool in
@@ -441,6 +447,10 @@ public struct ObjcLibrary: BazelTarget, UserConfigurable, SourceExcludable {
441447
if let value = value as? String {
442448
self.deps = self.deps <> AttrSet(basic: [value])
443449
}
450+
case .features:
451+
if let value = value as? String {
452+
self.features = self.features <> AttrSet(basic: [value])
453+
}
444454
}
445455

446456
}
@@ -620,9 +630,9 @@ public struct ObjcLibrary: BazelTarget, UserConfigurable, SourceExcludable {
620630
lib.prefixHeader, includes: lib.includes,
621631
sdkFrameworks: lib.sdkFrameworks, weakSdkFrameworks:
622632
lib.weakSdkFrameworks, sdkDylibs: lib.sdkDylibs, deps:
623-
deps, copts: lib.copts, bundles: lib.bundles, resources:
624-
lib.resources, publicHeaders: lib.publicHeaders,
625-
nonArcSrcs: nonArcSources, requiresArc:
633+
deps, copts: lib.copts, features: lib.features, bundles:
634+
lib.bundles, resources: lib.resources, publicHeaders:
635+
lib.publicHeaders, nonArcSrcs: nonArcSources, requiresArc:
626636
lib.requiresArc, isTopLevelTarget: lib.isTopLevelTarget)
627637

628638
}
@@ -891,6 +901,13 @@ public struct ObjcLibrary: BazelTarget, UserConfigurable, SourceExcludable {
891901
))
892902
}
893903

904+
if !lib.features.isEmpty {
905+
libArguments.append(.named(
906+
name: "features",
907+
value: lib.features.toSkylark()
908+
))
909+
}
910+
894911
let buildConfigDependenctCOpts: SkylarkNode =
895912
.functionCall(name: "select",
896913
arguments: [

Tests/BuildTests/Examples/React/Pods.WORKSPACE

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ new_pod_repository(
7373
podspec_url = "Vendor/PodSpecs/react-native-third-party-0.51.0/Folly.podspec",
7474
url = "https://github.com/facebook/folly/archive/v2016.09.26.00.zip",
7575
generate_module_map = False,
76-
user_options = [ "folly.copts += -IVendor/Glog" ],
76+
user_options = [
77+
"folly.copts += -IVendor/Glog",
78+
"folly.features += dead_strip",
79+
],
7780
install_script = """
7881
__INIT_REPO__
7982
# TODO: Why is the Podspec using this as a ModuleName, if Folly imports

bin/update_pods.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ def new_pod_repository(name,
392392
PlusEquals ( += ). Add an item to an array
393393
394394
Implemented for:
395-
`objc_library` [ `copts`, `deps`, `sdk_frameworks` ]
395+
`objc_library` [ `copts`, `deps`, `features`, `sdk_frameworks` ]
396396
397397
Example usage: add a custom define to the target, Texture's `copts`
398398
field

0 commit comments

Comments
 (0)