All builds working on linux, find base dir relative to bin dir
This commit is contained in:
parent
e4ddd9d8ca
commit
729fc277cb
1
.gitignore
vendored
1
.gitignore
vendored
@ -18,3 +18,4 @@ pdbs/
|
|||||||
game_web/
|
game_web/
|
||||||
.venv
|
.venv
|
||||||
build/
|
build/
|
||||||
|
bin/
|
||||||
|
@ -39,18 +39,22 @@ when ODIN_OS == .Windows {
|
|||||||
EXE_EXT :: ".exe"
|
EXE_EXT :: ".exe"
|
||||||
DLL_EXT :: ".dll"
|
DLL_EXT :: ".dll"
|
||||||
LIB_PREFIX :: ""
|
LIB_PREFIX :: ""
|
||||||
|
EMSCRIPTEN_SHELL_EXT :: ".bat"
|
||||||
} else when ODIN_OS == .Linux {
|
} else when ODIN_OS == .Linux {
|
||||||
EXE_EXT :: ".bin"
|
EXE_EXT :: ".bin"
|
||||||
DLL_EXT :: ".so"
|
DLL_EXT :: ".so"
|
||||||
LIB_PREFIX :: "lib"
|
LIB_PREFIX :: "lib"
|
||||||
|
EMSCRIPTEN_SHELL_EXT :: ""
|
||||||
} else when ODIN_OS == .Darwin {
|
} else when ODIN_OS == .Darwin {
|
||||||
EXE_EXT :: ".bin"
|
EXE_EXT :: ".bin"
|
||||||
DLL_EXT :: ".dylib"
|
DLL_EXT :: ".dylib"
|
||||||
LIB_PREFIX :: "lib"
|
LIB_PREFIX :: "lib"
|
||||||
|
EMSCRIPTEN_SHELL_EXT :: ""
|
||||||
} else {
|
} else {
|
||||||
EXE_EXT :: ""
|
EXE_EXT :: ""
|
||||||
DLL_EXT :: ""
|
DLL_EXT :: ""
|
||||||
LIB_PREFIX :: ""
|
LIB_PREFIX :: ""
|
||||||
|
EMSCRIPTEN_SHELL_EXT :: ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns a list of shared dependencies that have to be copied to out dir
|
// Returns a list of shared dependencies that have to be copied to out dir
|
||||||
@ -113,8 +117,8 @@ build_deps :: proc(opts: Options) -> []string {
|
|||||||
build_cmd := []string{"cmake", "--build", "build", "--config", "MinSizeRel"}
|
build_cmd := []string{"cmake", "--build", "build", "--config", "MinSizeRel"}
|
||||||
if !is_built || force {
|
if !is_built || force {
|
||||||
if opts.variant == .Web {
|
if opts.variant == .Web {
|
||||||
run_cmd(temp_concat({"emcmake.bat"}, prepare_cmd), cwd)
|
run_cmd(temp_concat({"emcmake" + EMSCRIPTEN_SHELL_EXT}, prepare_cmd), cwd)
|
||||||
run_cmd(temp_concat({"emmake.bat"}, build_cmd), cwd)
|
run_cmd(temp_concat({"emmake" + EMSCRIPTEN_SHELL_EXT}, build_cmd), cwd)
|
||||||
} else {
|
} else {
|
||||||
run_cmd(prepare_cmd, cwd)
|
run_cmd(prepare_cmd, cwd)
|
||||||
run_cmd(build_cmd, cwd)
|
run_cmd(build_cmd, cwd)
|
||||||
@ -199,11 +203,7 @@ setup_emsdk_env :: proc() {
|
|||||||
PATH_ENV_DELIMITER :: ":"
|
PATH_ENV_DELIMITER :: ":"
|
||||||
}
|
}
|
||||||
|
|
||||||
PATHS :: [3]string {
|
PATHS :: [2]string{"./libs/emsdk/upstream/bin", "./libs/emsdk/upstream/emscripten"}
|
||||||
"./libs/emsdk/upstream/bin",
|
|
||||||
"./libs/emsdk/upstream/emscripten",
|
|
||||||
"./libs/emsdk/ninja/git-release_64bit/bin",
|
|
||||||
}
|
|
||||||
|
|
||||||
paths: [len(PATHS)]string
|
paths: [len(PATHS)]string
|
||||||
for path, i in PATHS {
|
for path, i in PATHS {
|
||||||
@ -213,7 +213,7 @@ setup_emsdk_env :: proc() {
|
|||||||
set_env(
|
set_env(
|
||||||
"PATH",
|
"PATH",
|
||||||
strings.join(
|
strings.join(
|
||||||
{paths[0], paths[1], paths[2], os.get_env("PATH", context.temp_allocator)},
|
{paths[0], paths[1], os.get_env("PATH", context.temp_allocator)},
|
||||||
PATH_ENV_DELIMITER,
|
PATH_ENV_DELIMITER,
|
||||||
context.temp_allocator,
|
context.temp_allocator,
|
||||||
),
|
),
|
||||||
@ -258,7 +258,7 @@ main :: proc() {
|
|||||||
|
|
||||||
switch opts.variant {
|
switch opts.variant {
|
||||||
case .Hot_Reload:
|
case .Hot_Reload:
|
||||||
setup_bin_dir(opts, "./build/hotreload", shared_dep_paths)
|
setup_bin_dir(opts, "./bin/hotreload", shared_dep_paths)
|
||||||
|
|
||||||
is_running := process_exists("game" + EXE_EXT)
|
is_running := process_exists("game" + EXE_EXT)
|
||||||
if !is_running {
|
if !is_running {
|
||||||
@ -268,7 +268,7 @@ main :: proc() {
|
|||||||
"odin",
|
"odin",
|
||||||
"build",
|
"build",
|
||||||
"main_hot_reload",
|
"main_hot_reload",
|
||||||
"-out:./build/hotreload/game" + EXE_EXT,
|
"-out:./bin/hotreload/game" + EXE_EXT,
|
||||||
},
|
},
|
||||||
debug_flag,
|
debug_flag,
|
||||||
tracy_flag,
|
tracy_flag,
|
||||||
@ -286,7 +286,7 @@ main :: proc() {
|
|||||||
"-define:RAYLIB_SHARED=true",
|
"-define:RAYLIB_SHARED=true",
|
||||||
"-define:PHYSFS_SHARED=true",
|
"-define:PHYSFS_SHARED=true",
|
||||||
"-build-mode:dll",
|
"-build-mode:dll",
|
||||||
"-out:./build/hotreload/game_tmp" + DLL_EXT,
|
"-out:./bin/hotreload/game_tmp" + DLL_EXT,
|
||||||
},
|
},
|
||||||
tracy_flag,
|
tracy_flag,
|
||||||
debug_flag,
|
debug_flag,
|
||||||
@ -295,17 +295,17 @@ main :: proc() {
|
|||||||
),
|
),
|
||||||
"",
|
"",
|
||||||
)
|
)
|
||||||
rename("./build/hotreload/game_tmp" + DLL_EXT, "./build/hotreload/game" + DLL_EXT)
|
rename("./bin/hotreload/game_tmp" + DLL_EXT, "./bin/hotreload/game" + DLL_EXT)
|
||||||
|
|
||||||
if !is_running && opts.run {
|
if !is_running && opts.run {
|
||||||
run_cmd({"./build/hotreload/game" + EXE_EXT}, "")
|
run_cmd({"./bin/hotreload/game" + EXE_EXT}, "")
|
||||||
}
|
}
|
||||||
case .Desktop:
|
case .Desktop:
|
||||||
setup_bin_dir(opts, "./build/desktop", shared_dep_paths)
|
setup_bin_dir(opts, "./bin/desktop", shared_dep_paths)
|
||||||
|
|
||||||
cmd := slice.concatenate(
|
cmd := slice.concatenate(
|
||||||
[][]string {
|
[][]string {
|
||||||
[]string{"odin", "build", "main_release", "-out:./build/desktop/game" + EXE_EXT},
|
[]string{"odin", "build", "main_release", "-out:./bin/desktop/game" + EXE_EXT},
|
||||||
tracy_flag,
|
tracy_flag,
|
||||||
debug_flag,
|
debug_flag,
|
||||||
optimize_flag,
|
optimize_flag,
|
||||||
@ -315,8 +315,8 @@ main :: proc() {
|
|||||||
)
|
)
|
||||||
run_cmd(cmd, "")
|
run_cmd(cmd, "")
|
||||||
case .Web:
|
case .Web:
|
||||||
remove_all("./build/web")
|
remove_all("./bin/web")
|
||||||
mkdir_all("./build/web")
|
mkdir_all("./bin/web")
|
||||||
|
|
||||||
odin_root := run_cmd({"odin", "root"}, "")
|
odin_root := run_cmd({"odin", "root"}, "")
|
||||||
|
|
||||||
@ -328,7 +328,7 @@ main :: proc() {
|
|||||||
"main_web",
|
"main_web",
|
||||||
"-target:js_wasm32",
|
"-target:js_wasm32",
|
||||||
"-build-mode:obj",
|
"-build-mode:obj",
|
||||||
"-out:build/web/game",
|
"-out:bin/web/game",
|
||||||
},
|
},
|
||||||
COMMON_FLAGS,
|
COMMON_FLAGS,
|
||||||
debug_flag,
|
debug_flag,
|
||||||
@ -339,11 +339,11 @@ main :: proc() {
|
|||||||
|
|
||||||
run_cmd(
|
run_cmd(
|
||||||
{
|
{
|
||||||
"emcc.bat",
|
"emcc" + EMSCRIPTEN_SHELL_EXT,
|
||||||
"-g",
|
"-g",
|
||||||
"-o",
|
"-o",
|
||||||
"build/web/index.html",
|
"bin/web/index.html",
|
||||||
"build/web/game.wasm.o",
|
"bin/web/game.wasm.o",
|
||||||
"libs/raylib/zig-out-static/lib/libraylib.a",
|
"libs/raylib/zig-out-static/lib/libraylib.a",
|
||||||
"libs/physfs/build/libphysfs.a",
|
"libs/physfs/build/libphysfs.a",
|
||||||
"-sUSE_GLFW=3",
|
"-sUSE_GLFW=3",
|
||||||
@ -358,14 +358,14 @@ main :: proc() {
|
|||||||
},
|
},
|
||||||
"",
|
"",
|
||||||
)
|
)
|
||||||
remove_file("./build/web/game.wasm.o")
|
remove_file("./bin/web/game.wasm.o")
|
||||||
|
|
||||||
copy_file(
|
copy_file(
|
||||||
filepath.join(
|
filepath.join(
|
||||||
{odin_root, "core", "sys", "wasm", "js", "odin.js"},
|
{odin_root, "core", "sys", "wasm", "js", "odin.js"},
|
||||||
context.temp_allocator,
|
context.temp_allocator,
|
||||||
),
|
),
|
||||||
"./build/web/odin.js",
|
"./bin/web/odin.js",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
34
game/fs.odin
34
game/fs.odin
@ -3,7 +3,6 @@ package game
|
|||||||
import "base:runtime"
|
import "base:runtime"
|
||||||
import "core:c"
|
import "core:c"
|
||||||
import "core:log"
|
import "core:log"
|
||||||
import "core:path/filepath"
|
|
||||||
import "core:strings"
|
import "core:strings"
|
||||||
import "libs:physfs"
|
import "libs:physfs"
|
||||||
import rl "libs:raylib"
|
import rl "libs:raylib"
|
||||||
@ -11,6 +10,26 @@ import rl "libs:raylib"
|
|||||||
@(private = "file")
|
@(private = "file")
|
||||||
_ctx: runtime.Context
|
_ctx: runtime.Context
|
||||||
|
|
||||||
|
path_dir :: proc(path: string, num_dirs: int = 1) -> string {
|
||||||
|
when ODIN_OS == .Windows {
|
||||||
|
SEPARATOR :: rune('\\')
|
||||||
|
} else {
|
||||||
|
SEPARATOR :: rune('/')
|
||||||
|
}
|
||||||
|
count := 0
|
||||||
|
#reverse for rune, i in path {
|
||||||
|
if rune == SEPARATOR {
|
||||||
|
count += 1
|
||||||
|
|
||||||
|
if count == num_dirs {
|
||||||
|
return path[0:i]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return path
|
||||||
|
}
|
||||||
|
|
||||||
init_physfs :: proc(args: []string) {
|
init_physfs :: proc(args: []string) {
|
||||||
_ctx = context
|
_ctx = context
|
||||||
|
|
||||||
@ -18,20 +37,17 @@ init_physfs :: proc(args: []string) {
|
|||||||
physfs.setSaneConfig("serega", "gutter-runner", "zip", 0, 1)
|
physfs.setSaneConfig("serega", "gutter-runner", "zip", 0, 1)
|
||||||
|
|
||||||
// For non web builds, binary will live 2 subdirs below main content dir, so add it to search path
|
// For non web builds, binary will live 2 subdirs below main content dir, so add it to search path
|
||||||
if args[0] != "." {
|
when ODIN_OS != .JS {
|
||||||
base_dir := filepath.dir(
|
abs_path, ok := path_abs(args[0], context.temp_allocator)
|
||||||
filepath.dir(filepath.dir(args[0], context.temp_allocator), context.temp_allocator),
|
|
||||||
context.temp_allocator,
|
|
||||||
)
|
|
||||||
abs_base_dir, ok := filepath.abs(base_dir, context.temp_allocator)
|
|
||||||
assert(ok)
|
assert(ok)
|
||||||
err := physfs.mount(strings.clone_to_cstring(abs_base_dir, context.temp_allocator), "/", 1)
|
base_dir := path_dir(abs_path, 3)
|
||||||
|
err := physfs.mount(strings.clone_to_cstring(base_dir, context.temp_allocator), "/", 1)
|
||||||
|
|
||||||
if err == 0 {
|
if err == 0 {
|
||||||
log.panicf("physfs: failed to set base dir {0}", physfs.getLastError())
|
log.panicf("physfs: failed to set base dir {0}", physfs.getLastError())
|
||||||
}
|
}
|
||||||
|
|
||||||
log.infof("physfs: added {0} to search path", abs_base_dir)
|
log.infof("physfs: added {0} to search path", base_dir)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
8
game/fs_desktop.odin
Normal file
8
game/fs_desktop.odin
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#+build !js
|
||||||
|
package game
|
||||||
|
|
||||||
|
import "core:path/filepath"
|
||||||
|
|
||||||
|
path_abs :: proc(path: string, allocator := context.allocator) -> (string, bool) {
|
||||||
|
return filepath.abs(path, allocator)
|
||||||
|
}
|
6
game/fs_web.odin
Normal file
6
game/fs_web.odin
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#+build js
|
||||||
|
package game
|
||||||
|
|
||||||
|
path_abs :: proc(path: string, allocator := context.allocator) -> (string, bool) {
|
||||||
|
return path, true
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user