Change project structure for cross build

This commit is contained in:
Synthasmagoria 2026-09-01 14:12:06 +02:00
commit 80b3e83d4d
17 changed files with 44 additions and 43 deletions

View file

@ -8,7 +8,7 @@ if [[ -v 1 ]]; then
if [ "$1" = "DEBUG" ]; then if [ "$1" = "DEBUG" ]; then
ODIN_FLAGS="-debug" ODIN_FLAGS="-debug"
elif [ "$1" = "RELEASE" ]; then elif [ "$1" = "RELEASE" ]; then
ODIN_FLAGS="-o:minimal" ODIN_FLAGS="-o:speed"
else else
echo "Usage: <script> <DEBUG/RELEASE>" echo "Usage: <script> <DEBUG/RELEASE>"
exit 1 exit 1
@ -19,6 +19,6 @@ else
fi fi
mkdir -p $OUT_DIR mkdir -p $OUT_DIR
odin build src/ -out:"$OUT_DIR/$EXE_NAME" $ODIN_FLAGS odin build src/desktop -out:"$OUT_DIR/$EXE_NAME" $ODIN_FLAGS
cp -R $ASSETS_DIR ./$OUT_DIR/ cp -R $ASSETS_DIR ./$OUT_DIR/
echo "Desktop build created in ${OUT_DIR}" echo "Desktop build created in ${OUT_DIR}"

View file

@ -4,13 +4,13 @@ ASSETS_DIR="src/assets"
RAYLIB_PATH="src/libraries/raylib" RAYLIB_PATH="src/libraries/raylib"
EMSCRIPTEN_SDK_DIR="$HOME/programs/emsdk" EMSCRIPTEN_SDK_DIR="$HOME/programs/emsdk"
OUT_DIR="build/web" OUT_DIR="build/web"
INDEX_TEMPLATE_PATH="src/web/index_template.html"
if [[ -v 1 ]]; then if [[ -v 1 ]]; then
if [ "$1" = "DEBUG" ]; then if [ "$1" = "DEBUG" ]; then
ODIN_FLAGS="-debug" ODIN_FLAGS="-debug"
elif [ "$1" = "RELEASE" ]; then elif [ "$1" = "RELEASE" ]; then
# unsure if this will work ODIN_FLAGS=""
ODIN_FLAGS="-o:minimal"
else else
echo "Usage: <script> <DEBUG/RELEASE>" echo "Usage: <script> <DEBUG/RELEASE>"
exit 1 exit 1
@ -32,7 +32,7 @@ export EMSDK_QUIET=1
# The emcc call will be fed the actual raylib library file. That stuff will end # The emcc call will be fed the actual raylib library file. That stuff will end
# up in env.o # up in env.o
ODIN_DEFINES="-define:RAYLIB_WASM_LIB=env.o -define:RAYGUI_WASM_LIB=env.o" ODIN_DEFINES="-define:RAYLIB_WASM_LIB=env.o -define:RAYGUI_WASM_LIB=env.o"
odin build src/ -target:js_wasm32 -build-mode:obj $ODIN_DEFINES $ODIN_FLAGS -out:$OUT_DIR/$WASM_OBJ_NAME odin build src/web/ -target:js_wasm32 -build-mode:obj $ODIN_DEFINES $ODIN_FLAGS -out:$OUT_DIR/$WASM_OBJ_NAME
ODIN_PATH=$(odin root) ODIN_PATH=$(odin root)
@ -42,10 +42,10 @@ files="$OUT_DIR/$WASM_OBJ_NAME $RAYLIB_PATH/wasm/libraylib.a $RAYLIB_PATH/wasm/l
# index_template.html contains the javascript code that calls the procedures in # index_template.html contains the javascript code that calls the procedures in
# source/main_web/main_web.odin # source/main_web/main_web.odin
flags="-Oz -sASSERTIONS=0 --closure 0 -sEXPORTED_RUNTIME_METHODS=['HEAPF32'] -sUSE_GLFW=3 -sWASM_BIGINT -sWARN_ON_UNDEFINED_SYMBOLS=0 -sDECLARE_ASM_MODULE_EXPORTS=0 --shell-file index_template.html --preload-file src/assets" flags="-O0 -sEXPORTED_RUNTIME_METHODS=['HEAPF32'] -sUSE_GLFW=3 -sWASM_BIGINT -sWARN_ON_UNDEFINED_SYMBOLS=0 --shell-file $INDEX_TEMPLATE_PATH --preload-file src/assets"
# For debugging: Add `-g` to `emcc` (gives better error callstack in chrome) # For debugging: Add `-g` to `emcc` (gives better error callstack in chrome)
emcc -o $OUT_DIR/index.html $files $flags emcc -g -o $OUT_DIR/index.html $files $flags
rm -f $OUT_DIR/$WASM_OBJ_NAME rm -f $OUT_DIR/$WASM_OBJ_NAME

BIN
default

Binary file not shown.

View file

@ -1,4 +1,4 @@
package main package game
import rl "libraries/raylib" import rl "libraries/raylib"
import "core:math" import "core:math"

19
src/desktop/main.odin Normal file
View file

@ -0,0 +1,19 @@
#+build !wasm32, !wasm64p32
package main
import game ".."
import "core:os"
import "core:path/filepath"
main :: proc() {
exe_path := os.args[0]
exe_dir := filepath.dir(string(exe_path))
os.set_working_directory(exe_dir)
game.init()
for game.should_run() {
game.update()
}
game.shutdown()
}

View file

@ -1,4 +1,4 @@
package main package game
import "core:math/linalg" import "core:math/linalg"
import rl "libraries/raylib" import rl "libraries/raylib"

View file

@ -1,4 +1,4 @@
package main package game
import rl "libraries/raylib" import rl "libraries/raylib"
import "base:runtime" import "base:runtime"

View file

@ -1,18 +0,0 @@
package main
import rl "libraries/raylib"
import "core:log"
main :: proc() {
// exe_path := os.args[0]
// exe_dir := filepath.dir(string(exe_path))
// os.set_working_directory(exe_dir)
rl.ChangeDirectory(rl.GetApplicationDirectory())
context.logger = log.create_console_logger()
init()
for should_run() {
update()
}
shutdown()
}

View file

@ -1,4 +1,4 @@
package main package game
/* /*
Rules of matrices: Rules of matrices:
@ -1260,7 +1260,7 @@ ui_labeled_input_float_element :: proc(label: cstring, margin: f32, value: ^f32,
ui_labeled_input_text_element :: proc(label: cstring, margin: f32, str: []byte, allocator := context.temp_allocator) -> ^ui.Element { ui_labeled_input_text_element :: proc(label: cstring, margin: f32, str: []byte, allocator := context.temp_allocator) -> ^ui.Element {
label := fmt.ctprintf("%s: ", label) label := fmt.ctprintf("%s: ", label)
label_element := ui.element(.Label, {}, {label = label, color = ui.col(rl.WHITE), margin = margin}) label_element := ui.element(.Label, {}, {label = label, color = ui.col(rl.WHITE), margin = margin})
dimensions := ui.Dimensions{ui.Size_Pixels(64.0), ui.dimensions_pixels(ui.rect_get_size(ui.get_element_outer_area(label_element^))).height} dimensions := ui.Dimensions{ui.Size_Pixels(224.0), ui.dimensions_pixels(ui.rect_get_size(ui.get_element_outer_area(label_element^))).height}
ui.same_line() ui.same_line()
input_data := new(UiElementData_TextInput, context.temp_allocator) input_data := new(UiElementData_TextInput, context.temp_allocator)
input_data^ = {str = cstring(&str[0])} input_data^ = {str = cstring(&str[0])}

View file

@ -1,4 +1,4 @@
package main package game
PROJECT_DATA_HEADER :: "WOWOWOW THIS IS HEADER WOWOWOW" PROJECT_DATA_HEADER :: "WOWOWOW THIS IS HEADER WOWOWOW"
PROJECT_DATA_VERSION :: 1 PROJECT_DATA_VERSION :: 1

View file

@ -1,7 +1,7 @@
#+build !wasm32 #+build !wasm32
#+build !wasm64p32 #+build !wasm64p32
package main package game
import "core:os" import "core:os"
import "core:io" import "core:io"

View file

@ -1,5 +1,5 @@
#+build wasm32, wasm64p32 #+build wasm32, wasm64p32
package main package game
ProjectReadErrorType :: enum { ProjectReadErrorType :: enum {
LoadingProjectNotSupportedOnWeb, LoadingProjectNotSupportedOnWeb,

View file

@ -1,4 +1,4 @@
package main package game
import rl "libraries/raylib" import rl "libraries/raylib"
import "base:intrinsics" import "base:intrinsics"

View file

@ -1,7 +1,7 @@
#+build !wasm32 #+build !wasm32
#+build !wasm64p32 #+build !wasm64p32
package main package game
import "core:os" import "core:os"

View file

@ -4,7 +4,7 @@
#+build wasm32, wasm64p32 #+build wasm32, wasm64p32
package main package game
import "base:runtime" import "base:runtime"
import "core:log" import "core:log"

View file

@ -45,6 +45,7 @@
return WebAssembly.instantiateStreaming(fetch("index.wasm"), newImports).then(function(output) { return WebAssembly.instantiateStreaming(fetch("index.wasm"), newImports).then(function(output) {
var e = output.instance.exports; var e = output.instance.exports;
console.log(e);
odinMemoryInterface.setExports(e); odinMemoryInterface.setExports(e);
odinMemoryInterface.setMemory(e.memory); odinMemoryInterface.setMemory(e.memory);
return successCallback(output.instance); return successCallback(output.instance);

View file

@ -1,7 +1,6 @@
#+build wasm32, wasm64p32
package main package main
import game ".."
import "core:log" import "core:log"
import "core:mem" import "core:mem"
import "core:c" import "core:c"
@ -28,23 +27,23 @@ import "core:fmt"
web_context = context web_context = context
init() game.init()
} }
@export main_update :: proc "c" () -> bool { @export main_update :: proc "c" () -> bool {
context = web_context context = web_context
update() game.update()
return should_run() return game.should_run()
} }
@export main_end :: proc "c" () { @export main_end :: proc "c" () {
context = web_context context = web_context
shutdown() game.shutdown()
} }
@export web_window_size_changed :: proc "c" (w: c.int, h: c.int) { @export web_window_size_changed :: proc "c" (w: c.int, h: c.int) {
context = web_context context = web_context
parent_window_size_changed(int(w), int(h)) game.parent_window_size_changed(int(w), int(h))
} }
/////////////////////////////////////////////////////// ///////////////////////////////////////////////////////