Skip to content
This repository has been archived by the owner on Aug 14, 2022. It is now read-only.

Build on Apple Silicon fails #110

Closed
jt9897253 opened this issue Feb 3, 2021 · 16 comments
Closed

Build on Apple Silicon fails #110

jt9897253 opened this issue Feb 3, 2021 · 16 comments

Comments

@jt9897253
Copy link
Contributor

Using NDK 21.3.6528147
Branch 1.0.66 or develop

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
"swift" Build [host] is started.
mkdir -p "/swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift"
cd /swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift && ninja -j7
[20/802] Generating ../../../lib/swift/macosx/libswiftCompatibility50.a
FAILED: lib/swift/macosx/libswiftCompatibility50.a 
cd /swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift/stdlib/toolchain/Compatibility50 && /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo -create -output /swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift/./lib/swift/macosx/libswiftCompatibility50.a /swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift/lib/swift/macosx/x86_64/libswiftCompatibility50.a /swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift/lib/swift/macosx/arm64/libswiftCompatibility50.a /swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift/lib/swift/macosx/arm64e/libswiftCompatibility50.a
fatal error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: /swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift/lib/swift/macosx/x86_64/libswiftCompatibility50.a and /swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift/lib/swift/macosx/arm64/libswiftCompatibility50.a have the same architectures (arm64) and can't be in the same fat output file
[22/802] Linking CXX static library lib/swift/macosx/arm64e/libswiftCompatibility51.a
warning: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: archive library: lib/swift/macosx/arm64e/libswiftCompatibility51.a will be fat and ar(1) will not be able to operate on it
[26/802] Generating SyntaxNodes.cpp from SyntaxNodes.cpp.gyb with ptr size = 8
ninja: build stopped: subcommand failed.
Execution of command is failed:
cd /swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift && ninja -j7

If error was due Memory, CPU, or Disk peak resource usage (i.e. missed file while file exists),
then try to run previous command again. Build process will perform "configure" step again,
but most of compilation steps will be skipped.

/swift-everywhere-toolchain/lib/Tool.js:82
      throw error;
      ^

Error: Command failed: cd /swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift && ninja -j7
    at checkExecSyncError (node:child_process:682:11)
    at Object.execSync (node:child_process:719:15)
    at SwiftBuilder.execute (/swift-everywhere-toolchain/lib/Tool.js:72:10)
    at SwiftBuilder.executeBuild (/swift-everywhere-toolchain/lib/Builders/SwiftBuilder.js:159:10)
    at SwiftBuilder.build (/swift-everywhere-toolchain/lib/Builder.js:86:10)
    at SwiftBuilder.make (/swift-everywhere-toolchain/lib/Builder.js:97:10)
    at SwiftBuilder.runAction (/swift-everywhere-toolchain/lib/Builder.js:62:12)
    at Automation.runComponentAction (/swift-everywhere-toolchain/Automation.js:117:26)
    at Automation.stage3 (/swift-everywhere-toolchain/Automation.js:161:10)
    at Automation.build (/swift-everywhere-toolchain/Automation.js:142:10) {
  status: 1,
  signal: null,
  output: [ null, null, null ],
  pid: 63481,
  stdout: null,
  stderr: null
}

Looks like lipo is trying to add the same architecture twice in this command:

lipo: /swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift/lib/swift/macosx/x86_64/libswiftCompatibility50.a and /swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift/lib/swift/macosx/arm64/libswiftCompatibility50.a have the same architectures (arm64) and can't be in the same fat output file

The file libswiftCompatibility50.a already contains intel and arm64 slices:

% file /swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift/lib/swift/macosx/x86_64/libswiftCompatibility50.a

/swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift/lib/swift/macosx/x86_64/libswiftCompatibility50.a: Mach-O universal binary with 2 architectures: [x86_64:current ar archive random library] [arm64:current ar archive random library]
/swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift/lib/swift/macosx/x86_64/libswiftCompatibility50.a (for architecture x86_64):	current ar archive random library
/swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift/lib/swift/macosx/x86_64/libswiftCompatibility50.a (for architecture arm64):	current ar archive random library
@unknown0xff
Copy link

same question

@vgorloff
Copy link
Owner

vgorloff commented Feb 3, 2021

Seems known issue on Swift side: https://forums.swift.org/t/building-swift-fails-on-m1-mba/42181/4

@vgorloff
Copy link
Owner

vgorloff commented Feb 3, 2021

The issue seems fixed, but i don't see it in current Swift 5.3.5 release.

You can try to change this line of code: https://github.com/apple/swift/pull/34998/files#diff-1e7de1ae2d059d21e1dd75d5812d5a34b0222cef273b7c3a2af62eb747f9d20aL761

@jt9897253
Copy link
Contributor Author

Ok, I changed this line from set(SWIFT_PRIMARY_VARIANT_ARCH_default "x86_64") to set(SWIFT_PRIMARY_VARIANT_ARCH_default "arm64") in swift-everywhere-toolchain/ToolChain/Sources/swift/CMakeLists.txt

However, the change does not seem to get picked up or does not work.

@jt9897253
Copy link
Contributor Author

For now, I found the following workaround:

I compiled the toolchain on amd64, then copied it to the M1 machine.

When building the swift everywhere sample application, Android Studio complained about the swift binary not being signed. So I added Android Studio to the list of "developer tools" at -> system settings -> security -> privacy

After installing the Android Studio Simulator Preview for M1 I was able to run the example in the simulator.
Like this, the tests screens in the example app are working.

@vgorloff
Copy link
Owner

vgorloff commented Feb 7, 2021

Glad to know.
Meanwhile I am looking way to get some device with M1 chip.

@jt9897253
Copy link
Contributor Author

The issue seems fixed, but i don't see it in current Swift 5.3.5 release.

Looks like the patch is in the upcoming release/5.4 branch.

@michaelknoch
Copy link

Seems that the NDK is not yet compatible with Apple Silicon. However, compiling swift for android runs pretty fast under rosetta emulation on an M1. I heard that gradle and android studio are unusable slow when emulated. Might be worth trying to natively compile the java sources and use emulation for comping the swift sources until NDK and swift 5.4 is ready. @jt9897253

android/ndk#1299

@vgorloff
Copy link
Owner

@jt9897253
Copy link
Contributor Author

Testing with tag 1.0.69, NDK_VERSION 21.4.7075529, Xcode 12.5, macOS 11.4 results in the following error:

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
"yams" Configure [host] is started.
mkdir -p "/path/to/swift-everywhere-toolchain/ToolChain/Build/darwin-host/yams"
cd /path/to/swift-everywhere-toolchain/ToolChain/Build/darwin-host/yams && cmake \
   -G Ninja \
   -D CMAKE_INSTALL_PREFIX=/ \
   -D CMAKE_BUILD_TYPE=Release \
   /path/to/swift-everywhere-toolchain/ToolChain/Sources/yams
CMake Error at cmake/modules/SwiftSupport.cmake:35 (message):
  Unrecognized architecture on host system: arm64
Call Stack (most recent call first):
  Sources/Yams/CMakeLists.txt:31 (get_swift_host_arch)


-- Configuring incomplete, errors occurred!
See also "/path/to/swift-everywhere-toolchain/ToolChain/Build/darwin-host/yams/CMakeFiles/CMakeOutput.log".
See also "/path/to/swift-everywhere-toolchain/ToolChain/Build/darwin-host/yams/CMakeFiles/CMakeError.log".
Execution of command is failed:
cd /path/to/swift-everywhere-toolchain/ToolChain/Build/darwin-host/yams && cmake \
   -G Ninja \
   -D CMAKE_INSTALL_PREFIX=/ \
   -D CMAKE_BUILD_TYPE=Release \
   /path/to/swift-everywhere-toolchain/ToolChain/Sources/yams

If error was due Memory, CPU, or Disk peak resource usage (i.e. missed file while file exists),
then try to run previous command again. Build process will perform "configure" step again,
but most of compilation steps will be skipped.

/path/to/swift-everywhere-toolchain/lib/Tool.js:82
      throw error;
      ^

Error: Command failed: cd /path/to/swift-everywhere-toolchain/ToolChain/Build/darwin-host/yams && cmake \
   -G Ninja \
   -D CMAKE_INSTALL_PREFIX=/ \
   -D CMAKE_BUILD_TYPE=Release \
   /path/to/swift-everywhere-toolchain/ToolChain/Sources/yams
    at checkExecSyncError (child_process.js:640:11)
    at Object.execSync (child_process.js:676:15)
    at YAMSBuilder.execute (/path/to/swift-everywhere-toolchain/lib/Tool.js:72:10)
    at YAMSBuilder.executeCommands (/path/to/swift-everywhere-toolchain/lib/Tool.js:89:10)
    at YAMSBuilder.executeConfigure (/path/to/swift-everywhere-toolchain/lib/Builders/YAMSBuilder.js:43:10)
    at YAMSBuilder.configure (/path/to/swift-everywhere-toolchain/lib/Builder.js:79:10)
    at YAMSBuilder.make (/path/to/swift-everywhere-toolchain/lib/Builder.js:96:10)
    at YAMSBuilder.runAction (/path/to/swift-everywhere-toolchain/lib/Builder.js:62:12)
    at Automation.runComponentAction (/path/to/swift-everywhere-toolchain/Automation.js:138:25)
    at Automation.stage2 (/path/to/swift-everywhere-toolchain/Automation.js:166:10) {
  status: 1,
  signal: null,
  output: [ null, null, null ],
  pid: 48981,
  stdout: null,
  stderr: null
}

According to the YAMS changelog, version 4.0.2 and newer of yams to support apple silicon. However, the latest version shown in the changelog at swift-everywhere-toolchain/ToolChain/Sources/yams is 3.0.1.

I tested updating yams by changing the yams version in lib/Git/Revision.js to 9ff1cc9327586db4e0c8f46f064b6a82ec1566fa (version 4.0.6).

Now, yams builds cleanly on Apple Silicon. I'll create a pull request for this change.

However, the build still fails. Now with:

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
"swift-driver" Build [host] is started.
mkdir -p "/path/to/swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift-driver"
cd /path/to/swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift-driver && ninja -j7
[2/7] Linking C static library lib/libCSwiftDriver.a
warning: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: archive library: lib/libCSwiftDriver.a the table of contents is empty (no object file members in the library define global symbols)
[6/7] Linking Swift shared library lib/libSwiftDriverExecution.dylib
FAILED: lib/libSwiftDriverExecution.dylib Sources/SwiftDriverExecution/CMakeFiles/SwiftDriverExecution.dir/llbuild.swift.o Sources/SwiftDriverExecution/CMakeFiles/SwiftDriverExecution.dir/MultiJobExecutor.swift.o Sources/SwiftDriverExecution/CMakeFiles/SwiftDriverExecution.dir/SwiftDriverExecutor.swift.o swift/SwiftDriverExecution.swiftmodule 
: && /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc -output-file-map Sources/SwiftDriverExecution/CMakeFiles/SwiftDriverExecution.dir/Release/output-file-map.json -incremental -j 8 -emit-library -o lib/libSwiftDriverExecution.dylib -module-name SwiftDriverExecution -module-link-name SwiftDriverExecution -emit-module -emit-module-path swift/SwiftDriverExecution.swiftmodule -emit-dependencies -DSwiftDriverExecution_EXPORTS -O -swift-version 5 -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk -I /path/to/swift-everywhere-toolchain/ToolChain/Sources/swift-driver/Sources/_CSwiftDriver/include -I swift -I /path/to/swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift-tools-support-core/swift -I /path/to/swift-everywhere-toolchain/ToolChain/Build/darwin-host/llbuild/products/llbuildSwift -I /path/to/swift-everywhere-toolchain/ToolChain/Sources/llbuild/products/libllbuild/include /path/to/swift-everywhere-toolchain/ToolChain/Sources/swift-driver/Sources/SwiftDriverExecution/llbuild.swift /path/to/swift-everywhere-toolchain/ToolChain/Sources/swift-driver/Sources/SwiftDriverExecution/MultiJobExecutor.swift /path/to/swift-everywhere-toolchain/ToolChain/Sources/swift-driver/Sources/SwiftDriverExecution/SwiftDriverExecutor.swift  -Xlinker -install_name -Xlinker @rpath/libSwiftDriverExecution.dylib  -L /path/to/swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift-driver/lib  -L /path/to/swift-everywhere-toolchain/ToolChain/Build/darwin-host/llbuild/lib  -L /path/to/swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift-tools-support-core/lib  -L /path/to/swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift-driver/lib  -L /path/to/swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift-tools-support-core/lib  -L /path/to/swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift-tools-support-core/lib  -L /path/to/swift-everywhere-toolchain/ToolChain/Build/darwin-host/llbuild/lib -Xlinker -rpath -Xlinker /path/to/swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift-driver/lib -Xlinker -rpath -Xlinker /path/to/swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift-tools-support-core/lib -Xlinker -rpath -Xlinker /path/to/swift-everywhere-toolchain/ToolChain/Build/darwin-host/llbuild/lib  lib/libSwiftDriver.dylib  /path/to/swift-everywhere-toolchain/ToolChain/Build/darwin-host/llbuild/lib/libllbuildSwift.a  /path/to/swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift-tools-support-core/lib/libTSCUtility.dylib  lib/libSwiftOptions.dylib  /path/to/swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift-tools-support-core/lib/libTSCBasic.dylib  /path/to/swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift-tools-support-core/lib/libTSCLibc.dylib  /path/to/swift-everywhere-toolchain/ToolChain/Build/darwin-host/llbuild/lib/libllbuild.dylib && :
/path/to/swift-everywhere-toolchain/ToolChain/Sources/swift-driver/Sources/SwiftDriverExecution/llbuild.swift:21:29: error: module 'llbuildSwift' was created for incompatible target x86_64-apple-macos10.10: /path/to/swift-everywhere-toolchain/ToolChain/Build/darwin-host/llbuild/products/llbuildSwift/llbuildSwift.swiftmodule
@_implementationOnly import llbuildSwift
                            ^
ninja: build stopped: subcommand failed.
Execution of command is failed:
cd /path/to/swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift-driver && ninja -j7

If error was due Memory, CPU, or Disk peak resource usage (i.e. missed file while file exists),
then try to run previous command again. Build process will perform "configure" step again,
but most of compilation steps will be skipped.

/path/to/swift-everywhere-toolchain/lib/Tool.js:82
      throw error;
      ^

Error: Command failed: cd /path/to/swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift-driver && ninja -j7
    at checkExecSyncError (child_process.js:640:11)
    at Object.execSync (child_process.js:676:15)
    at SwiftDriverBuilder.execute (/path/to/swift-everywhere-toolchain/lib/Tool.js:72:10)
    at SwiftDriverBuilder.executeBuild (/path/to/swift-everywhere-toolchain/lib/Builders/SwiftDriverBuilder.js:62:10)
    at SwiftDriverBuilder.build (/path/to/swift-everywhere-toolchain/lib/Builder.js:86:10)
    at SwiftDriverBuilder.make (/path/to/swift-everywhere-toolchain/lib/Builder.js:97:10)
    at SwiftDriverBuilder.runAction (/path/to/swift-everywhere-toolchain/lib/Builder.js:62:12)
    at Automation.runComponentAction (/path/to/swift-everywhere-toolchain/Automation.js:140:32)
    at Automation.stage2 (/path/to/swift-everywhere-toolchain/Automation.js:170:10)
    at Automation.build (/path/to/swift-everywhere-toolchain/Automation.js:150:10) {
  status: 1,
  signal: null,
  output: [ null, null, null ],
  pid: 12986,
  stdout: null,
  stderr: null
}

@vgorloff
Copy link
Owner

vgorloff commented Jun 5, 2021

/path/to/swift-everywhere-toolchain/ToolChain/Sources/swift-driver/Sources/SwiftDriverExecution/llbuild.swift:21:29:
error: module 'llbuildSwift' was created for incompatible target x86_64-apple-macos10.10:
/path/to/swift-everywhere-toolchain/ToolChain/Build/darwin-host/llbuild/products/llbuildSwift/llbuildSwift.swiftmodule
@_implementationOnly import llbuildSwift
                            ^
ninja: build stopped: subcommand failed.

Yet another ARM build issue - error: module 'llbuildSwift' was created for incompatible target x86_64-apple-macos10.10.

I hope that, maybe, Swift v5.4.1 already have a fix for this issue. Will look on it.

@jt9897253
Copy link
Contributor Author

Problem persists for tag 1.0.70 with Swift 5.4.1

@jt9897253
Copy link
Contributor Author

After looking into this problem again, I made the following changes:

diff --git a/lib/Builders/LLBBuilder.js b/lib/Builders/LLBBuilder.js
index ce91447..724af96 100644
--- a/lib/Builders/LLBBuilder.js
+++ b/lib/Builders/LLBBuilder.js
@@ -26,6 +26,7 @@ const Builder = require("../Builder");
 const Component = require("../Components");
 const Archs = require("../Archs");
 const SwiftBuilder = require("./SwiftBuilder");
+const os = require('os');
 
 module.exports = class LLBBuilder extends Builder {
   constructor() {
@@ -42,13 +43,13 @@ module.exports = class LLBBuilder extends Builder {
       -D CMAKE_BUILD_TYPE=Release
       -D CMAKE_INSTALL_PREFIX=/
 
-      -D CMAKE_Swift_FLAGS="-Xlinker -v -Xfrontend -target -Xfrontend x86_64-apple-macos10.10 -target x86_64-apple-macos10.10 -v"
+      -D CMAKE_Swift_FLAGS="-Xlinker -v -Xfrontend -target -Xfrontend ${os.arch()}-apple-macos10.10 -target ${os.arch()}-apple-macos10.10 -v"
 
       // -D CMAKE_Swift_FLAGS="-Xfrontend -target-cpu -Xfrontend x86-64 -target-cpu x86-64 -Xlinker -v -Xlinker -arch -Xlinker x86_64 -Xfrontend -target -Xfrontend x86_64-apple-macos10.10 -target x86_64-apple-macos10.10 -sdk ${this.paths.xcMacOsSdkPath} -v"
 
       // See: https://github.com/apple/swift-driver#building-with-cmake
       -D LLBUILD_SUPPORT_BINDINGS=Swift
-      -D CMAKE_OSX_ARCHITECTURES=x86_64
+      -D CMAKE_OSX_ARCHITECTURES=${os.arch()}
 
       // Otherwise it fails to link one of dylib.
       -D BUILD_SHARED_LIBS=false

Now, running

node main.js llb:clean && node main.js llb:configure && node main.js llb:build

succeeds and

 lipo -info ./ToolChain/Build/darwin-host/llbuild/lib/libllbuildSwift.a

correctly returns arm64.

Also, building swift-driver with

 node main.js sd:clean && node main.js sd:configure && node main.js sd:build

no longer produces an error.

However, the next build error is

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
"swift" Build [host] is started.
mkdir -p "/path/to/swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift"
cd /path/to/swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift && ninja -j7
[10/867] Linking CXX static library lib/swift/macosx/arm64e/libswiftCompatibility50.a
warning: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: archive library: lib/swift/macosx/arm64e/libswiftCompatibility50.a will be fat and ar(1) will not be able to operate on it
[12/867] Linking CXX static library lib/swift/macosx/x86_64/libswiftCompatibility50.a
warning: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: archive library: lib/swift/macosx/x86_64/libswiftCompatibility50.a will be fat and ar(1) will not be able to operate on it
[13/867] Generating ../../../lib/swift/macosx/libswiftCompatibility50.a
FAILED: lib/swift/macosx/libswiftCompatibility50.a /path/to/swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift/lib/swift/macosx/libswiftCompatibility50.a 
cd /path/to/swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift/stdlib/toolchain/Compatibility50 && /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo -create -output /path/to/swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift/./lib/swift/macosx/libswiftCompatibility50.a /path/to/swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift/lib/swift/macosx/x86_64/libswiftCompatibility50.a /path/to/swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift/lib/swift/macosx/arm64/libswiftCompatibility50.a /path/to/swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift/lib/swift/macosx/arm64e/libswiftCompatibility50.a
fatal error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: /path/to/swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift/lib/swift/macosx/x86_64/libswiftCompatibility50.a and /path/to/swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift/lib/swift/macosx/arm64/libswiftCompatibility50.a have the same architectures (arm64) and can't be in the same fat output file
[19/867] Building CXX object stdlib/toolchain/Compatibility51/CMakeFiles/swiftCompatibility51-macosx-x86_64.dir/ProtocolConformance.cpp.o
ninja: build stopped: subcommand failed.
Execution of command is failed:
cd /path/to/swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift && ninja -j7

If error was due Memory, CPU, or Disk peak resource usage (i.e. missed file while file exists),
then try to run previous command again. Build process will perform "configure" step again,
but most of compilation steps will be skipped.

/path/to/swift-everywhere-toolchain/lib/Tool.js:82
      throw error;
      ^

Error: Command failed: cd /path/to/swift-everywhere-toolchain/ToolChain/Build/darwin-host/swift && ninja -j7
    at checkExecSyncError (child_process.js:760:11)
    at Object.execSync (child_process.js:833:15)
    at SwiftBuilder.execute (/path/to/swift-everywhere-toolchain/lib/Tool.js:72:10)
    at SwiftBuilder.executeBuild (/path/to/swift-everywhere-toolchain/lib/Builders/SwiftBuilder.js:166:10)
    at SwiftBuilder.build (/path/to/swift-everywhere-toolchain/lib/Builder.js:86:10)
    at SwiftBuilder.make (/path/to/swift-everywhere-toolchain/lib/Builder.js:97:10)
    at SwiftBuilder.runAction (/path/to/swift-everywhere-toolchain/lib/Builder.js:62:12)
    at Automation.runComponentAction (/path/to/swift-everywhere-toolchain/Automation.js:120:26)
    at Automation.stage3 (/path/to/swift-everywhere-toolchain/Automation.js:176:10)
    at Automation.build (/path/to/swift-everywhere-toolchain/Automation.js:151:10) {
  status: 1,
  signal: null,
  output: [ null, null, null ],
  pid: 85497,
  stdout: null,
  stderr: null
}

I had to manually apply the changes from https://github.com/apple/swift/pull/38415/files to work around this. Swift PR 38415 was referenced at https://bugs.swift.org/browse/SR-14035

That means I had to update the file at swift-everywhere-toolchain/ToolChain/Sources/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake:

diff --git a/stdlib/cmake/modules/AddSwiftStdlib.cmake b/stdlib/cmake/modules/AddSwiftStdlib.cmake
index 38191b01a64..b4b1f2ef1b7 100644
--- a/stdlib/cmake/modules/AddSwiftStdlib.cmake
+++ b/stdlib/cmake/modules/AddSwiftStdlib.cmake
@@ -2046,6 +2046,15 @@ function(add_swift_target_library name)
           list(APPEND THIN_INPUT_TARGETS ${VARIANT_NAME})
         endif()
       endif()
+
+      if(sdk IN_LIST SWIFT_APPLE_PLATFORMS)
+        # In the past, we relied on unsetting globally
+        # CMAKE_OSX_ARCHITECTURES to ensure that CMake would
+        # not add the -arch flag
+        # This is no longer the case when running on Apple Silicon,
+        # when CMake will enforce a default (see https://gitlab.kitware.com/cmake/cmake/-/merge_requests/5291)
+        set_property(TARGET ${VARIANT_NAME} PROPERTY OSX_ARCHITECTURES "${arch}")
+      endif()
     endforeach()
 
     # Configure module-only targets
@@ -2483,6 +2492,13 @@ function(add_swift_target_executable name)
       endif()
 
       if(${sdk} IN_LIST SWIFT_APPLE_PLATFORMS)
+        # In the past, we relied on unsetting globally
+        # CMAKE_OSX_ARCHITECTURES to ensure that CMake would
+        # not add the -arch flag
+        # This is no longer the case when running on Apple Silicon,
+        # when CMake will enforce a default (see https://gitlab.kitware.com/cmake/cmake/-/merge_requests/5291)
+        set_property(TARGET ${VARIANT_NAME} PROPERTY OSX_ARCHITECTURES "${arch}")
+
         add_custom_command_target(unused_var2
          COMMAND "codesign" "-f" "-s" "-" "${SWIFT_RUNTIME_OUTPUT_INTDIR}/${VARIANT_NAME}"
          CUSTOM_TARGET_NAME "${VARIANT_NAME}_signed"

Now everything compiles on apple silicon!

In case the above change to lib/Builders/LLBBuilder.js does not break the x64 build (which I can not test), I can create a PR.

@vgorloff
Copy link
Owner

Super. I will apply suggested changes in coming days and test on x64 machine.

vgorloff added a commit that referenced this issue Sep 17, 2021
vgorloff added a commit that referenced this issue Sep 17, 2021
vgorloff added a commit that referenced this issue Sep 17, 2021
vgorloff added a commit that referenced this issue Sep 17, 2021
commit 674ef01
Author: Vlad Gorlov <volodymyr.gorlov@gmail.com>
Date:   Fri Sep 17 15:57:09 2021 +0200

    #110 M1 chip fixes.

commit 0364e27
Author: Vlad Gorlov <volodymyr.gorlov@gmail.com>
Date:   Fri Sep 17 14:40:32 2021 +0200

    #110 M1 chip fixes.

commit 2bef968
Author: Vlad Gorlov <volodymyr.gorlov@gmail.com>
Date:   Fri Sep 17 09:54:37 2021 +0200

    #110 M1 chip fixes.
@vgorloff
Copy link
Owner

x86_64 build works on my side. Fix included into release https://github.com/vgorloff/swift-everywhere-toolchain/releases/tag/1.0.72. I hope that toolchain build still also works on Apple Silicon.

@jt9897253
Copy link
Contributor Author

Building release 1.0.72 on arm64/Apple Silicon succeeds. Thank's for merging the changes and maintaining this project!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants