Skip to content

Commit

Permalink
Add support for multi platform xcframeworks (#2691)
Browse files Browse the repository at this point in the history
  • Loading branch information
externl authored Sep 4, 2024
1 parent 250febb commit ac784b0
Show file tree
Hide file tree
Showing 20 changed files with 111 additions and 105 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ jobs:
test_flags: "--platform=x64 --config=Debug"
msbuild_project: "msbuild/ice.proj"

# Xcode SDK builds
# TODO - Should we also test the debug config here as well?
- os: macos-14
config: "xcodesdk"
working_directory: "cpp"
build_flags: "CONFIGS=xcodesdk PLATFORMS=iphonesimulator"
test_flags: "--config=xcodesdk --platform=iphonesimulator --controller-app"
build_cpp_and_python: true
# # Xcode SDK builds
# # TODO - Should we also test the debug config here as well?
# - os: macos-14
# config: "xcodesdk"
# working_directory: "cpp"
# build_flags: "CONFIGS=xcodesdk PLATFORMS=iphonesimulator"
# test_flags: "--config=xcodesdk --platform=iphonesimulator --controller-app"
# build_cpp_and_python: true

# MATLAB
- os: ubuntu-24.04
Expand Down
8 changes: 6 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,11 @@ let package = Package(
),
.target(
name: "IceImpl",
dependencies: ["IceCpp", "IceDiscoveryCpp", "IceLocatorDiscoveryCpp"],
dependencies: [
"IceCpp",
"IceDiscoveryCpp",
"IceLocatorDiscoveryCpp",
],
path: "swift/src/IceImpl",
cxxSettings: [
// We rely on a few private headers from Ice
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

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
6 changes: 6 additions & 0 deletions cpp/include/Ice/Ice.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@
# include "Ice/PropertiesAdmin.h"
# include "Ice/RemoteLogger.h"
# include "Ice/Router.h"

// Include Apple iAP headers if building for iOS
# if defined(__APPLE__) && TARGET_OS_IPHONE != 0
# include "ios/iAPConnectionInfo.h"
# include "ios/iAPEndpointInfo.h"
# endif
#endif

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef ICE_IAP_CONNECTION_INFO_H
#define ICE_IAP_CONNECTION_INFO_H

#include "Ice/Connection.h"
#include "../Connection.h"

#if defined(__clang__)
# pragma clang diagnostic push
Expand All @@ -19,7 +19,7 @@ namespace IceIAP
{
/**
* Provides access to the connection details of an IAP connection
* \headerfile IceIAP/IceIAP.h
* \headerfile Ice/Ice.h
*/
class ConnectionInfo : public Ice::ConnectionInfo
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef ICE_IAP_ENDPOINT_INFO_H
#define ICE_IAP_ENDPOINT_INFO_H

#include "Ice/Endpoint.h"
#include "../Endpoint.h"

#if defined(__clang__)
# pragma clang diagnostic push
Expand All @@ -19,7 +19,7 @@ namespace IceIAP
{
/**
* Provides access to an IAP endpoint information.
* \headerfile IceIAP/IceIAP.h
* \headerfile Ice/Ice.h
*/
class EndpointInfo : public Ice::EndpointInfo
{
Expand Down
11 changes: 0 additions & 11 deletions cpp/include/IceIAP/IceIAP.h

This file was deleted.

8 changes: 4 additions & 4 deletions cpp/src/IceIAP/Connector.h → cpp/src/Ice/ios/iAPConnector.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
#ifndef ICE_IAP_CONNECTOR_H
#define ICE_IAP_CONNECTOR_H

#include "../Ice/Connector.h"
#include "../Ice/ProtocolInstanceF.h"
#include "../Ice/TraceLevelsF.h"
#include "../Ice/TransceiverF.h"
#include "../Connector.h"
#include "../ProtocolInstanceF.h"
#include "../TraceLevelsF.h"
#include "../TransceiverF.h"
#include "Ice/Logger.h"

#import <ExternalAccessory/ExternalAccessory.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

#if TARGET_OS_IPHONE != 0

# include "../Ice/ProtocolInstance.h"
# include "Connector.h"
# include "EndpointI.h"
# include "Transceiver.h"
# include "../ProtocolInstance.h"
# include "iAPConnector.h"
# include "iAPEndpointI.h"
# include "iAPTransceiver.h"

using namespace std;
using namespace Ice;
Expand Down
6 changes: 3 additions & 3 deletions cpp/src/IceIAP/EndpointI.h → cpp/src/Ice/ios/iAPEndpointI.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#ifndef ICE_IAP_ENDPOINT_I_H
#define ICE_IAP_ENDPOINT_I_H

#include "../Ice/EndpointFactory.h"
#include "../Ice/EndpointI.h"
#include "../Ice/ProtocolInstanceF.h"
#include "../EndpointFactory.h"
#include "../EndpointI.h"
#include "../ProtocolInstanceF.h"
#include "Ice/SSL/ServerAuthenticationOptions.h"

#include <optional>
Expand Down
20 changes: 10 additions & 10 deletions cpp/src/IceIAP/EndpointI.mm → cpp/src/Ice/ios/iAPEndpointI.mm
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@

#if TARGET_OS_IPHONE != 0

# include "../Ice/DefaultsAndOverrides.h"
# include "../Ice/EndpointFactoryManager.h"
# include "../Ice/HashUtil.h"
# include "../Ice/Network.h"
# include "../Ice/ProtocolInstance.h"
# include "../Ice/ProtocolPluginFacade.h"
# include "Connector.h"
# include "EndpointI.h"
# include "../DefaultsAndOverrides.h"
# include "../EndpointFactoryManager.h"
# include "../HashUtil.h"
# include "../Network.h"
# include "../ProtocolInstance.h"
# include "../ProtocolPluginFacade.h"
# include "Ice/Initialize.h"
# include "Ice/InputStream.h"
# include "Ice/LocalExceptions.h"
# include "Ice/OutputStream.h"
# include "Ice/Properties.h"
# include "Ice/RegisterPlugins.h"
# include "IceIAP/ConnectionInfo.h"
# include "IceIAP/EndpointInfo.h"
# include "Ice/ios/iAPConnectionInfo.h"
# include "Ice/ios/iAPEndpointInfo.h"
# include "iAPConnector.h"
# include "iAPEndpointI.h"

# include <CoreFoundation/CoreFoundation.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
#ifndef ICE_IAP_TRANSCEIVER_H
#define ICE_IAP_TRANSCEIVER_H

#include "../Ice/Network.h"
#include "../Ice/ProtocolInstanceF.h"
#include "../Ice/Selector.h"
#include "../Ice/Transceiver.h"
#include "../Network.h"
#include "../ProtocolInstanceF.h"
#include "../Selector.h"
#include "../Transceiver.h"

#import <ExternalAccessory/ExternalAccessory.h>
#import <Foundation/Foundation.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

#if TARGET_OS_IPHONE != 0

# include "EndpointI.h"
# include "Transceiver.h"
# include "iAPEndpointI.h"
# include "iAPTransceiver.h"

# include "IceIAP/ConnectionInfo.h"
# include "Ice/ios/iAPConnectionInfo.h"

# include "../Ice/ProtocolInstance.h"
# include "../ProtocolInstance.h"
# include "Ice/Buffer.h"
# include "Ice/LocalExceptions.h"

Expand Down
14 changes: 0 additions & 14 deletions cpp/src/IceIAP/Makefile.mk

This file was deleted.

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)))
6 changes: 0 additions & 6 deletions swift/src/IceImpl/include/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@
#endif

#ifdef __cplusplus

# include <Ice/Ice.h>

# if TARGET_OS_IPHONE
# include <IceIAP/IceIAP.h>
# endif

#endif

#define ICE_SWIFT_UNAVAILABLE(msg) __attribute__((unavailable(msg)))
Loading

0 comments on commit ac784b0

Please sign in to comment.