Fix hot reload build
This commit is contained in:
parent
1e91121244
commit
04133ef95a
2
build.sh
2
build.sh
@ -1,3 +1,3 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
odin run ./builder -sanitize:address -- $@
|
||||
odin run ./builder -- $@
|
||||
|
@ -3,10 +3,12 @@ package builder
|
||||
import "core:flags"
|
||||
import "core:fmt"
|
||||
import "core:log"
|
||||
import "core:io"
|
||||
import os "core:os/os2"
|
||||
import "core:path/filepath"
|
||||
import "core:slice"
|
||||
import "core:strings"
|
||||
import "core:thread"
|
||||
|
||||
Build_Variant :: enum {
|
||||
Hot_Reload,
|
||||
@ -18,18 +20,19 @@ Options :: struct {
|
||||
variant: Build_Variant `usage:"Variant of the build"`,
|
||||
optimize: bool `args:"name=opt",usage:"Enable compiler optimizations"`,
|
||||
debug: bool `usage:"Enable debug symbols"`,
|
||||
rebuild_deps: bool `usage:"When enabled dependencies will be cleaned and rebuilt"`,
|
||||
force: bool `usage:"When enabled dependencies will be cleaned and rebuilt"`,
|
||||
tracy: bool `usage:"Enable tracy profiler"`,
|
||||
run: bool,
|
||||
}
|
||||
|
||||
temp_concat :: proc(left, right: []string) -> []string {
|
||||
result := slice.concatenate([][]string{left, right}, context.temp_allocator)
|
||||
temp_concat :: proc(strs: ..[]string) -> []string {
|
||||
result := slice.concatenate(strs, context.temp_allocator)
|
||||
return result
|
||||
}
|
||||
|
||||
build_deps :: proc(opts: Options) {
|
||||
log.infof("build_deps")
|
||||
force := opts.rebuild_deps
|
||||
force := opts.force
|
||||
shared := opts.variant == .Hot_Reload
|
||||
// Raylib
|
||||
{
|
||||
@ -59,7 +62,7 @@ build_deps :: proc(opts: Options) {
|
||||
{
|
||||
cwd := "./libs/physfs"
|
||||
file_name := shared ? "libphysfs.so" : "libphysfs.a"
|
||||
is_built := os.is_file(fmt.tprintf("./libs/physfs/%s", file_name))
|
||||
is_built := os.is_dir("./libs/physfs/build")
|
||||
if force {
|
||||
remove_all("./libs/physfs/build")
|
||||
}
|
||||
@ -72,6 +75,7 @@ build_deps :: proc(opts: Options) {
|
||||
"./physfs",
|
||||
}
|
||||
build_cmd := []string{"cmake", "--build", "build", "--config", "MinSizeRel"}
|
||||
if !is_built || force {
|
||||
if opts.variant == .Web {
|
||||
run_cmd(temp_concat({"emcmake.bat"}, prepare_cmd), cwd)
|
||||
run_cmd(temp_concat({"emmake.bat"}, build_cmd), cwd)
|
||||
@ -80,6 +84,7 @@ build_deps :: proc(opts: Options) {
|
||||
run_cmd(build_cmd, cwd)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Tracy
|
||||
if opts.tracy {
|
||||
@ -117,7 +122,7 @@ build_deps :: proc(opts: Options) {
|
||||
"-O2",
|
||||
"vendor/tracy/public/TracyClient.cpp",
|
||||
"-lws2_32",
|
||||
"-ldbghelp"
|
||||
"-ldbghelp",
|
||||
},
|
||||
shared ? {"-shared", "-o", TRACY_NAME_SHARED} : {"-c", "-o", "tracy.o"},
|
||||
},
|
||||
@ -148,7 +153,11 @@ setup_emsdk_env :: proc() {
|
||||
PATH_ENV_DELIMITER :: ":"
|
||||
}
|
||||
|
||||
PATHS :: [3]string{"./libs/emsdk/upstream/bin", "./libs/emsdk/upstream/emscripten", "./libs/emsdk/ninja/git-release_64bit/bin"}
|
||||
PATHS :: [3]string {
|
||||
"./libs/emsdk/upstream/bin",
|
||||
"./libs/emsdk/upstream/emscripten",
|
||||
"./libs/emsdk/ninja/git-release_64bit/bin",
|
||||
}
|
||||
|
||||
paths: [len(PATHS)]string
|
||||
for path, i in PATHS {
|
||||
@ -167,14 +176,12 @@ setup_emsdk_env :: proc() {
|
||||
set_env("EMSDK", absolute_path("./libs/emsdk"))
|
||||
}
|
||||
|
||||
archive_assets :: proc() {
|
||||
}
|
||||
|
||||
main :: proc() {
|
||||
context.logger = log.create_console_logger()
|
||||
opts := Options {
|
||||
tracy = true,
|
||||
debug = true,
|
||||
run = true,
|
||||
}
|
||||
flags.parse_or_exit(&opts, os.args, .Unix, context.temp_allocator)
|
||||
if opts.variant == .Web {
|
||||
@ -194,8 +201,26 @@ main :: proc() {
|
||||
case .Hot_Reload:
|
||||
remove_all("./build/hotreload")
|
||||
mkdir_all("./build/hotreload")
|
||||
cmd := slice.concatenate(
|
||||
[][]string {
|
||||
|
||||
is_main_built := os.is_file("./build/hotreload/game.bin")
|
||||
if !is_main_built || opts.force {
|
||||
run_cmd(
|
||||
temp_concat(
|
||||
[]string {
|
||||
"odin",
|
||||
"build",
|
||||
"main_hot_reload",
|
||||
"-out:./build/hotreload/game.bin",
|
||||
},
|
||||
debug_flag,
|
||||
tracy_flag,
|
||||
optimize_flag,
|
||||
COMMON_FLAGS,
|
||||
),
|
||||
"",
|
||||
)
|
||||
}
|
||||
build_game_cmd := temp_concat(
|
||||
[]string {
|
||||
"odin",
|
||||
"build",
|
||||
@ -209,11 +234,46 @@ main :: proc() {
|
||||
debug_flag,
|
||||
optimize_flag,
|
||||
COMMON_FLAGS,
|
||||
},
|
||||
context.temp_allocator,
|
||||
)
|
||||
run_cmd(cmd, "")
|
||||
build_game_lib :: proc(build_cmd: []string) {
|
||||
run_cmd(
|
||||
build_cmd,
|
||||
"",
|
||||
)
|
||||
rename("./build/hotreload/game_tmp.so", "./build/hotreload/game.so")
|
||||
}
|
||||
build_game_lib(build_game_cmd)
|
||||
|
||||
if opts.run {
|
||||
thread_ctx := context
|
||||
thread_ctx.user_ptr = &build_game_cmd
|
||||
thrd := thread.create_and_start(proc() {
|
||||
build_game_cmd := (cast(^[]string)context.user_ptr)^
|
||||
input := os.to_reader(os.stdin)
|
||||
|
||||
buf: [1024]u8
|
||||
for {
|
||||
n, err := io.read(input, buf[:])
|
||||
|
||||
for cmd in buf[0:n] {
|
||||
switch cmd {
|
||||
case 'r', 'R':
|
||||
build_game_lib(build_game_cmd)
|
||||
case:
|
||||
}
|
||||
}
|
||||
|
||||
if err == .EOF {
|
||||
break
|
||||
}
|
||||
|
||||
handle_error(err)
|
||||
}
|
||||
}, thread_ctx)
|
||||
|
||||
run_cmd({"./build/hotreload/game.bin"}, "")
|
||||
thread.join(thrd)
|
||||
}
|
||||
case .Desktop:
|
||||
remove_all("./build/desktop")
|
||||
mkdir_all("./build/desktop")
|
||||
@ -283,3 +343,4 @@ main :: proc() {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,9 +12,9 @@ when ODIN_OS == .Windows {
|
||||
}
|
||||
} else when ODIN_OS == .Linux || ODIN_OS == .Darwin {
|
||||
when PHYSFS_SHARED {
|
||||
foreign import lib "libphysfs.so"
|
||||
foreign import lib "build/libphysfs.so"
|
||||
} else {
|
||||
foreign import lib "libphysfs.a"
|
||||
foreign import lib "build/libphysfs.a"
|
||||
}
|
||||
} else when ODIN_ARCH == .wasm32 || ODIN_ARCH == .wasm64p32 {
|
||||
foreign import lib "env.o"
|
||||
|
Loading…
x
Reference in New Issue
Block a user