diff --git a/scripts/build_sokol_demo.sh b/scripts/build_sokol_demo.sh new file mode 100644 index 0000000..571d7c6 --- /dev/null +++ b/scripts/build_sokol_demo.sh @@ -0,0 +1,109 @@ +#!/bin/bash + +# Source the misc.sh script +source "$(dirname "$0")/helpers/misc.sh" + +# Get the root directory of the git repository +path_root=$(git rev-parse --show-toplevel) +path_backend="$path_root/backend" +path_build="$path_root/build" +path_examples="$path_root/examples" +path_scripts="$path_root/scripts" +path_thirdparty="$path_root/thirdparty" + +verify_path "$path_build" +verify_path "$path_thirdparty" + +# CPU Info +path_system_details="$path_build/system_details.ini" +if [ -f "$path_system_details" ]; then + source "$path_system_details" + CoreCount_Physical=$PhysicalCores + CoreCount_Logical=$LogicalCores +else + CoreCount_Physical=$(nproc --all) + CoreCount_Logical=$(nproc) + + echo "[CPU]" > "$path_system_details" + echo "PhysicalCores=$CoreCount_Physical" >> "$path_system_details" + echo "LogicalCores=$CoreCount_Logical" >> "$path_system_details" +fi +echo "Core Count - Physical: $CoreCount_Physical Logical: $CoreCount_Logical" + +url_freetype='https://github.com/Ed94/odin-freetype.git' +url_harfbuzz='https://github.com/Ed94/harfbuzz-odin.git' +url_sokol='https://github.com/floooh/sokol-odin.git' +url_sokol_tools='https://github.com/floooh/sokol-tools-bin.git' + +path_freetype="$path_thirdparty/freetype" +path_harfbuzz="$path_thirdparty/harfbuzz" +path_sokol="$path_thirdparty/sokol" +path_sokol_tools="$path_thirdparty/sokol-tools" + +sokol_build_clibs_command="$path_scripts/build_sokol_library.sh" + +clone_gitrepo "$path_freetype" "$url_freetype" +clone_gitrepo "$path_sokol_tools" "$url_sokol_tools" + +update_git_repo "$path_sokol" "$url_sokol" "$sokol_build_clibs_command" +update_git_repo "$path_harfbuzz" "$url_harfbuzz" "./scripts/build.sh" + +pushd "$path_thirdparty" > /dev/null + path_sokol_dlls="$path_sokol" + path_harfbuzz_dlls="$path_harfbuzz/lib/linux" + + for dll in "$path_sokol_dlls"/*.so; do + cp "$dll" "$path_build/" + done + + for dll in "$path_harfbuzz_dlls"/*.so; do + cp "$dll" "$path_build/" + done +popd > /dev/null + +# Source the odin compiler definitions +source "$(dirname "$0")/helpers/odin_compiler_defs.sh" + +pkg_collection_backend="backend=$path_backend" +pkg_collection_thirdparty="thirdparty=$path_thirdparty" + +pushd "$path_examples" > /dev/null + +function build_SokolBackendDemo { + echo 'Building VEFontCache: Sokol Backend Demo' + + # $compile_shaders="$path_scripts/compile_sokol_shaders.sh" + # bash "$compile_shaders" + + executable="$path_build/sokol_demo" + + build_args=( + "$command_build" + "./sokol_demo" + "$flag_output_path$executable" + "${flag_collection}${pkg_collection_backend}" + "${flag_collection}${pkg_collection_thirdparty}" + # "$flag_micro_architecture_native" + "$flag_use_separate_modules" + "${flag_thread_count}${CoreCount_Physical}" + # "$flag_optimize_none" + # "$flag_optimize_minimal" + # "$flag_optimize_speed" + "$flag_optimize_aggressive" + # "$flag_debug" + "$flag_show_timings" + # "$flag_show_system_call" + # "$flag_no_bounds_check" + # "$flag_no_thread_checker" + # "$flag_default_allocator_nil" + "${flag_max_error_count}10" + # "$flag_sanitize_address" + # "$flag_sanitize_memory" + ) + + invoke_with_color_coded_output "$odin_compiler ${build_args[*]}" +} + +build_SokolBackendDemo + +popd > /dev/null \ No newline at end of file diff --git a/scripts/build_sokol_library.sh b/scripts/build_sokol_library.sh new file mode 100644 index 0000000..ba77dea --- /dev/null +++ b/scripts/build_sokol_library.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +path_root="$(git rev-parse --show-toplevel)" +path_backend="$path_root/backend" +path_build="$path_root/build" +path_scripts="$path_root/scripts" +path_thirdparty="$path_root/thirdparty" + +path_sokol="$path_thirdparty/sokol" +path_sokol_examples="$path_sokol/examples" + +if [ -d "$path_sokol" ] && [ -d "$path_sokol/sokol" ]; then + mv "$path_sokol/sokol/"* "$path_sokol/" + rmdir "$path_sokol/sokol" + rm -rf "$path_sokol_examples" +fi + +pushd "$path_sokol" > /dev/null + +# Convert build_clibs_linux.sh to Unix line endings +if command -v dos2unix &> /dev/null; then + dos2unix "./build_clibs_linux.sh" +else + sed -i 's/\r$//' "./build_clibs_linux.sh" +fi + +# Make sure the script is executable +chmod +x "./build_clibs_linux.sh" + +check_and_install() { + if ! dpkg -s $1 &> /dev/null; then + echo "$1 not found. Attempting to install..." + sudo apt update && sudo apt install -y $1 + if [ $? -ne 0 ]; then + echo "Failed to install $1. Please install manually and try again." + exit 1 + fi + fi +} + +# Check for OpenGL and X11 development libraries +# check_and_install libgl1-mesa-dev +# check_and_install libx11-dev +# check_and_install libxcursor-dev +# check_and_install libxrandr-dev +# check_and_install libxinerama-dev +# check_and_install libxi-dev +# check_and_install libasound2-dev # ALSA development library + +# Run the build script +./build_clibs_linux.sh + +popd > /dev/null diff --git a/scripts/clean.sh b/scripts/clean.sh new file mode 100644 index 0000000..31613f8 --- /dev/null +++ b/scripts/clean.sh @@ -0,0 +1,9 @@ +path_root="$(git rev-parse --show-toplevel)" +path_backend="$path_root/backend" +path_build="$path_root/build" +path_examples="$path_root/examples" +path_scripts="$path_root/scripts" +path_thirdparty="$path_root/thirdparty" + +if [ -d "$path_build" ]; then rm -rf "$path_build"; fi +# if [ -d "$path_thirdparty" ]; then rm -rf "$path_thirdparty"; fi \ No newline at end of file diff --git a/scripts/compile_sokol_shaders.sh b/scripts/compile_sokol_shaders.sh new file mode 100644 index 0000000..695e215 --- /dev/null +++ b/scripts/compile_sokol_shaders.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +path_root="$(git rev-parse --show-toplevel)" +path_backend="$path_root/backend" +path_scripts="$path_root/scripts" +path_thirdparty="$path_root/thirdparty" + +path_sokol_tools="$path_thirdparty/sokol-tools" +sokol_shdc="$path_sokol_tools/bin/linux/sokol-shdc" + +path_backend_sokol="$path_backend/sokol" + +shadersrc_blit_atlas="$path_backend_sokol/blit_atlas.shdc.glsl" +shaderout_blit_atlas="$path_backend_sokol/blit_atlas.odin" + +shadersrc_draw_text="$path_backend_sokol/draw_text.shdc.glsl" +shaderout_draw_text="$path_backend_sokol/draw_text.odin" + +shadersrc_render_glyph="$path_backend_sokol/render_glyph.shdc.glsl" +shaderout_render_glyph="$path_backend_sokol/render_glyph.odin" + +flag_input="--input" +flag_output="--output" +flag_target_lang="--slang" +flag_format_odin="--format=sokol_odin" +flag_module="--module" + +pushd "$path_backend_sokol" > /dev/null + +"$sokol_shdc" "$flag_input" "$shadersrc_blit_atlas" \ + "$flag_output" "$shaderout_blit_atlas" \ + "$flag_target_lang" "glsl410:glsl300es:hlsl4:metal_macos:wgsl" \ + "$flag_format_odin" "$flag_module=blit_atlas" + +"$sokol_shdc" "$flag_input" "$shadersrc_render_glyph" \ + "$flag_output" "$shaderout_render_glyph" \ + "$flag_target_lang" "glsl410:glsl300es:hlsl4:metal_macos:wgsl" \ + "$flag_format_odin" "$flag_module=render_glyph" + +"$sokol_shdc" "$flag_input" "$shadersrc_draw_text" \ + "$flag_output" "$shaderout_draw_text" \ + "$flag_target_lang" "glsl410:glsl300es:hlsl4:metal_macos:wgsl" \ + "$flag_format_odin" "$flag_module=draw_text" + +popd > /dev/null diff --git a/scripts/helpers/misc.ps1 b/scripts/helpers/misc.ps1 index 9d150c3..eeaf1a6 100644 --- a/scripts/helpers/misc.ps1 +++ b/scripts/helpers/misc.ps1 @@ -7,20 +7,19 @@ function clone-gitrepo { param( [string] $path, [string] $url ) git clone $url $path } } - -function Get-IniContent { param([ string]$filePath ) +function Get-IniContent { param( [string] $path_file ) $ini = @{} $currentSection = $null - switch -regex -file $filePath + switch -regex -file $path_file { "^\[(.+)\]$" { $currentSection = $matches[1].Trim() - $ini[$currentSection] = @{} + $ini[ $currentSection ] = @{} } "^(.+?)\s*=\s*(.*)" { $key, $value = $matches[1].Trim(), $matches[2].Trim() if ($null -ne $currentSection) { - $ini[$currentSection][$key] = $value + $ini[ $currentSection ][ $key ] = $value } } } @@ -39,7 +38,6 @@ function Invoke-WithColorCodedOutput { param( [scriptblock] $command ) Write-Host "`t$_" -ForegroundColor $color } } - function Update-GitRepo { param( [string] $path, [string] $url, [string] $build_command ) diff --git a/scripts/helpers/misc.sh b/scripts/helpers/misc.sh new file mode 100644 index 0000000..9be2127 --- /dev/null +++ b/scripts/helpers/misc.sh @@ -0,0 +1,111 @@ +#!/bin/bash + +clone_gitrepo() { + local path="$1" + local url="$2" + + if [ -d "$path" ]; then + # git -C "$path" pull + : + else + echo "Cloning $url ..." + git clone "$url" "$path" + fi +} + +get_ini_content() { + local path_file="$1" + declare -A ini + + local current_section="" + while IFS= read -r line; do + if [[ $line =~ ^\[(.+)\]$ ]]; then + current_section="${BASH_REMATCH[1]}" + ini["$current_section"]="" + elif [[ $line =~ ^([^=]+)=(.*)$ ]]; then + local key="${BASH_REMATCH[1]}" + local value="${BASH_REMATCH[2]}" + if [ -n "$current_section" ]; then + ini["$current_section,$key"]="$value" + fi + fi + done < "$path_file" + + # To use this function, you would need to pass the result by reference + # and then access it in the calling function +} + +invoke_with_color_coded_output() { + local command="$1" + eval "$command" 2>&1 | while IFS= read -r line; do + if [[ "$line" =~ [Ee]rror ]]; then + echo -e "\033[0;31m\t$line\033[0m" # Red for errors + elif [[ "$line" =~ [Ww]arning ]]; then + echo -e "\033[0;33m\t$line\033[0m" # Yellow for warnings + else + echo -e "\033[0;37m\t$line\033[0m" # White for other output + fi + done +} + +update_git_repo() { + local path="$1" + local url="$2" + local build_command="$3" + + if [ -z "$build_command" ]; then + echo "Attempted to call update_git_repo without build_command specified" + return + fi + + local repo_name=$(basename "$url" .git) + + local last_built_commit="$path_build/last_built_commit_$repo_name.txt" + if [ ! -d "$path" ]; then + echo "Cloning repo from $url to $path" + git clone "$url" "$path" + + echo "Building $url" + pushd "$path" > /dev/null + eval "$build_command" + popd > /dev/null + + git -C "$path" rev-parse HEAD > "$last_built_commit" + binaries_dirty=true + echo + return + fi + + git -C "$path" fetch + local latest_commit_hash=$(git -C "$path" rev-parse '@{u}') + local last_built_hash="" + [ -f "$last_built_commit" ] && last_built_hash=$(cat "$last_built_commit") + + if [ "$latest_commit_hash" = "$last_built_hash" ]; then + echo + return + fi + + echo "Build out of date for: $path, updating" + echo 'Pulling...' + git -C "$path" pull + + echo "Building $url" + pushd "$path" > /dev/null + eval "$build_command" + popd > /dev/null + + echo "$latest_commit_hash" > "$last_built_commit" + binaries_dirty=true + echo +} + +verify_path() { + local path="$1" + if [ -d "$path" ]; then + return 0 + fi + + mkdir -p "$path" + return 1 +} \ No newline at end of file diff --git a/scripts/helpers/odin_compiler_defs.sh b/scripts/helpers/odin_compiler_defs.sh new file mode 100644 index 0000000..721aba0 --- /dev/null +++ b/scripts/helpers/odin_compiler_defs.sh @@ -0,0 +1,65 @@ +#!/bin/bash + +# Not meant to be used standalone + +# Odin Compiler Flags + +# For a breakdown of any flag, type -help +command_build='build' +command_check='check' +command_query='query' +command_report='report' +command_run='run' + +flag_build_mode='-build-mode:' +flag_build_mode_dll='-build-mode:dll' +flag_collection='-collection:' +flag_debug='-debug' +flag_define='-define:' +flag_default_allocator_nil='-default-to-nil-allocator' +flag_disable_assert='-disable-assert' +flag_dynamic_map_calls='-dynamic-map-calls' +flag_extra_assembler_flags='-extra_assembler-flags:' +flag_extra_linker_flags='-extra-linker-flags:' +flag_ignore_unknown_attributes='-ignore-unknown-attributes' +flag_keep_temp_files='-keep-temp-files' +flag_max_error_count='-max-error-count:' +flag_micro_architecture_native='-microarch:native' +flag_no_bounds_check='-no-bounds-check' +flag_no_crt='-no-crt' +flag_no_entrypoint='-no-entry-point' +flag_no_thread_local='-no-thread-local' +flag_no_thread_checker='-no-threaded-checker' +flag_output_path='-out=' +flag_optimization_level='-opt:' +flag_optimize_none='-o:none' +flag_optimize_minimal='-o:minimal' +flag_optimize_size='-o:size' +flag_optimize_speed='-o:speed' +flag_optimize_aggressive='-o:aggressive' +flag_pdb_name='-pdb-name:' +flag_sanitize_address='-sanitize:address' +flag_sanitize_memory='-sanitize:memory' +flag_sanitize_thread='-sanitize:thread' +flag_subsystem='-subsystem:' +flag_show_timings='-show-timings' +flag_show_more_timings='-show-more-timings' +flag_show_system_calls='-show-system-calls' +flag_target='-target:' +flag_thread_count='-thread-count:' +flag_use_lld='-lld' +flag_use_separate_modules='-use-separate-modules' +flag_vet_all='-vet' +flag_vet_unused_entities='-vet-unused' +flag_vet_semicolon='-vet-semicolon' +flag_vet_shadow_vars='-vet-shadowing' +flag_vet_using_stmt='-vet-using-stmt' + +# flag_msvc_link_disable_dynamic_base='/DYNAMICBASE:NO' +# flag_msvc_link_base_address='/BASE:' +# flag_msvc_link_fixed_base_address='/FIXED' +# flag_msvc_link_stack_size='/STACK' +# flag_msvc_link_debug='/DEBUG' + +# Assuming to be in default path, change if otherwise +odin_compiler='odin'