File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -51,35 +51,8 @@ installation path added to the `PATH` environment variable.
5151
5252### Examples
5353
54- ** Wasm file smaller than 2MB** : assuming we have a ` hello.wasm ` file inside the
55- ` /home/user/code/ ` directory
54+ See ` examples/wasi ` .
5655
57- A function can be created using this command:
58-
59- serverledge-cli create -f func-name \
60- --runtime wasi \
61- --src /home/user/code/hello.wasm \
62- --custom_image hello
63-
64- ** Python** (using the official build): assuming the ` .tar ` is hosted on
65- ` localhost:8000/python.tar ` and inside the ` .tar ` file there is a ` func.py `
66-
67- At the time of writing, the official build is provided by the maintainer of the
68- WASI platform in Python at the following [ link] ( https://github.com/brettcannon/cpython-wasi-build/releases/tag/v3.13.0 )
69-
70- Serverledge assumes the structure of the ` python.tar ` file to be the following:
71-
72- - ` func.py ` : the main source file; the name must be specified in the ` handler ` argument of the function creation
73- - ` python.wasm ` (obtained through the link above)
74- - ` lib/ ` (obtained through the link above)
75-
76- A function can be created using this command:
77-
78- serverledge-cli create -f func-name \
79- --runtime wasi \
80- --src http://localhost:8000/python.tar \
81- --custom_image python \
82- --handler func.py
8356
8457## Custom function runtimes
8558
Original file line number Diff line number Diff line change 1+ WASI-CC =$${HOME}/wasi-sdk/bin/clang
2+ WASI-LD =$${HOME}/wasi-sdk/bin/wasm-ld
3+
4+ CFLAGS=--sysroot =$${HOME}/wasi-sdk/share/wasi-sysroot
5+
6+ all :
7+ $(WASI-CC ) $(CFLAGS ) fibonacci.c -o fibonacci.wasm
8+
9+ clean :
10+ @rm -rf fibonacci.wasm
11+
12+
13+ .PHONY : all clean
Original file line number Diff line number Diff line change 1+ ## C
2+
3+ Download WASI SDK [ here] ( https://github.com/WebAssembly/wasi-sdk/releases ) .
4+ At the time of writing the latest release is WASI SDK 25
5+
6+ Update the location of the downloaded SDK in ` Makefile ` .
7+
8+ The example ` fibonacci.c ` is compiled to ` fibonacci.wasm ` :
9+
10+ make
11+
12+ The function can be created using this command:
13+
14+ serverledge-cli create -f fib-wasi \
15+ --runtime wasi \
16+ --src fibonacci.wasm \
17+ --custom_image fibonacci
18+
19+ ## Python
20+
21+ See the ` python ` directory.
Original file line number Diff line number Diff line change 1+ #include <stdint.h>
2+ #include <stdio.h>
3+
4+ uint32_t fib (uint32_t n ) {
5+ if (n <= 1 )
6+ return n ;
7+ return fib (n - 1 ) + fib (n - 2 );
8+ }
9+
10+ int main (int argc , char * * argv ) {
11+ uint32_t n = 30 ;
12+
13+ uint32_t result = fib (n );
14+ printf ("%u\n" , result );
15+ return 0 ;
16+ }
Original file line number Diff line number Diff line change 1+
2+ ** Python** (using the official build): assuming the ` .tar ` is hosted on
3+ ` localhost:8000/python.tar ` and inside the ` .tar ` file there is a ` sieve.py `
4+
5+ At the time of writing, the official build is provided by the maintainer of the
6+ WASI platform in Python at the following [ link] ( https://github.com/brettcannon/cpython-wasi-build/releases/tag/v3.13.0 )
7+
8+ Serverledge assumes the structure of the ` python.tar ` file to be the following:
9+
10+ - ` sieve.py ` : the main source file; the name must be specified in the ` handler ` argument of the function creation
11+ - ` python.wasm ` (obtained through the link above)
12+ - ` lib/ ` (obtained through the link above)
13+
14+ A function can be created using this command:
15+
16+ serverledge-cli create -f func-name \
17+ --runtime wasi \
18+ --src http://localhost:8000/python.tar \
19+ --custom_image python \
20+ --handler sieve.py
Original file line number Diff line number Diff line change 1+ import sys
2+ import json
3+
4+
5+ def sieve (limit : int ) -> list [int ]:
6+ sieve : list [bool ] = [False ] * (limit + 1 )
7+ primes : list [int ] = list ()
8+ for i in range (2 , limit + 1 ):
9+ if not sieve [i ]:
10+ primes .append (i )
11+ for j in range (i << 1 , limit + 1 , i ):
12+ sieve [j ] = True
13+ return primes
14+
15+
16+ if __name__ == "__main__" :
17+ limit = 100000
18+ if len (sys .argv ) > 1 :
19+ params = json .loads (sys .argv [1 ])
20+ if "limit" in params :
21+ limit = int (params ["limit" ])
22+ primes = sieve (limit )
23+
24+ print (primes )
25+
26+
27+ def handler (params , context ):
28+ limit = 100000
29+ if len (sys .argv ) > 1 :
30+ params = json .loads (sys .argv [1 ])
31+ if "limit" in params :
32+ limit = int (params ["limit" ])
33+ primes = sieve (limit )
34+
35+ print (primes )
36+ return primes
You can’t perform that action at this time.
0 commit comments