| Crates.io | compilet |
| lib.rs | compilet |
| version | 0.1.6 |
| created_at | 2023-05-14 18:17:51.686344+00 |
| updated_at | 2023-09-10 15:59:44.352608+00 |
| description | Server that compiles Rust, C, and C++ into WebAssembly. |
| homepage | https://github.com/wasm-oj/compilet |
| repository | https://github.com/wasm-oj/compilet |
| max_upload_size | |
| id | 864403 |
| size | 86,958 |
Server that compiles Rust, C, and C++ into WebAssembly.
We have a docker image available on Docker Hub (jacoblincool/compilet), the latest tag supports to compile Rust, C, and C++ out of the box.
You can also use the
rstag (~500MB compressed) to compile Rust only, or thectag (~150MB compressed) to compile C and C++ only.
Also, you can build your own image with the following command:
docker build -t compilet .
You can run the image with the following command:
docker run -p 8000:8000 jacoblincool/compilet
Or use the docker compose file to run the image:
docker compose up
You may need a
.envfile to set the environment variables. Check the.env.examplefile for more information.
Both of the commands above will run the server on port 8000, so you can access the server at http://localhost:8000. You can also change the port by setting the PORT environment variable.
You can also install the Compilet through Cargo:
cargo install compilet
It is more convenient to run is as a cli tool:
compilet compile <file>
# compilet compile -h for more information
Compilet uses JWT to validate the request. You can set the APP_SECRET environment variable to set the secret key for the JWT token, default is APP_SECRET.
You should pass the JWT token in the Authorization header with the Bearer scheme.
GET /validate endpoint to validate if the JWT token is valid. Status code 200 means the token is valid, otherwise the token is invalid.Compilet should be able to queue the compile request in the future. But currently, it just compiles the source code directly.
POST /compile endpoint to compile the source code into WebAssemblyPOST body:
{
"lang": "rs",
"code": "fn main() { println!(\"Hello, world!\"); }"
}
Response:
{
"success": true,
"message": "Compiled successfully",
"hash": "bb343b0950832ccd077f1515e842196f2ae4bb9e9261b0935ac57916c3cf305d",
"wasm": "<base64 encoded wasm binary>"
}
POST /submission endpoint to compile the source code into WebAssembly, but return immediately and compile the source code in the background.POST body:
{
"lang": "rs",
"code": "fn main() { println!(\"Hello, world!\"); }"
}
Response:
{
"message": "Submitted",
"hash": "bb343b0950832ccd077f1515e842196f2ae4bb9e9261b0935ac57916c3cf305d"
}
GET /submission/{hash} endpoint to get the status of the submission, and the compiled WebAssembly binary if the compilation is finished.Response:
{
"status": "pending",
"message": "Waiting for compilation",
"wasm": null
}
{
"status": "success",
"message": "Compiled successfully",
"wasm": "<base64 encoded wasm binary>"
}
{
"status": "failed",
"message": "Compilation failed (error message)",
"wasm": null
}
GET /system endpoint to get the system information (currently only the capabilities is implemented)Response:
{
"capabilities": {
"rs": "rust 2021 edition + rand 0.8.5, release build",
"c": "clang 16, level 3 optimizations",
"cpp": "clang++ 16, level 3 optimizations"
},
"status": {
"compiling": 0,
"pending": 0
}
}
After cloning the repository, you need to:
./scripts/stdlib.sh to download the WASI standard library for C, and C++.libclang_rt.builtins-wasm32.a to somewhere that Clang can find it. (e.g. /usr/lib/llvm16/lib/clang/16/lib/wasi) (You can do it later, the error message will tell you where to put it.)You can run the server in development mode with the following command:
cargo run
Build the server with the following command:
cargo build --release