12

I am totally new to swift. It has just been released as open source for linux and I wanted to try it. This is on ubuntu 14.04. clang is installed as per prerequisites.

<Edit>: requirements here request clang version 3.6 also on ubuntu 14.04. I had first tried these first steps with clang 3.4, but have since updated to 3.6 following the instructions in the link and retried. Same result.</Edit>

I have downloaded https://swift.org/builds/ubuntu1404/swift-2.2-SNAPSHOT-2015-12-01-b/swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu14.04.tar.gz to ~/Downloads/. Transcript of installation and first step in swift:

$ cd /tmp
$ tar xf ~/Downloads/swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu14.04.tar.gz 
$ PATH=/tmp/swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu14.04/usr/bin/:"$PATH"
$ clang++ --version
Ubuntu clang version 3.6.0-2ubuntu1~trusty1 (tags/RELEASE_360/final) (based on LLVM 3.6.0)
Target: x86_64-pc-linux-gnu
Thread model: posix
$ which swift
/tmp/swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu14.04/usr/bin//swift
$ swift --version
Swift version 2.2-dev (LLVM 46be9ff861, Clang 4deb154edc, Swift 778f82939c)
Target: x86_64-unknown-linux-gnu
$ swift
Welcome to Swift version 2.2-dev (LLVM 46be9ff861, Clang 4deb154edc, Swift 778f82939c). Type :help for assistance.
  1> 1 + 2
opening import file for module 'SwiftShims': No such file or directory
  1>  

According to this getting started guide it should have printed instead

$R0: Int = 3

What's wrong and how can I fix it?

Edit: Trying to find that file manually: It is apparently not contained in the installation:

$ find swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu14.04/ | grep -i shims
swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu14.04/usr/lib/swift/shims
swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu14.04/usr/lib/swift/shims/FoundationShims.h
swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu14.04/usr/lib/swift/shims/SwiftStddef.h
swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu14.04/usr/lib/swift/shims/module.map
swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu14.04/usr/lib/swift/shims/UnicodeShims.h
swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu14.04/usr/lib/swift/shims/GlobalObjects.h
swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu14.04/usr/lib/swift/shims/HeapObject.h
swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu14.04/usr/lib/swift/shims/RuntimeShims.h
swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu14.04/usr/lib/swift/shims/RefCount.h
swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu14.04/usr/lib/swift/shims/RuntimeStubs.h
swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu14.04/usr/lib/swift/shims/LibcShims.h
swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu14.04/usr/lib/swift/shims/CoreFoundationShims.h
swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu14.04/usr/lib/swift/shims/SwiftStdint.h

Edit: When I try the swift build helloworld example, this output is produced:

/tmp/Hello$ swift build
<unknown>:0: error: opening import file for module 'Swift': No such file or directory
swift-build: exit(1): ["/tmp/swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu14.04/usr/bin/swiftc", "--driver-mode=swift", "-I", "/tmp/swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu14.04/usr/lib/swift/pm", "-L", "/tmp/swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu14.04/usr/lib/swift/pm", "-lPackageDescription", "/tmp/Hello/Package.swift"]

Edit: new findings up to 2015-12-22

Since I posted this question, at least two more snapshots of swift for linux have been released: 2015-12-10 and 2015-12-18. I have tried these, but they do not fix the issue.

This mailing list thread here (post 1, post 2, post 3) is about the same problem. It was suggested there that installation of swift under the home directory would help. It did not help in my case, the error message is still the same.

More interestingly, that mailing list thread contains an analysis of the REPL error created with strace. It would be interesting to compare that particular strace output with the strace output from a system where REPL works.

Edit: More info up to 2015-12-26:

A new swift release is out, dated 2015-12-22. This release exhibits the same problem.

Another thread concerning this problem has appeared on the swift mailing list starting here. The user experiencing the problem has also posted strace output here.

timbo
  • 13,244
  • 8
  • 51
  • 71
Ludwig Schulze
  • 2,155
  • 1
  • 17
  • 36
  • @shellter This is about getting a programming environment to work. Of course, such a question touches both topics, the specific programming environment as well as the system where it is installed. However, my feeling is that this is more likely solved by someone who knows Swift programming than by someone who knows Unix. – Ludwig Schulze Dec 03 '15 at 23:20
  • 1
    Yes, Well defended, maybe I was a little too hasty. I've retracted my close vote. Good luck! – shellter Dec 03 '15 at 23:50
  • There is actually a better approach assuming you are familiar with `git`. If you look at each of the Github repositories listed in https://swift.org/source-code/ you will see that there is a `swift-2.2-branch`. Clone all the repositories as detailed at `swift.org` and then switch to the `swift-2.2-branch`. Then you can build and update whenever suits. There is also a tag matching the downloads so you can build to a specific version that matches the `swift.org` downloads. As version 2.2 approaches release, there will likely be fewer and fewer significant changes. – timbo Dec 28 '15 at 02:59
  • @timbo thanks for the contribution, but I have to ask: a better aproach to achieve what? My interest is to learn swift, a new programming language. I tried to install swift as a first step. Following the instructions to perform the installation I ran into the problem described in the question. Sometimes I try new binary releases to see if the problem is solved. So far it is not. In what sense would building from source be a better approach? – Ludwig Schulze Dec 28 '15 at 22:12
  • It would be a better approach to keep Swift up to date as it approaches the 2.2 release & to look at the internals, but admittedly not the best approach to learn it from scratch. If you simply want it installed, there **must** be someone (or a group of people) who are putting an Ubuntu package together. A HomeBrew package has already appeared on OS X. – timbo Dec 28 '15 at 22:23

5 Answers5

13

I had the exact same problem. It turns out that I had added the ppa:ubuntu-toolchain-r/test repo in order to install g++-4.9 on my Mint distro (17.2). Once I purged the repository and restored various libraries to their original versions, swift finally worked for me.

Specifically, I had to run

sudo apt-get install ppa-purge
sudo ppa-purge -d trusty ppa:ubuntu-toolchain-r/test

While cleaning up, ppa-purge was complaining that in order to resolve conflicts, it would have to remove quite a few packages it could not find in the Ubuntu Trusty repo (including really core ones like build-essential, xorg, gcc, x11-xserver-utils...), so I made a note and reinstalled these right away after the purge. Just be very careful.

I think some of the libraries overridden when installing g++ 4.9 were creating a conflict. I've verified all this on a fresh Mint install too.

James D
  • 1,580
  • 1
  • 13
  • 9
  • Very promising hint! I do not have that ppa installed, by I have an installation of g++-5 built from source, and that installation is mirrored into /usr/local with the help of GNU stow. After hiding that installation with "sudo stow -D gcc-5", I can, for the first time, execute the REPL command without getting the error. Your answer, therefore, seems to address the "how can I fix it" part of my question, and is a starting point towards the "what's wrong" part. Upvoted. Will do some more tests (run strace with and without g++-5 in PATH). Good chance to get the bounty in the end. – Ludwig Schulze Dec 28 '15 at 22:42
  • Having compared strace with and without custom gcc-5 installation in /usr/local, the only strace-visible differences are where libstdc++.so.6 and libgcc_s.so.1 are loaded from, /usr/local/lib or /lib. Around the point of error, both versions try to open file "/tmp/swift-2.2-SNAPSHOT-2015-12-22-a-ubuntu14.04/usr/lib/swift/linux/x86_64/SwiftShims.swiftmodule", fail, then open "/tmp/swift-2.2-SNAPSHOT-2015-12-22-a-ubuntu14.04/usr/lib/swift/shims/module.map" and succeed, read from it and close it. The only strace-visible difference here is that the gcc-5 version prints an error and exits. – Ludwig Schulze Dec 28 '15 at 23:29
  • 1
    Summarizing, swift on linux is fragile, but that's ok, as it is very new. To reduce the headaches for people like me who want to try it, swift-for-linux prerequesites should advise against having non-standard installations of gcc, g++, libgcc, libstdc++ installed on the system used to run swift. – Ludwig Schulze Dec 28 '15 at 23:40
  • Thanks! Yes, if it helps you, I isolated the specific package from upstream that triggers it to being libstdc++6. I'm not sure beyond that whether the issue should be fixed in swift or in libstdc++. – James D Dec 28 '15 at 23:55
3

This is not really an answer -- I have the same problem as OP -- but SwiftShims is actually defined the module.map file in your file listing above:

module SwiftShims {
  header "CoreFoundationShims.h"
  header "FoundationShims.h"
  header "GlobalObjects.h"
  header "HeapObject.h"
  header "LibcShims.h"
  header "RefCount.h"
  header "RuntimeShims.h"
  header "RuntimeStubs.h"
  header "SwiftStddef.h"
  header "SwiftStdint.h"
  header "UnicodeShims.h"
  export *
}

https://github.com/apple/swift/blob/8d9ef80304d7b36e13619ea50e6e76f3ec9221ba/stdlib/public/SwiftShims/module.map

solidsnack
  • 1,631
  • 16
  • 26
  • Thanks for the input. So far I know nothing about swift. I have no idea what a module is and how it relates to the error message that complains about a missing file or directory – Ludwig Schulze Dec 04 '15 at 18:19
  • I finally got around this by not installing in `/usr/local`. I'm not sure what your set up was like but I'm sure it's different from mine was. – solidsnack Dec 11 '15 at 03:59
  • not in /usr/local, but instead where? As for my setup, exactly as detailed in the question, first shell command is cd /tmp – Ludwig Schulze Dec 11 '15 at 06:08
  • List members recommended unpacking it in `~/`. https://lists.swift.org/pipermail/swift-users/Week-of-Mon-20151207/000196.html – solidsnack Dec 22 '15 at 08:10
  • Thanks, I have also found that mailing list thread in the meantime. Have set Swift up under $HOME. It does not help: The error message is still the same. – Ludwig Schulze Dec 22 '15 at 10:35
  • To be honest I am not able to get it working either anymore. Had it set up on a spare machine and haven't touched it in a week or so (went back to Mac development). – solidsnack Dec 24 '15 at 10:42
2

I repeated the same steps as you described on a brand-new Ubuntu 14.04 Azure VM and got the expected

$R0: Int = 3

Interestingly, it worked fine even without Clang or GCC! Later I installed Clang-3.5, and it worked as well.

Is it possible that they have sneaked in a new tarball with the same name? The MD5 hash of the one I got is here:

user@ubuntu1:/tmp/junk$ md5sum swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu14.04.tar.gz 
a93f52921c491b747cad256904c8742f  swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu14.04.tar.gz

Does yours match? If so, you may want to try a different installation of Ubuntu 14.04 if you have access to one.

I have also been able to successfully use swift build as instructed in https://swift.org/getting-started/#using-the-build-system . Removing the clang-3.5 package broke swift build, just as I had suspected, but REPL swift still worked as it did originally, before installing Clang for the first time. Then I installed Clang-3.4, and swift build was back in business.

Update 1/3/2016:

Using the hints from the various comments on this question, I've been able to reproduce the error on my Ubuntu 14.04 Azure VM. As an alternative solution, the problem can also be addressed by manipulating $LD_LIBRARY_PATH, see Unable to compile "hello world" program with Swift on Ubuntu 14.04.

Community
  • 1
  • 1
Anatoli P
  • 4,791
  • 1
  • 18
  • 22
1

Had the same issue, what I missed was that I didn't get the keys for the package and verify it before extracting.

  1. Download the package
  2. wget -q -O - https://swift.org/keys/all-keys.asc | gpg --import
  3. gpg --keyserver hkp://pool.sks-keyservers.net --refresh-keys Swift
  4. gpg --verify swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu14.04.tar.gz.sig
  5. tar xzf swift-2.2-SNAPSHOT-2015-12-01-b-ubuntu14.04.tar.gz
  6. add PATH=/path/to/usr/bin:"${PATH}" to your .bashrc
  7. finally run swift

You should see:

Welcome to Swift version 2.2-dev (LLVM 46be9ff861, Clang 4deb154edc, Swift 778f82939c). Type :help for assistance.
1> 1+1
$R0: Int = 2
orkoden
  • 18,946
  • 4
  • 59
  • 50
osleonard
  • 595
  • 5
  • 22
  • I didn't do anything about the keys, and still didn't get the error. It would be interesting to know if the key verification works for the OP. – Anatoli P Dec 10 '15 at 04:27
  • @orkoden Your edit has given the answer a different meaning than the original. Your new version suggests that the download should be checked for integrity. The original answer suggests that the download should by signed before it could work. – Ludwig Schulze Dec 10 '15 at 13:29
  • The original comment said the download should be signed. But the following commands never sign anything. `gpg --verify ` checks the existing signature. – orkoden Dec 10 '15 at 13:31
  • 1
    @orkoden See my comment to OmniProg's response, I have already checked the download for integrity. MD5 collisions are far too unlikely that a download error will pass this check but fail the GPG signature test. Such a corruption would hint strongly at a very resourceful attacker targetting programming language enthusiasts. Again, very very unlikely. Still I am going to check the GPG signature. – Ludwig Schulze Dec 10 '15 at 13:44
  • @osleonard As orkoden points out, in the original response you suggest signing the download, but you do not sign, but instead check the integrity of the download. Did you really just have the impression that you signed something, and after that it worked, while before it did not? Or did the gpg --verify command inform you that the signature did not match the file, and you have downloaded the swift package a second time? – Ludwig Schulze Dec 10 '15 at 13:48
  • 1
    @orkoden Yes the original answer was not coherent, in prosa it talked about signing, while in code what it did was checking. My take on this is that osleonard really had the impression that he needed to sign something to make it work, misunderstanding what he was actually doing. This has a strong voodoo vibe. Maybe I should dance three times around the computer and see if swift starts to function. Still I do not know what my error message is about and would like an explanation from someone who understands swift. – Ludwig Schulze Dec 10 '15 at 14:00
  • Have you installed `libicu-dev `? – orkoden Dec 10 '15 at 14:19
  • libicu-dev is installed, in version 52.1-3ubuntu0.4. And I have done the gpg signature check, 'Good signature from "Swift Automatic Signing Key #1 "'. Repeating the unpacking and checking steps still ends with the same error. – Ludwig Schulze Dec 10 '15 at 23:20
1

Following the advice of James D, I tried to run

sudo apt-get install ppa-purge
sudo ppa-purge -d trusty ppa:ubuntu-toolchain-r/test

However, this did not work. What's strange, is that what did work doesn't make sense. For me, I got it working by installing the above ppa first and then purging it. The whole command set that got me working was

sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install g++-4.9 # This step may be optional

sudo apt-get install ppa-purge
sudo ppa-purge -d trusty ppa:ubuntu-toolchain-r/test
jyapayne
  • 610
  • 6
  • 13