Skip to content

Commit

Permalink
Merge pull request #78277 from andrurogerz/swift-inspect-linux-cmake
Browse files Browse the repository at this point in the history
[swift-inspect] support CMake build for Linux
  • Loading branch information
compnerd authored Dec 19, 2024
2 parents 009fd94 + b73c54b commit b0123bc
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tools/swift-inspect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@ if(WIN32)
Sources/SwiftInspectClient/SwiftInspectClient.cpp)
target_link_libraries(SwiftInspectClient PRIVATE
SwiftInspectClientInterface)
elseif(LINUX)
add_library(LinuxSystemHeaders INTERFACE)
target_include_directories(LinuxSystemHeaders INTERFACE
Sources/SwiftInspectLinux/SystemHeaders)

add_library(SwiftInspectLinux STATIC
Sources/SwiftInspectLinux/ElfFile.swift
Sources/SwiftInspectLinux/LinkMap.swift
Sources/SwiftInspectLinux/MemoryMap.swift
Sources/SwiftInspectLinux/Process.swift
Sources/SwiftInspectLinux/ProcFS.swift
Sources/SwiftInspectLinux/SymbolCache.swift)
target_compile_options(SwiftInspectLinux PRIVATE
-Xcc -D_GNU_SOURCE)
target_link_libraries(SwiftInspectLinux PUBLIC
LinuxSystemHeaders)
endif()

add_executable(swift-inspect
Expand All @@ -38,6 +54,7 @@ add_executable(swift-inspect
Sources/swift-inspect/Operations/DumpRawMetadata.swift
Sources/swift-inspect/Backtrace.swift
Sources/swift-inspect/DarwinRemoteProcess.swift
Sources/swift-inspect/LinuxRemoteProcess.swift
Sources/swift-inspect/main.swift
Sources/swift-inspect/Process.swift
Sources/swift-inspect/RemoteMirror+Extensions.swift
Expand All @@ -54,6 +71,9 @@ target_link_libraries(swift-inspect PRIVATE
if(WIN32)
target_link_libraries(swift-inspect PRIVATE
SwiftInspectClientInterface)
elseif(LINUX)
target_link_libraries(swift-inspect PRIVATE
SwiftInspectLinux)
endif()

install(TARGETS swift-inspect
Expand Down
9 changes: 9 additions & 0 deletions tools/swift-inspect/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ In order to build on Windows with CMake, some additional parameters must be pass
cmake -B out -G Ninja -S . -D ArgumentParser_DIR=... -D CMAKE_Swift_FLAGS="-Xcc -I%SDKROOT%\usr\include\swift\SwiftRemoteMirror"
~~~

In order to build on Linux with CMake, some additional parameters must be passed to the build tool to locate the necessary Swift modules.

~~~
cmake -B out -G Ninja -S . -D ArgumentParser_DIR=... -D CMAKE_Swift_FLAGS="-Xcc -I$(git rev-parse --show-toplevel)/include/swift/SwiftRemoteMirror"
~~~

Building with CMake requires a local copy of [swift-argument-parser](https://github.com/apple/swift-argument-parser) built with CMake.
The `ArumentParser_DIR=` definition must refer to the `cmake/modules` sub-directory of the swift-argument-parser build output directory.

### Using

The following inspection operations are available currently.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@
//
//===----------------------------------------------------------------------===//

#pragma once

#include <linux/auxvec.h>
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@
//
//===----------------------------------------------------------------------===//

#pragma once

#include <elf.h>
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@
//
//===----------------------------------------------------------------------===//

#pragma once

#include <link.h>
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@
//
//===----------------------------------------------------------------------===//

#pragma once

#include <sys/uio.h>

0 comments on commit b0123bc

Please sign in to comment.