Skip to content

Commit

Permalink
possibly-working framework
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Schore <[email protected]>
  • Loading branch information
goaway committed Jun 28, 2019
1 parent 63a5c69 commit 19493a3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
40 changes: 20 additions & 20 deletions bazel/swift_static_framework.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,48 @@ load("@build_bazel_rules_swift//swift:swift.bzl", "SwiftInfo", "swift_library")
MINIMUM_IOS_VERSION = "11.0"

_PLATFORM_TO_SWIFTMODULE = {
"ios_armv7": "arm",
"ios_arm64": "arm64",
"ios_i386": "i386",
"ios_x86_64": "x86_64",
}

def _tar_binary_arg(module_name, input_file):
def _zip_binary_arg(module_name, input_file):
return "{module_name}.framework/{module_name}={file_path}".format(
module_name = module_name,
file_path = input_file.path,
)

def _tar_swift_arg(module_name, swift_identifier, input_file):
def _zip_swift_arg(module_name, swift_identifier, input_file):
return "{module_name}.framework/Modules/{module_name}.swiftmodule/{swift_identifier}.{ext}={file_path}".format(
module_name = module_name,
swift_identifier = swift_identifier,
ext = input_file.extension,
file_path = input_file.path,
)

def _prebuilt_swift_static_framework_impl(ctx):
def _swift_static_framework_impl(ctx):
module_name = ctx.attr.framework_name
fat_file = ctx.outputs.fat_file

input_archives = []
input_modules_docs = []
tar_args = [_tar_binary_arg(module_name, fat_file)]
zip_args = [_zip_binary_arg(module_name, fat_file)]

for platform, archive in ctx.split_attr.archive.items():
swiftmodule_identifier = _PLATFORM_TO_SWIFTMODULE[platform]
if not swiftmodule_identifier:
fail("Unhandled platform '{}'".format(platform))
library = archive[CcInfo].linking_context.libraries_to_link.to_list()[0].pic_static_library
library = archive[CcInfo].linking_context.libraries_to_link[0].pic_static_library
swift_info = archive[SwiftInfo]
swiftdoc = swift_info.direct_swiftdocs[0]
swiftmodule = swift_info.direct_swiftmodules[0]

input_archives.append(library)
input_modules_docs += [swiftdoc, swiftmodule]
tar_args += [
_tar_swift_arg(module_name, swiftmodule_identifier, swiftdoc),
_tar_swift_arg(module_name, swiftmodule_identifier, swiftmodule),
zip_args += [
_zip_swift_arg(module_name, swiftmodule_identifier, swiftdoc),
_zip_swift_arg(module_name, swiftmodule_identifier, swiftmodule),
]

ctx.actions.run(
Expand All @@ -64,9 +66,9 @@ def _prebuilt_swift_static_framework_impl(ctx):
inputs = input_modules_docs + [fat_file],
outputs = [output_file],
mnemonic = "CreateSwiftFrameworkTar",
progress_message = "Creating framework tar for {}".format(module_name),
executable = ctx.executable._create_tar,
arguments = [output_file.path] + tar_args,
progress_message = "Creating framework zip for {}".format(module_name),
executable = ctx.executable._zipper,
arguments = ["c", output_file.path] + zip_args,
)

return [
Expand All @@ -75,8 +77,8 @@ def _prebuilt_swift_static_framework_impl(ctx):
),
]

_prebuilt_swift_static_framework = rule(
implementation = _prebuilt_swift_static_framework_impl,
_swift_static_framework = rule(
implementation = _swift_static_framework_impl,
attrs = dict(
archive = attr.label(
mandatory = True,
Expand All @@ -88,21 +90,20 @@ _prebuilt_swift_static_framework = rule(
platform_type = attr.string(
default = str(apple_common.platform_type.ios),
),
_create_tar = attr.label(
default = "//tools:create_tar",
_zipper = attr.label(
default = "@bazel_tools//tools/zip:zipper",
cfg = "host",
executable = True,
),
),
outputs = {
"fat_file": "%{framework_name}.fat",
"output_file": "%{framework_name}.tar.bz2",
"output_file": "%{framework_name}.zip",
},
)

def prebuilt_swift_static_framework(
def swift_static_framework(
name,
version = None,
srcs = [],
copts = [],
deps = []):
Expand All @@ -111,7 +112,6 @@ def prebuilt_swift_static_framework(
Args:
name: The name of the module, the framework's name will be this name
appending Framework so you can depend on this from other modules
version: The version of the library for use with metadata files
srcs: Custom source paths for the swift files
copts: Any custom swiftc opts passed through to the swift_library
deps: Any deps the swift_library requires
Expand All @@ -127,7 +127,7 @@ def prebuilt_swift_static_framework(
)

framework_name = name + "Framework"
_prebuilt_swift_static_framework(
_swift_static_framework(
name = framework_name,
framework_name = name,
archive = name,
Expand Down
4 changes: 2 additions & 2 deletions library/swift/BUILD
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
licenses(["notice"]) # Apache 2

load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
load("//bazel:swift_static_framework.bzl", "prebuilt_swift_static_framework")
load("//bazel:swift_static_framework.bzl", "swift_static_framework")

prebuilt_swift_static_framework(
swift_static_framework(
name = "swift_framework",
srcs = ["Envoy.swift"],
deps = ["//library/objective-c:envoy_engine_objc_lib"]
Expand Down

0 comments on commit 19493a3

Please sign in to comment.