Skip to content

Commit 156f80b

Browse files
committed
working on build
0 parents  commit 156f80b

File tree

7 files changed

+829
-0
lines changed

7 files changed

+829
-0
lines changed

.github/workflows/publish.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Publish
2+
3+
on:
4+
push:
5+
branches: [main]
6+
workflow_dispatch:
7+
8+
permissions:
9+
pages: write
10+
id-token: write
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Install WASI SDK
18+
uses: konsumer/install-wasi-sdk@v1
19+
with:
20+
version: "25"
21+
- name: Configure CMake
22+
run: cmake -B build -DCMAKE_TOOLCHAIN_FILE=$WASI_SDK_PATH/share/cmake/wasi-sdk.cmake -DCMAKE_BUILD_TYPE=Release
23+
- name: Build CMake
24+
run: cmake --build build
25+
- name: Copy Cart
26+
run: cp *.null0 webroot/
27+
- name: Upload artifact
28+
uses: actions/upload-pages-artifact@v3
29+
with:
30+
path: ./webroot
31+
32+
deploy:
33+
needs: build
34+
environment:
35+
name: github-pages
36+
url: ${{ steps.deployment.outputs.page_url }}
37+
runs-on: ubuntu-latest
38+
steps:
39+
- name: Deploy to GitHub Pages
40+
id: deployment
41+
uses: actions/deploy-pages@v4

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.DS_Store
2+
.vscode
3+
build
4+
*.null0

CMakeLists.txt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
project(mygame)
3+
4+
# this pulls the current cart-header from remote
5+
file(DOWNLOAD
6+
"https://raw.githubusercontent.com/notnullgames/null0/refs/heads/main/carts/c/null0.h"
7+
"${CMAKE_CURRENT_SOURCE_DIR}/src/null0.h"
8+
)
9+
10+
# this creates a main.wasm and zips it into a cart in project-root
11+
function (BUILD_CART_C name cart_dir)
12+
set(CART_TEMP "${CMAKE_CURRENT_BINARY_DIR}/${name}_c_temp/")
13+
add_executable(${name}_c_wasm "${cart_dir}/main.c")
14+
target_include_directories(${name}_c_wasm PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/c")
15+
add_custom_target(${name} ALL
16+
COMMAND ${CMAKE_COMMAND} -E make_directory "${CART_TEMP}"
17+
COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:${name}_c_wasm>" "${CART_TEMP}/main.wasm"
18+
COMMAND ${CMAKE_COMMAND} -E copy_directory "${cart_dir}" "${CART_TEMP}"
19+
COMMAND ${CMAKE_COMMAND} -E rm -f "${CART_TEMP}/*.c"
20+
COMMAND ${CMAKE_COMMAND} -E rm -f "${CART_TEMP}/*.h"
21+
COMMAND ${CMAKE_COMMAND} -E chdir "${CART_TEMP}" ${CMAKE_COMMAND} -E tar "cf" "${CMAKE_CURRENT_BINARY_DIR}/${name}.null0" --format=zip .
22+
COMMAND ${CMAKE_COMMAND} -E rm -rf "${CART_TEMP}"
23+
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_BINARY_DIR}/${name}.null0" "${CMAKE_CURRENT_SOURCE_DIR}"
24+
DEPENDS ${name}_c_wasm
25+
COMMENT "Creating cart ${name}.null0"
26+
)
27+
endfunction()
28+
29+
# build your cart
30+
BUILD_CART_C("${PROJECT_NAME}" "${CMAKE_CURRENT_SOURCE_DIR}/src")

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
This is a basic example cart in C for the [null0](https://notnull.games/null0) game-engine.
2+
3+
## usage
4+
5+
Carts run natively, and on the web. This repo will auto-publish to github-pages on push, so users can check out your cart.
6+
7+
They can also install [the native runtime](https://github.com/notnullgames/null0/releases) and use it to run your cart.
8+
9+
## developing
10+
11+
Make sure you have [wasi-sdk](https://github.com/WebAssembly/wasi-sdk/releases) installed and `WASI_SDK_PATH` set to it's location (eg `/opt/wasi-sdk`.)
12+
13+
Then you can do this:
14+
15+
```sh
16+
$WASI_SDK_PATH/bin/clang src/main.c -o src/main.wasm
17+
cd src
18+
zip -r ../cart.null0 -x '*.h' '*.c' .
19+
```
20+
21+
You can also use cmake (recommended) to build a complete cart:
22+
23+
```sh
24+
cmake -B build -DCMAKE_TOOLCHAIN_FILE=$WASI_SDK_PATH/share/cmake/wasi-sdk.cmake -DCMAKE_BUILD_TYPE=Release
25+
cmake --build build
26+
```

src/main.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include "null0.h"
2+
3+
int main() {
4+
// no update needed, since this does not change
5+
u32 bg = image_gradient(SCREEN_WIDTH, SCREEN_HEIGHT, BLUE, GREEN, RED, YELLOW);
6+
draw_image(bg, 0, 0);
7+
draw_text(FONT_DEFAULT, "Welcome to null0!!!", 230, 230, BLACK);
8+
draw_text(FONT_DEFAULT, "Welcome to null0!!!", 231, 231, RAYWHITE);
9+
}

0 commit comments

Comments
 (0)