Skip to content

Commit

Permalink
add support to SPM SystemLibrary
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmarcal-faire committed Nov 5, 2024
1 parent 19ef290 commit 99d8e62
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
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

0 comments on commit 99d8e62

Please sign in to comment.