swift-atomics icon indicating copy to clipboard operation
swift-atomics copied to clipboard

Building on Windows

Open stevapple opened this issue 3 years ago • 11 comments

Swift Atomics doesn't compile on Windows.

Information

  • Package version: main, 1.0.2
  • Platform version: Windows 10 21H1
  • Swift version: compnerd.org Swift version 5.6.2 (swift-5.6.2-RELEASE)

Checklist

  • [x] If possible, I've reproduced the issue using the main branch of this package.
  • [x] I've searched for existing reports of the same issue.

Steps to Reproduce

Clone & checkout the repository on a Windows machine with Swift toolchain installed. Use swift build to compile.

Expected behavior

The package is supposed to compile successfully.

Actual behavior

swift-output.txt

stevapple avatar Aug 08 '22 13:08 stevapple

Interesting:

[2/13] Compiling Atomics AtomicOptional.swift
<module-includes>:1:10: note: in file included from <module-includes>:1:
#include "_AtomicsShims.h"
         ^
C:\Users\stevapple\workspace\Using\swift-atomics\Sources\_AtomicsShims\include/_AtomicsShims.h:96:1: error: use of undeclared identifier 'memory_order_acquire'
SWIFTATOMIC_THREAD_FENCE_FN(acquire)
^
C:\Users\stevapple\workspace\Using\swift-atomics\Sources\_AtomicsShims\include/_AtomicsShims.h:93:25: note: expanded from macro 'SWIFTATOMIC_THREAD_FENCE_FN'
    atomic_thread_fence(memory_order_##order);                          \
                        ^
<scratch space>:20:1: note: expanded from here
memory_order_acquire
^
<module-includes>:1:10: note: in file included from <module-includes>:1:
#include "_AtomicsShims.h"
         ^
C:\Users\stevapple\workspace\Using\swift-atomics\Sources\_AtomicsShims\include/_AtomicsShims.h:97:1: error: use of undeclared identifier 'memory_order_release'
SWIFTATOMIC_THREAD_FENCE_FN(release)
^
C:\Users\stevapple\workspace\Using\swift-atomics\Sources\_AtomicsShims\include/_AtomicsShims.h:93:25: note: expanded from macro 'SWIFTATOMIC_THREAD_FENCE_FN'
    atomic_thread_fence(memory_order_##order);                          \
                        ^
<scratch space>:20:1: note: expanded from here
memory_order_release
^
<module-includes>:1:10: note: in file included from <module-includes>:1:
#include "_AtomicsShims.h"
         ^
C:\Users\stevapple\workspace\Using\swift-atomics\Sources\_AtomicsShims\include/_AtomicsShims.h:98:1: error: use of undeclared identifier 'memory_order_acq_rel'
SWIFTATOMIC_THREAD_FENCE_FN(acq_rel)
^
C:\Users\stevapple\workspace\Using\swift-atomics\Sources\_AtomicsShims\include/_AtomicsShims.h:93:25: note: expanded from macro 'SWIFTATOMIC_THREAD_FENCE_FN'
    atomic_thread_fence(memory_order_##order);                          \
                        ^
<scratch space>:20:1: note: expanded from here
memory_order_acq_rel
^
<module-includes>:1:10: note: in file included from <module-includes>:1:
#include "_AtomicsShims.h"
         ^
C:\Users\stevapple\workspace\Using\swift-atomics\Sources\_AtomicsShims\include/_AtomicsShims.h:99:1: error: use of undeclared identifier 'memory_order_seq_cst'
SWIFTATOMIC_THREAD_FENCE_FN(seq_cst)
^
C:\Users\stevapple\workspace\Using\swift-atomics\Sources\_AtomicsShims\include/_AtomicsShims.h:93:25: note: expanded from macro 'SWIFTATOMIC_THREAD_FENCE_FN'
    atomic_thread_fence(memory_order_##order);                          \
                        ^
<scratch space>:20:1: note: expanded from here
memory_order_seq_cst
^
<module-includes>:1:10: note: in file included from <module-includes>:1:
#include "_AtomicsShims.h"
         ^
C:\Users\stevapple\workspace\Using\swift-atomics\Sources\_AtomicsShims\include/_AtomicsShims.h:270:1: error: use of undeclared identifier 'memory_order_relaxed'
SWIFTATOMIC_DEFINE_INTEGER_TYPE(SIMPLE, Int, intptr_t, intptr_t)
^
C:\Users\stevapple\workspace\Using\swift-atomics\Sources\_AtomicsShims\include/_AtomicsShims.h:260:3: note: expanded from macro 'SWIFTATOMIC_DEFINE_INTEGER_TYPE'
  SWIFTATOMIC_DEFINE_TYPE(variant, swiftType, cType, storageType)      \
  ^
C:\Users\stevapple\workspace\Using\swift-atomics\Sources\_AtomicsShims\include/_AtomicsShims.h:253:3: note: expanded from macro 'SWIFTATOMIC_DEFINE_TYPE'
  SWIFTATOMIC_LOAD_FNS(swiftType, cType, storageType)                  \
  ^
C:\Users\stevapple\workspace\Using\swift-atomics\Sources\_AtomicsShims\include/_AtomicsShims.h:220:3: note: expanded from macro 'SWIFTATOMIC_LOAD_FNS'
  SWIFTATOMIC_LOAD_FN(swiftType, cType, storageType, relaxed)          \
  ^
C:\Users\stevapple\workspace\Using\swift-atomics\Sources\_AtomicsShims\include/_AtomicsShims.h:134:28: note: expanded from macro 'SWIFTATOMIC_LOAD_FN'
                           memory_order_##order));                      \
                           ^
<scratch space>:20:1: note: expanded from here
memory_order_relaxed
^
<module-includes>:1:10: note: in file included from <module-includes>:1:
#include "_AtomicsShims.h"
         ^
C:\Users\stevapple\workspace\Using\swift-atomics\Sources\_AtomicsShims\include/_AtomicsShims.h:270:1: error: use of undeclared identifier 'memory_order_acquire'
SWIFTATOMIC_DEFINE_INTEGER_TYPE(SIMPLE, Int, intptr_t, intptr_t)
^
C:\Users\stevapple\workspace\Using\swift-atomics\Sources\_AtomicsShims\include/_AtomicsShims.h:260:3: note: expanded from macro 'SWIFTATOMIC_DEFINE_INTEGER_TYPE'
  SWIFTATOMIC_DEFINE_TYPE(variant, swiftType, cType, storageType)      \
  ^
C:\Users\stevapple\workspace\Using\swift-atomics\Sources\_AtomicsShims\include/_AtomicsShims.h:253:3: note: expanded from macro 'SWIFTATOMIC_DEFINE_TYPE'
  SWIFTATOMIC_LOAD_FNS(swiftType, cType, storageType)                  \
  ^
C:\Users\stevapple\workspace\Using\swift-atomics\Sources\_AtomicsShims\include/_AtomicsShims.h:221:3: note: expanded from macro 'SWIFTATOMIC_LOAD_FNS'
  SWIFTATOMIC_LOAD_FN(swiftType, cType, storageType, acquire)          \
  ^
C:\Users\stevapple\workspace\Using\swift-atomics\Sources\_AtomicsShims\include/_AtomicsShims.h:134:28: note: expanded from macro 'SWIFTATOMIC_LOAD_FN'
                           memory_order_##order));                      \
                           ^
<scratch space>:20:1: note: expanded from here
memory_order_acquire
^
<module-includes>:1:10: note: in file included from <module-includes>:1:
#include "_AtomicsShims.h"
         ^
C:\Users\stevapple\workspace\Using\swift-atomics\Sources\_AtomicsShims\include/_AtomicsShims.h:270:1: error: use of undeclared identifier 'memory_order_seq_cst'
SWIFTATOMIC_DEFINE_INTEGER_TYPE(SIMPLE, Int, intptr_t, intptr_t)
^
C:\Users\stevapple\workspace\Using\swift-atomics\Sources\_AtomicsShims\include/_AtomicsShims.h:260:3: note: expanded from macro 'SWIFTATOMIC_DEFINE_INTEGER_TYPE'
  SWIFTATOMIC_DEFINE_TYPE(variant, swiftType, cType, storageType)      \
  ^
C:\Users\stevapple\workspace\Using\swift-atomics\Sources\_AtomicsShims\include/_AtomicsShims.h:253:3: note: expanded from macro 'SWIFTATOMIC_DEFINE_TYPE'
  SWIFTATOMIC_LOAD_FNS(swiftType, cType, storageType)                  \
  ^
C:\Users\stevapple\workspace\Using\swift-atomics\Sources\_AtomicsShims\include/_AtomicsShims.h:222:3: note: expanded from macro 'SWIFTATOMIC_LOAD_FNS'
  SWIFTATOMIC_LOAD_FN(swiftType, cType, storageType, seq_cst)
  ^
C:\Users\stevapple\workspace\Using\swift-atomics\Sources\_AtomicsShims\include/_AtomicsShims.h:134:28: note: expanded from macro 'SWIFTATOMIC_LOAD_FN'
                           memory_order_##order));                      \
                           ^
<scratch space>:20:1: note: expanded from here
memory_order_seq_cst
^
<module-includes>:1:10: note: in file included from <module-includes>:1:
#include "_AtomicsShims.h"
         ^
C:\Users\stevapple\workspace\Using\swift-atomics\Sources\_AtomicsShims\include/_AtomicsShims.h:270:1: error: use of undeclared identifier 'memory_order_relaxed'
SWIFTATOMIC_DEFINE_INTEGER_TYPE(SIMPLE, Int, intptr_t, intptr_t)
^
C:\Users\stevapple\workspace\Using\swift-atomics\Sources\_AtomicsShims\include/_AtomicsShims.h:260:3: note: expanded from macro 'SWIFTATOMIC_DEFINE_INTEGER_TYPE'
  SWIFTATOMIC_DEFINE_TYPE(variant, swiftType, cType, storageType)      \
  ^
C:\Users\stevapple\workspace\Using\swift-atomics\Sources\_AtomicsShims\include/_AtomicsShims.h:254:3: note: expanded from macro 'SWIFTATOMIC_DEFINE_TYPE'
  SWIFTATOMIC_STORE_FNS(swiftType, cType, storageType)                 \
  ^
C:\Users\stevapple\workspace\Using\swift-atomics\Sources\_AtomicsShims\include/_AtomicsShims.h:215:3: note: expanded from macro 'SWIFTATOMIC_STORE_FNS'
  SWIFTATOMIC_STORE_FN(swiftType, cType, storageType, relaxed)         \
  ^
C:\Users\stevapple\workspace\Using\swift-atomics\Sources\_AtomicsShims\include/_AtomicsShims.h:146:27: note: expanded from macro 'SWIFTATOMIC_STORE_FN'
                          memory_order_##order);                        \
                          ^
<scratch space>:20:1: note: expanded from here
memory_order_relaxed
^
(etc)

lorentey avatar Aug 08 '22 20:08 lorentey

Presumably enum memory_order is somehow missing from stdatomic.h on this config; we'll need to take a look at the header files that apply here and see where it leads us.

lorentey avatar Aug 08 '22 20:08 lorentey

I guess the not-founds are related to swiftc not recognizing Clang’s header include path. This is what I get now:

administrator@iZslngp7ujsw3eZ C:\Users\Administrator\Developer\swift-atomics>swift build -Xswiftc -I -Xswiftc C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\lib\clang\13.0.0\include                                                            
Building for debugging...                                                                 
[1/1] Compiling _AtomicsShims src\_AtomicsShims.c                                         
Assertion failed: Loc.isValid() && "Can't get file characteristic of invalid loc!", file D:\a\1\s\llvm-project\clang\lib\Basic\SourceManager.cpp, line 1473                         
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project and the crash backtrace.                                                                                                                              
Stack dump:                                                                                                                                                     
0.      <eof> parser at end of file                                                                                                                             
 #0 0x00007ff747944345 (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x4d14345)                                   
 #1 0x00007fffb557d88d (C:\Windows\System32\ucrtbase.dll+0x6d88d)                                                                                               
 #2 0x00007fffb557e761 (C:\Windows\System32\ucrtbase.dll+0x6e761)                                                                                               
 #3 0x00007fffb55800c1 (C:\Windows\System32\ucrtbase.dll+0x700c1)                                                                                               
 #4 0x00007fffb55803f1 (C:\Windows\System32\ucrtbase.dll+0x703f1)                                                                                               
 #5 0x00007ff7477dcf72 (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x4bacf72)                                   
 #6 0x00007ff747784ce8 (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x4b54ce8)                                   
 #7 0x00007ff743e37a29 (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x1207a29)                                   
 #8 0x00007ff743e52141 (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x1222141)                                   
 #9 0x00007ff743e5934f (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x122934f)                                   
#10 0x00007ff74642f776 (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x37ff776)                                   
#11 0x00007ff74642377e (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x37f377e)                                   
#12 0x00007ff746420921 (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x37f0921)                                   
#13 0x00007ff74644a083 (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x381a083)                                   
#14 0x00007ff74616664c (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x353664c)                                   
#15 0x00007ff7462e1ef4 (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x36b1ef4)                                   
#16 0x00007ff74614c795 (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x351c795)                                   
#17 0x00007ff74614c5a8 (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x351c5a8)                                   
#18 0x00007ff746135c2c (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x3505c2c)                                   
#19 0x00007ff746132e3a (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x3502e3a)                                   
#20 0x00007ff747924994 (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x4cf4994)                                   
#21 0x00007ff747924b7f (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x4cf4b7f)                                   
#22 0x00007ff74792454f (C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin\swiftc.exe+0x4cf454f)                                   
#23 0x00007fffb553268a (C:\Windows\System32\ucrtbase.dll+0x2268a)                                                                                               
#24 0x00007fffb5d97974 (C:\Windows\System32\KERNEL32.DLL+0x17974)                                                                                               
#25 0x00007fffb8baa2f1 (C:\Windows\SYSTEM32\ntdll.dll+0x5a2f1)

@lorentey Seems a compiler bug now?

stevapple avatar Aug 12 '22 08:08 stevapple

Huh, it does smell like there's a compiler bug involved then. It would be useful to get symbols and/or line-level debug info for that stack trace. 🤔

lorentey avatar Aug 12 '22 16:08 lorentey

It's super unfortunate that stack trace on Windows doesn’t contain symbol names. Any suggestions for further debugging?

stevapple avatar Aug 12 '22 16:08 stevapple

I haven't immediately found docs for that -- this may be worth asking about in the Windows section of the forums. Note that the assertion could be a side effect of manually adding the clang headers to the module path; it isn't necessarily relevant to the original build failure.

lorentey avatar Aug 12 '22 17:08 lorentey

Note that the assertion could be a side effect of manually adding the clang headers to the module path; it isn't necessarily relevant to the original build failure.

I filed apple/swift#60534 for this one. Will try with VS 2022 to see if anything’s different.

The original one should be triggered by missing Clang header. VS 2022 provides a stdatomics.h but that’s C++ only (so Clang prefers its own implementation), and I suspect that’s why some symbols are missing.

stevapple avatar Aug 12 '22 17:08 stevapple

I'm going to close the issue with the following conclusions:

  • Atomics is not compatible with Visual Studio 2019 and older. Use VS 2022 instead.
  • A problem within toolchain packaging caused building to fail, which is discussed in https://github.com/apple/swift/issues/60534 and being fixed by https://github.com/apple/swift-installer-scripts/pull/144.
  • For workaround, see https://github.com/apple/swift/issues/60534#issuecomment-1255051994.

stevapple avatar Sep 22 '22 13:09 stevapple

Not sure why this was closed. IIUC, the package still has problems building on Windows.

lorentey avatar Apr 01 '23 01:04 lorentey

The work in progress to eliminate _AtomicsShims would likely help with this platform, too.

lorentey avatar Apr 01 '23 01:04 lorentey

I pieced together some workarounds from the links above in this comment:

https://github.com/apple/swift-atomics/issues/79#issuecomment-1492792028

Unfortunately building this on Windows is still failing with a JSON decoding error during -emit-module. I'm giving up on trying to make 1.1.0 work on Windows; PRs would of course be appreciated. I'd be happy to ship potential fixes in future releases.

lorentey avatar Apr 01 '23 02:04 lorentey