Skip to content

Fix CMake build on Linux #238

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
Sep 20, 2020
Merged

Fix CMake build on Linux #238

merged 1 commit into from
Sep 20, 2020

Conversation

gmittert
Copy link
Contributor

@gmittert gmittert commented Sep 14, 2020

  • TestHelpers has a implicit dependency on Foundation through
    ArgumentParser, so it needs to link against Foundation
  • The find package calls should be REQUIRED and CONFIG so they can take
    advantage of CMake configs

Checklist

  • I've added at least one test that validates that my change is working, if appropriate
  • I've followed the code style of the rest of the project
  • I've read the Contribution Guidelines
  • I've updated the documentation if necessary

@gmittert
Copy link
Contributor Author

@swift-ci please test platform

@gmittert
Copy link
Contributor Author

ping @natecook1000

@natecook1000
Copy link
Member

@swift-ci Please test

@natecook1000
Copy link
Member

@gmittert Thanks for the contribution! I don't think our CI testing exercises the CMake build path yet — can you tell me the configuration where you're seeing this go wrong, so that I can verify locally?

@natecook1000
Copy link
Member

@compnerd Would you mind giving this a review?

@@ -5,4 +5,4 @@ set_target_properties(ArgumentParserTestHelpers PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
target_link_libraries(ArgumentParserTestHelpers PUBLIC
ArgumentParser
XCTest)
XCTest Foundation)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: would be nice to do one entry per line

CMakeLists.txt Outdated
find_package(XCTest QUIET)
find_package(dispatch QUIET CONFIG REQUIRED)
find_package(Foundation QUIET CONFIG REQUIRED)
find_package(XCTest QUIET CONFIG REQUIRED)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm worried about this part of the change. With this it is impossible to actually build with a prebuilt toolchain image. The CONFIG is fine, the REQUIRED is the piece that worries me.

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'll remove both the QUIET and the REQUIRED then. My main concern was that it was silently failing and was a pain to debug why.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The thing is that it isn't an absolutely required thing - so the non QUIET form could be confusing too. But I would be fine with it being non-quiet as long as it is not required.

@gmittert
Copy link
Contributor Author

@natecook1000 The precise invocation I use is a little complex since we have a lot of infrastructure to support cross compiling so I'm unfortunately not able to give you a command to run, but it's something like:

cmake -G Ninja
-DCMAKE_MAKE_PROGRAM="/usr/bin/ninja"
-DCMAKE_BUILD_TYPE="Release"
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_INSTALL_PREFIX=
-DTOOLCHAIN_SOURCE_DIR=/data/users/gwenm/toolchain
-DTOOLCHAIN_BUILD_DIR=/data/users/gwenm/toolchain/build/Release
-DCMAKE_TRY_COMPILE_PLATFORM_VARIABLES=TOOLCHAIN_SOURCE_DIR
-DCMAKE_TOOLCHAIN_FILE="/path/to/platform/specific/toolchain/file"
-DUSE_CMAKE_INSTALL=YES
-Ddispatch_DIR=/path/to/swift-corelibs-libdispatch/cmake/modules
-DFoundation_DIR=/path/to/swift-corelibs-foundation/cmake/modules
-DXCTest_DIR=/path/to/swift-corelibs-xctest/cmake/modules
-C "/path/to/platform/specific/cache/vars/linux-x86_64.cmake"
/data/users/gwenm/toolchain_dev/external/swift-argument-parser

But really the important part is configuring via setting Xyz_DIR to locally build projects instead of building against a prebuilt toolchain.

- TestHelpers has a implicit dependency on Foundation through
  ArgumentParser, so it needs to link against Foundation
- The find package calls should be REQUIRED and CONFIG so they can take
  advantage of CMake configs
@compnerd
Copy link
Collaborator

@gmittert - most of that is specific to the setup that you are building in. (e.g. the caches). I think that it is probably easier to explain with the CI I have setup on Azure (https://github.com/compnerd/swift-build/blob/master/swift-argument-parser.yml)

cmake ^
      -B $(Build.BinariesDirectory)/swift-argument-parser ^
      -D BUILD_SHARED_LIBS=YES ^
      -D BUILD_TESTING=NO ^
      -D CMAKE_BUILD_TYPE=Release ^
      -D CMAKE_Swift_COMPILER=S:\b\1\bin\swiftc.exe ^
      -G Ninja ^
      -S $(Build.SourcesDirectory)/swift-argument-parser

This is Windows specific, but very easy to generalize to other platforms. The important thing is to use a swift compiler from a swift build tree rather than than from an installed image.

@gmittert
Copy link
Contributor Author

Alright, updated the line spacing and removed REQUIRED. @compnerd exactly, my particular set up isn't particularly optimized for external reproducibility, but the important part is building against locally built dependencies a la the Windows build.

@gmittert
Copy link
Contributor Author

@swift-ci please test platform

Copy link
Collaborator

@compnerd compnerd left a comment

Choose a reason for hiding this comment

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

LGTM

@natecook1000
Copy link
Member

Thanks to you both!

@swift-ci Please test

@natecook1000 natecook1000 merged commit cb1f045 into apple:master Sep 20, 2020
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.

3 participants