Skip to content

Instantly share code, notes, and snippets.

@doublec
Created November 23, 2018 10:23
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doublec/c723924fd252cd4cf6774ed84d1edbe8 to your computer and use it in GitHub Desktop.
Save doublec/c723924fd252cd4cf6774ed84d1edbe8 to your computer and use it in GitHub Desktop.
Building a static urweb executable
# Build musl libc
$ git clone git://git.musl-libc.org/musl
$ cd musl
$ ./configure
$ make
$ sudo make install
$ export PATH=$PATH:/usr/local/musl/bin/
# build libz for musl
$ wget https://zlib.net/zlib-1.2.11.tar.gz
$ tar xvf zlib-1.2.11.tar.gz
$ cd zlib-1.2.11/
$ CC=musl-gcc ./configure --prefix=/usr/local/musl -static
$ make
$ sudo make install
# build openssl for musl
$ wget https://www.openssl.org/source/openssl-1.1.0j.tar.gz
$ tar xvf openssl-1.1.0j.tar.gz
$ cd openssl-1.1.0j/
$ CC=musl-gcc ./Configure --prefix=/usr/local/musl linux-x86_64 no-shared no-async no-engine
$ make
$ sudo make install
# Test UrWeb application
# musl lacks timelocal, create a stub C file with a dummy implementation
# timelocal is only used in urweb for fromDatetime
$ cat time.c
#include <time.h>
time_t timelocal(struct tm *tm);
time_t timelocal(struct tm *tm) {
return (time_t)0;
}
$ musl-gcc -c time.c
# Create a project file that links against time.o
$ cat hello.urp
link time.o
hello
# Create hello.ur
$ cat hello.ur
val x = "Hi"
fun main () : transaction page = return <xml><body>{[x]}</body></xml>
# Build example
$ urweb -ccompiler "musl-gcc" -static hello
$ ldd hello.exe
not a dynamic executable
$ ./hello.exe
Database connection initialized.
Starting the Ur/Web native HTTP server, which is intended for use
ONLY DURING DEVELOPMENT. You probably want to use one of the other backends,
behind a production-quality HTTP server, for a real deployment.
Listening on port 8080....
Database connection initialized.
Database connection initialized.
$ curl http://127.0.0.1:8080/Hello/main
<!DOCTYPE html><html><head></head><body>Hi</body></html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment