Skip to content

Swift: expose Swift version #18

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 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ message("Using Swift_CONFIG: ${Clang_CONFIG}")
add_executable(codeql-swift-artifacts empty.cpp)
target_link_libraries(codeql-swift-artifacts PRIVATE LLVMSupport swiftFrontendTool swiftCompilerModules)

set (CODEQL_SWIFT_VERSION_MAJOR ${SWIFT_VERSION_MAJOR})
set (CODEQL_SWIFT_VERSION_MINOR ${SWIFT_VERSION_MINOR})
set (CODEQL_SWIFT_VERSION_PATCH ${SWIFT_VERSION_PATCH})

configure_file(${CMAKE_SOURCE_DIR}/CodeQLSwiftVersion.h.in
${SWIFT_BINARY_DIR}/include/swift/CodeQLSwiftVersion.h)

if(APPLE)
execute_process(
COMMAND xcrun -find swiftc
Expand Down
9 changes: 9 additions & 0 deletions CodeQLSwiftVersion.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifndef CODEQL_SWIFT_VERSION_H
#define CODEQL_SWIFT_VERSION_H

#cmakedefine CODEQL_SWIFT_VERSION_MAJOR @CODEQL_SWIFT_VERSION_MAJOR@
#cmakedefine CODEQL_SWIFT_VERSION_MINOR @CODEQL_SWIFT_VERSION_MINOR@
#cmakedefine CODEQL_SWIFT_VERSION_PATCH @CODEQL_SWIFT_VERSION_PATCH@

#endif // CODEQL_SWIFT_VERSION_H

15 changes: 15 additions & 0 deletions patches/swift/expose-swift-version.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git a/cmake/modules/SwiftConfig.cmake.in b/cmake/modules/SwiftConfig.cmake.in
index 262ed49d8fc..e13988f1513 100644
--- a/cmake/modules/SwiftConfig.cmake.in
+++ b/cmake/modules/SwiftConfig.cmake.in
@@ -2,6 +2,10 @@

@SWIFT_CONFIG_CODE@

+set(SWIFT_VERSION_MAJOR @SWIFT_VERSION_MAJOR@)
+set(SWIFT_VERSION_MINOR @SWIFT_VERSION_MINOR@)
+set(SWIFT_VERSION_PATCH @SWIFT_VERSION_PATCHLEVEL@)
+
set(SWIFT_VERSION @SWIFT_VERSION@)
set(SWIFT_MAIN_SRC_DIR @SWIFT_SOURCE_DIR@)

1 change: 1 addition & 0 deletions pkg_swift_llvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def configure_dummy_project(tmp, prefixes):
print(script_dir)
shutil.copy(script_dir / "CMakeLists.txt", tmp / "CMakeLists.txt")
shutil.copy(script_dir / "empty.cpp", tmp / "empty.cpp")
shutil.copy(script_dir / "CodeQLSwiftVersion.h.in", tmp / "CodeQLSwiftVersion.h.in")
tgt = tmp / "build"
tgt.mkdir()
prefixes = ';'.join(str(p) for p in prefixes)
Expand Down