Skip to content

Commit

Permalink
iOS Framework build support (#104)
Browse files Browse the repository at this point in the history
* Add build_ios_xcframework.py script

* Always use x64 for iphone simulator

* Add links to wiki page for ios

* Code formatting
  • Loading branch information
johnwason committed Jun 30, 2023
1 parent 86ffc6f commit 881276a
Show file tree
Hide file tree
Showing 7 changed files with 230 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -357,4 +357,5 @@ generated_src
*.asv

vcpkg
.cache
build_xcframework
.cache
7 changes: 6 additions & 1 deletion docs/common/building.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- [Mac OSX](#mac-osx)
- [Swig](#swig)
- [MATLAB Mex](#matlab-mex)
- [iOS](#ios)


The software is tested using GitHub Actions continuous integration. See .github/workflows/main.yml for more information.
Expand Down Expand Up @@ -75,4 +76,8 @@ https://github.com/swig/swig/wiki/Getting-Started for instructions.

### MATLAB Mex

MATLAB install required for build. CMake FindMatlab module is used to locate the MATLAB build dependencies. Be sure to build the MEX file against static boost libraries. Linux will require Boost to be built from source with "-fPIC" C++ gcc option. The apt repository static libraries cannot be used because they were not built with "-fPIC".
MATLAB install required for build. CMake FindMatlab module is used to locate the MATLAB build dependencies. Be sure to build the MEX file against static boost libraries. Linux will require Boost to be built from source with "-fPIC" C++ gcc option. The apt repository static libraries cannot be used because they were not built with "-fPIC".

### iOS

See https://github.com/robotraconteur/robotraconteur/wiki/iOS
8 changes: 6 additions & 2 deletions docs/common/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
- [Debian 10 (buster)](#debian-10-buster)
- [Raspbian 10 (buster)](#raspbian-10-buster)
- [Mac OSX](#mac-osx)

- [iOS](#ios)

### Windows

Expand Down Expand Up @@ -177,4 +177,8 @@ The Java library is available to download from the github release.

[![View robotraconteur on File Exchange](https://www.mathworks.com/matlabcentral/images/matlab-file-exchange.svg)](https://www.mathworks.com/matlabcentral/fileexchange/80509-robotraconteur)

The MATLAB toolbox can be downloaded from the Matlab File Exchange. [https://www.mathworks.com/matlabcentral/fileexchange/80509-robotraconteur](https://www.mathworks.com/matlabcentral/fileexchange/80509-robotraconteur) Click "Download from GitHub" and save the file. Open the file with MATLAB to install the toolbox.
The MATLAB toolbox can be downloaded from the Matlab File Exchange. [https://www.mathworks.com/matlabcentral/fileexchange/80509-robotraconteur](https://www.mathworks.com/matlabcentral/fileexchange/80509-robotraconteur) Click "Download from GitHub" and save the file. Open the file with MATLAB to install the toolbox.

### iOS

See https://github.com/robotraconteur/robotraconteur/wiki/iOS
45 changes: 45 additions & 0 deletions packaging/ios/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AvailableLibraries</key>
<array>
<dict>
<key>HeadersPath</key>
<string>../../vcpkg/installed/arm-ios/include</string>
<key>LibraryIdentifier</key>
<string>ios</string>
<key>LibraryPath</key>
<string>../../combined_lib/robotraconteur_and_deps-ios.a</string>
<key>SupportedArchitectures</key>
<array>
<string>arm</string>
<string>arm64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
</dict>
<dict>
<key>HeadersPath</key>
<string>../../vcpkg/installed/x64-ios/include</string>
<key>LibraryIdentifier</key>
<string>ios-simulator</string>
<key>LibraryPath</key>
<string>../../combined_lib/robotraconteur_and_deps-iphonesimulator.a</string>
<key>SupportedArchitectures</key>
<array>
<!--<string>arm64</string>-->
<!--<string>x86_64</string>-->
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
</array>
<key>CFBundlePackageType</key>
<string>XFWK</string>
<key>XCFrameworkFormatVersion</key>
<string>1.0</string>
</dict>
</plist>
22 changes: 22 additions & 0 deletions packaging/ios/ports/robotraconteur/portfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
include(vcpkg_common_functions)

vcpkg_configure_cmake(
SOURCE_PATH
${CMAKE_CURRENT_LIST_DIR}/../../..
OPTIONS
-DBUILD_GEN=OFF
-DBUILD_TEST=OFF
-DBUILD_TESTING=OFF
-DBUILD_SHARED_LIBS=OFF
-DOPENSSL_USE_STATIC_LIBS=ON)

vcpkg_install_cmake()

vcpkg_fixup_cmake_targets(CONFIG_PATH "lib/cmake/RobotRaconteur")

vcpkg_copy_pdbs()

file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/bin/)
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/bin)
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include)
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/share)
39 changes: 39 additions & 0 deletions packaging/ios/ports/robotraconteur/vcpkg.json.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "robotraconteur",
"version-semver": "@{VERSION}",
"homepage": "http://robotraconteur.com",
"description": "The Robot Raconteur communication framework core library",
"dependencies": [
"boost-algorithm",
"boost-array",
"boost-asio",
"boost-assign",
"boost-atomic",
"boost-bind",
"boost-config",
"boost-container",
"boost-date-time",
"boost-smart-ptr",
"boost-filesystem",
"boost-foreach",
"boost-format",
"boost-function",
"boost-interprocess",
"boost-intrusive",
"boost-lexical-cast",
"boost-locale",
"boost-random",
"boost-range",
"boost-regex",
"boost-scope-exit",
"boost-signals2",
"boost-thread",
"boost-tuple",
"boost-unordered",
"boost-utility",
"boost-uuid",
"boost-program-options",
"openssl",
"gtest"
]
}
110 changes: 110 additions & 0 deletions packaging/scripts/build_ios_xcframework.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import subprocess
from pathlib import Path
import re
import shutil
import platform

ios_triplets = [
"arm-ios",
"arm64-ios",
"x64-ios"
]


archs = {
"arm-ios": "armv7",
"arm64-ios": "arm64",
"x86-ios": "x86",
"x64-ios": "x86_64",
"arm64-iphonesimulator": "arm64"
}

src_root = Path(__file__).parent.parent.parent.absolute()

# Make sure we are in the right place!
rr_header = src_root / "RobotRaconteurCore/include/RobotRaconteur/RobotRaconteurConfig.h"
with open(rr_header) as f:
f1 = f.read()
ver_str_m = re.search(
"ROBOTRACONTEUR_VERSION_TEXT \"(\\d+\\.\\d+\\.\\d+)\"", f1)
ver_str = ver_str_m.group(1)
print("version " + ver_str)

build_dir = src_root / "build_xcframework"
build_dir.mkdir(exist_ok=True)

vcpkg_dir = build_dir / "vcpkg"

if not vcpkg_dir.is_dir():
subprocess.check_call(["git", "clone", "--depth=1",
"https://github.com/microsoft/vcpkg.git"], cwd=build_dir)

if not (vcpkg_dir / "vcpkg").is_file():
subprocess.check_call("./bootstrap-vcpkg.sh", cwd=vcpkg_dir)

# shutil.copy(src_root / "packaging/ios/CMakeLists-openssl-unix.txt",
# build_dir / "vcpkg/ports/openssl/unix/CMakeLists.txt")

triplets_dir = src_root / "packaging/ios/triplets"
ports_in_dir = src_root / "packaging/ios/ports"
ports_dir = build_dir / "ports"
ports_rr_dir = ports_dir / "robotraconteur"
ports_rr_dir.mkdir(exist_ok=True, parents=True)

with open(ports_in_dir / "robotraconteur/vcpkg.json.in") as f:
vcpkg_json_input = f.read()

vcpkg_json_file = vcpkg_json_input.replace("@{VERSION}", ver_str)
print(vcpkg_json_file)
with open(ports_rr_dir / "vcpkg.json", "w") as f:
f.write(vcpkg_json_file)
shutil.copy(ports_in_dir / "robotraconteur/portfile.cmake",
ports_rr_dir / "portfile.cmake")

combined_lib_dir = build_dir / "combined_lib"
combined_lib_dir_tmp = combined_lib_dir / "tmp"
combined_lib_dir.mkdir(exist_ok=True, parents=True)
combined_lib_dir_tmp.mkdir(exist_ok=True, parents=True)

for triplet in ios_triplets:
subprocess.check_call(["./vcpkg", "install", f"--triplet={triplet}",
f"--overlay-ports={ports_dir}", f"--overlay-triplets={triplets_dir}", "robotraconteur"], cwd=vcpkg_dir)

combined_lib_arch = archs[triplet]
combined_lib_path = (combined_lib_dir_tmp /
f"robotraconteur_and_deps-{triplet}.a").absolute()
subprocess.check_call([f"libtool -static -o {combined_lib_path} *.a"],
shell=True, cwd=vcpkg_dir / f"installed/{triplet}/debug/lib")

combined_lipo_ios = ("arm64-ios", "arm-ios")


combined_lipo_sim = ("x64-ios",)


lib_args = " ".join(
[f"robotraconteur_and_deps-{c1}.a" for c1 in combined_lipo_ios])
subprocess.check_call(
f"lipo {lib_args} -create -output ../robotraconteur_and_deps-ios.a", shell=True, cwd=combined_lib_dir_tmp)
sim_lib_args = " ".join(
[f"robotraconteur_and_deps-{c1}.a" for c1 in combined_lipo_sim])
subprocess.check_call(
f"lipo {sim_lib_args} -create -output ../robotraconteur_and_deps-iphonesimulator.a", shell=True, cwd=combined_lib_dir_tmp)

(build_dir / "robotraconteur.xcframework/ios").mkdir(exist_ok=True, parents=True)
(build_dir / "robotraconteur.xcframework/ios-simulator").mkdir(exist_ok=True, parents=True)

with open(src_root / "packaging/ios/Info.plist", "r") as f:
plist_in = f.read()

if 'x64-ios' in triplet:
plist = plist_in.replace(
"<!--<string>x86_64</string>-->", "<string>x86_64</string>")
else:
plist = plist_in.replace(
"<!--<string>arm64</string>-->", "<string>arm64</string>")

with open(build_dir / "robotraconteur.xcframework/Info.plist", "w") as f:
f.write(plist)

# shutil.copy(src_root / "packaging/ios/Info.plist", build_dir / "robotraconteur.xcframework/Info.plist")

0 comments on commit 881276a

Please sign in to comment.