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

Add support for multi platform xcframeworks #2691

Merged
merged 9 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
13 changes: 11 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let package = Package(
defaultLocalization: "en",
platforms: [
.macOS(.v14),
.iOS(.v12),
.iOS(.v17),
],
products: [
.library(name: "Ice", targets: ["Ice"]),
Expand Down Expand Up @@ -66,7 +66,12 @@ let package = Package(
),
.target(
name: "IceImpl",
dependencies: ["IceCpp", "IceDiscoveryCpp", "IceLocatorDiscoveryCpp"],
dependencies: [
"IceCpp",
"IceDiscoveryCpp",
"IceLocatorDiscoveryCpp",
.target(name:"IceIAPCpp", condition: .when(platforms: [.iOS]))
],
path: "swift/src/IceImpl",
cxxSettings: [
// We rely on a few private headers from Ice
Expand All @@ -91,6 +96,10 @@ let package = Package(
path: "cpp/lib/IceLocatorDiscovery.xcframework"

),
.binaryTarget(
name: "IceIAPCpp",
path: "cpp/lib/IceIAP.xcframework"
),
.executableTarget(
name: "slice2swift",
dependencies: ["mcpp"],
Expand Down
16 changes: 12 additions & 4 deletions config/Make.rules.Darwin
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

supported-platforms = macosx iphoneos iphonesimulator

xcframeworks = Ice IceDiscovery IceLocatorDiscovery IceIAP

macosx_ar = libtool
macosx_cppflags = -mmacosx-version-min=12.00
macosx_ldflags = $(macosx_cppflags) \
Expand All @@ -15,16 +17,22 @@ iphoneos_cc = xcrun -sdk iphoneos clang
iphoneos_cxx = xcrun -sdk iphoneos clang++
iphoneos_cppflags = -miphoneos-version-min=15.0 -arch arm64 -fembed-bitcode
iphoneos_ldflags = -miphoneos-version-min=15.0 -arch arm64
iphoneos_configs = %xcodesdk
iphoneos_targetdir = $(if $(filter %/build,$5),/iphoneos)
iphoneos_configs = %static
iphoneos_targetdir = /iphoneos
# TODO: disable all install for this platform
iphoneos_installdir = /iphoneos
iphoneos_components = $(xcframeworks)

iphonesimulator_ar = libtool
iphonesimulator_cc = xcrun -sdk iphonesimulator clang
iphonesimulator_cxx = xcrun -sdk iphonesimulator clang++
iphonesimulator_cppflags = -mios-simulator-version-min=15.0
iphonesimulator_ldflags = $(iphonesimulator_cppflags)
iphonesimulator_configs = %xcodesdk
iphonesimulator_targetdir = $(if $(filter %/build,$5),/iphonesimulator)
iphonesimulator_configs = %static
iphonesimulator_targetdir = /iphonesimulator
# TODO: disable all install for this platform
iphonesimulator_installdir = /iphonesimulator
iphonesimulator_components = $(xcframeworks)

ifneq ($(shell command -v brew 2> /dev/null),)
MCPP_HOME ?= $(shell brew --prefix mcpp)
Expand Down
4 changes: 4 additions & 0 deletions cpp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ include $(foreach p,$(load_first),src/$p/Makefile.mk)
include $(filter-out $(foreach p,$(load_first),%/src/$p/Makefile.mk),$(shell find $(lang_srcdir)/src -name Makefile.mk))
$(call make-projects,$(projects),make-cpp-src-project,,$(filter all cpp,$(ICE_BIN_DIST)))

ifeq ($(os),Darwin)
$(call make-xcframeworks)
endif

#
# Now, create and load test projects.
#
Expand Down
49 changes: 30 additions & 19 deletions cpp/config/Make.xcframework.rules
Original file line number Diff line number Diff line change
@@ -1,37 +1,48 @@
# Copyright (c) ZeroC, Inc. All rights reserved.

# Gets the library path for a platform (macosx does not have a platform directory)
# $(call xcframework-library,Ice,macosx) => lib/Ice/libIce.a
# $(call xcframework-library,Ice,iphoneos) => lib/iphoneos/libIce.a
xcframework-library = lib/$(if $(filter macosx,$2),,$2/)lib$1.a

# Gets a list of library paths for a component for all platforms
xcframework-libraries = $(foreach p,$($1_platforms),$(call xcframework-library,$1,$p))

# Gets a list of component flags used when generating an xcframework. One set of flags per platform.
xcframework-flags = $(foreach p,$($1_platforms),-library $(call xcframework-library,$1,$p) $(if $2,-headers include/$1))

# Creates a xcframework from a static component and its headers
# $1: The name of the framework (Ice, IceDiscovery, etc.)
# $2: The platform
# $3: Output path
define create-xcframework-from-library
# Note: Th headers are coppied into the root of the Headers directory. We move the headers into Header/$1 so that we can
# include Ice as <Ice/Ice.h>. We also copy the generated headers into the Headers/$1 directory.
#
# $(call create-xcframework,$1=framework-name)
define create-xcframework

lib/$1.xcframework: lib/lib$1.a
$(E) Creating lib/$1.xcframework
lib/$1.xcframework: $(call xcframework-libraries,$1)
$(E) Creating lib/$1.xcframework from $(call xcframework-libraries,$1)
$(Q)$(RM) -r lib/$1.xcframework
$(Q)if [ -d include/$1 ]; then \
xcodebuild -create-xcframework -library lib/lib$1.a -headers include/$1 -output lib/$1.xcframework ; \
mkdir -p lib/$1.xcframework/macos-arm64/Headers/$1 ; \
find lib/$1.xcframework/macos-arm64/Headers/* -prune ! -name $1 -exec mv {} lib/$1.xcframework/macos-arm64/Headers/$1 \; ; \
cp include/generated/$1/*.h lib/$1.xcframework/macos-arm64/Headers/$1 ; \
xcodebuild -create-xcframework $(call xcframework-flags,$1,true) -output lib/$1.xcframework ; \
find lib/$1.xcframework -name Headers -prune -exec mv {} {}_$1 \; -exec mkdir {} \; -exec mv {}_$1 {}/$1 \; ; \
if [ -d include/generated/$1 ]; then \
find lib/$1.xcframework -name Headers -prune -exec cp -r include/generated/$1/* {}/$1 \; ; \
fi \
else \
xcodebuild -create-xcframework -library lib/lib$1.a -output lib/$1.xcframework; \
xcodebuild -create-xcframework $(call xcframework-flags,$1) -output lib/$1.xcframework; \
fi

srcs all:: lib/$1.xcframework

clean::
$(E) Cleaning lib/$1.xcframework
$(Q)$(RM) -r lib/$1.xcframework

endef

ifeq ($(filter $(CONFIGS),static),)
Ice_always_enable_configs := static
IceDiscovery_always_enable_configs := static
IceLocatorDiscovery_always_enable_configs := static
ifeq ($(filter $(config),static),)
$(foreach f, $(xcframeworks), $(eval $f_always_enable_configs := static))
endif

$(eval $(call create-xcframework-from-library,Ice))
$(eval $(call create-xcframework-from-library,IceDiscovery))
$(eval $(call create-xcframework-from-library,IceLocatorDiscovery))
define make-xcframeworks
$(foreach f, $(xcframeworks),\
$(if $($f_platforms),$(eval $(call create-xcframework,$f))))
endef
2 changes: 1 addition & 1 deletion cpp/src/IceIAP/Makefile.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

$(project)_libraries = IceIAP

IceIAP_configs := xcodesdk
IceIAP_configs := static
IceIAP_platforms := iphoneos iphonesimulator

IceIAP_targetdir := $(libdir)
Expand Down
15 changes: 9 additions & 6 deletions swift/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ $1:: test/ios/TestDriverApp.xcodeproj
-project test/ios/TestDriverApp.xcodeproj \
-scheme TestDriverApp \
-configuration $(CONFIG) \
-arch arm64 \
-sdk $2 $3

endef

all:: tests

srcs:
srcs::
$(Q)swift build $(SWIFT_BUILD_FLAGS)

tests::
Expand All @@ -32,13 +34,14 @@ install::
@echo nothing to install

clean::
$(Q)rm -rf .build
$(Q)rm -rf ../.build
$(Q)rm -rf test/.build

distclean:: clean

# test-app-platforms ?= iphonesimulator iphoneos
# We just build the test app for the iphonesimulator platform by default
test-app-platforms ?= $(filter iphonesimulator, $(platforms))

# $(foreach p,$(test-app-platforms),$(eval $(call xcode-test-app-rule,tests,$p,build)))
# $(foreach p,$(test-app-platforms),$(eval $(call xcode-test-app-rule,clean,$p,clean)))
# $(foreach p,$(test-app-platforms),$(eval $(call xcode-test-app-rule,distclean,$p,clean)))
$(foreach p,$(test-app-platforms),$(eval $(call xcode-test-app-rule,tests,$p,build)))
$(foreach p,$(test-app-platforms),$(eval $(call xcode-test-app-rule,clean,$p,clean)))
$(foreach p,$(test-app-platforms),$(eval $(call xcode-test-app-rule,distclean,$p,clean)))
2 changes: 1 addition & 1 deletion swift/test/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ let package = Package(
defaultLocalization: "en",
platforms: [
.macOS(.v14),
.iOS(.v12),
.iOS(.v17),
],
products: [
.library(name: "TestCommon", targets: ["TestCommon"]),
Expand Down
3 changes: 2 additions & 1 deletion swift/test/ios/TestDriverApp/ControllerI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class ProcessControllerI: CommonProcessController {
_ipv4 = ipv4
_ipv6 = ipv6

//TODO: remove the queues
_serverDispatchQueue = DispatchQueue(label: "Server", qos: .background)
_clientDispatchQueue = DispatchQueue(label: "Client", qos: .background)
}
Expand Down Expand Up @@ -197,7 +198,7 @@ class ControllerHelperI: ControllerHelper, TextWriter {

let className = "\(_testName).\(_exe)"

_queue.async {
Task {
do {
let testHelper = TestBundle.getTestHelper(name: className)
testHelper.setControllerHelper(controllerHelper: self)
Expand Down
Loading