Skip to content
This repository has been archived by the owner on Sep 13, 2024. It is now read-only.

unbit/uwsgi-swift

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

uwsgi-swift

uWSGI plugin for Apple Swift integration

This is a super-experimental plugin aimed at embedding swift apps into uWSGI.

It currently works only on OSX

The plugin includes a swift module from which you can start building better integration:

import Foundation

public func application(s : NSDictionary) -> NSArray {
        print("Hello World")
        print(s["REQUEST_METHOD"])
        print(s)
        print("ready for response")
        let chunk0 : NSData! = "Hello ".dataUsingEncoding(NSUTF8StringEncoding)
        let chunk1 : NSData! = "World".dataUsingEncoding(NSUTF8StringEncoding)
        return ["200 OK", ["Foo": ["Bar", "Ops"]], [chunk0, chunk1]] as NSArray
}

as you can see, Objective-C native types are expected at the lower level, consider making some kind of wrapping to Swift native types (read: re-encode application() arguments to [String : String] and pass it to another swift function)

The plugin is 2.x friendly:

uwsgi --build-plugin https://github.com/unbit/uwsgi-swift

or (once the repository is cloned)

uwsgi --build-plugin uwsgi-swift

The plugin has hardcoded mangled entry point (so do not change function signature or the plugin will crash):

char *symbol_name = "_TF7example11applicationFCSo12NSDictionaryCSo7NSArray";

it maps to example.application function. Feel free to change it and rebuild the plugin (use the nm command line tool to get the symbol name)

To build example.swift as a shared library

xcrun -sdk macosx swiftc -emit-library example.swift 

this will result in libexample.dylib

You can run uWSGI in swift mode with:

uwsgi --dlopen libexample.dylib --plugin swift_plugin.so --swift-func application --http-socket :9090 --threads 50 -p 2 -M

this will run an http server on port 9090 with two processes with 50 threads each.

The memory model of the plugin is still unimplemented, so expect extreme leaks.

About

uWSGI plugin for Apple Swift integration

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published