Skip to content
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

feat: add support for systemLibrary targets #1323

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions swiftpkg/internal/pkginfos.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,18 @@ def _new_target_from_json_maps(
pkg_path = pkg_path,
sources = clang_src_info.explicit_srcs + clang_src_info.hdrs,
)
elif module_type == module_types.system_library:
clang_src_info = _new_clang_src_info_from_sources(
repository_ctx = repository_ctx,
pkg_path = pkg_path,
c99name = c99name,
target_path = target_path,
source_paths = source_paths,
public_hdrs_path = public_hdrs_path,
exclude_paths = exclude_paths,
other_hdr_srch_paths = [],
)


return _new_target(
name = target_name,
Expand Down
44 changes: 42 additions & 2 deletions swiftpkg/internal/swiftpkg_build_files.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -641,8 +641,48 @@ def _starlarkify_clang_attrs(repository_ctx, attrs):

# buildifier: disable=unused-variable
def _system_library_build_file(target):
# GH009(chuck): Implement _system_library_build_file
return None
attrs = {
"visibility": ["//:__subpackages__"],
}

# These flags are used by SPM when compiling clang modules.
copts = [
# Enable 'blocks' language feature
"-fblocks",
# Synthesize retain and release calls for Objective-C pointers
"-fobjc-arc",
# Enable support for PIC macros
"-fPIC",
# The SWIFT_PACKAGE define is a magical value that SPM uses when it
# builds clang libraries that will be used as Swift modules.
"-DSWIFT_PACKAGE=1",
]
attrs["copts"] = copts

module_map_file = target.clang_src_info.modulemap_path
attrs["module_map"] = module_map_file

# System library targets must include a modulemap file.
# https://github.com/swiftlang/swift-package-manager/blob/12c14222fdde2ffd8303a2c805fed1b1eb802e5c/Sources/PackageLoading/PackageBuilder.swift#L853
if not module_map_file:
fail("Expected a modulemap file for a system library target. name: ", target.name)

header_files = target.clang_src_info.hdrs
attrs["hdrs"] = header_files

bzl_target_name = pkginfo_targets.bazel_label_name(target)

decls = [
build_decls.new(
kind = objc_kinds.library,
name = bzl_target_name,
attrs = attrs,
)
]

return build_files.new(
decls = decls,
)

# MARK: - Apple xcframework Targets

Expand Down
Loading