Skip to content

Instantly share code, notes, and snippets.

@timburks
Created February 15, 2017 18:35
Show Gist options
  • Save timburks/435cdaec6090e56b95f35be660de84fc to your computer and use it in GitHub Desktop.
Save timburks/435cdaec6090e56b95f35be660de84fc to your computer and use it in GitHub Desktop.
Run Swift on Google Cloud Shell! Here are instructions for using OpenAPI Compiler to generate a Swift client and server for a REST API.
# Run OpenAPI Compiler and Swift in Cloud Shell
# First use apt-get to install packages needed to run Swift
sudo apt-get update
sudo apt-get install -y clang clang-3.8 lldb-3.8 libicu-dev libtool libcurl4-openssl-dev libbsd-dev build-essential libssl-dev uuid-dev curl unzip
# Next create a ~/local directory for some tools that we'll download
cd
mkdir -p local
# Add $HOME/local/bin to your path by adding the following to your .bashrc
# export PATH=.:$HOME/local/bin:$PATH
# After you've done the above step, reload .bashrc
source ~/.bashrc
# Download and install Swift in ~/local
SWIFT_BRANCH=swift-3.0.2-release
SWIFT_VERSION=swift-3.0.2-RELEASE
SWIFT_PLATFORM=ubuntu14.04
SWIFT_URL=https://swift.org/builds/$SWIFT_BRANCH/$(echo "$SWIFT_PLATFORM" | tr -d .)/$SWIFT_VERSION/$SWIFT_VERSION-$SWIFT_PLATFORM.tar.gz
echo $SWIFT_URL
curl -fSsL $SWIFT_URL -o swift.tar.gz
tar -xzf swift.tar.gz --strip-components=2 --directory=local
# Download and install the protocol buffer compiler in ~/local
PROTOC_URL=https://github.com/google/protobuf/releases/download/v3.2.0rc2/protoc-3.2.0rc2-linux-x86_64.zip
echo $PROTOC_URL
curl -fSsL $PROTOC_URL -o protoc.zip
unzip protoc.zip -d local
# Download and build OpenAPI Compiler (openapic)
go get github.com/googleapis/openapi-compiler/openapic
# Build the Swift code generator plugin
cd ~/gopath/src/github.com/googleapis/openapi-compiler/plugins/swift/openapi_swift_generator
make
# Generate and build the bookstore example
cd examples/bookstore
make
# Start the bookstore server
.build/debug/Server &
# Run the swift unit tests
swift test
# Open the web preview button and visit /shelves
@alyeung
Copy link

alyeung commented Feb 18, 2017

hey timburks - nice walkthrough.

For the newbie (like me) it might be helpful to provide a link to the command edit short cuts for vi when editing the .bashrc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment