Skip to content

Commit

Permalink
Switch to Bazel 4, migrate ObjcProvider compile info to CcCompilation…
Browse files Browse the repository at this point in the history
…Context (bazel-xcode#174)

* Use Bazel 4.0.0

* Use latest rules_apple
* --spawn_strategy=standalone is deprecated
* use_top_level_targets_for_symlinks fixed bazel-bin symlink
* Set bazelversion 4.0.0 in every .bazelversion
* Change gen_includes to use a CcInfo
* Use CcInfo for module maps
* Make the React example actually build an iOS app
  • Loading branch information
dgcoffman authored Mar 31, 2021
1 parent 58906de commit db17580
Show file tree
Hide file tree
Showing 56 changed files with 651 additions and 450 deletions.
4 changes: 2 additions & 2 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# A few settings for XCHammer's .bazelrc
# Debugging: Use the remapping feature of rules_swift.
build \
--spawn_strategy=standalone \
--spawn_strategy=local \
--strategy=SwiftCompile=worker \
--swiftcopt=-Xwrapped-swift=-debug-prefix-pwd-is-dot \
--experimental_strict_action_env=true

test \
--spawn_strategy=standalone \
--spawn_strategy=local \

2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.4.1
4.0.0
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ external
Pods/
PodsHost/
*.xcworkspace
PodToBUILD.zip
9 changes: 5 additions & 4 deletions BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
load("@build_bazel_rules_apple//apple:macos.bzl", "macos_command_line_application", "macos_unit_test")
load("@rules_cc//cc:defs.bzl", "objc_library")

objc_library(
name = "ObjcSupport",
Expand All @@ -8,7 +9,7 @@ objc_library(
includes = ["Sources/ObjcSupport/include"]
)

# PodToBUILD is a core library enabling Skylark code generation
# PodToBUILD is a core library enabling Starlark code generation
swift_library(
name = "PodToBUILD",
srcs = glob(["Sources/PodToBUILD/*.swift"]),
Expand Down Expand Up @@ -53,7 +54,7 @@ swift_library(

alias(name = "update_pods", actual = "//bin:update_pods")

# This tests RepoToolsCore and Skylark logic
# This tests RepoToolsCore and Starlark logic
swift_library(
name = "PodToBUILDTestsLib",
srcs = glob(["Tests/PodToBUILDTests/*.swift"]),
Expand All @@ -68,13 +69,13 @@ macos_unit_test(
)

swift_library(
name = "BuildTestsLib",
name = "BuildTestsLib",
srcs = glob(["Tests/BuildTests/*.swift"]),
deps = [":RepoToolsCore", "@podtobuild-SwiftCheck//:SwiftCheck"],
data = glob(["Examples/**/*.podspec.json"])
)

# This tests RepoToolsCore and Skylark logic
# This tests RepoToolsCore and Starlark logic
macos_unit_test(
name = "BuildTests",
deps = [":BuildTestsLib"],
Expand Down
39 changes: 29 additions & 10 deletions BazelExtensions/extensions.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This file is part of PodSpecToBUILD
# Warning: this file is not accounted for as an explict imput into the build.
# Warning: this file is not accounted for as an explicit input into the build.
# Therefore, bin/RepoTools must be updated when this changes.

# Acknowledgements
Expand Down Expand Up @@ -157,7 +157,7 @@ def _module_map_impl(ctx):
relative_path = "".join(["../" for i in range(len(module_map.dirname.split("/")))])

system_tag = " [system] "
content = "module " + module_name + (system_tag if ctx.attr.is_system else "" ) + " {\n"
content = "module " + module_name + (system_tag if ctx.attr.is_system else "" ) + " {\n"
umbrella_header_file = None
if ctx.attr.umbrella_hdr:
# Note: this umbrella header is created internally.
Expand Down Expand Up @@ -190,24 +190,31 @@ module {module_name}.Swift {{
# If the name is `module.modulemap` we propagate this as an include. If a
# module map is added to `objc_library` as a dep, bazel will add these
# automatically and add a _single_ include to this module map. Ideally there
# would be an API to invoke clang with -fmodule-map=
# would be an API to invoke clang with -fmodule-map=
providers = []
if ctx.attr.module_map_name == "module.modulemap":
provider_hdr = [module_map] + ([umbrella_header_file] if umbrella_header_file else [])
objc_provider = apple_common.new_objc_provider(
module_map=depset([module_map]),
include=depset([ctx.outputs.module_map.dirname]),
header=depset(provider_hdr)
)

compilation_context = cc_common.create_compilation_context(
includes=depset([ctx.outputs.module_map.dirname]))

providers.append(CcInfo(compilation_context=compilation_context))
else:
# This is an explicit module map. Currently, we use these for swift only
provider_hdr = [module_map] + ([umbrella_header_file] if umbrella_header_file else [])
objc_provider = apple_common.new_objc_provider(
header=depset(provider_hdr + [module_map])
)

providers.append(objc_provider)

return struct(
files=depset([module_map]),
providers=[objc_provider],
providers=providers,
objc=objc_provider,
headers=depset([module_map]),
)
Expand Down Expand Up @@ -257,12 +264,19 @@ def gen_module_map(name,
def _gen_includes_impl(ctx):
includes = []
includes.extend(ctx.attr.include)

for target in ctx.attr.include_files:
for f in target.files.to_list():
includes.append(f.path)

return apple_common.new_objc_provider(
include=depset(includes))
compilation_context = cc_common.create_compilation_context(
includes=depset(includes))

return [
CcInfo(compilation_context=compilation_context),
# objc_library deps requires an ObjcProvider
apple_common.new_objc_provider()
]

_gen_includes = rule(
implementation=_gen_includes_impl,
Expand Down Expand Up @@ -310,10 +324,15 @@ def _make_headermap_impl(ctx):

# Extract propagated headermaps
for hdr_provider in ctx.attr.deps:
if not hasattr(hdr_provider, "objc"):
continue
hdrs = []

if CcInfo in hdr_provider:
compilation_context = hdr_provider[CcInfo].compilation_context
hdrs.extend(compilation_context.headers.to_list())

if hasattr(hdr_provider, "objc"):
hdrs.extend(hdr_provider.objc.direct_headers)

hdrs = hdr_provider.objc.header.to_list()
for hdr in hdrs:
if hdr.path.endswith(".hmap"):
# Add headermaps
Expand Down
1 change: 1 addition & 0 deletions Examples/.PodsHost/BUILD

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Examples/ArcSplitting/.bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.4.1
4.0.0
2 changes: 2 additions & 0 deletions Examples/ArcSplitting/BUILD
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
load("@rules_cc//cc:defs.bzl", "objc_library")

objc_library(name="all", deps=["//Vendor/ArcSplitting:ArcSplitting"])
25 changes: 9 additions & 16 deletions Examples/ArcSplitting/WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "rules_pods",
urls = ["https://note-this-is-overridden"],
)

git_repository(
http_archive(
name = "build_bazel_rules_apple",
remote = "https://github.com/bazelbuild/rules_apple.git",
commit = "1cdaf74e44c4c969d7ee739b3a0f11b993c49d2a",
sha256 = "a41a75c291c69676b9974458ceee09aea60cee0e1ee282e27cdc90b679dfd30f",
url = "https://github.com/bazelbuild/rules_apple/releases/download/0.21.2/rules_apple.0.21.2.tar.gz",
)

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

git_repository(
name = "build_bazel_rules_swift",
remote = "https://github.com/bazelbuild/rules_swift.git",
commit = "d07d880dcf939e0ad98df4dd723f8516bf8a2867",
apple_rules_dependencies()

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

apple_rules_dependencies()
apple_support_dependencies()

load(
"@build_bazel_rules_swift//swift:repositories.bzl",
Expand All @@ -32,16 +32,9 @@ load(

swift_rules_dependencies()

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

apple_support_dependencies()
load(
"@com_google_protobuf//:protobuf_deps.bzl",
"protobuf_deps",
)

protobuf_deps()

4 changes: 2 additions & 2 deletions Examples/BasiciOS/.bazelrc
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# A few settings for XCHammer's .bazelrc
# Debugging: Use the remapping feature of rules_swift.
build \
--spawn_strategy=standalone \
--spawn_strategy=local \
--strategy=SwiftCompile=worker \
--swiftcopt=-Xwrapped-swift=-debug-prefix-pwd-is-dot \
--experimental_strict_action_env=true

test \
--spawn_strategy=standalone \
--spawn_strategy=local \

2 changes: 1 addition & 1 deletion Examples/BasiciOS/.bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.4.1
4.0.0
1 change: 1 addition & 0 deletions Examples/BasiciOS/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@build_bazel_rules_apple//apple:ios.bzl", "ios_application")
load("@rules_cc//cc:defs.bzl", "objc_library")

# This is needed for implicit entitlement rules created for
# files.
Expand Down
30 changes: 13 additions & 17 deletions Examples/BasiciOS/WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "rules_pods",
urls = ["https://note-this-is-overridden.com"],
urls = ["https://note-this-is-overridden"],
)
load("@rules_pods//BazelExtensions:workspace.bzl", "new_pod_repository")

load("@rules_pods//BazelExtensions:workspace.bzl", "new_pod_repository")

git_repository(
http_archive(
name = "build_bazel_rules_apple",
remote = "https://github.com/bazelbuild/rules_apple.git",
commit = "1cdaf74e44c4c969d7ee739b3a0f11b993c49d2a",
sha256 = "a41a75c291c69676b9974458ceee09aea60cee0e1ee282e27cdc90b679dfd30f",
url = "https://github.com/bazelbuild/rules_apple/releases/download/0.21.2/rules_apple.0.21.2.tar.gz",
)

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

git_repository(
name = "build_bazel_rules_swift",
remote = "https://github.com/bazelbuild/rules_swift.git",
commit = "d07d880dcf939e0ad98df4dd723f8516bf8a2867",
apple_rules_dependencies()

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

apple_rules_dependencies()
apple_support_dependencies()

load(
"@build_bazel_rules_swift//swift:repositories.bzl",
Expand All @@ -33,16 +34,11 @@ load(

swift_rules_dependencies()

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

apple_support_dependencies()
load(
"@com_google_protobuf//:protobuf_deps.bzl",
"protobuf_deps",
)

protobuf_deps()

new_pod_repository(
Expand Down
2 changes: 1 addition & 1 deletion Examples/ChildPodspec/.bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.4.1
4.0.0
2 changes: 2 additions & 0 deletions Examples/ChildPodspec/BUILD
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
load("@rules_cc//cc:defs.bzl", "objc_library")

objc_library(name="all", deps=["//Vendor/Parent:Parent"])
24 changes: 9 additions & 15 deletions Examples/ChildPodspec/WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "rules_pods",
urls = ["https://note-this-is-overridden"],
)

git_repository(
http_archive(
name = "build_bazel_rules_apple",
remote = "https://github.com/bazelbuild/rules_apple.git",
commit = "1cdaf74e44c4c969d7ee739b3a0f11b993c49d2a",
sha256 = "a41a75c291c69676b9974458ceee09aea60cee0e1ee282e27cdc90b679dfd30f",
url = "https://github.com/bazelbuild/rules_apple/releases/download/0.21.2/rules_apple.0.21.2.tar.gz",
)

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

git_repository(
name = "build_bazel_rules_swift",
remote = "https://github.com/bazelbuild/rules_swift.git",
commit = "d07d880dcf939e0ad98df4dd723f8516bf8a2867",
apple_rules_dependencies()

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

apple_rules_dependencies()
apple_support_dependencies()

load(
"@build_bazel_rules_swift//swift:repositories.bzl",
Expand All @@ -32,12 +32,6 @@ load(

swift_rules_dependencies()

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

apple_support_dependencies()
load(
"@com_google_protobuf//:protobuf_deps.bzl",
"protobuf_deps",
Expand Down
Loading

0 comments on commit db17580

Please sign in to comment.