Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/keynmol/scala-native-microhttpd-example


https://github.com/keynmol/scala-native-microhttpd-example

Last synced: 2 months ago
JSON representation

Awesome Lists containing this project

README

        

# Scala 3 Native ❤️ libmicrohttpd

I recently discovered there's a relatively small HTTP server library
called microhttpd by the GNU project: https://www.gnu.org/software/libmicrohttpd/manual/html_node/index.html

This small project contains:
- `microhttpd.bindings.scala` - Microhttpd bindings generated by [sn-bindgen](https://sn-bindgen.indoorvivants.com/quickstart/index.html), my binding generator
- `run.server.scala` - the logic to run a simple web server that responds with JSON
- `DangerZone.scala` - absolutely horrific experiment in memory management to
circumvent combined limitations of Zone from Scala Native and C's function pointers. I'm pursuing a life long goal to have a CVE named after me.

## Running

This is a [Scala CLI](https://scala-cli.virtuslab.org/) project.

Personally, I run it using my [sn-vcpkg](https://github.com/indoorvivants/sn-vcpkg#scala-cli) project to avoid messing with flags by hand:

```
cs launch com.indoorvivants.vcpkg:sn-vcpkg_3:latest.release -- \
scala-cli libmicrohttpd -- run .
```

But if you know what you're doing, "just" install "libmicrohttpd" and adjust the linking flags required to run it:

```
scala-cli run . --native-linking -lmicrohttpd
```