Swift compile for iOS (standalone not Xcode)

Questions and Answers about all things *OS (macOS, iOS, tvOS, watchOS)

Swift compile for iOS (standalone not Xcode)

Postby acura » Mon Aug 20, 2018 8:11 pm

Hmm why even bother when you have C?
I wanted to try.

So AAPL cannot get the swift coherent and doesn't bundle swift dylibs so it isn't really any point.
But this is what I have got so far.

Code: Select all
swiftc-iphone
SDKROOT="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk"
xcrun -sdk iphoneos swiftc -sdk $SDKROOT -target arm64-apple-ios11.0 $*


Signed binary with:
Code: Select all
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>platform-application</key>
    <true/>
    <key>com.apple.private.security.container-required</key>
    <false/>
</dict>
</plist>


Change rpath of binary with install_name_tool -rpath.


This gives error:
I was lazy so just tried to set rpath to . and copy binary to some app that is bundled with swift dylibs.
Code: Select all
-bash-3.2# ./out.bin
dyld: Library not loaded: @rpath/libswiftCore.dylib
  Referenced from: /private/var/containers/Bundle/Application/AF753029-6524-406E-8F7C-24A58F69929B/PhotoExplore.app/Frameworks/./out.bin
  Reason: no suitable image found.  Did find:
   ./libswiftCore.dylib: code signature invalid for './libswiftCore.dylib'

Abort trap: 6


Checking signatures.
Code: Select all
-bash-3.2# jtool --sig out.bin
Blob at offset: 52880 (1008 bytes) is an embedded signature
Code Directory (669 bytes)
      Version:     20001
      Flags:       none
      CodeLimit:   0xce90
      Identifier:  main (0x58)
      CDHash:        2632c56df837aa111d8230354af70a5d58e7b9b39235c90ba4b37a1836b5bdea (computed)
      # of Hashes: 13 code + 5 special
      Hashes @253 size: 32 Type: SHA-256
 Empty requirement set (12 bytes)
Entitlements (279 bytes) (use --ent to view)

Code: Select all
-bash-3.2# jtool --sig libswiftCore.dylib
Fat binary, big-endian,  3 architectures: armv7, armv7s, arm64
Specify one of these architectures with -arch switch, or export the ARCH environment variable
-bash-3.2# ARCH=arm64 !!
ARCH=arm64 jtool --sig libswiftCore.dylib
Blob at offset: 5742128 (82512 bytes) is an embedded signature
Code Directory (28174 bytes)
      Version:     20200
      Flags:       none
      CodeLimit:   0x579e30
      Identifier:  com.apple.dt.runtime.swiftCore (0x34)
      Team ID:     R23KN2NN42 (0x34)
      CDHash:        f9543cb8019308b2b774353dd37c55b52235ae47 (computed)
      # of Hashes: 1402 code + 2 special
      Hashes @134 size: 20 Type: SHA-1
Requirement Set (200 bytes) with 1 requirement:
   0: Designated Requirement (@20, 168 bytes): SIZE: 168
      Ident: (com.apple.dt.runtime.swiftCore) AND Apple Generic Anchor
Cert field
Unknown opcode 7375626a - has Apple changed the op codes?Please notify J!
False Info plist
Code Directory (45022 bytes)
      Version:     20200
      Flags:       none
      CodeLimit:   0x579e30
      Identifier:  com.apple.dt.runtime.swiftCore (0x34)
      Team ID:     R23KN2NN42 (0x34)
      CDHash:        781853721309b5bdd1a822b3e860cc10332d8a1e3117c552f96cfb18c029cec4 (computed)
      # of Hashes: 1402 code + 2 special
      Hashes @158 size: 32 Type: SHA-256
Blob Wrapper (4722 bytes) (0x10000 is CMS (RFC3852) signature)
CA: Apple Certification Authority CN: Apple Root CA
CA: Apple Worldwide Developer Relations CN: Apple Worldwide Developer Relations Certification Authority
CA: Apple Certification Authority CN: Apple Root CA
CA: Apple Certification Authority CN: Apple Root CA
Time: 180616175346Z


So the binary must be signed with apple certs?
acura
 
Posts: 21
Joined: Thu Feb 15, 2018 9:16 pm

Re: Swift compile for iOS (standalone not Xcode)

Postby acura » Wed Aug 22, 2018 8:15 pm

Re-signed dylib with jtool --sign:
Code: Select all
dyld: Library not loaded: @rpath/libswiftCore.dylib
  Referenced from: /private/var/containers/Bundle/Application/4BAE728A-7321-420B-B4B6-6A87E36BFEDF/multi_path.app/binpack64-256/usr/local/bin/./out.bin
  Reason: no suitable image found.  Did find:
   ./libswiftCore.dylib: code signing blocked mmap() of './libswiftCore.dylib'
acura
 
Posts: 21
Joined: Thu Feb 15, 2018 9:16 pm

Re: Swift compile for iOS (standalone not Xcode)

Postby morpheus » Wed Aug 22, 2018 10:26 pm

Sign also with skip-library-validation to get past that annoyance of mmap(2), which is library validation (enforcing same Team ID)
morpheus
Site Admin
 
Posts: 705
Joined: Thu Apr 11, 2013 6:24 pm

Re: Swift compile for iOS (standalone not Xcode)

Postby acura » Thu Aug 23, 2018 8:02 pm

morpheus wrote:Sign also with skip-library-validation to get past that annoyance of mmap(2), which is library validation (enforcing same Team ID)


Thank you! :D
I had a quick try. But still got mmap error.

Used the full com.apple... entitlement. Will give it another try when I can spend some more time on it.
acura
 
Posts: 21
Joined: Thu Feb 15, 2018 9:16 pm

Re: Swift compile for iOS (standalone not Xcode)

Postby acura » Sun Aug 26, 2018 6:52 pm

So now I got it working. Some reboot of iDevice helped it seems.

And to run a simple application just using CoreFoundation these libraries were needed:
libswiftCore.dylib
libswiftCoreFoundation.dylib
libswiftDarwin.dylib
libswiftDispatch.dylib
libswiftObjectiveC.dylib
libswiftSwiftOnoneSupport.dylib
acura
 
Posts: 21
Joined: Thu Feb 15, 2018 9:16 pm


Return to Questions and Answers

Who is online

Users browsing this forum: No registered users and 5 guests