Search code examples
swiftcompilationcmakeninjademangler

libswiftDemangle.so on Linux


While compiling Swift on Mac machine, there is a dynamic library libswiftDemangle.dylib created. I need the dynamic library created on Linux machine as well, however, the dynamic library isn't created after a compilation of a source code.

The file CMakeLists.txt at lib/SwiftDemangle/CMakeLists.txt contains:

add_swift_library(swiftDemangle SHARED
  SwiftDemangle.cpp
  MangleHack.cpp
  LINK_LIBRARIES swiftBasic)

directive, however the library isn't created.

I use this command ./swift/utils/build-script -R -c --build-subdir build --install-prefix /mnt/servers/swift/install -j4 to build the project, eventually it runs cmake and ninja to build the project.

Any ideas?


Solution

  • I can take a shot at explaining why the library is not getting built on Linux, even if it's late probably.
    The main subdirectory containing the library you mention is:

    https://github.com/apple/swift/tree/master/lib
    

    To build the libs in that directory, which are organized in subdirectories, the following CMakeLists.txt is used:

    https://github.com/apple/swift/blob/master/lib/CMakeLists.txt.

    As can be clearly seen in this file, the library that you mention is only built if the system is OSX/Darwin and not in the Linux case. The relevant code in the aforementioned CMakeLists.txt is:

    add_subdirectory(RemoteAST)
    add_subdirectory(Sema)
    add_subdirectory(Serialization)
    if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
      add_subdirectory(SwiftDemangle)
    endif()
    add_subdirectory(SIL)
    add_subdirectory(SILGen)  
    

    As you can see it,

    if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
      add_subdirectory(SwiftDemangle)
    endif()
    

    prevents SwiftDemangle to be built on Linux.
    A superficial double check can be to look at:

    https://github.com/apple/swift/blob/master/lib/SwiftDemangle/CMakeLists.txt
    

    which will install or simlynk only *.dylib files.
    It it worth mentioning that the swift-demangle tool (different from what you asked)

    https://github.com/apple/swift/tree/master/tools/swift-demangle
    

    is built on Linux.