diff --git a/ols.json b/ols.json new file mode 100644 index 0000000..4f0edda --- /dev/null +++ b/ols.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://raw.githubusercontent.com/DanielGavin/ols/master/misc/ols.schema.json", + "odin_command": "odin.exe", + "collections": [ + { + "name": "backend", + "path": "./backend" + }, + { + "name": "examples", + "path": "./sectr" + }, + { + "name": "thirdparty", + "path": "./thirdparty" + } + ], + "enable_document_symbols": true, + "enable_fake_methods": true, + "enable_format": false, + "enable_hover": true, + "enable_semantic_tokens": false, + "enable_snippets": false, + "enable_references": true, + "thread_pool_count": 10, + "enable_inlay_hints": true, + "enable_procedure_context": true, + "enable_procedure_snippet": false, + "verbose": true, + "disable_parser_errors": true +} diff --git a/scripts/build_sokol_demo.ps1 b/scripts/build_sokol_demo.ps1 new file mode 100644 index 0000000..9ea4d61 --- /dev/null +++ b/scripts/build_sokol_demo.ps1 @@ -0,0 +1,77 @@ +$path_root = git rev-parse --show-toplevel +$path_backend = join-path $path_backend 'backend' +$path_binaries = join-path $path_bin 'binaries' +$path_examples = join-path $path_examples 'examples' +$path_scripts = join-path $path_root 'scripts' +$path_thirdparty = join-path $path_root 'thirdparty' + +verify-path $path_binaries +verify-path $path_thirdparty + +$misc = join-path $PSScriptRoot 'helpers/misc.ps1' +. $misc + +$url_sokol = 'https://github.com/Ed94/sokol-odin.git' +$url_sokol_tools = 'https://github.com/floooh/sokol-tools-bin.git' + +$path_sokol = join-path $path_thirdparty 'sokol' +$path_sokol_tools = join-path $path_thirdparty 'sokol-tools' + +$sokol_build_clibs_command = join-path $path_scripts 'build_sokol_library.ps1' + +clone-gitrepo $path_sokol_tools $url_sokol_tools +Update-GitRepo -path $path_sokol -url $url_sokol -build_command $sokol_build_clibs_command + +push-location $path_thirdparty + $path_sokol_dlls = join-path $path_sokol 'sokol' + + $third_party_dlls = Get-ChildItem -Path $path_sokol_dlls -Filter '*.dll' + foreach ($dll in $third_party_dlls) { + $destination = join-path $path_binaries $dll.Name + Copy-Item $dll.FullName -Destination $destination -Force + } +pop-location + +$odin_compiler_defs = join-path $PSScriptRoot 'helpers/odin_compiler_defs.ps1' +. $odin_compiler_defs + +$pkg_collection_backend = 'backend=' + $path_backend +$pkg_collection_thirdparty = 'thirdparty=' + $path_thirdparty + +push-location $path_examples + +function build-SokolBackendDemo +{ + write-host 'Building VEFontCache: Sokol Backend Demo' + + $build_args = @() + $build_args += $command_build + $build_args += './sokol_demo' + $build_args += $flag_output_path + $executable + $build_args += ($flag_collection + $pkg_collection_backend) + $build_args += ($flag_collection + $pkg_collection_thirdparty) + # $build_args += $flag_micro_architecture_native + $build_args += $flag_use_separate_modules + $build_args += $flag_thread_count + $CoreCount_Physical + # $build_args += $flag_optimize_none + # $build_args += $flag_optimize_minimal + # $build_args += $flag_optimize_speed + $build_args += $falg_optimize_aggressive + $build_args += $flag_debug + $build_args += $flag_pdb_name + $pdb + $build_args += $flag_subsystem + 'windows' + # $build_args += ($flag_extra_linker_flags + $linker_args ) + $build_args += $flag_show_timings + # $build_args += $flag_show_system_call + # $build_args += $flag_no_bounds_check + # $build_args += $flag_no_thread_checker + # $build_args += $flag_default_allocator_nil + $build_args += ($flag_max_error_count + '10') + # $build_args += $flag_sanitize_address + # $build_args += $flag_sanitize_memory + + Invoke-WithColorCodedOutput { & $odin_compiler $build_args } +} +build-SokolBackendDemo + +pop-location diff --git a/scripts/build_sokol_library.ps1 b/scripts/build_sokol_library.ps1 new file mode 100644 index 0000000..dd82a6f --- /dev/null +++ b/scripts/build_sokol_library.ps1 @@ -0,0 +1,18 @@ +$devshell = Join-Path $PSScriptRoot 'devshell.ps1' +& $devshell -arch amd64 + +$path_root = git rev-parse --show-toplevel +$path_backend = join-path $path_backend 'backend' +$path_binaries = join-path $path_bin 'binaries' +$path_scripts = join-path $path_root 'scripts' +$path_thirdparty = join-path $path_root 'thirdparty' + +$path_sokol = Join-Path $path_thirdparty 'sokol' +if (test-path $path_sokol) +{ + Move-Item -Path "$path_sokol/sokol/*" -Destination $path_sokol -Force + Remove-Item -Path $path_sokol -Recurse -Force + Remove-Item -Path $path_sokol_examples -Recurse -Force +} + +& '.\build_clibs_windows.cmd' diff --git a/scripts/compile_sokol_shaders.ps1 b/scripts/compile_sokol_shaders.ps1 new file mode 100644 index 0000000..4ae6c3d --- /dev/null +++ b/scripts/compile_sokol_shaders.ps1 @@ -0,0 +1,31 @@ +$path_root = git rev-parse --show-toplevel +$path_backend = join-path $path_root 'backend' +$path_scripts = join-path $path_root 'scripts' +$path_thirdparty = join-path $path_root 'thirdparty' + +$path_sokol_tools = join-path $path_thirdparty 'sokol-tools' +$sokol_shdc = join-path $path_sokol_tools 'bin/win32/sokol-shdc.exe' + +$path_backend_sokol = join-path $path_backend 'sokol' + +$shadersrc_blit_atlas = join-path $path_backend_sokol 'blit_atlas.shdc.glsl' +$shaderout_blit_atlas = join-path $path_backend_sokol 'blit_atlas.odin' + +$shadersrc_draw_text = join-path $path_backend_sokol 'draw_text.shdc.glsl' +$shaderout_draw_text = join-path $path_backend_sokol 'draw_text.odin' + +$shadersrc_render_glyph = join-path $path_backend_sokol 'render_glyph.shdc.glsl' +$shaderout_render_glyph = join-path $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' + +push-location $path_backend_sokol +& $sokol_shdc --input $shadersrc_simple_font_glyph --output $shaderout_simple_font_glyph --slang 'hlsl4' $flag_format_odin +& $sokol_shdc --input $shadersrc_blit_atlas --output $shaderout_blit_atlas --slang 'hlsl4' $flag_format_odin $flag_module='blit_atlas' +& $sokol_shdc --input $shadersrc_render_glyph --output $shaderout_render_glyph --slang 'hlsl4' $flag_format_odin $flag_module='render_glyph' +& $sokol_shdc --input $shadersrc_draw_text --output $shaderout_draw_text --slang 'hlsl4' $flag_format_odin $flag_module='draw_text' +pop-location diff --git a/scripts/devshell.ps1 b/scripts/devshell.ps1 new file mode 100644 index 0000000..33ca0ce --- /dev/null +++ b/scripts/devshell.ps1 @@ -0,0 +1,28 @@ +if ($env:VCINSTALLDIR) { + return +} + +$ErrorActionPreference = "Stop" + +# Use vswhere to find the latest Visual Studio installation +$vswhere_out = & "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -latest -property installationPath +if ($null -eq $vswhere_out) { + Write-Host "ERROR: Visual Studio installation not found" + exit 1 +} + +# Find Launch-VsDevShell.ps1 in the Visual Studio installation +$vs_path = $vswhere_out +$vs_devshell = Join-Path $vs_path "\Common7\Tools\Launch-VsDevShell.ps1" + +if ( -not (Test-Path $vs_devshell) ) { + Write-Host "ERROR: Launch-VsDevShell.ps1 not found in Visual Studio installation" + Write-Host Tested path: $vs_devshell + exit 1 +} + +# Launch the Visual Studio Developer Shell +Push-Location +write-host @args +& $vs_devshell @args +Pop-Location diff --git a/scripts/helpers/misc.ps1 b/scripts/helpers/misc.ps1 new file mode 100644 index 0000000..8045452 --- /dev/null +++ b/scripts/helpers/misc.ps1 @@ -0,0 +1,80 @@ +function clone-gitrepo { param( [string] $path, [string] $url ) + if (test-path $path) { + # git -C $path pull + } + else { + Write-Host "Cloning $url ..." + git clone $url $path + } +} + +# TODO(Ed): This is garbage for odin's output.. +function Invoke-WithColorCodedOutput { param( [scriptblock] $command ) + & $command 2>&1 | ForEach-Object { + # Write-Host "Type: $($_.GetType().FullName)" # Add this line for debugging + $color = 'White' # Default text color + switch ($_) { + { $_ -imatch "error" } { $color = 'Red'; break } + { $_ -imatch "warning" } { $color = 'Yellow'; break } + } + Write-Host "`t$_" -ForegroundColor $color + } +} + +function Update-GitRepo +{ + param( [string] $path, [string] $url, [string] $build_command ) + + if ( $build_command -eq $null ) { + write-host "Attempted to call Update-GitRepo without build_command specified" + return + } + + $repo_name = $url.Split('/')[-1].Replace('.git', '') + + $last_built_commit = join-path $path_build "last_built_commit_$repo_name.txt" + if ( -not(test-path -Path $path)) + { + write-host "Cloining repo from $url to $path" + git clone $url $path + + write-host "Building $url" + push-location $path + & "$build_command" + pop-location + + git -C $path rev-parse HEAD | out-file $last_built_commit + $script:binaries_dirty = $true + write-host + return + } + + git -C $path fetch + $latest_commit_hash = git -C $path rev-parse '@{u}' + $last_built_hash = if (Test-Path $last_built_commit) { Get-Content $last_built_commit } else { "" } + + if ( $latest_commit_hash -eq $last_built_hash ) { + write-host + return + } + + write-host "Build out of date for: $path, updating" + write-host 'Pulling...' + git -C $path pull + + write-host "Building $url" + push-location $path + & $build_command + pop-location + + $latest_commit_hash | out-file $last_built_commit + $script:binaries_dirty = $true + write-host +} + +function verify-path { param( $path ) + if (test-path $path) {return $true} + + new-item -ItemType Directory -Path $path + return $false +} diff --git a/scripts/helpers/odin_compiler_defs.ps1 b/scripts/helpers/odin_compiler_defs.ps1 new file mode 100644 index 0000000..af28e7c --- /dev/null +++ b/scripts/helpers/odin_compiler_defs.ps1 @@ -0,0 +1,63 @@ +# Not meant to be used standalone + +# Odin Compiler Flags + +# For a beakdown 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' +$falg_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.exe'