This repository has been archived by the owner on Apr 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update docs from github.com/stealthrocket/timecraft@76eba4c35a5b38e60…
…3b85e135f5c788851265fcb
- Loading branch information
1 parent
0139432
commit a765fcf
Showing
4 changed files
with
118 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
label: "Applications" | ||
position: 1 | ||
link: | ||
type: generated-index | ||
title: "Applications" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Go | ||
|
||
## Preparing Go | ||
|
||
Go 1.21, due to be released in August 2023, will be able to natively compile Go applications to WebAssembly. | ||
|
||
```console | ||
$ GOOS=wasip1 GOARCH=wasm go build ... | ||
``` | ||
|
||
Since Go 1.21 has not been released yet, you can use [`gotip`](https://pkg.go.dev/golang.org/dl/gotip) to test these features before release: | ||
|
||
```console | ||
$ go install golang.org/dl/gotip@latest | ||
$ gotip download | ||
``` | ||
|
||
```console | ||
$ GOOS=wasip1 GOARCH=wasm gotip build ... | ||
``` | ||
|
||
## Compiling your application | ||
|
||
Instead of using `go build`, use: | ||
|
||
```console | ||
$ GOOS=wasip1 GOARCH=wasm gotip build -o app.wasm <path/to/main/pkg> | ||
``` | ||
|
||
This will build a WebAssembly module that can be run with Timecraft. | ||
|
||
## Running your application with Timecraft | ||
|
||
To run your application: | ||
|
||
```console | ||
$ timecraft run app.wasm | ||
``` | ||
|
||
Command-line arguments can be specified after the WebAssembly module. To prevent | ||
Timecraft from interpreting command-line options for the application, use: | ||
|
||
```console | ||
$ timecraft run -- app.wasm arg1 arg2 ... | ||
``` | ||
|
||
Note that environment variables passed to Timecraft are automatically passed to the | ||
WebAssembly module. | ||
|
||
## Networking applications | ||
|
||
You may quickly find that the networking capabilities of `GOOS=wasip1` are limited. | ||
|
||
We have created a library to help with common use cases, such as creating HTTP servers | ||
and connecting to databases. See https://github.com/stealthrocket/net for usage details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Python | ||
|
||
Python applications aren't compiled to WebAssembly. Rather, a Python interpreter (CPython) | ||
is compiled to WebAssembly and interprets your Python application as it would normally. | ||
|
||
Minor patches have been made to both the CPython interpreter and standard library to ensure | ||
that applications are able to create POSIX style sockets. This enables Python applications to | ||
create servers and connect to databases. We intend to upstream our patches at some stage. | ||
|
||
## Preparing Python | ||
|
||
We provide a pre-compiled Python interpreter and patched standard library. You can download them by running | ||
|
||
``` | ||
curl -fsSL https://timecraft.s3.amazonaws.com/python/main/python.wasm -o python.wasm | ||
curl -fsSL https://timecraft.s3.amazonaws.com/python/main/python311.zip -o python311.zip | ||
``` | ||
|
||
To build Python from scratch, see the instructions in the | ||
[`./python`](https://github.com/stealthrocket/timecraft/tree/main/python) dir. | ||
|
||
## Running your application with Timecraft | ||
|
||
### Preparing dependencies | ||
|
||
It's recommended that you install your Python dependencies in a virtualenv: | ||
|
||
```console | ||
$ python3 -m venv env | ||
$ source ./env/bin/activate | ||
(env) $ pip install -r /path/to/requirements.txt | ||
``` | ||
|
||
### Running Timecraft | ||
|
||
The Python interpreter needs to know where dependencies are installed | ||
and where the standard library ZIP is located. | ||
|
||
Assuming both the interpreter (`python.wasm`) and standard library (`python311.zip`) | ||
are located in the current directory, you can pass this information to the | ||
interpreter like so: | ||
|
||
``` | ||
$ export PYTHONHOME=env | ||
$ export PYTHONPATH=python311.zip:$PYTHONHOME | ||
``` | ||
|
||
You can now run your application: | ||
|
||
``` | ||
$ timecraft run python.wasm main.py | ||
``` |