Skip to content

Commit b0123bc

Browse files
authored
Merge pull request #78277 from andrurogerz/swift-inspect-linux-cmake
[swift-inspect] support CMake build for Linux
2 parents 009fd94 + b73c54b commit b0123bc

File tree

6 files changed

+37
-0
lines changed

6 files changed

+37
-0
lines changed

tools/swift-inspect/CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,22 @@ if(WIN32)
2727
Sources/SwiftInspectClient/SwiftInspectClient.cpp)
2828
target_link_libraries(SwiftInspectClient PRIVATE
2929
SwiftInspectClientInterface)
30+
elseif(LINUX)
31+
add_library(LinuxSystemHeaders INTERFACE)
32+
target_include_directories(LinuxSystemHeaders INTERFACE
33+
Sources/SwiftInspectLinux/SystemHeaders)
34+
35+
add_library(SwiftInspectLinux STATIC
36+
Sources/SwiftInspectLinux/ElfFile.swift
37+
Sources/SwiftInspectLinux/LinkMap.swift
38+
Sources/SwiftInspectLinux/MemoryMap.swift
39+
Sources/SwiftInspectLinux/Process.swift
40+
Sources/SwiftInspectLinux/ProcFS.swift
41+
Sources/SwiftInspectLinux/SymbolCache.swift)
42+
target_compile_options(SwiftInspectLinux PRIVATE
43+
-Xcc -D_GNU_SOURCE)
44+
target_link_libraries(SwiftInspectLinux PUBLIC
45+
LinuxSystemHeaders)
3046
endif()
3147

3248
add_executable(swift-inspect
@@ -38,6 +54,7 @@ add_executable(swift-inspect
3854
Sources/swift-inspect/Operations/DumpRawMetadata.swift
3955
Sources/swift-inspect/Backtrace.swift
4056
Sources/swift-inspect/DarwinRemoteProcess.swift
57+
Sources/swift-inspect/LinuxRemoteProcess.swift
4158
Sources/swift-inspect/main.swift
4259
Sources/swift-inspect/Process.swift
4360
Sources/swift-inspect/RemoteMirror+Extensions.swift
@@ -54,6 +71,9 @@ target_link_libraries(swift-inspect PRIVATE
5471
if(WIN32)
5572
target_link_libraries(swift-inspect PRIVATE
5673
SwiftInspectClientInterface)
74+
elseif(LINUX)
75+
target_link_libraries(swift-inspect PRIVATE
76+
SwiftInspectLinux)
5777
endif()
5878

5979
install(TARGETS swift-inspect

tools/swift-inspect/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ In order to build on Windows with CMake, some additional parameters must be pass
3232
cmake -B out -G Ninja -S . -D ArgumentParser_DIR=... -D CMAKE_Swift_FLAGS="-Xcc -I%SDKROOT%\usr\include\swift\SwiftRemoteMirror"
3333
~~~
3434

35+
In order to build on Linux with CMake, some additional parameters must be passed to the build tool to locate the necessary Swift modules.
36+
37+
~~~
38+
cmake -B out -G Ninja -S . -D ArgumentParser_DIR=... -D CMAKE_Swift_FLAGS="-Xcc -I$(git rev-parse --show-toplevel)/include/swift/SwiftRemoteMirror"
39+
~~~
40+
41+
Building with CMake requires a local copy of [swift-argument-parser](https://github.com/apple/swift-argument-parser) built with CMake.
42+
The `ArumentParser_DIR=` definition must refer to the `cmake/modules` sub-directory of the swift-argument-parser build output directory.
43+
3544
### Using
3645

3746
The following inspection operations are available currently.

tools/swift-inspect/Sources/SwiftInspectLinux/SystemHeaders/auxvec.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#pragma once
14+
1315
#include <linux/auxvec.h>

tools/swift-inspect/Sources/SwiftInspectLinux/SystemHeaders/elf.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#pragma once
14+
1315
#include <elf.h>

tools/swift-inspect/Sources/SwiftInspectLinux/SystemHeaders/link.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#pragma once
14+
1315
#include <link.h>

tools/swift-inspect/Sources/SwiftInspectLinux/SystemHeaders/uio.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#pragma once
14+
1315
#include <sys/uio.h>

0 commit comments

Comments
 (0)