Skip to content

Instantly share code, notes, and snippets.

@marcrasi
Created February 22, 2019 04:30
Show Gist options
  • Save marcrasi/84ec3e9308f3694aa8c7cd2b8d8c1715 to your computer and use it in GitHub Desktop.
Save marcrasi/84ec3e9308f3694aa8c7cd2b8d8c1715 to your computer and use it in GitHub Desktop.
Installing Swift Packages in Colab

First the package needs a dynamic library product. You might have to modify the package to have one. Here's an example.

Now make a notebook that clones the package, builds the package, and copies the build artifacts into the right places. Here's an example.

In a Swift notebook, dlopen the shared library and then import the module. For example:

import Glibc
dlopen("/swift/toolchain/usr/lib/swift/linux/libDeckOfPlayingCards.so", RTLD_NOW)
import DeckOfPlayingCards

Now you can use it. For example:

print(Deck.standard52CardDeck())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment