-
Notifications
You must be signed in to change notification settings - Fork 247
build: introduce a CMake based build for swift-format #677
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#[[ | ||
This source file is part of the swift-format open source project | ||
|
||
Copyright (c) 2024 Apple Inc. and the swift-format project authors | ||
Licensed under Apache License v2.0 with Runtime Library Exception | ||
|
||
See https://swift.org/LICENSE.txt for license information | ||
#]] | ||
|
||
cmake_minimum_required(VERSION 3.19.0) | ||
|
||
if(POLICY CMP0077) | ||
cmake_policy(SET CMP0077 NEW) | ||
endif() | ||
if(POLICY CMP0091) | ||
cmake_policy(SET CMP0091 NEW) | ||
endif() | ||
|
||
project(SwiftFormat | ||
LANGUAGES C Swift) | ||
|
||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) | ||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) | ||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) | ||
|
||
set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift) | ||
set(CMAKE_Swift_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY MultiThreadedDLL) | ||
|
||
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules) | ||
|
||
include(FetchContent) | ||
include(GNUInstallDirs) | ||
include(SwiftSupport) | ||
|
||
find_package(Foundation CONFIG) | ||
|
||
set(_SF_VENDOR_DEPENDENCIES) | ||
|
||
set(BUILD_EXAMPLES NO) | ||
set(BUILD_TESTING NO) | ||
|
||
find_package(ArgumentParser CONFIG) | ||
if(NOT ArgumentParser_FOUND) | ||
FetchContent_Declare(ArgumentParser | ||
GIT_REPOSITORY https://github.com/apple/swift-argument-parser | ||
GIT_TAG 1.2.3) | ||
list(APPEND _SF_VENDOR_DEPENDENCIES ArgumentParser) | ||
endif() | ||
|
||
find_package(cmark-gfm CONFIG) | ||
if(NOT cmark-gfm_FOUND) | ||
FetchContent_Declare(cmark-gfm | ||
GIT_REPOSITORY https://github.com/apple/swift-cmark | ||
GIT_TAG gfm) | ||
list(APPEND _SF_VENDOR_DEPENDENCIES cmark-gfm) | ||
endif() | ||
|
||
find_package(SwiftMarkdown CONFIG) | ||
if(NOT SwiftMarkdown_FOUND) | ||
# TODO(compnerd) we need a latest version for now as we need the CMake support | ||
# which is untagged. | ||
FetchContent_Declare(Markdown | ||
GIT_REPOSITORY https://github.com/apple/swift-markdown | ||
GIT_TAG main) | ||
list(APPEND _SF_VENDOR_DEPENDENCIES Markdown) | ||
endif() | ||
|
||
find_package(SwiftSyntax CONFIG) | ||
if(NOT SwiftSyntax_FOUND) | ||
FetchContent_Declare(Syntax | ||
GIT_REPOSITORY https://github.com/apple/swift-syntax | ||
GIT_TAG main) | ||
list(APPEND _SF_VENDOR_DEPENDENCIES Syntax) | ||
endif() | ||
|
||
if(_SF_VENDOR_DEPENDENCIES) | ||
FetchContent_MakeAvailable(${_SF_VENDOR_DEPENDENCIES}) | ||
|
||
if(NOT TARGET SwiftMarkdown::Markdown) | ||
add_library(SwiftMarkdown::Markdown ALIAS Markdown) | ||
endif() | ||
|
||
if(NOT TARGET SwiftSyntax::SwiftSyntax) | ||
add_library(SwiftSyntax::SwiftSyntax ALIAS SwiftSyntax) | ||
add_library(SwiftSyntax::SwiftSyntaxBuilder ALIAS SwiftSyntaxBuilder) | ||
add_library(SwiftSyntax::SwiftOperators ALIAS SwiftOperators) | ||
add_library(SwiftSyntax::SwiftParser ALIAS SwiftParser) | ||
add_library(SwiftSyntax::SwiftParserDiagnostics ALIAS SwiftParserDiagnostics) | ||
endif() | ||
endif() | ||
|
||
add_subdirectory(Sources) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#[[ | ||
This source file is part of the swift-format open source project | ||
|
||
Copyright (c) 2024 Apple Inc. and the swift-format project authors | ||
Licensed under Apache License v2.0 with Runtime Library Exception | ||
|
||
See https://swift.org/LICENSE.txt for license information | ||
#]] | ||
|
||
add_subdirectory(SwiftFormat) | ||
add_subdirectory(_SwiftFormatInstructionCounter) | ||
add_subdirectory(swift-format) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
#[[ | ||
This source file is part of the swift-format open source project | ||
|
||
Copyright (c) 2024 Apple Inc. and the swift-format project authors | ||
Licensed under Apache License v2.0 with Runtime Library Exception | ||
|
||
See https://swift.org/LICENSE.txt for license information | ||
#]] | ||
|
||
add_library(SwiftFormat | ||
compnerd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
API/Configuration+Default.swift | ||
API/Configuration.swift | ||
API/DebugOptions.swift | ||
API/Finding.swift | ||
API/FindingCategorizing.swift | ||
API/Indent.swift | ||
API/SwiftFormatError.swift | ||
API/SwiftFormatter.swift | ||
API/SwiftLinter.swift | ||
Core/Context.swift | ||
Core/DocumentationComment.swift | ||
Core/DocumentationCommentText.swift | ||
Core/Finding+Convenience.swift | ||
Core/FindingEmitter.swift | ||
Core/FormatPipeline.swift | ||
Core/FunctionDeclSyntax+Convenience.swift | ||
Core/ImportsXCTestVisitor.swift | ||
Core/LazySplitSequence.swift | ||
Core/LintPipeline.swift | ||
Core/ModifierListSyntax+Convenience.swift | ||
Core/Parsing.swift | ||
Core/Pipelines+Generated.swift | ||
Core/RememberingIterator.swift | ||
Core/Rule.swift | ||
Core/RuleBasedFindingCategory.swift | ||
Core/RuleMask.swift | ||
Core/RuleNameCache+Generated.swift | ||
Core/RuleRegistry+Generated.swift | ||
Core/RuleState.swift | ||
Core/SyntaxFormatRule.swift | ||
Core/SyntaxLintRule.swift | ||
Core/SyntaxProtocol+Convenience.swift | ||
Core/Trivia+Convenience.swift | ||
Core/WithSemicolonSyntax.swift | ||
PrettyPrint/Comment.swift | ||
PrettyPrint/Indent+Length.swift | ||
PrettyPrint/PrettyPrint.swift | ||
PrettyPrint/PrettyPrintFindingCategory.swift | ||
PrettyPrint/Token.swift | ||
PrettyPrint/TokenStreamCreator.swift | ||
PrettyPrint/Verbatim.swift | ||
PrettyPrint/WhitespaceFindingCategory.swift | ||
PrettyPrint/WhitespaceLinter.swift | ||
Rules/AllPublicDeclarationsHaveDocumentation.swift | ||
Rules/AlwaysUseLiteralForEmptyCollectionInit.swift | ||
Rules/AlwaysUseLowerCamelCase.swift | ||
Rules/AmbiguousTrailingClosureOverload.swift | ||
Rules/BeginDocumentationCommentWithOneLineSummary.swift | ||
Rules/DoNotUseSemicolons.swift | ||
Rules/DontRepeatTypeInStaticProperties.swift | ||
Rules/FileScopedDeclarationPrivacy.swift | ||
Rules/FullyIndirectEnum.swift | ||
Rules/GroupNumericLiterals.swift | ||
Rules/IdentifiersMustBeASCII.swift | ||
Rules/NeverForceUnwrap.swift | ||
Rules/NeverUseForceTry.swift | ||
Rules/NeverUseImplicitlyUnwrappedOptionals.swift | ||
Rules/NoAccessLevelOnExtensionDeclaration.swift | ||
Rules/NoAssignmentInExpressions.swift | ||
Rules/NoBlockComments.swift | ||
Rules/NoCasesWithOnlyFallthrough.swift | ||
Rules/NoEmptyTrailingClosureParentheses.swift | ||
Rules/NoLabelsInCasePatterns.swift | ||
Rules/NoLeadingUnderscores.swift | ||
Rules/NoParensAroundConditions.swift | ||
Rules/NoPlaygroundLiterals.swift | ||
Rules/NoVoidReturnOnFunctionSignature.swift | ||
Rules/OmitExplicitReturns.swift | ||
Rules/OneCasePerLine.swift | ||
Rules/OneVariableDeclarationPerLine.swift | ||
Rules/OnlyOneTrailingClosureArgument.swift | ||
Rules/OrderedImports.swift | ||
Rules/ReplaceForEachWithForLoop.swift | ||
Rules/ReturnVoidInsteadOfEmptyTuple.swift | ||
Rules/TypeNamesShouldBeCapitalized.swift | ||
Rules/UseEarlyExits.swift | ||
Rules/UseExplicitNilCheckInConditions.swift | ||
Rules/UseLetInEveryBoundCaseVariable.swift | ||
Rules/UseShorthandTypeNames.swift | ||
Rules/UseSingleLinePropertyGetter.swift | ||
Rules/UseSynthesizedInitializer.swift | ||
Rules/UseTripleSlashForDocumentationComments.swift | ||
Rules/UseWhereClausesInForLoops.swift | ||
Rules/ValidateDocumentationComments.swift) | ||
target_link_libraries(SwiftFormat PUBLIC | ||
SwiftMarkdown::Markdown | ||
SwiftSyntax::SwiftSyntax | ||
SwiftSyntax::SwiftSyntaxBuilder | ||
SwiftSyntax::SwiftOperators | ||
SwiftSyntax::SwiftParser | ||
SwiftSyntax::SwiftParserDiagnostics | ||
libcmark-gfm | ||
libcmark-gfm-extensions) | ||
|
||
_install_target(SwiftFormat) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#[[ | ||
This source file is part of the swift-format open source project | ||
|
||
Copyright (c) 2024 Apple Inc. and the swift-format project authors | ||
Licensed under Apache License v2.0 with Runtime Library Exception | ||
|
||
See https://swift.org/LICENSE.txt for license information | ||
#]] | ||
|
||
add_library(_SwiftFormatInstructionCounter STATIC | ||
src/InstructionsExecuted.c) | ||
target_include_directories(_SwiftFormatInstructionCounter PUBLIC | ||
include) |
3 changes: 3 additions & 0 deletions
3
Sources/_SwiftFormatInstructionCounter/include/module.modulemap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module _SwiftFormatInstructionCounter { | ||
header "InstructionsExecuted.h" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#[[ | ||
This source file is part of the swift-format open source project | ||
|
||
Copyright (c) 2024 Apple Inc. and the swift-format project authors | ||
Licensed under Apache License v2.0 with Runtime Library Exception | ||
|
||
See https://swift.org/LICENSE.txt for license information | ||
#]] | ||
|
||
add_executable(swift-format | ||
PrintVersion.swift | ||
SwiftFormatCommand.swift | ||
VersionOptions.swift | ||
Frontend/ConfigurationLoader.swift | ||
Frontend/FormatFrontend.swift | ||
Frontend/Frontend.swift | ||
Frontend/LintFrontend.swift | ||
Subcommands/DumpConfiguration.swift | ||
Subcommands/Format.swift | ||
Subcommands/Lint.swift | ||
Subcommands/LintFormatOptions.swift | ||
Subcommands/PerformanceMeasurement.swift | ||
Utilities/Diagnostic.swift | ||
Utilities/DiagnosticsEngine.swift | ||
Utilities/FileHandleTextOutputStream.swift | ||
Utilities/FileIterator.swift | ||
Utilities/FormatError.swift | ||
Utilities/StderrDiagnosticPrinter.swift | ||
Utilities/TTY.swift) | ||
target_link_libraries(swift-format PRIVATE | ||
_SwiftFormatInstructionCounter | ||
ArgumentParser | ||
SwiftFormat | ||
SwiftParser | ||
SwiftSyntax) | ||
|
||
_install_target(swift-format) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#[[ | ||
This source file is part of the swift-format open source project | ||
|
||
Copyright (c) 2024 Apple Inc. and the swift-format project authors | ||
Licensed under Apache License v2.0 with Runtime Library Exception | ||
|
||
See https://swift.org/LICENSE.txt for license information | ||
#]] | ||
|
||
set(SWIFT_FORMAT_EXPORTS_FILE | ||
${CMAKE_CURRENT_BINARY_DIR}/SwiftFormatExports.cmake) | ||
|
||
configure_file(SwiftFormatConfig.cmake.in | ||
${CMAKE_CURRENT_BINARY_DIR}/SwiftFormatConfig.cmake) | ||
|
||
get_property(SWIFT_FORMAT_EXPORTS GLOBAL PROPERTY SWIFT_FORMAT_EXPORTS) | ||
export(TARGETS ${SWIFT_FORMAT_EXPORTS} | ||
NAMESPACE SwiftFormat:: | ||
FILE ${SWIFT_FORMAT_EXPORTS_FILE} | ||
EXPORT_LINK_INTERFACE_LIBRARIES) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#[[ | ||
This source file is part of the swift-format open source project | ||
|
||
Copyright (c) 2024 Apple Inc. and the swift-format project authors | ||
Licensed under Apache License v2.0 with Runtime Library Exception | ||
|
||
See https://swift.org/LICENSE.txt for license information | ||
#]] | ||
|
||
if(NOT TARGET SwiftFormat) | ||
include("@SWIFT_FORMAT_EXPORTS_FILE@") | ||
endif() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.