swiftlang / swift-docker

Docker Official Image packaging for Swift
https://swift.org
Apache License 2.0
1.37k stars 184 forks source link

Missing LD_LIBRARY_PATH path for macros usage #411

Open vsarunas opened 2 months ago

vsarunas commented 2 months ago

Hi @shahmishal !

In order to compile using macros, LD_LIBRARY_PATH needs to be extended otherwise getting compilation errors:

 error: external macro implementation type 'FoundationMacros.PredicateMacro' could not be found for macro 'Predicate'; compiler plugin '/usr/lib/swift/host/plugins/libFoundationMacros.so' could not be loaded;  libswift_StringProcessing.so: cannot open shared object file: No such file or directory
 31 |         self.context = context
 32 |         
 33 |         let allInstruments = #Predicate<InstrumentReferenceData> { _ in
    |                              `- error: external macro implementation type 'FoundationMacros.PredicateMacro' could not be found for macro 'Predicate'; compiler plugin '/usr/lib/swift/host/plugins/libFoundationMacros.so' could not be loaded;  libswift_StringProcessing.so: cannot open shared object file: No such file or directory
 34 |             true
 35 |         }

FoundationEssentials.Predicate:2:40: note: 'Predicate' declared here
1 | @available(macOS 14, iOS 17, tvOS 17, watchOS 10, *)
2 | @freestanding(expression) public macro Predicate<each Input>(_ body: (repeat each Input) -> Bool) -> Predicate<repeat each Input> = #externalMacro(module: "FoundationMacros", type: "PredicateMacro")
  |                                        `- note: 'Predicate' declared here

Several libraries cannot be found:

$ docker run -t  swiftlang/swift:nightly-main-jammy ldd /usr/lib/swift/host/plugins/libFoundationMacros.so
    linux-vdso.so.1 (0x00007ffdc13f6000)
    libSwiftSyntaxMacros.so => /usr/lib/swift/host/plugins/../libSwiftSyntaxMacros.so (0x00007f2816014000)
    libSwiftSyntaxBuilder.so => /usr/lib/swift/host/plugins/../libSwiftSyntaxBuilder.so (0x00007f2815f70000)
    libSwiftParserDiagnostics.so => /usr/lib/swift/host/plugins/../libSwiftParserDiagnostics.so (0x00007f2815e90000)
    libSwiftBasicFormat.so => /usr/lib/swift/host/plugins/../libSwiftBasicFormat.so (0x00007f2815e6c000)
    libSwiftParser.so => /usr/lib/swift/host/plugins/../libSwiftParser.so (0x00007f2815c71000)
    libSwiftDiagnostics.so => /usr/lib/swift/host/plugins/../libSwiftDiagnostics.so (0x00007f2815c4a000)
    libSwiftSyntax.so => /usr/lib/swift/host/plugins/../libSwiftSyntax.so (0x00007f28151f3000)
    libswiftCore.so => not found
    libswift_Concurrency.so => not found
    libswift_StringProcessing.so => not found
    libswift_RegexParser.so => not found
    libswiftGlibc.so => not found
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f2815107000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f2814ede000)
    libswiftGlibc.so => /usr/lib/swift/host/plugins/../../linux/libswiftGlibc.so (0x00007f2814ecb000)
    libswift_Concurrency.so => /usr/lib/swift/host/plugins/../../linux/libswift_Concurrency.so (0x00007f2814e34000)
    libswiftCore.so => /usr/lib/swift/host/plugins/../../linux/libswiftCore.so (0x00007f2814772000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f281606c000)
    libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f2814546000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f2814526000)
    libdispatch.so => /usr/lib/swift/host/plugins/../../linux/libdispatch.so (0x00007f28144c6000)
    libBlocksRuntime.so => /usr/lib/swift/host/plugins/../../linux/libBlocksRuntime.so (0x00007f28144c0000)

If this is set correctly then libs are found:

docker run -t -e LD_LIBRARY_PATH=/usr/lib/swift/linux  swiftlang/swift:nightly-main-jammy   ldd /usr/lib/swift/host/plugins/libFoundationMacros.so
    linux-vdso.so.1 (0x00007ffdb0da5000)
    libSwiftSyntaxMacros.so => /usr/lib/swift/host/plugins/../libSwiftSyntaxMacros.so (0x00007f40419d3000)
    libSwiftSyntaxBuilder.so => /usr/lib/swift/host/plugins/../libSwiftSyntaxBuilder.so (0x00007f404192f000)
    libSwiftParserDiagnostics.so => /usr/lib/swift/host/plugins/../libSwiftParserDiagnostics.so (0x00007f404184f000)
    libSwiftBasicFormat.so => /usr/lib/swift/host/plugins/../libSwiftBasicFormat.so (0x00007f404182b000)
    libSwiftParser.so => /usr/lib/swift/host/plugins/../libSwiftParser.so (0x00007f404162e000)
    libSwiftDiagnostics.so => /usr/lib/swift/host/plugins/../libSwiftDiagnostics.so (0x00007f4041609000)
    libSwiftSyntax.so => /usr/lib/swift/host/plugins/../libSwiftSyntax.so (0x00007f4040bb2000)
    libswiftCore.so => /usr/lib/swift/linux/libswiftCore.so (0x00007f40404f2000)
    libswift_Concurrency.so => /usr/lib/swift/linux/libswift_Concurrency.so (0x00007f404045b000)
    libswift_StringProcessing.so => /usr/lib/swift/linux/libswift_StringProcessing.so (0x00007f404037d000)
    libswift_RegexParser.so => /usr/lib/swift/linux/libswift_RegexParser.so (0x00007f4040265000)
    libswiftGlibc.so => /usr/lib/swift/linux/libswiftGlibc.so (0x00007f4040250000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f4040166000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f403ff3d000)
    libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f403fd11000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f403fcf1000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f4041a2b000)
    libdispatch.so => /usr/lib/swift/linux/libdispatch.so (0x00007f403fc8f000)
    libBlocksRuntime.so => /usr/lib/swift/linux/libBlocksRuntime.so (0x00007f403fc8b000)

I'm not sure if this should be set in build scripts to set to RPATH via compile time or solved on container level via the following:

RUN echo "/usr/lib/swift/linux" > /etc/ld.so.conf.d/swift.conf && ldconfig

As the only affected library islibFoundationMacros.so