Deploy to iOS simulator in pyqtdeloy-3.3.0

Patrick Stinson patrickkidd at gmail.com
Sun May 4 15:51:24 BST 2025


No, its a pyqtdeploy-sysroot issue.

- It looks like the `apple_sdk` is hardcoded in the pyqtdeploy platform and
there is no way to extend it. See hack below
- The python component won't build because getentropy, sendfile, and chroot
are not available (I don't use the latter two so luckily could just make
them a noop)
- The zlib plugin doesn't have a way to compile with both architectures, so
you have to hack that too.
- You can't have two sysroots in the same --sysroots-dir (I imagine because
of the unextendable platforms isse) so you have to make a separate one for
the simulator

with contextlib.ExitStack() as stack:
stack.enter_context(
patch.dict(
os.environ,
{"PATH": "/Users/patrick/dev/lib/Qt/5.15.2/ios/bin:" + os.getenv("PATH")},
)
)
if os.getenv("PK_IPHONE_SIMULATOR"):
stack.enter_context(
patch("pyqtdeploy.platforms.iOS.sdk_name", "iphonesimulator")
)
stack.enter_context(
patch("pyqtdeploy.platforms.iOS.sdk_prefix", "iPhoneOSSimulator")
)

pyqtdeploysysroot_main.main()



class PythonComponent(Python.PythonComponent):

def run(self, *args, capture=False):
"""Add multiprocessing to make."""
qt = self.get_component("Qt")

_args = tuple(args)
if args[0] == self.host_make:
self.verbose("Adding args for concurrent build.")
if os.name == "nt":
os.environ["CL"] = "/MP"
else:
_args += ("-j16",)
elif args[0] == qt.host_qmake and self.target_arch_name == "macos-64":
_args += ("QMAKE_CFLAGS=-Wno-implicit-function-declaration",)
with contextlib.ExitStack() as stack:
if args[0] == self.host_make and self.target_arch_name == "ios-64":
stack.enter_context(
patch.dict(
os.environ,
{"LDFLAGS": os.environ["LDFLAGS"] + " -framework Security"},
)
)
ret = super().run(*_args, capture=capture)
return ret

def unpack_archive(self, archive, chdir=True):
archive_root = super().unpack_archive(archive, chdir)
self.patch_file("Python/bootstrap_hash.c", self._patch_boostrap_hash)
if self.target_platform_name == "ios":
self.patch_file("Modules/posixmodule.c", self._patch_posixmodule_ios)
return archive_root

@staticmethod
def _patch_boostrap_hash(line, patch_file):
patch_file.write(
line.replace(
'#include "Python.h"',
"""
#include "Python.h"
#include <Security/Security.h>
""",
).replace(
"getentropy(buffer, len)",
"SecRandomCopyBytes(kSecRandomDefault, size, buffer) == errSecSuccess ? 0 :
-1",
)
)
@staticmethod
def _patch_posixmodule_ios(line, patch_file):
patch_file.write(
line.replace(
"#ifdef HAVE_CHROOT",
"#if HAVE_CHROOT\n\n int chroot(const char *path) {return 1;}\n\n",
).replace(
"#ifdef HAVE_SENDFILE",
"#ifdef HAVE_SENDFILE\n\n int sendfile(int, int, off_t, off_t *, struct
sf_hdtr *, int) {return -1;}",
)
)




class zlibComponent(zlib.zlibComponent):

def run(self, *args, capture=False):

IPHONE_SIMULATOR = (
self.target_platform_name == "ios"
and self._sysroot.target.platform.sdk_name == "iphonesimulator"
)
_args = args
with contextlib.ExitStack() as stack:
if (
args[0] in (self.host_make, "./configure")
and IPHONE_SIMULATOR
and self.install_from_source
):
stack.enter_context(
patch.dict(
os.environ,
{
"CFLAGS": "-fembed-bitcode -O3 -arch x86_64 -isysroot "
+ self.apple_sdk
},
)
)
return super().run(*_args, capture=capture)



On Sat, May 3, 2025 at 1:16 PM Phil Thompson <phil at riverbankcomputing.com>
wrote:

> On 03/05/2025 18:38, Patrick Stinson wrote:
> > What is the correct way to build for iOS simulator in pyqtdeploy-3.3.0?
> >
> > I am looking through the sysroot / platform src in pyqtdeploy and
> > having
> > trouble finding the thread through the code to a component parameter,
> > subclassing a Platform, building a separate sysroot for iOS or
> > something
> > else. Not seeing anything in the docs, searched for "simulator"
> >
> > Cheers,
> > -patrick
>
> Isn't that an Xcode issue?
>
> Phil
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20250504/1ac16a7d/attachment.htm>


More information about the PyQt mailing list