index-import icon indicating copy to clipboard operation
index-import copied to clipboard

Feature request: Support building on Linux

Open Wilfred opened this issue 11 months ago • 6 comments

I have some Linux-based Swift projects and I'd love to use index-import. Would you be open to PRs that let this project build on Linux as well as macOS?

Wilfred avatar Feb 04 '25 01:02 Wilfred

#119 would be the first step for this.

Wilfred avatar Feb 04 '25 01:02 Wilfred

Yep totally happy to support this!

keith avatar Feb 04 '25 06:02 keith

I did a quick test and it looks like this patch (adjusted for platform conditionals) works to build with dispatch:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3e81d34..ceb339d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -23,6 +23,13 @@ FetchContent_Declare(
 )
 FetchContent_MakeAvailable(re2)

+FetchContent_Declare(
+  dispatch
+  GIT_REPOSITORY "https://github.com/swiftlang/swift-corelibs-libdispatch.git"
+  GIT_TAG "release/6.0"
+)
+FetchContent_MakeAvailable(dispatch)
+
 find_package(Clang CONFIG REQUIRED)

 function(add_index_executable execname)
@@ -34,7 +41,7 @@ function(add_index_executable execname)
   if(NOT LLVM_ENABLE_RTTI)
     target_compile_options("${execname}" PRIVATE -fno-rtti)
   endif()
-  target_link_libraries("${execname}" PRIVATE clangIndexDataStore re2::re2)
+  target_link_libraries("${execname}" PRIVATE clangIndexDataStore re2::re2 dispatch)
   target_link_options("${execname}" PRIVATE -dead_strip)
 endfunction()

i imagine we could also stop using that API but maybe this is worth doing instead

keith avatar Feb 04 '25 06:02 keith

Thanks, I'll give that a try. I was even wondering if doing something like

#ifdef USE_DISPATCH
dispatch_apply(...)
#else
for { ... }
#endif

would make sense. Do you think dispatch is a significant performance win? It seems like Swift actors see more active upstream development than libdispatch these days.

Wilfred avatar Feb 04 '25 18:02 Wilfred

i think that being multi-threaded is a huge win. but we could try to use something lower level if we wanted.

keith avatar Feb 04 '25 18:02 keith

here are the stats https://github.com/MobileNativeFoundation/index-import/commit/6558426c58d8aab2264b6ce1fd19ae653b56bc89

keith avatar Feb 04 '25 18:02 keith