Skip to content

Commit 079cfa4

Browse files
committed
basic idea for C carts
0 parents  commit 079cfa4

9 files changed

Lines changed: 1059 additions & 0 deletions

File tree

.github/workflows/carts.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
on: push
2+
3+
jobs:
4+
build:
5+
name: Build & Publish Cart
6+
runs-on: ubuntu-latest
7+
steps:
8+
- name: Checkout
9+
uses: actions/checkout@v4
10+
- name: Build C colorbars cart
11+
run: docker run -v ./carts/c/colorbars:/src -v .:/out konsumer/null0-cart-c colorbars_c
12+
- name: Upload C colorbars cart artifact
13+
uses: actions/upload-artifact@v4
14+
with:
15+
name: colorbars_c
16+
path: colorbars_c.null0

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.DS_Store
2+
out/

README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
The idea here is a central place for some exmaple-carts for [null0](https://github.com/notnullgames/null0). I also use this as a central place to store docker containers for building them.
2+
3+
- You will need docker installed to use these, which greatly simplifies your setup.
4+
- volume-mount your cart in `/src`
5+
- volume-mount your output-dir in `/out`
6+
- the first param is the name of the cart
7+
- put any filenames you don't want packaged in your cart, in `.cartignore` (.gitignore syntax)
8+
9+
### available containers
10+
11+
- `konsumer/null0-cart-c`
12+
- `konsumer/null0-cart-quickjs`
13+
- `konsumer/null0-cart-nelua`
14+
- `konsumer/null0-cart-assemblyscript`
15+
- `konsumer/null0-cart-nim`
16+
- `konsumer/null0-cart-zig`
17+
- `konsumer/null0-cart-rust`
18+
- `konsumer/null0-cart-py2wasm`
19+
20+
### example usage
21+
22+
```sh
23+
# build a cart from main.c (and assets) in current dir, output to ~/Desktop/tester.null0
24+
docker run -it -v .:/src -v ~/Desktop:/out konsumer/null0-cart-c tester
25+
```
26+
27+
## usage in Github CI
28+
29+
you can easily use it in Github Actions:
30+
31+
```yml
32+
# github/workflows/publish.yml
33+
34+
on: push
35+
36+
jobs:
37+
build:
38+
name: Build & Publish Cart
39+
runs-on: ubuntu-latest
40+
steps:
41+
- name: Checkout
42+
uses: actions/checkout@v4
43+
- name: Build C Cart
44+
run: docker run -v .:/src -v .:/out konsumer/null0-cart-c tester
45+
- name: Upload cart artifact
46+
uses: actions/upload-artifact@v4
47+
with:
48+
name: tester
49+
path: tester.null0
50+
```
51+
52+
## development
53+
54+
This is really just notes for me:
55+
56+
```sh
57+
# build
58+
docker build -t konsumer/null0-cart-c docker -f docker/null0-cart-c.Dockerfile
59+
60+
# test
61+
docker run -it -v ./carts/c/colorbars:/src -v ./out:/out konsumer/null0-cart-c colorbars
62+
63+
# publish
64+
docker push konsumer/null0-cart-c
65+
```

carts/c/colorbars/.cartignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.c
2+
*.h

carts/c/colorbars/main.c

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#include "null0.h"
2+
3+
int main() {
4+
Color colors[26];
5+
6+
colors[0] = LIGHTGRAY;
7+
colors[1] = GRAY;
8+
colors[2] = DARKGRAY;
9+
colors[3] = YELLOW;
10+
colors[4] = GOLD;
11+
colors[5] = ORANGE;
12+
colors[6] = PINK;
13+
colors[7] = RED;
14+
colors[8] = MAROON;
15+
colors[9] = GREEN;
16+
colors[10] = LIME;
17+
colors[11] = DARKGREEN;
18+
colors[12] = BLANK;
19+
colors[13] = SKYBLUE;
20+
colors[14] = DARKBLUE;
21+
colors[15] = PURPLE;
22+
colors[16] = VIOLET;
23+
colors[17] = DARKPURPLE;
24+
colors[18] = BEIGE;
25+
colors[19] = BROWN;
26+
colors[20] = DARKBROWN;
27+
colors[21] = WHITE;
28+
colors[22] = BLACK;
29+
colors[23] = BLUE;
30+
colors[24] = MAGENTA;
31+
colors[25] = RAYWHITE;
32+
33+
int margin = 10;
34+
float bar_width = (SCREEN_WIDTH / (26.0 * 2)) + (margin / 4);
35+
float bar_height = SCREEN_HEIGHT - (margin * 2.0);
36+
37+
// it doesn't change, so just draw it once
38+
39+
int d = SCREEN_HEIGHT / 4;
40+
int i = 0;
41+
while (d) {
42+
draw_circle(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, d -= bar_width, i++ % 2 ? WHITE : RED);
43+
}
44+
45+
int x;
46+
for (x = 0; x < 26; x++) {
47+
draw_rectangle(margin + (x * (bar_width + margin)), margin, bar_width, bar_height, colors[x]);
48+
if (x == 0) {
49+
draw_rectangle_outline(margin + (x * (bar_width + margin)), margin, bar_width, bar_height, 1, WHITE);
50+
} else {
51+
draw_rectangle_outline(margin + (x * (bar_width + margin)), margin, bar_width, bar_height, 1, LIGHTGRAY);
52+
}
53+
}
54+
55+
return 0;
56+
}

docker/build_c.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
3+
# this will compile a C cart for null0
4+
5+
# Check if all required arguments are provided
6+
if [ -z "${1}" ]; then
7+
echo "Usage: $0 CART_NAME"
8+
echo ""
9+
echo "Arguments:"
10+
echo " CART_NAME Name of the output cart (without .null0 extension)"
11+
exit 1
12+
fi
13+
14+
CART_NAME="${1}"
15+
16+
export PATH="${PATH}:/opt/wasi-sdk/bin"
17+
18+
echo "Compiling C cart from /src/ to /out/"
19+
clang --version
20+
21+
mkdir -p "/tmp/${CART_NAME}"
22+
23+
cp -R /src/* /src/.* "/tmp/${CART_NAME}/"
24+
cd "/tmp/${CART_NAME}/"
25+
clang -I /usr/local/include/ -o main.wasm main.c
26+
27+
/usr/local/bin/zipcart.sh "${CART_NAME}" "/tmp/${CART_NAME}/" /out

0 commit comments

Comments
 (0)