-
Notifications
You must be signed in to change notification settings - Fork 273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.swift{module,doc} files not included in framework #223
Comments
Here is my framework layout:
It was created like this:
Note that doing a |
If I remove the I'm unable to import it, then. |
Here is what I'm expecting:
|
yes, |
Does it support I'm guessing it's going to be simpler to add it in rules_apple rather than escape the sandbox to find the |
The tricky part is that each |
Multi-arch Swift modules in a framework are represented as a directory instead of a single file:
So theoretically, an Fundamentally, however, to address the original issue, this is another side effect of the fact that ( |
In the end I got it working without a post processor because the rule needs a split configuration, and the post processor is compiled with the What I'm doing is leveraging I'm also doing a pre-processor to extract the It may not handle all the cases, but it's working fine for my needs. I didn't feel like patching I cannot yet share the code as it's part of our internal bazel rules. |
I'm looking into this now but I'm not entirely sure how to collect the multiple swiftmodule files in order to output them in the expected format shown above. I'm able to access the SwiftInfo from the |
It looks like rules_apple/apple/bundling/ios_rules.bzl Line 402 in 0e593c7
|
Here is my rule: load("@build_bazel_rules_swift//swift:swift.bzl", "SwiftInfo")
load("@build_bazel_rules_apple//apple:providers.bzl", "AppleBundleInfo")
load(
"@build_bazel_rules_apple//apple:ios.bzl",
_ios_static_framework = "ios_static_framework",
)
_CPUS = {
"ios_armv7": "arm",
"ios_arm64": "arm64",
"ios_i386": "x86",
"ios_x86_64": "x86_64",
}
_SCRIPT = """\
{zipper} x {framework}
{zipper} c {new_framework} $(find {framework_name} -type f) $@
rm -rf {framework}
"""
def _module_zipper_arg(framework, module_name, cpu, file):
return "{framework}/Modules/{module_name}.swiftmodule/{cpu}.{ext}={file_path}".format(
framework = framework,
module_name = module_name,
cpu = cpu,
ext = file.extension,
file_path = file.path,
)
def _objc_headers_impl(ctx):
headers = []
for dep in ctx.attr.deps:
objc_headers = dep[apple_common.Objc].header.to_list()
for hdr in objc_headers:
if hdr.owner == dep.label:
headers.append(hdr)
return [
DefaultInfo(
files = depset(headers),
),
]
_objc_headers = rule(
_objc_headers_impl,
attrs = {
"deps": attr.label_list(
providers = [SwiftInfo],
),
},
)
def _framework_swift_postprocess_impl(ctx):
bundle_info = ctx.attr.framework[AppleBundleInfo]
framework_name = bundle_info.bundle_name + bundle_info.bundle_extension
new_framework = ctx.actions.declare_file(ctx.label.name + ".zip")
infiles = [
ctx.file.framework,
]
zipper_args = []
for arch, deps in ctx.split_attr.deps.items():
cpu = _CPUS.get(arch)
if not cpu:
continue
for d in deps:
objc_info = d[apple_common.Objc]
swift_info = d[SwiftInfo]
swiftmodule = swift_info.direct_swiftmodules[0]
swiftdoc = swift_info.direct_swiftdocs[0]
infiles.extend([swiftmodule, swiftdoc])
zipper_args.extend([
_module_zipper_arg(framework_name, swift_info.module_name, cpu, swiftmodule),
_module_zipper_arg(framework_name, swift_info.module_name, cpu, swiftdoc),
])
ctx.actions.run_shell(
inputs = infiles,
outputs = [new_framework],
mnemonic = "SwiftFrameworkPostProcess",
progress_message = "Postprocessing %s for Swift support" % framework_name,
command = _SCRIPT.format(
framework = ctx.file.framework.path,
framework_name = framework_name,
new_framework = new_framework.path,
zipper = ctx.executable._zipper.path,
),
arguments = zipper_args,
tools = [
ctx.executable._zipper,
],
)
return [
DefaultInfo(
files = depset([new_framework]),
),
]
_framework_swift_postprocess = rule(
_framework_swift_postprocess_impl,
attrs = {
"platform_type": attr.string(),
"minimum_os_version": attr.string(),
"framework": attr.label(
providers = [AppleBundleInfo],
allow_single_file = True,
),
"deps": attr.label_list(
providers = [SwiftInfo],
cfg = apple_common.multi_arch_split,
),
"_zipper": attr.label(
default = "@bazel_tools//tools/zip:zipper",
cfg = "host",
executable = True,
),
},
)
def ios_static_framework(name, minimum_os_version, hdrs=[], deps=[], visibility=None, **kwargs):
_objc_headers(
name = name + ".hdrs",
deps = deps,
)
_ios_static_framework(
name = name + ".intermediate",
hdrs = hdrs + [name + ".hdrs"],
minimum_os_version = minimum_os_version,
deps = deps,
**kwargs
)
_framework_swift_postprocess(
name = name,
platform_type = "ios",
minimum_os_version = minimum_os_version,
framework = name + ".intermediate",
deps = deps,
visibility = visibility,
)
``` |
Forgive my poor copy paste as I'm on my phone |
Thanks for sharing. It looks like I'm currently not hitting the codepath I expected here rules_apple/apple/bundling/rule_factory.bzl Lines 476 to 489 in 0e593c7
use_binary_rule is always True for ios_static_framework
|
@steeve do you use slack? There's a slack channel that's focused on Bazel for iOS / swift, if you're interested in joining. |
I do, happy to join in :) |
@kastiglione mind inviting me as well? :) |
@steeve looks like you have a typo in your |
@keith not sure, do you have any doc/example? |
If it works I guess everything is fine, but if you build a framework for a 32 bit simulator in Xcode you end up with |
Ah ! So indeed it's a typo of mine
On Fri 5 Oct 2018 at 01:51, Keith Smiley ***@***.***> wrote:
If it works I guess everything is fine, but if you build a framework for a
32 bit simulator in Xcode you end up with i386.swiftdoc and
i386.swiftmodule
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#223 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAIY-yBLAAHkrn-rzVPu-cgc9AVprQczks5uhp8bgaJpZM4WVTeV>
.
--
twitter.com/steeve
github.com/steeve
linkd.in/smorin
|
We've pushed the rule we've started using for this here https://github.com/ios-bazel-users/ios-bazel-users/tree/master/prebuilt_swift_static_framework |
@keith Were you able to use static frameworks built with the |
We don't have that use case in our code, but if you added that to the files being zipped it should work fine! |
Thanks. I'll try to figure that out. |
#355 for the |
FYI at this point swiftinterface and swiftdoc files are in the ios_static_framework, so this issue as it currently stands might be closable. But there might need to be a new issue for #223 (comment) |
I think the original issue is fixed here, if there are still issues with ObjC interop we should open a new issue |
When building an
ios_framework
orios_static_framework
around aswift_library
, several issues arise:module.modulemap
is only created if there arehdrs
in the bundle or objc deps withsdk_framework
swiftmodule
andswiftdoc
files are not bundledIn the end, the XCode complains that the framework is not useable.
The text was updated successfully, but these errors were encountered: