Thursday, December 15, 2016

Installing Swift 3.0.2 on Ubuntu on Windows 10

I followed the instructions at the Swift download page in the Linux section. I used the “Swift 3.0.2 RELEASE - Ubuntu 14.04” download. This environment variable remembers the location where I downloaded it.

export SWIFT_ROOT=$HOME/swift

Hello world works

At this point, I can run a simple hello world program. I created a file called hello.swift with the following contents:

print("Hello world")

Then I ran it as such:

swift hello.swift

As expected, it printed hello world.

Executable stack issues

But then I found that I wasn’t able to use the package manager to build an existing Swift package called LogicSim that I created on my Mac, which worked there. When I went to that directory and ran swift build, I got the following error:

/home/anoop/swift/usr/bin/swift-build: error while loading shared libraries: libFoundation.so: cannot enable executable stack as shared object requires: Invalid argument

The fix

Apparently that error is caused by some flag in the shared object ELF file libFoundation.so. To clear it, I ran the following commands

sudo apt-get install execstack
sudo execstack -c $SWIFT_ROOT/swift/usr/lib/swift/linux/libFoundation.so

That fixed the above error, but…

Operation not permitted errors within .build folder

Now when I try swift build I get these errors

warning: minimum recommended clang is version 3.6, otherwise you may encounter linker errors.
Compile Swift Module 'LogicSim' (4 sources)
<unknown>:0: error: error opening '/mnt/c/Users/anoop/GoogleDrive/Swift/LogicSim/.build/debug/LogicSim.build/Module~partial.swiftmodule' for output: Operation not permitted
<unknown>:0: error: error opening '/mnt/c/Users/anoop/GoogleDrive/Swift/LogicSim/.build/debug/LogicSim.build/Port~partial.swiftmodule' for output: Operation not permitted
<unknown>:0: error: error opening '/mnt/c/Users/anoop/GoogleDrive/Swift/LogicSim/.build/debug/LogicSim.build/AndGateModule~partial.swiftmodule' for output: Operation not permitted
<unknown>:0: error: error opening '/mnt/c/Users/anoop/GoogleDrive/Swift/LogicSim/.build/debug/LogicSim.build/main~partial.swiftmodule' for output: Operation not permitted
<unknown>:0: error: build had 1 command failures
error: exit(1): /home/anoop/swift/usr/bin/swift-build-tool -f /mnt/c/Users/anoop/GoogleDrive/Swift/LogicSim/.build/debug.yaml

The fix

I didn’t really know why this was happening. I suspected bad permission bits in the directory, since it resides on my C: drive, inside my Google Drive folder, which was being synced from when I worked on it on my mac. I just removed the build directory and tried again:

rm -r .build
swift build

Surprisingly, the build succeeds without errors!

I also ran the executable to make sure it works as expected, and it did.

.build/Debug/LogicSim

Written with StackEdit.

No comments:

Post a Comment