Skip to content

build: allow fallback for CMAKE_Swift_COMPILER migration #38239

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

Closed
wants to merge 2 commits into from

Conversation

compnerd
Copy link
Member

@compnerd compnerd commented Jul 2, 2021

The original change c0d6d8f added a
soft migration path from SWIFT_NATIVE_SWIFT_TOOLS_PATH to
CMAKE_Swift_COMPILER, which broke some setups. Subsequently
9da7665 added an overly restrictive
check to ensure that CMAKE_Swift_COMPILER is always set when
SWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER is set. This loosens the check
to ensure that either CMAKE_Swift_COMPILER or
SWIFT_NATIVE_SWIFT_TOOLS_PATH can be used during the migration.

Replace this paragraph with a description of your changes and rationale. Provide links to external references/discussions if appropriate.

Resolves SR-NNNN.

The original change c0d6d8f added a
soft migration path from `SWIFT_NATIVE_SWIFT_TOOLS_PATH` to
`CMAKE_Swift_COMPILER`, which broke some setups.  Subsequently
9da7665 added an overly restrictive
check to ensure that `CMAKE_Swift_COMPILER` is always set when
`SWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER` is set.  This loosens the check
to ensure that either `CMAKE_Swift_COMPILER` or
`SWIFT_NATIVE_SWIFT_TOOLS_PATH` can be used during the migration.
@compnerd
Copy link
Member Author

compnerd commented Jul 2, 2021

CC: @davezarzycki

@compnerd
Copy link
Member Author

compnerd commented Jul 2, 2021

@swift-ci please test

@compnerd
Copy link
Member Author

compnerd commented Jul 2, 2021

@davezarzycki davezarzycki self-requested a review July 3, 2021 02:26
Copy link
Contributor

@davezarzycki davezarzycki left a comment

Choose a reason for hiding this comment

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

Verified. I restored my setup to how it was before #38123. That is to say, I changed my build scripts to no longer let Swift's CMake find the installed swift once again. I then applied #38238, this pull request, and did a clean build. Everything works. Thanks!

Copy link
Contributor

@davezarzycki davezarzycki left a comment

Choose a reason for hiding this comment

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

Wait, I forgot a restorative change. The bug still exists:

cd /home/dave/b/u/t/tools/swift/stdlib/public/core && /usr/bin/python3.9 /home/dave/ro_s/u/swift/utils/line-directive @/home/dave/b/u/t/tools/swift/stdlib/public/core/dfaab9867ab9868918d54c7626d620fe0cb9c79c.txt -- -c -sdk / -target x86_64-unknown-linux-gnu -resource-dir /home/dave/b/u/t/./lib/swift -O -D INTERNAL_CHECKS_ENABLED -D SWIFT_RUNTIME_OS_VERSIONING -module-cache-path /home/dave/b/u/t/./module-cache -no-link-objc-runtime -enable-library-evolution -Xfrontend -enforce-exclusivity=unchecked -nostdimport -parse-stdlib -module-name Swift -Xfrontend -group-info-path -Xfrontend /home/dave/ro_s/u/swift/stdlib/public/core/GroupInfo.json -swift-version 5 -runtime-compatibility-version none -disable-autolinking-runtime-compatibility-dynamic-replacements -warn-swift3-objc-inference-complete -Xfrontend -verify-syntax-tree -Xllvm -sil-inline-generics -Xllvm -sil-partial-specialization -Xfrontend -enable-experimental-concise-pound-file -Xfrontend -enable-ossa-modules -Xcc -DswiftCore_EXPORTS -warn-implicit-overrides -module-link-name swiftCore -whole-module-optimization -parse-as-library -I /home/dave/b/u/t/./lib/swift/linux -o /home/dave/b/u/t/tools/swift/stdlib/public/core/LINUX/x86_64/Swift.o @/home/dave/b/u/t/tools/swift/stdlib/public/core/dfaab9867ab9868918d54c7626d620fe0cb9c79c.txt
Traceback (most recent call last):
  File "/home/dave/ro_s/u/swift/utils/line-directive", line 742, in <module>
    run()
  File "/home/dave/ro_s/u/swift/utils/line-directive", line 694, in run
    command = subprocess.Popen(
  File "/usr/lib64/python3.9/subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib64/python3.9/subprocess.py", line 1821, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '-c'

@davezarzycki
Copy link
Contributor

Weird, the following results in NOTFOUND and FALSE respectively but no error is generated:

if (SWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER)
  if (NOT CMAKE_Swift_COMPILER AND NOT SWIFT_PREBUILT_SWIFT)
    message(ERROR "Swift Compiler not found and SWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER is set")
  endif()
endif()

@compnerd
Copy link
Member Author

compnerd commented Jul 3, 2021

Huh? That sounds like the issue, but why?

Add a workaround for `NOT CMAKE_Swift_COMPILER` not evaluating properly.
@compnerd
Copy link
Member Author

compnerd commented Jul 3, 2021

@davezarzycki - I added a horrible workaround to the CMake in the hopes that it evaluates properly.

Copy link
Contributor

@davezarzycki davezarzycki left a comment

Choose a reason for hiding this comment

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

So overall, after the STREQUAL fix, the net result is the same to me. I can't use SWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER anymore unless I supply a pre-built Swift, which if that's the goal, then fine, I can live without SWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER.

CC @gottesmm

CMakeLists.txt Outdated
Comment on lines 540 to 541
if (SWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER)
if (NOT CMAKE_Swift_COMPILER AND NOT SWIFT_PREBUILT_SWIFT)
if ("${CMAKE_Swift_COMPILER}" STREQUAL "CMAKE_Swift_COMPILER-NOTFOUND" AND NOT SWIFT_PREBUILT_SWIFT)
Copy link
Contributor

Choose a reason for hiding this comment

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

In my testing and debugging, it needs to be: "${CMAKE_Swift_COMPILER}" STREQUAL "NOTFOUND"

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, okay.

@compnerd
Copy link
Member Author

compnerd commented Jul 4, 2021

Wait, I'm not sure how the build is supposed to work in this case. You are saying that CMake doesn't find the Swift compiler nor is SWIFT_PREBUILT_SWIFT set, so how is it supposed to find swiftc? Is the expectation that it will find it in the path?

@davezarzycki
Copy link
Contributor

One of the supported build modes uses the just built swiftc to compile swift code (see the top level CMakeLists.txt, line 578). But after @gottesmm's change, this mode became incompatible with SWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER.

@compnerd
Copy link
Member Author

compnerd commented Jul 4, 2021

Ah, for that I think that we should definitely get @gottesmm's opinion on introducing a more precise SWIFT_BUILD_SWIFT_STANDARD_LIBRARY_WITH_HOST_COMPILER instead of misattributing the compilation of the standard library to the runtime. The runtime is technically below the standard library, and building that with the host compiler is different than building the stdlib with the host compiler.

@davezarzycki
Copy link
Contributor

Right, I was allowing for a liberal definition of "runtime" or that the build variable name was no longer ideal but otherwise ya, we need @gottesmm's input.

@davezarzycki
Copy link
Contributor

@gottesmm -- ping?

1 similar comment
@davezarzycki
Copy link
Contributor

@gottesmm -- ping?

@compnerd
Copy link
Member Author

This is woefully out of date at this point, closing this off. I imagine that is now longer valuable.

@compnerd compnerd closed this Mar 29, 2023
@compnerd compnerd deleted the lax-checking branch March 29, 2023 01:11
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.

2 participants