Giter Club home page Giter Club logo

onlineswiftplayground's Introduction

SwiftPlayground.run

Platform Twitter

Online Swift Playground. Implemented in Swift.

TBA. Checkout http://SwiftPlayground.run

SwiftPlayground.run

Installation & Run

$ git clone https://github.com/krzyzanowskim/OnlineSwiftPlayground.git
$ cd OnlineSwiftPlayground
$ ./run.sh

The run.sh script will generate Xcode project (on macOS) and bootstrap the environment. run.sh needs npm to be installed to work properly. Bootstraping involves

  1. Download Swift Toochains supported by the playground
  2. Pre-build support module using the toolchains
  3. Install dependencies
  4. Launches web server on localhost on port 8080

Now you could access playground pointing web browser to 127.0.0.1:8080.

Development

Xcode

Generate Xcode project

$ swift package generate-xcodeproj

React

Web user interface is build with React and webpack.

$ npm run build

Docker

krzyzanowskim/onlineswiftplayground

Download the latest image:

$ docker pull krzyzanowskim/onlineswiftplayground

or build docker image by yourself:

$ git clone https://github.com/krzyzanowskim/OnlineSwiftPlayground.git
$ cd OnlineSwiftPlayground
$ docker buildx create --use
$ docker buildx build --platform=linux/amd64,linux/arm64 . -t krzyzanowskim/onlineswiftplayground

then run container:

$ docker run -d -p 8080:8080 --name onlineswiftplayground -t krzyzanowskim/onlineswiftplayground

and wait until docker container is up (usually several seconds).

Playground is available at http://localhost:8080. If the docker setup uses VirtualBox, the you can get the IP address from docker-machine ip command.

$ open http://$(docker-machine ip):8080

Config

Third party frameworks should be copied to Frameworks directory (Frameworks are for macOS host only)

See config/ for GitHub auth. sample config.

Author

SwiftPlayground.run is owned and maintained by Marcin Krzyzanowski

You can follow me on Twitter at @krzyzanowskim for project updates and releases.

License

Creative Commons Attribution Non Commercial 4.0. See LICENSE file.

onlineswiftplayground's People

Contributors

alvarhansen avatar arunkpatra avatar dependabot[bot] avatar gtranchedone avatar josefdolezal avatar krzyzanowskim avatar valeriyvan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

onlineswiftplayground's Issues

No browser caching?

It seems on every refresh of the page, the same resources are downloaded over and over again. It would be more efficient to have caching on the client side, hence less CO2 emission.

⌘ + ENTER to run code

Any ideas to support the ⌘ + ENTER keystroke combination to run the code in the playground? Essentially, this key combination would do whatever happens when the green Run button is clicked. That would be cool!

Can't scroll in code window and output window

Sometimes scrolling within the code window and output window does not work properly.

This is a screenrecording of the issue in the output window, couldn't replicate again the code window issue.

ezgif com-video-to-gif (5)

Using Chrome Version 81.0.4044.129 (Official Build) (64-bit) on MacOS.
Code wrote in the Code Window to reproduce the issue in the Output Window:

import Foundation

class Adapter: NSObject {
    static var lat: Int = {
        // some calculations
        print("lat")
        return 1
    }()
}

print(Adapter.lat)
print(Adapter.lat)

class Adapter2: NSObject {
    static var width: Int {
        // some calculations
        print("width")
        return 1
    }
}

print(Adapter2.width)
print(Adapter2.width)

Running OnlineSwiftPlayground locally - error: no such module 'OnlinePlayground'

I tried to build and run locally. The UI came up fine and the backend started fine as well. I'm running on macOS Catalina, Xcode 11.1. However, when the call eventually lands up at the backend, what I get back in the UI is error: no such module 'OnlinePlayground'. Please see screenshot. Could you please help to shed some light and help me debug this?
Screen Shot 2019-10-18 at 4 19 04 PM

Server hangs on macOS after a while

I've noticed the server stop responding after some time (usually ~2 days) and can't properly restart it. Not sure what the NIO is doing but I have to reboot (or logout) the user to unbind. It's weird. Does it ring any bell @josefdolezal?

Launched as

.build/swift-5.7-RELEASE/x86_64-apple-macosx/release/PlaygroundServer serve --hostname 0.0.0.0

It may, or may not be related to vapor/vapor#2502

Asserts don't work

If you include "assert()" in the source code they don't seem to be evaluated. To reproduce the error just try assert(false). Nothing happens when executing.

Support embedding source in URL

The idea comes from typescript playground. If you open up the following
https://www.typescriptlang.org/play/index.html#src=console.log(%22Hello%22)%3B , you'll see that the source is console.log("Hello"); which was embedded in hash as #src=conso..... So, you get point.

This way it would be really easy to share some runnable snippets to online.swiftplayground.run. Including the swift version as well it would be something like this:
http://online.swiftplayground.run/#v=4.2&src=print(%22Hello%22)

A bit related to #5

Compiler error when not importing anything

Trying a code snippet that doesn't import anything doesn't work for me on http://online.swiftplayground.run/. When trying just print("lol"), the output is the following:

Swift version 4.0.3 (swift-4.0.3-RELEASE)
Target: x86_64-unknown-linux-gnu
/usr/bin/swift -frontend -c -primary-file /tmp/C32686A8-2BA6-4678-B992-3301A819626C.XrYPNz/main.swift -target x86_64-unknown-linux-gnu -disable-objc-interop -I /swiftplayground/.build/release -gnone -suppress-warnings -swift-version 4 -enforce-exclusivity=checked -module-name SwiftPlayground -o /tmp/main-e86eb6.o
/usr/bin/swift-autolink-extract /tmp/main-e86eb6.o -o /tmp/main-a37d34.autolink
/usr/bin/clang++ -fuse-ld=gold -target x86_64-unknown-linux-gnu -Xlinker -rpath -Xlinker /usr/lib/swift/linux /usr/lib/swift/linux/x86_64/swift_begin.o /tmp/main-e86eb6.o -L /swiftplayground/.build/release -lOnlinePlayground -L /usr/lib/swift/linux -lswiftCore --target=x86_64-unknown-linux-gnu @/tmp/main-a37d34.autolink /usr/lib/swift/linux/x86_64/swift_end.o -o /tmp/C32686A8-2BA6-4678-B992-3301A819626C.XrYPNz/main
/swiftplayground/.build/release/libOnlinePlayground.a(OnlinePlayground.swift.o):/swiftplayground/.build/x86_64-unknown-linux/release/OnlinePlayground.build/OnlinePlayground.swift.o:_swift_FORCE_LOAD_$_swiftGlibc_$_OnlinePlayground: error: undefined reference to '_swift_FORCE_LOAD_$_swiftGlibc'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.