Swiftgen: Homebrew on ARM (Apple Silicon) support

Created on 19 Dec 2020  ·  9Comments  ·  Source: SwiftGen/SwiftGen

Hi everyone! I know it's mostly Homebrew issue but I was curious if this is 100% Homebrew problem or something can be done in SwiftGen (already posted in Homebrew's issues list about that one).

I installed the swiftgen via homebrew like this:

brew install --build-from-source swiftgen

Got following errors at the end of the build (see full output: https://gist.github.com/bdolewski/53359ba6379c7c8834939265bd9e7e8b)

==> bundle exec rake cli:install[/opt/homebrew/Cellar/swiftgen/6.4.0/bin,/opt/homebrew/Cellar/swiftgen/6.4.0/lib,/opt/homebrew/Cellar/swi
Error: Failed applying an ad-hoc signature to /opt/homebrew/Cellar/swiftgen/6.4.0/lib/Commander.framework/Versions/A/Commander
Error: Failed applying an ad-hoc signature to /opt/homebrew/Cellar/swiftgen/6.4.0/lib/Kanna.framework/Versions/A/Kanna
Error: Failed applying an ad-hoc signature to /opt/homebrew/Cellar/swiftgen/6.4.0/lib/PathKit.framework/Versions/A/PathKit
Error: Failed applying an ad-hoc signature to /opt/homebrew/Cellar/swiftgen/6.4.0/lib/Stencil.framework/Versions/A/Stencil
Error: Failed applying an ad-hoc signature to /opt/homebrew/Cellar/swiftgen/6.4.0/lib/StencilSwiftKit.framework/Versions/A/StencilSwiftKit
Error: Failed applying an ad-hoc signature to /opt/homebrew/Cellar/swiftgen/6.4.0/lib/SwiftGenKit.framework/Versions/A/SwiftGenKit
Error: Failed applying an ad-hoc signature to /opt/homebrew/Cellar/swiftgen/6.4.0/lib/Yams.framework/Versions/A/Yams
🍺  /opt/homebrew/Cellar/swiftgen/6.4.0: 203 files, 19.9MB, built in 1 minute 2 seconds

SwiftGen is installed but when I try to run it it's killed by macOS (I guess is something related to signing code of Kanna, PathKit and Stencil frameworks.

➜  ~ swiftgen
[1]    28873 killed     swiftgen
➜  ~ 
duplicate

All 9 comments

Afaik homebrew does not support ARM yet. You can work around it by prefacing any brew command with this:

arch -x86_64 brew ...

For more info read this article: https://soffes.blog/homebrew-on-apple-silicon

From other issues/comments here, I'm pretty sure SwiftGen works on ARM when installed via Mint (https://github.com/yonaskolb/Mint).

Hi @djbe
That's correct - Homebrew does not support Apple Silicon yet. That's why I wanted to check things out as an early adopter 😉

I downloaded zip file from stable branch. I run build script using command bundle exec rake cli:install.
Got following build log (the last part is similar to the output from Homebrew):

SwiftGen-stable bundle exec rake cli:install
== Building Binary ==
set -o pipefail && (\
 xcrun xcodebuild -workspace "SwiftGen.xcworkspace" -scheme "swiftgen" -configuration "Release" -derivedDataPath "/Users/bartoszdolewski/Downloads/SwiftGen-stable/build" TEMPLATE_PATH="../templates" SWIFTGEN_OTHER_LDFLAGS="-sectcreate __TEXT __info_plist /Users/bartoszdolewski/Downloads/SwiftGen-stable/build/Build/Products/Release/swiftgen.app/Contents/Info.plist" 'OTHER_LDFLAGS=$(inherited) -Wl,-headerpad_max_install_names'  \
) | bundle exec xcpretty -c
objc[48411]: Class AMSupportURLConnectionDelegate is implemented in both ?? (0x1f15278f0) and ?? (0x113f702b8). One of the two will be used. Which one is undefined.
objc[48411]: Class AMSupportURLSession is implemented in both ?? (0x1f1527940) and ?? (0x113f70308). One of the two will be used. Which one is undefined.
▸ Running script '⚠️ SwiftLint'
▸ Compiling SwiftGenKit_vers.c
▸ Compiling SwiftGenKit_vers.c
▸ Linking SwiftGenKit
▸ Linking SwiftGenKit
▸ Generating 'SwiftGenKit.framework.dSYM'
▸ Signing /Users/bartoszdolewski/Downloads/SwiftGen-stable/build/Build/Products/Release/SwiftGenKit.framework
▸ Touching SwiftGenKit.framework (in target 'SwiftGenKit' from project 'SwiftGen')
▸ Processing SwiftGen-Info.plist
▸ Running script '[CP] Check Pods Manifest.lock'
▸ Running script '⚠️ SwiftLint'
▸ Linking swiftgen
▸ Linking swiftgen
▸ Copying /Users/bartoszdolewski/Downloads/SwiftGen-stable/templates
▸ Generating 'swiftgen.app.dSYM'
▸ Copying /Users/bartoszdolewski/Downloads/SwiftGen-stable/build/Build/Products/Release/SwiftGenKit.framework
▸ Signing /Users/bartoszdolewski/Downloads/SwiftGen-stable/build/Build/Products/Release/swiftgen.app/Contents/Frameworks/SwiftGenKit.framework
▸ Running script '[CP] Embed Pods Frameworks'
▸ Touching swiftgen.app (in target 'swiftgen' from project 'SwiftGen')
    The macOS deployment target 'MACOSX_DEPLOYMENT_TARGET' is set to 10.6, but the range of supported deployment target versions is 10.9 to 11.1.99. (in target 'SwiftLint' from project 'SwiftLint')
▸ Build Succeeded
== Installing binary in /Users/bartoszdolewski/Downloads/SwiftGen-stable/build/swiftgen/bin ==
mkdir -p "/Users/bartoszdolewski/Downloads/SwiftGen-stable/build/swiftgen/bin" && \
cp -f "/Users/bartoszdolewski/Downloads/SwiftGen-stable/build/Build/Products/Release/swiftgen.app/Contents/MacOS/swiftgen" "/Users/bartoszdolewski/Downloads/SwiftGen-stable/build/swiftgen/bin/swiftgen"
== Installing frameworks in /Users/bartoszdolewski/Downloads/SwiftGen-stable/build/swiftgen/lib ==
if [ -d "/Users/bartoszdolewski/Downloads/SwiftGen-stable/build/swiftgen/lib" ]; then rm -rf "/Users/bartoszdolewski/Downloads/SwiftGen-stable/build/swiftgen/lib"; fi && \
mkdir -p "/Users/bartoszdolewski/Downloads/SwiftGen-stable/build/swiftgen/lib" && \
cp -fR "/Users/bartoszdolewski/Downloads/SwiftGen-stable/build/Build/Products/Release/swiftgen.app/Contents/Frameworks/" "/Users/bartoszdolewski/Downloads/SwiftGen-stable/build/swiftgen/lib"
== Removing bundled swift libraries from /Users/bartoszdolewski/Downloads/SwiftGen-stable/build/swiftgen/lib ==
rm "/Users/bartoszdolewski/Downloads/SwiftGen-stable/build/swiftgen/lib"/libswift*.dylib
== Fixing binary's @rpath ==
 xcrun install_name_tool -delete_rpath "@executable_path/../Frameworks" "/Users/bartoszdolewski/Downloads/SwiftGen-stable/build/swiftgen/bin/swiftgen" && \
 xcrun install_name_tool -add_rpath "@executable_path/../lib" "/Users/bartoszdolewski/Downloads/SwiftGen-stable/build/swiftgen/bin/swiftgen"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/install_name_tool: warning: changes being made to the file will invalidate the code signature in: /Users/bartoszdolewski/Downloads/SwiftGen-stable/build/swiftgen/bin/swiftgen (for architecture x86_64)
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/install_name_tool: warning: changes being made to the file will invalidate the code signature in: /Users/bartoszdolewski/Downloads/SwiftGen-stable/build/swiftgen/bin/swiftgen (for architecture arm64)
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/install_name_tool: warning: changes being made to the file will invalidate the code signature in: /Users/bartoszdolewski/Downloads/SwiftGen-stable/build/swiftgen/bin/swiftgen (for architecture x86_64)
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/install_name_tool: warning: changes being made to the file will invalidate the code signature in: /Users/bartoszdolewski/Downloads/SwiftGen-stable/build/swiftgen/bin/swiftgen (for architecture arm64)
== Installing templates in /Users/bartoszdolewski/Downloads/SwiftGen-stable/build/swiftgen/templates ==
mkdir -p "/Users/bartoszdolewski/Downloads/SwiftGen-stable/build/swiftgen/templates" && \
cp -r "templates/" "/Users/bartoszdolewski/Downloads/SwiftGen-stable/build/swiftgen/templates"
Finished installing. Binary is available in: /Users/bartoszdolewski/Downloads/SwiftGen-stable/build/swiftgen/bin

Tried to run swiftgen but it was killed by macOS (code sign?)

➜  SwiftGen-stable pwd
/Users/bartoszdolewski/Downloads/SwiftGen-stable
➜  SwiftGen-stable cd build/swiftgen 
➜  swiftgen ls
bin       lib       templates
➜  swiftgen cd bin 
➜  bin ls
swiftgen
➜  bin ./swiftgen 
[1]    48906 killed     ./swiftgen

However I opened SwiftGen.xcworkspace in Xcode 12.3 and build & run SwiftGen without any issues.

Hmmm curious, I wonder if there's a difference between the 2. Will have to investigate.

Probably refs #805.

To me looks like some difference between build configs/setups. Seems like Xcode 12.3 can handle it but commands produced by rake does something different with signing the code that used to work on Intel CPU's (I assume rake runs on Intel without any warnings. I don't believe that signing issues are only present on arm64 but not on x86 - I guess it would fail the same way).
Maybe some commands are out of order for Apple Silicon. Is there something I can try/test to help you out?

This is the log message from macOS's Console.app:

Process:               swiftgen [75042]
Path:                  /opt/homebrew/*/swiftgen
Identifier:            swiftgen
Version:               ???
Code Type:             ARM-64 (Native)
Parent Process:        zsh [29332]
Responsible:           Terminal [1119]
User ID:               501

Date/Time:             2020-12-24 12:45:15.529 +0100
OS Version:            macOS 11.1 (20C69)
Report Version:        12
Anonymous UUID:        AA9CCC4E-BFEB-F56D-D2BD-6F5BD784FE66

Sleep/Wake UUID:       B770D309-D0B8-415C-A110-691B0CC43FC2

Time Awake Since Boot: 55000 seconds
Time Since Wake:       1700 seconds

System Integrity Protection: enabled

Crashed Thread:        Unknown

Exception Type:        EXC_BAD_ACCESS (Code Signature Invalid)
Exception Codes:       0x0000000000000032, 0x000000010432c000
Exception Note:        EXC_CORPSE_NOTIFY

Termination Reason:    Namespace CODESIGNING, Code 0x2

kernel messages:

Backtrace not available

Unknown thread crashed with ARM Thread State (64-bit):
    x0: 0x000000010432c000   x1: 0x000000016bad3888   x2: 0x000000016bad3838   x3: 0x0000000104438802
    x4: 0x0000000000000070   x5: 0x0000000000000073   x6: 0x000000016bad35e0   x7: 0x00000000000006f0
    x8: 0x000000016bad3868   x9: 0x000000016bad3848  x10: 0x000000010445a4a0  x11: 0x0000000000000000
   x12: 0x0000000000000000  x13: 0x000000000000002b  x14: 0x0000000000000000  x15: 0x0000000000000000
   x16: 0x000000010440c624  x17: 0x000000010440d624  x18: 0x0000000000000000  x19: 0x000000016bad3888
   x20: 0x000000010432c000  x21: 0x000000016bad3838  x22: 0x000000010432c000  x23: 0x000000016bad39e8
   x24: 0x000000016bad3aa8  x25: 0x000000016bad3920  x26: 0x0000000000000000  x27: 0x0000000000000000
   x28: 0x000000016bad39c8   fp: 0x000000016bad3820   lr: 0x802580010440c5ec
    sp: 0x000000016bad37a0   pc: 0x000000010440ea1c cpsr: 0x80000000
   far: 0x000000010432c000  esr: 0x92000007


Binary images description not available


External Modification Summary:
  Calls made by other processes targeting this process:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0
  Calls made by this process:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0
  Calls made by all processes on this machine:
    task_for_pid: 127830
    thread_create: 0
    thread_set_state: 118

brew reinstall --debug swiftgen 
/opt/homebrew/Library/Homebrew/brew.rb (Formulary::FormulaLoader): loading /opt/homebrew/Library/Taps/homebrew/homebrew-core/Formula/swiftgen.rb
==> Cloning https://github.com/SwiftGen/SwiftGen.git
git --git-dir /Users/bamboo/Library/Caches/Homebrew/swiftgen--git/.git status -s
Updating /Users/bamboo/Library/Caches/Homebrew/swiftgen--git
git config remote.origin.url https://github.com/SwiftGen/SwiftGen.git
git config remote.origin.fetch \+refs/tags/6.4.0:refs/tags/6.4.0
git config remote.origin.tagOpt --no-tags
git --git-dir /Users/bamboo/Library/Caches/Homebrew/swiftgen--git/.git rev-parse -q --verify 6.4.0\^\{commit\}
==> Checking out tag 6.4.0

.....

==> bundle install --without development release
==> bundle exec rake cli:install[/opt/homebrew/Cellar/swiftgen/6.4.0/bin,/opt/homebrew/Cellar/swiftgen/6.4.0/lib,/opt/homebrew/Cella
/opt/homebrew/Library/Homebrew/shims/scm/git --version
==> Fixing /opt/homebrew/opt/swiftgen/bin/swiftgen permissions from 755 to 555
==> Fixing /opt/homebrew/opt/swiftgen/lib/Commander.framework/Versions/A/Commander permissions from 755 to 444
==> Fixing /opt/homebrew/opt/swiftgen/lib/Commander.framework/Versions/A/Resources/Info.plist permissions from 644 to 444
==> Fixing /opt/homebrew/opt/swiftgen/lib/Commander.framework/Versions/A/_CodeSignature/CodeResources permissions from 644 to 444
==> Fixing /opt/homebrew/opt/swiftgen/lib/Kanna.framework/Versions/A/Kanna permissions from 755 to 444
==> Fixing /opt/homebrew/opt/swiftgen/lib/Kanna.framework/Versions/A/Resources/Info.plist permissions from 644 to 444
==> Fixing /opt/homebrew/opt/swiftgen/lib/Kanna.framework/Versions/A/_CodeSignature/CodeResources permissions from 644 to 444
==> Fixing /opt/homebrew/opt/swiftgen/lib/PathKit.framework/Versions/A/PathKit permissions from 755 to 444
==> Fixing /opt/homebrew/opt/swiftgen/lib/PathKit.framework/Versions/A/Resources/Info.plist permissions from 644 to 444
==> Fixing /opt/homebrew/opt/swiftgen/lib/PathKit.framework/Versions/A/_CodeSignature/CodeResources permissions from 644 to 444
==> Fixing /opt/homebrew/opt/swiftgen/lib/Stencil.framework/Versions/A/Resources/Info.plist permissions from 644 to 444
==> Fixing /opt/homebrew/opt/swiftgen/lib/Stencil.framework/Versions/A/Stencil permissions from 755 to 444
==> Fixing /opt/homebrew/opt/swiftgen/lib/Stencil.framework/Versions/A/_CodeSignature/CodeResources permissions from 644 to 444
==> Fixing /opt/homebrew/opt/swiftgen/lib/StencilSwiftKit.framework/Versions/A/Resources/Info.plist permissions from 644 to 444
==> Fixing /opt/homebrew/opt/swiftgen/lib/StencilSwiftKit.framework/Versions/A/StencilSwiftKit permissions from 755 to 444
==> Fixing /opt/homebrew/opt/swiftgen/lib/StencilSwiftKit.framework/Versions/A/_CodeSignature/CodeResources permissions from 644 to 444
==> Fixing /opt/homebrew/opt/swiftgen/lib/SwiftGenKit.framework/Versions/A/Resources/Info.plist permissions from 644 to 444
==> Fixing /opt/homebrew/opt/swiftgen/lib/SwiftGenKit.framework/Versions/A/SwiftGenKit permissions from 755 to 444
==> Fixing /opt/homebrew/opt/swiftgen/lib/SwiftGenKit.framework/Versions/A/_CodeSignature/CodeResources permissions from 644 to 444
==> Fixing /opt/homebrew/opt/swiftgen/lib/Yams.framework/Versions/A/Resources/Info.plist permissions from 644 to 444
==> Fixing /opt/homebrew/opt/swiftgen/lib/Yams.framework/Versions/A/Yams permissions from 755 to 444
==> Fixing /opt/homebrew/opt/swiftgen/lib/Yams.framework/Versions/A/_CodeSignature/CodeResources permissions from 644 to 444
==> Changing dylib ID of /opt/homebrew/Cellar/swiftgen/6.4.0/lib/Commander.framework/Versions/A/Commander
  from @rpath/Commander.framework/Versions/A/Commander
    to /opt/homebrew/opt/swiftgen/lib/Commander.framework/Versions/A/Commander
==> Codesigning /opt/homebrew/Cellar/swiftgen/6.4.0/lib/Commander.framework/Versions/A/Commander
==> Codesigning (2nd try) /opt/homebrew/Cellar/swiftgen/6.4.0/lib/Commander.framework/Versions/A/Commander
Error: Failed applying an ad-hoc signature to /opt/homebrew/Cellar/swiftgen/6.4.0/lib/Commander.framework/Versions/A/Commander
==> Changing dylib ID of /opt/homebrew/Cellar/swiftgen/6.4.0/lib/Kanna.framework/Versions/A/Kanna
  from @rpath/Kanna.framework/Versions/A/Kanna
    to /opt/homebrew/opt/swiftgen/lib/Kanna.framework/Versions/A/Kanna
==> Codesigning /opt/homebrew/Cellar/swiftgen/6.4.0/lib/Kanna.framework/Versions/A/Kanna
==> Codesigning (2nd try) /opt/homebrew/Cellar/swiftgen/6.4.0/lib/Kanna.framework/Versions/A/Kanna
Error: Failed applying an ad-hoc signature to /opt/homebrew/Cellar/swiftgen/6.4.0/lib/Kanna.framework/Versions/A/Kanna
==> Changing dylib ID of /opt/homebrew/Cellar/swiftgen/6.4.0/lib/PathKit.framework/Versions/A/PathKit
  from @rpath/PathKit.framework/Versions/A/PathKit
    to /opt/homebrew/opt/swiftgen/lib/PathKit.framework/Versions/A/PathKit
==> Codesigning /opt/homebrew/Cellar/swiftgen/6.4.0/lib/PathKit.framework/Versions/A/PathKit
==> Codesigning (2nd try) /opt/homebrew/Cellar/swiftgen/6.4.0/lib/PathKit.framework/Versions/A/PathKit
Error: Failed applying an ad-hoc signature to /opt/homebrew/Cellar/swiftgen/6.4.0/lib/PathKit.framework/Versions/A/PathKit
==> Changing dylib ID of /opt/homebrew/Cellar/swiftgen/6.4.0/lib/Stencil.framework/Versions/A/Stencil
  from @rpath/Stencil.framework/Versions/A/Stencil
    to /opt/homebrew/opt/swiftgen/lib/Stencil.framework/Versions/A/Stencil
==> Codesigning /opt/homebrew/Cellar/swiftgen/6.4.0/lib/Stencil.framework/Versions/A/Stencil
==> Codesigning (2nd try) /opt/homebrew/Cellar/swiftgen/6.4.0/lib/Stencil.framework/Versions/A/Stencil
Error: Failed applying an ad-hoc signature to /opt/homebrew/Cellar/swiftgen/6.4.0/lib/Stencil.framework/Versions/A/Stencil
==> Changing dylib ID of /opt/homebrew/Cellar/swiftgen/6.4.0/lib/StencilSwiftKit.framework/Versions/A/StencilSwiftKit
  from @rpath/StencilSwiftKit.framework/Versions/A/StencilSwiftKit
    to /opt/homebrew/opt/swiftgen/lib/StencilSwiftKit.framework/Versions/A/StencilSwiftKit
==> Codesigning /opt/homebrew/Cellar/swiftgen/6.4.0/lib/StencilSwiftKit.framework/Versions/A/StencilSwiftKit
==> Codesigning (2nd try) /opt/homebrew/Cellar/swiftgen/6.4.0/lib/StencilSwiftKit.framework/Versions/A/StencilSwiftKit
Error: Failed applying an ad-hoc signature to /opt/homebrew/Cellar/swiftgen/6.4.0/lib/StencilSwiftKit.framework/Versions/A/StencilSwiftKit
==> Changing dylib ID of /opt/homebrew/Cellar/swiftgen/6.4.0/lib/SwiftGenKit.framework/Versions/A/SwiftGenKit
  from @rpath/SwiftGenKit.framework/Versions/A/SwiftGenKit
    to /opt/homebrew/opt/swiftgen/lib/SwiftGenKit.framework/Versions/A/SwiftGenKit
==> Codesigning /opt/homebrew/Cellar/swiftgen/6.4.0/lib/SwiftGenKit.framework/Versions/A/SwiftGenKit
==> Codesigning (2nd try) /opt/homebrew/Cellar/swiftgen/6.4.0/lib/SwiftGenKit.framework/Versions/A/SwiftGenKit
Error: Failed applying an ad-hoc signature to /opt/homebrew/Cellar/swiftgen/6.4.0/lib/SwiftGenKit.framework/Versions/A/SwiftGenKit
==> Changing dylib ID of /opt/homebrew/Cellar/swiftgen/6.4.0/lib/Yams.framework/Versions/A/Yams
  from @rpath/Yams.framework/Versions/A/Yams
    to /opt/homebrew/opt/swiftgen/lib/Yams.framework/Versions/A/Yams
==> Codesigning /opt/homebrew/Cellar/swiftgen/6.4.0/lib/Yams.framework/Versions/A/Yams
==> Codesigning (2nd try) /opt/homebrew/Cellar/swiftgen/6.4.0/lib/Yams.framework/Versions/A/Yams
Error: Failed applying an ad-hoc signature to /opt/homebrew/Cellar/swiftgen/6.4.0/lib/Yams.framework/Versions/A/Yams

codesign is failing on permission issue ( understandable as the files are not writable.)
Can someone explain me why file permission is set to -w before applying signature?

I checked in Mint installation and it's working fine on Apple Silicon.
Try :-

To install Mint:- brew install mint
To Install SwiftLint:- sudo mint install realm/SwiftLint
To Install SwiftGen:- sudo mint install SwiftGen/SwiftGen
To manually run the SwiftLint and SwiftGen (navigate to project folder) :- mint run swiftgen and mint run swiftlint

Closing this as a duplicate of #805. Hope to create a release in the coming week.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

taykay08 picture taykay08  ·  3Comments

filip-zielinski picture filip-zielinski  ·  3Comments

embassem picture embassem  ·  3Comments

kacper1703 picture kacper1703  ·  3Comments

stuffmc picture stuffmc  ·  3Comments