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

[SR-1191] Failed to use REPL with SPM built modules #5462

Closed
swift-ci opened this issue Apr 8, 2016 · 13 comments
Closed

[SR-1191] Failed to use REPL with SPM built modules #5462

swift-ci opened this issue Apr 8, 2016 · 13 comments
Labels

Comments

@swift-ci
Copy link
Contributor

swift-ci commented Apr 8, 2016

Previous ID SR-1191
Radar None
Original Reporter dreymonde (JIRA User)
Type Bug
Status Resolved
Resolution Won't Do
Environment

OS X 10.11, DEVELOPMENT-SNAPSHOT-2016-03-24-a

Additional Detail from JIRA
Votes 2
Component/s LLDB for Swift, Package Manager
Labels Bug, REPL
Assignee None
Priority Medium

md5: ac28f4342824c5000f6ec58e6cf6e10f

relates to:

  • SR-1573 A way to launch swift REPL with all swift modules in a package

Issue Description:

SPM built modules are unable to use with REPL.

$ swift build
Compiling Swift Module 'Analysis' (7 sources)
$ swift -I .build/debug

import statement works, but then error occurs:

  1> import Analysis
  2> let list: List = [2, 3, 4]
list: Analysis.List = {
  elements = <extracting data from value failed>

}
error: Couldn't lookup symbols:
  __TMO8Analysis9DataPoint
  __TFO8Analysis9DataPointCfT14integerLiteralSi_S0_
  __TFV8Analysis4ListCft12arrayLiteralGSaOS_9DataPoint__S0_

UPDATE
Error descriptions on Linux seems to be more informative:

swift -L .build/debug -I .build/debug
Welcome to Swift version 3.0-dev (LLVM b010debd0e, Clang 3e4d01d89b, Swift 7182c58cb2). Type :help for assistance.
  1> import Analysis
  2> let list: List = [1, 2, 3, 4, false, "string"]
list: Analysis.List = {
  elements = <extracting data from value failed>

}
error: Couldn't lookup symbols:
  Analysis.List.init (arrayLiteral : Swift.Array<Analysis.DataPoint>...) -> Analysis.List
  Analysis.DataPoint.init (booleanLiteral : Swift.Bool) -> Analysis.DataPoint
  Analysis.DataPoint.init (integerLiteral : Swift.Int) -> Analysis.DataPoint
  type metadata for Analysis.DataPoint
  Analysis.DataPoint.init (stringLiteral : Swift.String) -> Analysis.DataPoint
@belkadan
Copy link

belkadan commented Apr 8, 2016

I think you need a -L flag there too, but maybe there should be a nice way to do this (e.g. if you start the REPL in a package directory, you automatically get -I and -L for the package and any dependencies).

@swift-ci
Copy link
Contributor Author

swift-ci commented Apr 8, 2016

Comment by Oleg Dreyman (JIRA)

@belkadan thanks for the reply! I tried to add -L, but that still doesn’t work.

$ swift -I .build/debug -L .build/debug
Welcome to Apple Swift version 3.0-dev (LLVM b010debd0e, Clang 3e4d01d89b, Swift 7182c58cb2). Type :help for assistance.
  1> import Analysis
  2> let list: List = [1, 2, 3, 4]
list: Analysis.List = {
  elements = <extracting data from value failed>

}
error: Couldn't lookup symbols:
  __TMO8Analysis9DataPoint
  __TFO8Analysis9DataPointCfT14integerLiteralSi_S0_
  __TFV8Analysis4ListCft12arrayLiteralGSaOS_9DataPoint__S0_

@mxcl
Copy link
Contributor

mxcl commented Apr 11, 2016

Auto-link issue? I have no idea how the auto-linking works. I tried reading up on it, but didn't find much material.

@trfiala
Copy link
Mannequin

trfiala mannequin commented Apr 25, 2016

Sean Callanan will probably want to take a look at this.

@ddunbar
Copy link
Member

ddunbar commented Apr 30, 2016

We don't currently compile a DSO for each Swift module, so this certainly can't work until that happens.

@mxcl
Copy link
Contributor

mxcl commented May 2, 2016

I tried with PackageDescription with swiftpm and it doesn't work there either.

✔ 10:32 ~/src/swiftpm [master L|✔] $ swift build
Compile Swift Module 'libc' (3 sources)
Compile Swift Module 'PackageDescription' (6 sources)
Compile Swift Module 'OptionsParser' (3 sources)
Compile Swift Module 'POSIX' (24 sources)
Compile Swift Module 'Utility' (14 sources)
Linking .build/debug/libPackageDescription.dylib
Compile Swift Module 'PackageType' (6 sources)
Compile Swift Module 'Build' (12 sources)
Compile Swift Module 'Get' (10 sources)
Compile Swift Module 'ManifestParser' (3 sources)
Compile Swift Module 'Multitool' (4 sources)
Compile Swift Module 'Transmute' (9 sources)
Compile Swift Module 'Xcodeproj' (4 sources)
Compile Swift Module 'swifttest' (4 sources)
Linking .build/debug/swift-test
Compile Swift Module 'swiftbuild' (7 sources)
Linking .build/debug/swift-build
✔ 10:32 ~/src/swiftpm [master L|✔] $ swift -I.build/debug -L.build/debug
Welcome to Apple Swift version 3.0-dev (LLVM 752e1430fc, Clang 1e6cba3ce3, Swift d525b8320b). Type :help for assistance.
  1> import PackageDescription
  2> let v = Version(1,2,3)
v: PackageDescription.Version = {
  major = <extracting data from value failed>

  minor = <extracting data from value failed>

  patch = <extracting data from value failed>

  prereleaseIdentifiers = <extracting data from value failed>

  buildMetadataIdentifier = <extracting data from value failed>

}
error: Couldn't lookup symbols:
  __TFV18PackageDescription7VersionCfTSiSiSi21prereleaseIdentifiersGSaSS_23buildMetadataIdentifierGSqSS__S0_
 __TIFV18PackageDescription7VersioncFTSiSiSi21prereleaseIdentifiersGSaSS_23buildMetadataIdentifierGSqSS__S0_A2_
 __TIFV18PackageDescription7VersioncFTSiSiSi21prereleaseIdentifiersGSaSS_23buildMetadataIdentifierGSqSS__S0_A3_

@ankitspd
Copy link
Member

ankitspd commented May 2, 2016

Works if you have dylibs and `$ swift -I .build/debug -L .build/debug -l<modulename>`
how about `$ swift build --repl` launches this for the user?

@mxcl
Copy link
Contributor

mxcl commented May 2, 2016

Confirmed:

✔ 10:40 ~/src/swiftpm [master L|✔] $ swift -I.build/debug -L.build/debug -lPackageDescription
Welcome to Apple Swift version 3.0-dev (LLVM 752e1430fc, Clang 1e6cba3ce3, Swift d525b8320b). Type :help for assistance.
  1> import PackageDescription
  2> let v = Version(1,2,3)
v: PackageDescription.Version = {
  major = 1
  minor = 2
  patch = 3
  prereleaseIdentifiers = 0 values
  buildMetadataIdentifier = nil
}

It's a mystery to me when auto-linking works or not. Though I guess this is outside of that system.

@ankitspd
Copy link
Member

ankitspd commented Sep 1, 2016

This is not a bug, as noted in comments REPL works fine if passed correct flags

@swift-ci
Copy link
Contributor Author

swift-ci commented Jan 4, 2017

Comment by Robert Atkins (JIRA)

I'm doing swift -I.build/debug -L.build/debug -lFoo and it's not working for me (getting the OP's "error = <extracting data from value failed>") but I don't "have dylibs". How do I "get dylibs" in 2017? It doesn't seem to be an spm option anymore.

@ankitspd
Copy link
Member

ankitspd commented Jan 4, 2017

You can produce dylib products once the product proposal is implemented.
https://github.com/apple/swift-evolution/blob/master/proposals/0146-package-manager-product-definitions.md

as of now there is a product API (see swiftpm's Package.swift) but we don't recommend using it as it will be removed without deprecation.

@swift-ci
Copy link
Contributor Author

swift-ci commented Jan 4, 2017

Comment by Robert Atkins (JIRA)

adding:

products.append(
    Product(name: "Foo", type: .Library(.Dynamic), modules: "Foo")
)

to my Package.swift gets me a libFoo.so, but I get basically the same error when I try to do anything with it in the REPL. Am I missing something?

(This is just a temporary thing to try and debug a test that passes on macOS but fails on Linux, so I don't mind hacking around.)

UPDATE: Turns out this was working all along, but the specific function I was trying to call in my Foo has some other kind of problem which was leading me to think the import process itself was broken.

@swift-ci
Copy link
Contributor Author

swift-ci commented Dec 1, 2017

Comment by Jonathan McAllister (JIRA)

In case someone finds this ticket searching for help on how to import spm packages in the repl with swift 4, here is a helpful write up https://github.com/profburke/swiftreplmadness

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants