Building Swift fails on M1 MBA

Is building the Swift compiler on Apple Silicon Macs supported yet?

I'm currently seeing a failure in clang-rt attempting to build with an M1 MacBook Air:

[371/1854][ 20%][11.945s] Building C object lib/tsan/CMakeFiles/clang_rt.tsan_osx_dynamic.dir/rtl/tsan_rtl_aarch64.S.o
FAILED: lib/tsan/CMakeFiles/clang_rt.tsan_osx_dynamic.dir/rtl/tsan_rtl_aarch64.S.o 
/Users/toon/GitHub/build/Ninja-ReleaseAssert/llvm-macosx-arm64/./bin/clang -Dclang_rt_tsan_osx_dynamic_EXPORTS -I/Users/toon/GitHub/llvm-project/compiler-rt/lib/tsan/.. -x c  -Wall -Wno-unused-parameter -O3 -DNDEBUG -arch arm64 -isysroot /Applications/ -fPIC  -stdlib=libc++ -mmacosx-version-min=10.9 -isysroot /Applications/ -fno-lto -fPIC -fno-builtin -fno-exceptions -funwind-tables -fno-stack-protector -fno-sanitize=safe-stack -fvisibility=hidden -fno-lto -O3 -gline-tables-only -Wno-gnu -Wno-variadic-macros -Wno-c99-extensions -Wno-non-virtual-dtor -fPIE -fno-rtti -Wframe-larger-than=530 -Wglobal-constructors --sysroot=. -MD -MT lib/tsan/CMakeFiles/clang_rt.tsan_osx_dynamic.dir/rtl/tsan_rtl_aarch64.S.o -MF lib/tsan/CMakeFiles/clang_rt.tsan_osx_dynamic.dir/rtl/tsan_rtl_aarch64.S.o.d -o lib/tsan/CMakeFiles/clang_rt.tsan_osx_dynamic.dir/rtl/tsan_rtl_aarch64.S.o -c /Users/toon/GitHub/llvm-project/compiler-rt/lib/tsan/rtl/tsan_rtl_aarch64.S
/Users/toon/GitHub/llvm-project/compiler-rt/lib/tsan/rtl/tsan_rtl_aarch64.S:7:1: error: expected identifier or '('
.align  2
1 error generated.
[380/1854][ 20%][13.385s] Building CXX object lib/tsan/CMakeFiles/clang_rt.tsan_osx_dynamic.dir/rtl/tsan_interceptors_posix.cpp.o
ninja: build stopped: subcommand failed.
[3808/3859][ 98%][2001.846s] Building CXX object tools/clang/tools/extra/clangd/CMakeFiles/obj.clangDaemon.dir/index/Background.cpp.o
FAILED: tools/clang/runtime/compiler-rt-stamps/compiler-rt-build 

Any guidance - even just a "wait, that isn't supported publicly yet" would be helpful. Thanks!

It looks like there was a bug in some cmake workaround goop. Does this PR help?

1 Like

Thanks for the pointer! Yep, that gets me past libunwind, at least.


Looks like the next issue is some architecture confusion. It's trying to lipo together macosx/x86_64/libswiftCompatibility50.a (which contains x86_64 and arm64) +
macosx/arm64/libswiftCompatibility50.a (which contains arm64) +
macosx/arm64e/libswiftCompatibility50.a (which contains arm64 and arm64e).

... and erroring because this would be multiple arm64 segments in the resulting fat library. For my own sanity I really try to avoid build system debugging, so I'll leave it for now for someone else to figure out. :slight_smile:


arm64e isn't supported for third-party code anyway, currently, so you could try just disabling building the arm64e slice.


I'm currently building with

utils/build-script --skip-build-benchmarks \
  --skip-ios --skip-watchos --skip-tvos \
  --swift-darwin-supported-archs "arm64" \
  --sccache --release-debuginfo --test

as described in the Getting Started guide, the only difference being the --swift-darwin-supported-archs option, but I'm getting a different error:

ninja: error: 'stdlib/swift-test-stdlib-macosx-x86_64',
needed by 'stdlib/CMakeFiles/swift-test-stdlib', missing and no known rule to make it

I've tracked all seemingly relevant CMake target creation code that could be related, but I'm not able to find where exactly this missing target dependency is generated. Has anyone else stumbled upon this error?

Are you building on M1? If not, it may be pulling in the host arch somewhere.

You can check what arches it's configuring by examining the CMake output: look for the part that says Architectures:. It should only list arm64, otherwise it didn't filter others out here or it's getting pulled in by mistake elsewhere in the CMake config.

I'm building on the DTK, although I hope there should be no difference between the DTK and M1 when it comes to toolchain builds.

The Architectures: output seems to be what one would expect

-- OS X SDK:
--   Object File Format: MACHO
--   Swift Standard Library Path: macosx
--   Version: 11.0
--   Build number: 20A2408
--   Deployment version: 10.9
--   Version min name: macosx
--   Triple name: macosx
--   Simulator: FALSE
--   Architectures: arm64
--   arm64 triple: arm64-apple-macosx
--   Module triple: arm64-apple-macos
--   arm64 Path: /Applications/

I think I found it: try changing this default stdlib arch to arm64. It is later used to set the stdlib dependency here, wrongly if the primary SDK arch is set wrongly.


Lovely, that helps indeed. Thank you so much!

I created to resolve this, keeping it as a draft as I'm not sure this is the best approach yet...


Issue also observed in Android toolchain: Build on Apple Silicon fails · Issue #110 · vgorloff/swift-everywhere-toolchain · GitHub

Hi Joe. I'm hitting the same error as @gregtitus. How do I disable building the arm64e slice?

Never mind, I didn't add swift-darwin-supported-archs initially. It's working now!

Terms of Service

Privacy Policy

Cookie Policy