Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extensions on system types (like stat or time_t) go missing in importing module #2

Open
helje5 opened this issue Aug 3, 2020 · 6 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@helje5
Copy link
Contributor

helje5 commented Aug 3, 2020

Macro (and NIO) itself works fine, but stat and timespec extensions in xsys and fs do not make it through to connect in MacroExpress.

swift build --destination /usr/local/lib/swift/dst/x86_64-unknown-linux/swift-5.3-ubuntu16.04.xtoolchain/destination.json
/Users/helge/dev/Swift/Macro/MacroExpress/Sources/connect/ServeStatic.swift:129:16: error: value of type 'stat_struct' (aka 'stat') has no member 'isDirectory'
      if lStat.isDirectory() {
         ~~~~~ ^~~~~~~~~~~

This is declared just fine in Macro/fs/Utils/StatStruct.swift.

@helje5 helje5 changed the title MacroExpress doesn't compile due to missing Macro extensions Issues with #ifdef'ed extensions not compiling in consuming module Aug 4, 2020
@helje5
Copy link
Contributor Author

helje5 commented Aug 4, 2020

This can be reproduced with two simple packages:

mkdir LibBase LibDep
cd LibBase && swift package init --type library && git init && cd ..
cd LibDep && swift package init --type library && cd ..

LibBase.swift:

#if os(Windows)
  import WinSDK
#elseif os(Linux)
  import struct Glibc.timespec
  public typealias timespec = Glibc.timespec
  
  public extension timespec {
    static func demo() -> timespec { return timespec() }
  }
#else // Darwin
  import struct Darwin.timespec
  public typealias timespec = Darwin.timespec
  
  public extension timespec {
    static func demo() -> timespec { return timespec() }
  }
#endif // Darwin

libdep Package.swift:

// swift-tools-version:5.3
import PackageDescription

let package = Package(
    name: "LibDep",
    dependencies: [ .package(url: "../LibBase", .branch("master")) ],
    targets: [ .target(name: "LibDep", dependencies: [ "LibBase" ]) ]
)

LibDep.swift:

import LibBase

func doIt() {
  let x = timespec.demo()
  print("X:", x)
}

Compile:

brew install spmdestinations/tap/spm-dest-5.3-x86_64-ubuntu16.04
swift build --destination \
  /usr/local/lib/swift/dst/x86_64-unknown-linux/swift-5.3-ubuntu16.04.xtoolchain/destination.json
Zini18:LibDep helge$ swift build --destination /usr/local/lib/swift/dst/x86_64-unknown-linux/swift-5.3-ubuntu16.04.xtoolchain/destination.json
/Users/helge/Dropbox/dev/Tests/RepoXIssue/LibDep/Sources/LibDep/LibDep.swift:4:20: error: type 'timespec' has no member 'demo'
  let x = timespec.demo()
          ~~~~~~~~ ^~~~

Doing the compilation on the host (or in Docker) works just fine.

@helje5
Copy link
Contributor Author

helje5 commented Aug 4, 2020

Call one looks good (--emit-module mode?):

/usr/local/lib/swift/dst/x86_64-unknown-linux/swift-5.3-ubuntu16.04.xtoolchain/swift.xctoolchain/usr/bin/swiftc \
  -module-name LibDep -incremental -emit-dependencies -emit-module \
  -emit-module-path /Users/helge/Dropbox/dev/Tests/RepoXIssue/LibDep/.build/x86_64-unknown-linux/debug/LibDep.swiftmodule \
  -output-file-map /Users/helge/Dropbox/dev/Tests/RepoXIssue/LibDep/.build/x86_64-unknown-linux/debug/LibDep.build/output-file-map.json \
  -parse-as-library \
  -c /Users/helge/Dropbox/dev/Tests/RepoXIssue/LibDep/Sources/LibDep/LibDep.swift \
  -I /Users/helge/Dropbox/dev/Tests/RepoXIssue/LibDep/.build/x86_64-unknown-linux/debug \
  -target x86_64-unknown-linux -swift-version 5 -enable-batch-mode \
  -index-store-path /Users/helge/Dropbox/dev/Tests/RepoXIssue/LibDep/.build/x86_64-unknown-linux/debug/index/store \
  -use-ld=lld \
  -tools-directory /usr/local/lib/swift/dst/x86_64-unknown-linux/swift-5.3-ubuntu16.04.xtoolchain/swift.xctoolchain/usr/bin \
  -sdk /usr/local/lib/swift/dst/x86_64-unknown-linux/swift-5.3-ubuntu16.04.xtoolchain/x86_64-ubuntu16.04.sdk \
  -Onone -enable-testing -g -j12 -DSWIFT_PACKAGE -DDEBUG \
  -module-cache-path /Users/helge/Dropbox/dev/Tests/RepoXIssue/LibDep/.build/x86_64-unknown-linux/debug/ModuleCache \
  -parseable-output -color-diagnostics

Seems to have the right switches on.

Call two fails:

/usr/local/Cellar/spm-dest-5.3-x86_64-ubuntu16.04/2020-07-31/lib/swift/dst/x86_64-unknown-linux/swift-5.3-ubuntu16.04.xtoolchain/swift.xctoolchain/usr/bin/swift \
  -frontend -c \
  -primary-file /Users/helge/Dropbox/dev/Tests/RepoXIssue/LibDep/Sources/LibDep/LibDep.swift \
  -emit-module-path /Users/helge/Dropbox/dev/Tests/RepoXIssue/LibDep/.build/x86_64-unknown-linux/debug/LibDep.build/LibDep~partial.swiftmodule \
  -emit-module-doc-path /Users/helge/Dropbox/dev/Tests/RepoXIssue/LibDep/.build/x86_64-unknown-linux/debug/LibDep.build/LibDep~partial.swiftdoc \
  -emit-module-source-info-path /Users/helge/Dropbox/dev/Tests/RepoXIssue/LibDep/.build/x86_64-unknown-linux/debug/LibDep.build/LibDep~partial.swiftsourceinfo \
  -emit-dependencies-path /Users/helge/Dropbox/dev/Tests/RepoXIssue/LibDep/.build/x86_64-unknown-linux/debug/LibDep.build/LibDep.d \
  -emit-reference-dependencies-path /Users/helge/Dropbox/dev/Tests/RepoXIssue/LibDep/.build/x86_64-unknown-linux/debug/LibDep.build/LibDep.swiftdeps \
  -target x86_64-unknown-linux \
  -disable-objc-interop \
  -sdk /usr/local/lib/swift/dst/x86_64-unknown-linux/swift-5.3-ubuntu16.04.xtoolchain/x86_64-ubuntu16.04.sdk \
  -I /Users/helge/Dropbox/dev/Tests/RepoXIssue/LibDep/.build/x86_64-unknown-linux/debug \
  -color-diagnostics -enable-testing -g \
  -module-cache-path /Users/helge/Dropbox/dev/Tests/RepoXIssue/LibDep/.build/x86_64-unknown-linux/debug/ModuleCache \
  -swift-version 5 -Onone -D SWIFT_PACKAGE -D DEBUG \
  -enable-anonymous-context-mangled-names \
  -parse-as-library \
  -module-name LibDep \
  -o /Users/helge/Dropbox/dev/Tests/RepoXIssue/LibDep/.build/x86_64-unknown-linux/debug/LibDep.build/LibDep.swift.o \
  -index-store-path /Users/helge/Dropbox/dev/Tests/RepoXIssue/LibDep/.build/x86_64-unknown-linux/debug/index/store \
  -index-system-modules
/Users/helge/Dropbox/dev/Tests/RepoXIssue/LibDep/Sources/LibDep/LibDep.swift:4:20: error: type 'timespec' has no member 'demo'
  let x = timespec.demo()
          ~~~~~~~~ ^~~~

Though it does pretty much correct as well? 🤔

@helje5
Copy link
Contributor Author

helje5 commented Aug 4, 2020

Ready to use tarball to demo the issue: https://helgehess.eu/patches/RepoXIssue-2020-08-04-1.tgz

@helje5 helje5 changed the title Issues with #ifdef'ed extensions not compiling in consuming module Issues with extensions not being imported in consuming module Aug 4, 2020
@helje5
Copy link
Contributor Author

helje5 commented Aug 4, 2020

It's not related to the ifdef's, same error w/ this LibBase.swift:

import Glibc
public typealias timespec = Glibc.timespec
public extension timespec {
  static func demo() -> timespec { return timespec() }
}

@helje5
Copy link
Contributor Author

helje5 commented Aug 4, 2020

Hm, it is restricted to such libc types though, e.g. an extension to Formatter DOES work.

@helje5 helje5 changed the title Issues with extensions not being imported in consuming module Extensions on system types (like stat or time_t) go missing in importing module Aug 4, 2020
@helje5
Copy link
Contributor Author

helje5 commented Aug 5, 2020

Adding

  -resource-dir /usr/local/lib/swift/dst/x86_64-unknown-linux/swift-5.3-ubuntu16.04.xtoolchain/x86_64-ubuntu16.04.sdk/usr/lib/swift \

gives

<unknown>:0: error: missing required module 'SwiftShims'

Looks like the Ubuntu SDK is missing the shims.

@helje5 helje5 added bug Something isn't working help wanted Extra attention is needed labels Aug 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant