Skip to content

build: fix accidental cmake expansions #65534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 24, 2023

Conversation

stephank
Copy link
Contributor

@stephank stephank commented Apr 30, 2023

As of CMake 3.25, there are now global variables LINUX=1, ANDROID=1, etc. These conflict with expressions that used these names as unquoted strings in positions where CMake accepts 'variable|string', for example:

  • if(sdk STREQUAL LINUX) would fail, because LINUX is now defined and expands to 1, where it would previously coerce to a string.

  • if(${sdk} STREQUAL "LINUX") would fail if sdk=LINUX, because the left-hand side expands twice.

In this patch, I looked for a number of patterns to fix up, sometimes a little defensively:

  • Quoted right-hand side of STREQUAL where I was confident it was intended to be a string literal.

  • Removed manual variable expansion on left-hand side of STREQUAL, MATCHES and IN_LIST where I was confident it was unintended.

Fixes #65028.


Question: I have a branch for 5.8. This is what I've actually been testing in Nixpkgs, and that builds on x86-64 Linux and aarch64 macOS. Between 5.8 and main, it looks like the only conflicts were CMake additions in main. Should I open a PR against release/5.8 now, or after review?

@finagolfin
Copy link
Member

Should I open a PR against release/5.8 now, or after review?

The way it usually works is that you get it into main first and if nothing breaks, you can cherry-pick it for the release branches and submit pulls for those, eg this recent 5.8 pull #63995.

@xedin xedin removed their request for review May 1, 2023 16:55
@ahoppen ahoppen removed their request for review May 1, 2023 18:44
@rintaro rintaro removed their request for review May 1, 2023 23:21
@egorzhdan
Copy link
Contributor

@swift-ci please smoke test

@tokyovigilante
Copy link

Thanks, can confirm this significantly improves build progress on Fedora 39 (rawhide), however I still see the following building Swift:

240/1501][ 15%][17.157s] Building CXX object lib/Demangling/CMakeFiles/swiftDemangling.dir/ManglingUtils.cpp.o
FAILED: lib/Demangling/CMakeFiles/swiftDemangling.dir/ManglingUtils.cpp.o
/usr/lib64/ccache/clang++ -DCMARK_STATIC_DEFINE -DGTEST_HAS_RTTI=0 -DLLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING=1 -DSWIFT_STDLIB_HAS_TYPE_PRINTING=1 -DSWIFT_SUPPORT_OLD_MANGLING=1 -DSWIFT_THREADING_LINUX -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_LIBCPP_ENABLE_ASSERTIONS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/ryan/Projects/Develop/swift-source/build/buildbot_linux/swift-linux-x86_64/lib/Demangling -I/home/ryan/Projects/Develop/swift-source/swift/lib/Demangling -I/home/ryan/Projects/Develop/swift-source/swift/stdlib/public/SwiftShims -I/home/ryan/Projects/Develop/swift-source/build/buildbot_linux/swift-linux-x86_64/include -I/home/ryan/Projects/Develop/swift-source/swift/include -I/home/ryan/Projects/Develop/swift-source/llvm-project/llvm/include -I/home/ryan/Projects/Develop/swift-source/build/buildbot_linux/llvm-linux-x86_64/include -I/home/ryan/Projects/Develop/swift-source/llvm-project/clang/include -I/home/ryan/Projects/Develop/swift-source/build/buildbot_linux/llvm-linux-x86_64/tools/clang/include -I/home/ryan/Projects/Develop/swift-source/cmark/src/include -I/home/ryan/Projects/Develop/swift-source/build/buildbot_linux/cmark-linux-x86_64/src -I/home/ryan/Projects/Develop/swift-source/swift-corelibs-libdispatch/src/BlocksRuntime -I/home/ryan/Projects/Develop/swift-source/swift-corelibs-libdispatch -Wno-unknown-warning-option -Werror=unguarded-availability-new -fno-stack-protector -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-class-memaccess -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -Werror=switch -Wdocumentation -Wimplicit-fallthrough -Wunreachable-code -Woverloaded-virtual -DOBJC_OLD_DISPATCH_PROTOTYPES=0 -O3 -DNDEBUG -std=c++17  -fno-exceptions -funwind-tables -fno-rtti -Werror=gnu -Werror=c++98-compat-extra-semi -UNDEBUG -target x86_64-unknown-linux-gnu -O2 -g0 -march=core2 -MD -MT lib/Demangling/CMakeFiles/swiftDemangling.dir/ManglingUtils.cpp.o -MF lib/Demangling/CMakeFiles/swiftDemangling.dir/ManglingUtils.cpp.o.d -o lib/Demangling/CMakeFiles/swiftDemangling.dir/ManglingUtils.cpp.o -c /home/ryan/Projects/Develop/swift-source/swift/lib/Demangling/ManglingUtils.cpp
/home/ryan/Projects/Develop/swift-source/swift/lib/Demangling/ManglingUtils.cpp:83:16: error: no member named 'None' in namespace 'llvm'
  return llvm::None;
         ~~~~~~^
1 error generated.
[241/1501][ 16%][17.294s] Building CXX object lib/Demangling/CMakeFiles/swiftDemangling.dir/Demangler.cpp.o
FAILED: lib/Demangling/CMakeFiles/swiftDemangling.dir/Demangler.cpp.o
/usr/lib64/ccache/clang++ -DCMARK_STATIC_DEFINE -DGTEST_HAS_RTTI=0 -DLLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING=1 -DSWIFT_STDLIB_HAS_TYPE_PRINTING=1 -DSWIFT_SUPPORT_OLD_MANGLING=1 -DSWIFT_THREADING_LINUX -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_LIBCPP_ENABLE_ASSERTIONS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/ryan/Projects/Develop/swift-source/build/buildbot_linux/swift-linux-x86_64/lib/Demangling -I/home/ryan/Projects/Develop/swift-source/swift/lib/Demangling -I/home/ryan/Projects/Develop/swift-source/swift/stdlib/public/SwiftShims -I/home/ryan/Projects/Develop/swift-source/build/buildbot_linux/swift-linux-x86_64/include -I/home/ryan/Projects/Develop/swift-source/swift/include -I/home/ryan/Projects/Develop/swift-source/llvm-project/llvm/include -I/home/ryan/Projects/Develop/swift-source/build/buildbot_linux/llvm-linux-x86_64/include -I/home/ryan/Projects/Develop/swift-source/llvm-project/clang/include -I/home/ryan/Projects/Develop/swift-source/build/buildbot_linux/llvm-linux-x86_64/tools/clang/include -I/home/ryan/Projects/Develop/swift-source/cmark/src/include -I/home/ryan/Projects/Develop/swift-source/build/buildbot_linux/cmark-linux-x86_64/src -I/home/ryan/Projects/Develop/swift-source/swift-corelibs-libdispatch/src/BlocksRuntime -I/home/ryan/Projects/Develop/swift-source/swift-corelibs-libdispatch -Wno-unknown-warning-option -Werror=unguarded-availability-new -fno-stack-protector -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-class-memaccess -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -Werror=switch -Wdocumentation -Wimplicit-fallthrough -Wunreachable-code -Woverloaded-virtual -DOBJC_OLD_DISPATCH_PROTOTYPES=0 -O3 -DNDEBUG -std=c++17  -fno-exceptions -funwind-tables -fno-rtti -Werror=gnu -Werror=c++98-compat-extra-semi -UNDEBUG -target x86_64-unknown-linux-gnu -O2 -g0 -march=core2 -MD -MT lib/Demangling/CMakeFiles/swiftDemangling.dir/Demangler.cpp.o -MF lib/Demangling/CMakeFiles/swiftDemangling.dir/Demangler.cpp.o.d -o lib/Demangling/CMakeFiles/swiftDemangling.dir/Demangler.cpp.o -c /home/ryan/Projects/Develop/swift-source/swift/lib/Demangling/Demangler.cpp
In file included from /home/ryan/Projects/Develop/swift-source/swift/lib/Demangling/Demangler.cpp:23:
In file included from /home/ryan/Projects/Develop/swift-source/swift/include/swift/Strings.h:16:
/home/ryan/Projects/Develop/swift-source/swift/include/swift/Basic/LLVM.h:65:30: error: redefinition of 'Optional' as different kind of symbol
  template<typename T> class Optional;
                             ^
/home/ryan/Projects/Develop/swift-source/llvm-project/llvm/include/llvm/ADT/Optional.h:24:20: note: previous definition is here
template <class T> using Optional = std::optional<T>;
                   ^
1 error generated.
[247/1501][ 16%][21.886s] Building CXX object stdlib/public/RemoteInspection/CMakeFiles/swiftRemoteInspection-linux-x86_64.dir/TypeRefBuilder.cpp.o
ninja: build stopped: subcommand failed.
ERROR: command terminated with a non-zero exit status 1, aborting

ERROR: command terminated with a non-zero exit status 1, aborting

@stephank
Copy link
Contributor Author

stephank commented May 3, 2023

It's possible I missed some detail on the main branch. I built this change on main without testing, then backported to 5.8 and tested that, because my intent was to package 5.8 for Nixpkgs.

I'm currently not setup to easily test other branches of Swift than the one version we package in Nixpkgs. Adding some support for that to Nixpkgs is something I'd like, but also a bit of work. I can't really plan that work, because this is spare time effort for me. :)

Perhaps a follow-up PR can fix further issues?

@tokyovigilante
Copy link

Ok, thanks, I appreciate your efforts anyway and good to have some idea of the root cause. The above is against -next so I will try a -main build also.

@bnbarham
Copy link
Contributor

bnbarham commented May 3, 2023

Ok, thanks, I appreciate your efforts anyway and good to have some idea of the root cause. The above is against -next so I will try a -main build also.

next will definitely not build. We branch next onto rebranch periodically and fix up the new LLVM API at that point based on a stable/* branch in the apple LLVM fork.

@tokyovigilante
Copy link

Understood, thanks! I have now tried a -main build which was successful with these patches, thanks!

@tokyovigilante
Copy link

Just noting that changes in b586604 mean that the changes in stdlib/public/Cxx/std/CMakeLists.txt now need to be made to stdlib/public/Cxx/libstdcxx/CMakeLists.txt. Have retested more recent main(eb76d9a) and build succeeds on Fedora with this change.

@finagolfin
Copy link
Member

@stephank, please rebase.

@compnerd, this appears to work well, fixing a recent CMake issue on linux, mind reviewing?

@@ -427,7 +427,7 @@ function(_add_host_variant_link_flags target)
#
# TODO: Evaluate/enable -f{function,data}-sections --gc-sections for bfd,
# gold, and lld.
if(NOT CMAKE_BUILD_TYPE STREQUAL Debug AND CMAKE_SYSTEM_NAME MATCHES Darwin)
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug" AND CMAKE_SYSTEM_NAME MATCHES Darwin)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the RHS of the MATCHES be quoted as well? While a regex, it is still stringly-typed right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've not seen any breakage because of this in our Nixpkgs build. MATCHES RHS doesn't accept variable, so should be safe, I believe.

However, if you'd like me to fix this up, it's easy enough to grep. There are only 18 occurrences. (And FWIW, no cases of LINUX or ANDROID.)

@compnerd compnerd requested a review from etcwilde May 15, 2023 14:16
@finagolfin
Copy link
Member

@stephank, this cannot go anywhere till you rebase and fix any conflicts.

@finagolfin
Copy link
Member

@bnbarham, would you run the mac CI on this again? Let's see if the last failure reproduces, as I suspect it was spurious.

@bnbarham
Copy link
Contributor

bnbarham commented Jul 3, 2023

I don't think I've seen that one (and I'm wrangling this week). But I'll re-run 👍

@bnbarham
Copy link
Contributor

bnbarham commented Jul 3, 2023

@swift-ci please test macOS platform

@finagolfin
Copy link
Member

OK, it reproduces.

@stephank, any idea why this pull would be failing like this on macOS alone?

@stephank
Copy link
Contributor Author

I've been staring at the PR, but can't find my mistake. It seems the Jenkins log has expired. I'll try to find some time to reproduce it soon.

@finagolfin
Copy link
Member

@kateinoigakukun, would you run the mac CI on this again, so he can examine the log, as the prior log has been removed?

@kateinoigakukun
Copy link
Member

@swift-ci please test macOS platform

@stephank
Copy link
Contributor Author

For reference:

FAILED: stdlib/public/Cxx/WATCHOS_SIMULATOR/arm64/Cxx.o 
cd /Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/swift-macosx-x86_64/stdlib/public/Cxx && /Applications/Xcode.app/Contents/Developer/usr/bin/python3 /Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/swift/utils/line-directive @/Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/swift-macosx-x86_64/stdlib/public/Cxx/f141d0b80036276a8e5dc363a1815fcf946ca02e.txt -- /Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/swift-macosx-x86_64/./bin/swiftc -c -sdk /Applications/Xcode.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator9.1.sdk -target arm64-apple-watchos4.0 -resource-dir /Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/swift-macosx-x86_64/./lib/swift -F/Applications/Xcode.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator9.1.sdk/../../../Developer/Library/Frameworks -O -D INTERNAL_CHECKS_ENABLED -D SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY -D SWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED -D SWIFT_ENABLE_RUNTIME_FUNCTION_COUNTERS -D SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING -D SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING -D SWIFT_ENABLE_EXPERIMENTAL_OBSERVATION -D SWIFT_RUNTIME_OS_VERSIONING -D SWIFT_STDLIB_ENABLE_UNICODE_DATA -D SWIFT_STDLIB_ENABLE_VECTOR_TYPES -D SWIFT_STDLIB_HAS_COMMANDLINE -D SWIFT_STDLIB_HAS_STDIN -D SWIFT_STDLIB_HAS_ENVIRON -Xcc -DSWIFT_STDLIB_HAS_ENVIRON -D SWIFT_THREADING_DARWIN -tools-directory /Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/llvm-macosx-x86_64/./bin -module-cache-path /Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/swift-macosx-x86_64/./module-cache -no-link-objc-runtime -enable-library-evolution -library-level api -Xfrontend -require-explicit-availability=ignore -Xfrontend -enforce-exclusivity=unchecked -D SWIFT_ENABLE_REFLECTION -module-name Cxx -swift-version 5 -runtime-compatibility-version none -disable-autolinking-runtime-compatibility-dynamic-replacements -Xfrontend -disable-autolinking-runtime-compatibility-concurrency -diagnostic-style swift -Xfrontend -enable-experimental-cxx-interop -Xcc -nostdinc++ -warn-implicit-overrides -Xfrontend -enable-ossa-modules -Xfrontend -enable-lexical-lifetimes=false -Xfrontend -disable-implicit-concurrency-module-import -Xfrontend -disable-implicit-string-processing-module-import -Xfrontend -prespecialize-generic-metadata -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 9999:macOS\ 9999,\ iOS\ 9999,\ watchOS\ 9999,\ tvOS\ 9999 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.0:macOS\ 10.14.4,\ iOS\ 12.2,\ watchOS\ 5.2,\ tvOS\ 12.2 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.1:macOS\ 10.15,\ iOS\ 13.0,\ watchOS\ 6.0,\ tvOS\ 13.0 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.2:macOS\ 10.15.4,\ iOS\ 13.4,\ watchOS\ 6.2,\ tvOS\ 13.4 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.3:macOS\ 11.0,\ iOS\ 14.0,\ watchOS\ 7.0,\ tvOS\ 14.0 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.4:macOS\ 11.3,\ iOS\ 14.5,\ watchOS\ 7.4,\ tvOS\ 14.5 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.5:macOS\ 12.0,\ iOS\ 15.0,\ watchOS\ 8.0,\ tvOS\ 15.0 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.6:macOS\ 12.3,\ iOS\ 15.4,\ watchOS\ 8.5,\ tvOS\ 15.4 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.7:macOS\ 13.0,\ iOS\ 16.0,\ watchOS\ 9.0,\ tvOS\ 16.0 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.8:macOS\ 13.3,\ iOS\ 16.4,\ watchOS\ 9.4,\ tvOS\ 16.4 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.9:macOS\ 9999,\ iOS\ 9999,\ watchOS\ 9999,\ tvOS\ 9999 -Xfrontend -target-min-inlining-version -Xfrontend min -whole-module-optimization -save-optimization-record=bitstream -color-diagnostics -parse-as-library -resource-dir /Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/swift-macosx-x86_64/./lib/swift -I /Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/swift-macosx-x86_64/./lib/swift/watchsimulator -o /Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/swift-macosx-x86_64/stdlib/public/Cxx//WATCHOS_SIMULATOR/arm64/Cxx.o @/Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/swift-macosx-x86_64/stdlib/public/Cxx/f141d0b80036276a8e5dc363a1815fcf946ca02e.txt
<unknown>:0: warning: the '-enable-experimental-cxx-interop' flag is deprecated; please pass '-cxx-interoperability-mode=' instead
<unknown>:0: note: Swift will maintain source compatibility for imported APIs based on the selected compatibility mode, so updating the Swift compiler will not change how APIs are imported
<unknown>:0: error: could not find module 'Swift' for target 'arm64-apple-watchos'; found: x86_64-apple-watchos-simulator, i386-apple-watchos-simulator, arm64-apple-watchos-simulator, at: /Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/swift-macosx-x86_64/lib/swift/watchsimulator/Swift.swiftmodule
[2972/7122][ 41%][1048.565s] cd /Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/swift-macosx-x86_64/stdlib/public/Cxx && /Users/ec2-user/jenkins/workspace/oss-swift-test-stdlib-with-toolchain/cmake-bin/CMake.app/Contents/bin/cmake -E remove -f /Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/swift-macosx-x86_64/./lib/swift/watchsimulator/Cxx.swiftmodule/arm64-apple-watchos-simulator.swiftmodule /Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/swift-macosx-x86_64/./lib/swift/watchsimulator/Cxx.swiftmodule/arm64-apple-watchos-simulator.swiftdoc /Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/swift-macosx-x86_64/./lib/swift/watchsimulator/Cxx.swiftmodule/arm64-apple-watchos-simulator.swiftinterface /Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/swift-macosx-x86_64/./lib/swift/watchsimulator/Cxx.swiftmodule/arm64-apple-watchos-simulator.private.swiftinterface && /Users/ec2-user/jenkins/workspace/oss-swift-test-stdlib-with-toolchain/cmake-bin/CMake.app/Contents/bin/cmake -E make_directory /Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/swift-macosx-x86_64/./lib/swift/watchsimulator /Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/swift-macosx-x86_64/./lib/swift/watchsimulator/Cxx.swiftmodule && /Applications/Xcode.app/Contents/Developer/usr/bin/python3 /Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/swift/utils/line-directive @/Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/swift-macosx-x86_64/stdlib/public/Cxx/f141d0b80036276a8e5dc363a1815fcf946ca02e.txt -- /Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/swift-macosx-x86_64/./bin/swiftc -emit-module -o /Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/swift-macosx-x86_64/./lib/swift/watchsimulator/Cxx.swiftmodule/arm64-apple-watchos-simulator.swiftmodule -avoid-emit-module-source-info -sdk /Applications/Xcode.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator9.1.sdk -target arm64-apple-watchos4.0 -resource-dir /Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/swift-macosx-x86_64/./lib/swift -F/Applications/Xcode.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator9.1.sdk/../../../Developer/Library/Frameworks -O -D INTERNAL_CHECKS_ENABLED -D SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY -D SWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED -D SWIFT_ENABLE_RUNTIME_FUNCTION_COUNTERS -D SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING -D SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING -D SWIFT_ENABLE_EXPERIMENTAL_OBSERVATION -D SWIFT_RUNTIME_OS_VERSIONING -D SWIFT_STDLIB_ENABLE_UNICODE_DATA -D SWIFT_STDLIB_ENABLE_VECTOR_TYPES -D SWIFT_STDLIB_HAS_COMMANDLINE -D SWIFT_STDLIB_HAS_STDIN -D SWIFT_STDLIB_HAS_ENVIRON -Xcc -DSWIFT_STDLIB_HAS_ENVIRON -D SWIFT_THREADING_DARWIN -tools-directory /Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/llvm-macosx-x86_64/./bin -module-cache-path /Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/swift-macosx-x86_64/./module-cache -no-link-objc-runtime -enable-library-evolution -library-level api -Xfrontend -require-explicit-availability=ignore -Xfrontend -enforce-exclusivity=unchecked -D SWIFT_ENABLE_REFLECTION -module-name Cxx -swift-version 5 -runtime-compatibility-version none -disable-autolinking-runtime-compatibility-dynamic-replacements -Xfrontend -disable-autolinking-runtime-compatibility-concurrency -diagnostic-style swift -Xfrontend -enable-experimental-cxx-interop -Xcc -nostdinc++ -warn-implicit-overrides -Xfrontend -enable-ossa-modules -Xfrontend -enable-lexical-lifetimes=false -Xfrontend -disable-implicit-concurrency-module-import -Xfrontend -disable-implicit-string-processing-module-import -Xfrontend -prespecialize-generic-metadata -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 9999:macOS\ 9999,\ iOS\ 9999,\ watchOS\ 9999,\ tvOS\ 9999 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.0:macOS\ 10.14.4,\ iOS\ 12.2,\ watchOS\ 5.2,\ tvOS\ 12.2 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.1:macOS\ 10.15,\ iOS\ 13.0,\ watchOS\ 6.0,\ tvOS\ 13.0 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.2:macOS\ 10.15.4,\ iOS\ 13.4,\ watchOS\ 6.2,\ tvOS\ 13.4 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.3:macOS\ 11.0,\ iOS\ 14.0,\ watchOS\ 7.0,\ tvOS\ 14.0 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.4:macOS\ 11.3,\ iOS\ 14.5,\ watchOS\ 7.4,\ tvOS\ 14.5 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.5:macOS\ 12.0,\ iOS\ 15.0,\ watchOS\ 8.0,\ tvOS\ 15.0 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.6:macOS\ 12.3,\ iOS\ 15.4,\ watchOS\ 8.5,\ tvOS\ 15.4 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.7:macOS\ 13.0,\ iOS\ 16.0,\ watchOS\ 9.0,\ tvOS\ 16.0 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.8:macOS\ 13.3,\ iOS\ 16.4,\ watchOS\ 9.4,\ tvOS\ 16.4 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.9:macOS\ 9999,\ iOS\ 9999,\ watchOS\ 9999,\ tvOS\ 9999 -Xfrontend -target-min-inlining-version -Xfrontend min -whole-module-optimization -save-optimization-record=bitstream -color-diagnostics -parse-as-library -resource-dir /Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/swift-macosx-x86_64/./lib/swift -I /Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/swift-macosx-x86_64/./lib/swift/watchsimulator -emit-module-interface-path /Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/swift-macosx-x86_64/./lib/swift/watchsimulator/Cxx.swiftmodule/arm64-apple-watchos-simulator.swiftinterface -emit-private-module-interface-path /Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/swift-macosx-x86_64/./lib/swift/watchsimulator/Cxx.swiftmodule/arm64-apple-watchos-simulator.private.swiftinterface -Xfrontend -experimental-skip-non-inlinable-function-bodies @/Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/swift-macosx-x86_64/stdlib/public/Cxx/f141d0b80036276a8e5dc363a1815fcf946ca02e.txt
FAILED: lib/swift/watchsimulator/Cxx.swiftmodule/arm64-apple-watchos-simulator.swiftmodule lib/swift/watchsimulator/Cxx.swiftmodule/arm64-apple-watchos-simulator.swiftdoc lib/swift/watchsimulator/Cxx.swiftmodule/arm64-apple-watchos-simulator.swiftinterface lib/swift/watchsimulator/Cxx.swiftmodule/arm64-apple-watchos-simulator.private.swiftinterface 
cd /Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/swift-macosx-x86_64/stdlib/public/Cxx && /Users/ec2-user/jenkins/workspace/oss-swift-test-stdlib-with-toolchain/cmake-bin/CMake.app/Contents/bin/cmake -E remove -f /Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/swift-macosx-x86_64/./lib/swift/watchsimulator/Cxx.swiftmodule/arm64-apple-watchos-simulator.swiftmodule /Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/swift-macosx-x86_64/./lib/swift/watchsimulator/Cxx.swiftmodule/arm64-apple-watchos-simulator.swiftdoc /Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/swift-macosx-x86_64/./lib/swift/watchsimulator/Cxx.swiftmodule/arm64-apple-watchos-simulator.swiftinterface /Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/swift-macosx-x86_64/./lib/swift/watchsimulator/Cxx.swiftmodule/arm64-apple-watchos-simulator.private.swiftinterface && /Users/ec2-user/jenkins/workspace/oss-swift-test-stdlib-with-toolchain/cmake-bin/CMake.app/Contents/bin/cmake -E make_directory /Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/swift-macosx-x86_64/./lib/swift/watchsimulator /Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/swift-macosx-x86_64/./lib/swift/watchsimulator/Cxx.swiftmodule && /Applications/Xcode.app/Contents/Developer/usr/bin/python3 /Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/swift/utils/line-directive @/Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/swift-macosx-x86_64/stdlib/public/Cxx/f141d0b80036276a8e5dc363a1815fcf946ca02e.txt -- /Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/swift-macosx-x86_64/./bin/swiftc -emit-module -o /Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/swift-macosx-x86_64/./lib/swift/watchsimulator/Cxx.swiftmodule/arm64-apple-watchos-simulator.swiftmodule -avoid-emit-module-source-info -sdk /Applications/Xcode.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator9.1.sdk -target arm64-apple-watchos4.0 -resource-dir /Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/swift-macosx-x86_64/./lib/swift -F/Applications/Xcode.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator9.1.sdk/../../../Developer/Library/Frameworks -O -D INTERNAL_CHECKS_ENABLED -D SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY -D SWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED -D SWIFT_ENABLE_RUNTIME_FUNCTION_COUNTERS -D SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING -D SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING -D SWIFT_ENABLE_EXPERIMENTAL_OBSERVATION -D SWIFT_RUNTIME_OS_VERSIONING -D SWIFT_STDLIB_ENABLE_UNICODE_DATA -D SWIFT_STDLIB_ENABLE_VECTOR_TYPES -D SWIFT_STDLIB_HAS_COMMANDLINE -D SWIFT_STDLIB_HAS_STDIN -D SWIFT_STDLIB_HAS_ENVIRON -Xcc -DSWIFT_STDLIB_HAS_ENVIRON -D SWIFT_THREADING_DARWIN -tools-directory /Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/llvm-macosx-x86_64/./bin -module-cache-path /Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/swift-macosx-x86_64/./module-cache -no-link-objc-runtime -enable-library-evolution -library-level api -Xfrontend -require-explicit-availability=ignore -Xfrontend -enforce-exclusivity=unchecked -D SWIFT_ENABLE_REFLECTION -module-name Cxx -swift-version 5 -runtime-compatibility-version none -disable-autolinking-runtime-compatibility-dynamic-replacements -Xfrontend -disable-autolinking-runtime-compatibility-concurrency -diagnostic-style swift -Xfrontend -enable-experimental-cxx-interop -Xcc -nostdinc++ -warn-implicit-overrides -Xfrontend -enable-ossa-modules -Xfrontend -enable-lexical-lifetimes=false -Xfrontend -disable-implicit-concurrency-module-import -Xfrontend -disable-implicit-string-processing-module-import -Xfrontend -prespecialize-generic-metadata -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 9999:macOS\ 9999,\ iOS\ 9999,\ watchOS\ 9999,\ tvOS\ 9999 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.0:macOS\ 10.14.4,\ iOS\ 12.2,\ watchOS\ 5.2,\ tvOS\ 12.2 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.1:macOS\ 10.15,\ iOS\ 13.0,\ watchOS\ 6.0,\ tvOS\ 13.0 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.2:macOS\ 10.15.4,\ iOS\ 13.4,\ watchOS\ 6.2,\ tvOS\ 13.4 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.3:macOS\ 11.0,\ iOS\ 14.0,\ watchOS\ 7.0,\ tvOS\ 14.0 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.4:macOS\ 11.3,\ iOS\ 14.5,\ watchOS\ 7.4,\ tvOS\ 14.5 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.5:macOS\ 12.0,\ iOS\ 15.0,\ watchOS\ 8.0,\ tvOS\ 15.0 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.6:macOS\ 12.3,\ iOS\ 15.4,\ watchOS\ 8.5,\ tvOS\ 15.4 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.7:macOS\ 13.0,\ iOS\ 16.0,\ watchOS\ 9.0,\ tvOS\ 16.0 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.8:macOS\ 13.3,\ iOS\ 16.4,\ watchOS\ 9.4,\ tvOS\ 16.4 -Xfrontend -define-availability -Xfrontend SwiftStdlib\ 5.9:macOS\ 9999,\ iOS\ 9999,\ watchOS\ 9999,\ tvOS\ 9999 -Xfrontend -target-min-inlining-version -Xfrontend min -whole-module-optimization -save-optimization-record=bitstream -color-diagnostics -parse-as-library -resource-dir /Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/swift-macosx-x86_64/./lib/swift -I /Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/swift-macosx-x86_64/./lib/swift/watchsimulator -emit-module-interface-path /Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/swift-macosx-x86_64/./lib/swift/watchsimulator/Cxx.swiftmodule/arm64-apple-watchos-simulator.swiftinterface -emit-private-module-interface-path /Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/swift-macosx-x86_64/./lib/swift/watchsimulator/Cxx.swiftmodule/arm64-apple-watchos-simulator.private.swiftinterface -Xfrontend -experimental-skip-non-inlinable-function-bodies @/Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/swift-macosx-x86_64/stdlib/public/Cxx/f141d0b80036276a8e5dc363a1815fcf946ca02e.txt
<unknown>:0: warning: the '-enable-experimental-cxx-interop' flag is deprecated; please pass '-cxx-interoperability-mode=' instead
<unknown>:0: note: Swift will maintain source compatibility for imported APIs based on the selected compatibility mode, so updating the Swift compiler will not change how APIs are imported
<unknown>:0: error: could not find module 'Swift' for target 'arm64-apple-watchos'; found: x86_64-apple-watchos-simulator, i386-apple-watchos-simulator, arm64-apple-watchos-simulator, at: /Users/ec2-user/jenkins/workspace/swift-PR-macos/branch-main/build/buildbot_incremental/swift-macosx-x86_64/lib/swift/watchsimulator/Swift.swiftmodule

@finagolfin
Copy link
Member

I don't think it's setting the Apple targets the way it should. I diffed a recent passing build log against this one and see two mistakes in the CMake config, both related to the simulators.

The passing one says:

-- iOS Simulator SDK:
--   Object File Format: MACHO
--   Swift Standard Library Path: iphonesimulator
--   Threading Package: darwin
--   Version: 16.2
--   Build number: 20C52
--   Deployment version: 11.0
--   Triple name: ios
--   Simulator: TRUE
--   Architectures: x86_64;arm64
--
-- Assuming watchOS Simulator SDK at /Applications/Xcode.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator9.1.sdk supports architecture i386
-- watchOS Simulator SDK:
--   Object File Format: MACHO
--   Swift Standard Library Path: watchsimulator
--   Threading Package: darwin
--   Version: 9.1
--   Build number: 20S71
--   Deployment version: 4.0
--   Triple name: watchos
--   Simulator: TRUE

while this pull strangely produces this, ie both simulator SDKs are not listed as simulators:

-- iOS Simulator SDK:
--   Object File Format: MACHO
--   Swift Standard Library Path: iphonesimulator
--   Threading Package: darwin
--   Version: 16.2
--   Build number: 20C52
--   Deployment version: 11.0
--   Triple name: ios
--   Simulator: FALSE
--   Architectures: x86_64;arm64
--
-- Assuming watchOS Simulator SDK at /Applications/Xcode.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator9.1.sdk supports architecture i386
-- watchOS Simulator SDK:
--   Object File Format: MACHO
--   Swift Standard Library Path: watchsimulator
--   Threading Package: darwin
--   Version: 9.1
--   Build number: 20S71
--   Deployment version: 4.0
--   Triple name: watchos
--   Simulator: FALSE

As of CMake 3.25, there are now global variables `LINUX=1`, `ANDROID=1`,
etc. These conflict with expressions that used these names as unquoted
strings in positions where CMake accepts 'variable|string', for example:

- `if(sdk STREQUAL LINUX)` would fail, because `LINUX` is now defined and
  expands to 1, where it would previously coerce to a string.

- `if(${sdk} STREQUAL "LINUX")` would fail if `sdk=LINUX`, because the
  left-hand side expands twice.

In this patch, I looked for a number of patterns to fix up, sometimes a
little defensively:

- Quoted right-hand side of `STREQUAL` where I was confident it was
  intended to be a string literal.

- Removed manual variable expansion on left-hand side of `STREQUAL`,
  `MATCHES` and `IN_LIST` where I was confident it was unintended.

Fixes swiftlang#65028.
@stephank
Copy link
Contributor Author

Right, it looks like macro arguments are interpolated differently, and are not actually variables. They can't be used in variable position:

cmake_minimum_required(VERSION 3.10)
project(cmaktest)

macro(foo name)
  message("Testing: ${name}")

  if(name MATCHES "simulator")
    message("Y")
  else()
    message("N")
  endif()
endmacro()

foo(watchsimulator)

Prints:

Testing: watchsimulator
N

Fixes are:

  • if("${name}" MATCHES ...
  • Changing it to a function
  • Creating an actual variable (set(name ...) before the macro call

The xcrun_name use was the only instance I could find where this happens. I changed that to a quoted expansion, and rebased.

@etcwilde
Copy link
Contributor

Right, it looks like macro arguments are interpolated differently, and are not actually variables.

Oh yeah! I'd forgotten about that. Another reason why I usually like to steer away from macros. Thanks for looking into this further.

@finagolfin
Copy link
Member

@bnbarham, hopefully one last CI run?

@bnbarham
Copy link
Contributor

@swift-ci please test

@finagolfin
Copy link
Member

Sourcekit-lsp test on linux CI timed out, appears completely unrelated, that CI alone will need to be rerun.

@etcwilde
Copy link
Contributor

@swift-ci please test Linux

@stephank
Copy link
Contributor Author

I think that's the same sourcekit-lsp timeout error again?

@bnbarham
Copy link
Contributor

@swift-ci please test Linux

@bnbarham
Copy link
Contributor

I think that's the same sourcekit-lsp timeout error again?

Yes, the revert wasn't merged until this morning.

@finagolfin
Copy link
Member

@al45tair, ready for merge.

@finagolfin
Copy link
Member

@etcwilde, ready for merge.

@etcwilde etcwilde merged commit 669285f into swiftlang:main Jul 24, 2023
@finagolfin
Copy link
Member

@stephank, do you want to submit this for 5.9 next? See the 5.9 release process and a recent example pull, #67391.

@RemiBardon
Copy link

@stephank Do you have any plan on backporting to release/5.8? I'm having the issue as well on Exherbo

@stephank
Copy link
Contributor Author

stephank commented Aug 2, 2023

@stephank Do you have any plan on backporting to release/5.8? I'm having the issue as well on Exherbo

I don't have a need for it myself, so was not planning on doing it. Is there even going to be another 5.8 release?

This is the patch Nixpkgs currently uses for 5.8: https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/compilers/swift/compiler/patches/swift-cmake-3.25-compat.patch

@finagolfin
Copy link
Member

Is there even going to be another 5.8 release?

There might: the fall release like 5.9 usually releases in September, and there is sometimes an August patch release before that.

@etcwilde, wdyt, should he submit this for 5.8 too?

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

Successfully merging this pull request may close these issues.

[CMake 3.25+]: Swift 5.8: Fails to compile bootstrap1 modules
9 participants