2024-01-21 08:16:12 -08:00
|
|
|
|
cls
|
2024-03-02 07:24:09 -08:00
|
|
|
|
write-host "Build.ps1"
|
2024-01-21 08:16:12 -08:00
|
|
|
|
|
2024-01-22 18:38:09 -08:00
|
|
|
|
$incremental_checks = Join-Path $PSScriptRoot 'helpers/incremental_checks.ps1'
|
|
|
|
|
. $incremental_checks
|
2024-03-02 07:24:09 -08:00
|
|
|
|
write-host 'incremental_checks.ps1 imported'
|
|
|
|
|
|
|
|
|
|
$ini_parser = join-path $PSScriptRoot 'helpers/ini.ps1'
|
|
|
|
|
. $ini_parser
|
|
|
|
|
write-host 'ini.ps1 imported'
|
2024-01-22 18:38:09 -08:00
|
|
|
|
|
2024-01-21 21:22:06 -08:00
|
|
|
|
$path_root = git rev-parse --show-toplevel
|
2024-01-22 18:38:09 -08:00
|
|
|
|
$path_code = join-path $path_root 'code'
|
|
|
|
|
$path_build = join-path $path_root 'build'
|
|
|
|
|
$path_scripts = join-path $path_root 'scripts'
|
|
|
|
|
$path_thirdparty = join-path $path_root 'thirdparty'
|
2024-03-19 15:52:33 -07:00
|
|
|
|
$path_toolchain = join-path $path_root 'toolchain'
|
|
|
|
|
$path_odin = join-path $path_toolchain 'odin'
|
2024-01-21 08:16:12 -08:00
|
|
|
|
|
2024-03-02 07:24:09 -08:00
|
|
|
|
if ( -not( test-path $path_build) ) {
|
|
|
|
|
new-item -ItemType Directory -Path $path_build
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$path_system_details = join-path $path_build 'system_details.ini'
|
|
|
|
|
if ( test-path $path_system_details ) {
|
|
|
|
|
$iniContent = Get-IniContent $path_system_details
|
|
|
|
|
$CoreCount_Physical = $iniContent["CPU"]["PhysicalCores"]
|
|
|
|
|
$CoreCount_Logical = $iniContent["CPU"]["LogicalCores"]
|
|
|
|
|
}
|
|
|
|
|
elseif ( $IsWindows ) {
|
2024-02-27 04:50:57 -08:00
|
|
|
|
$CPU_Info = Get-CimInstance –ClassName Win32_Processor | Select-Object -Property NumberOfCores, NumberOfLogicalProcessors
|
|
|
|
|
$CoreCount_Physical, $CoreCount_Logical = $CPU_Info.NumberOfCores, $CPU_Info.NumberOfLogicalProcessors
|
2024-03-02 07:24:09 -08:00
|
|
|
|
|
|
|
|
|
new-item -path $path_system_details -ItemType File
|
|
|
|
|
"[CPU]" | Out-File $path_system_details
|
|
|
|
|
"PhysicalCores=$CoreCount_Physical" | Out-File $path_system_details -Append
|
|
|
|
|
"LogicalCores=$CoreCount_Logical" | Out-File $path_system_details -Append
|
2024-02-27 04:50:57 -08:00
|
|
|
|
}
|
2024-03-02 07:24:09 -08:00
|
|
|
|
write-host "Core Count - Physical: $CoreCount_Physical Logical: $CoreCount_Logical"
|
2024-02-27 04:50:57 -08:00
|
|
|
|
|
2024-01-21 08:16:12 -08:00
|
|
|
|
# Odin Compiler Flags
|
|
|
|
|
|
2024-02-27 06:32:26 -08:00
|
|
|
|
# For a beakdown of any flag, type <odin_compiler> <command> -help
|
2024-02-27 04:50:57 -08:00
|
|
|
|
$command_build = 'build'
|
|
|
|
|
$command_check = 'check'
|
|
|
|
|
$command_query = 'query'
|
|
|
|
|
$command_report = 'report'
|
|
|
|
|
$command_run = 'run'
|
|
|
|
|
|
2024-02-27 06:32:26 -08:00
|
|
|
|
$flag_build_mode = '-build-mode:'
|
|
|
|
|
$flag_build_mode_dll = '-build-mode:dll'
|
|
|
|
|
$flag_collection = '-collection:'
|
|
|
|
|
$flag_debug = '-debug'
|
|
|
|
|
$flag_define = '-define:'
|
2024-03-11 23:32:46 -07:00
|
|
|
|
$flag_default_allocator_nil = '-default-to-nil-allocator'
|
2024-02-27 06:32:26 -08:00
|
|
|
|
$flag_disable_assert = '-disable-assert'
|
2024-03-11 23:32:46 -07:00
|
|
|
|
$flag_dynamic_map_calls = '-dynamic-map-calls'
|
2024-02-27 06:32:26 -08:00
|
|
|
|
$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'
|
2024-03-11 23:32:46 -07:00
|
|
|
|
$flag_max_error_count = '-max-error-count:'
|
|
|
|
|
$flag_micro_architecture_native = '-microarch:native'
|
2024-02-27 06:32:26 -08:00
|
|
|
|
$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'
|
2024-03-11 23:32:46 -07:00
|
|
|
|
$flag_no_thread_checker = '-no-threaded-checker'
|
2024-02-27 06:32:26 -08:00
|
|
|
|
$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:'
|
2024-03-11 23:32:46 -07:00
|
|
|
|
$flag_sanitize_address = '-sanitize:address'
|
|
|
|
|
$flag_sanitize_memory = '-sanitize:memory'
|
|
|
|
|
$flag_sanitize_thread = '-sanitize:thread'
|
2024-02-27 06:32:26 -08:00
|
|
|
|
$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'
|
2024-01-21 08:16:12 -08:00
|
|
|
|
|
2024-02-27 04:50:57 -08:00
|
|
|
|
$flag_msvc_link_disable_dynamic_base = '/DYNAMICBASE:NO'
|
|
|
|
|
$flag_msvc_link_base_address = '/BASE:'
|
|
|
|
|
$flag_msvc_link_fixed_base_address = '/FIXED'
|
2024-03-13 21:00:29 -07:00
|
|
|
|
$flag_msvc_link_stack_size = '/STACK'
|
2024-01-21 08:16:12 -08:00
|
|
|
|
|
2024-02-27 04:50:57 -08:00
|
|
|
|
$msvc_link_default_base_address = 0x180000000
|
2024-01-21 08:16:12 -08:00
|
|
|
|
|
2024-02-27 04:50:57 -08:00
|
|
|
|
push-location $path_root
|
|
|
|
|
$update_deps = join-path $path_scripts 'update_deps.ps1'
|
|
|
|
|
$odin_compiler = join-path $path_odin 'odin.exe'
|
2024-03-10 07:31:21 -07:00
|
|
|
|
$raddbg = "C:/dev/raddbg/raddbg.exe"
|
2024-03-02 07:24:09 -08:00
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|
2024-01-21 08:16:12 -08:00
|
|
|
|
}
|
2024-01-22 18:38:09 -08:00
|
|
|
|
|
2024-01-21 08:16:12 -08:00
|
|
|
|
function build-prototype
|
|
|
|
|
{
|
|
|
|
|
push-location $path_code
|
|
|
|
|
$project_name = 'sectr'
|
|
|
|
|
|
2024-02-27 04:50:57 -08:00
|
|
|
|
write-host "`nBuilding Sectr Prototype`n"
|
2024-01-25 07:49:57 -08:00
|
|
|
|
|
2024-02-12 17:52:56 -08:00
|
|
|
|
$module_host = join-path $path_code 'host'
|
|
|
|
|
$module_sectr = $path_code
|
|
|
|
|
|
2024-02-27 04:50:57 -08:00
|
|
|
|
$pkg_collection_thirdparty = 'thirdparty=' + $path_thirdparty
|
|
|
|
|
|
|
|
|
|
$host_process_active = Get-Process | Where-Object {$_.Name -like 'sectr_host*'}
|
|
|
|
|
if ( -not $host_process_active ) {
|
2024-02-27 06:32:26 -08:00
|
|
|
|
# We cannot update thidparty dependencies during hot-reload.
|
2024-02-27 04:50:57 -08:00
|
|
|
|
& $update_deps
|
|
|
|
|
write-host
|
|
|
|
|
}
|
2024-02-13 23:27:21 -08:00
|
|
|
|
|
2024-03-01 12:23:32 -08:00
|
|
|
|
$module_build_failed = 0
|
|
|
|
|
$module_built = 1
|
|
|
|
|
$module_unchanged = 2
|
|
|
|
|
|
2024-02-13 23:27:21 -08:00
|
|
|
|
function build-sectr
|
|
|
|
|
{
|
|
|
|
|
$should_build = check-ModuleForChanges $module_sectr
|
|
|
|
|
if ( -not( $should_build)) {
|
|
|
|
|
write-host 'Skipping sectr build, module up to date'
|
2024-03-01 12:23:32 -08:00
|
|
|
|
return $module_unchanged
|
2024-02-13 23:27:21 -08:00
|
|
|
|
}
|
|
|
|
|
|
2024-02-27 06:32:26 -08:00
|
|
|
|
write-host 'Building Sectr Module'
|
2024-02-13 23:27:21 -08:00
|
|
|
|
$module_dll = join-path $path_build ( $project_name + '.dll' )
|
|
|
|
|
$pdb = join-path $path_build ( $project_name + '.pdb' )
|
|
|
|
|
|
2024-03-20 17:50:46 -07:00
|
|
|
|
if (test-path $pdb) {
|
|
|
|
|
remove-item $pdb
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-27 04:50:57 -08:00
|
|
|
|
$linker_args = ""
|
|
|
|
|
$linker_args += ( $flag_msvc_link_disable_dynamic_base + ' ' )
|
|
|
|
|
$linker_args += ( $flag_msvc_link_fixed_base_address + ' ' )
|
|
|
|
|
$linker_args += ( $flag_msvc_link_base_address + '0x20000000000' )
|
|
|
|
|
# $linker_args += ( $flag_msvc_link_base_address + '0x200000000' )
|
|
|
|
|
|
2024-02-13 23:27:21 -08:00
|
|
|
|
$build_args = @()
|
2024-02-27 04:50:57 -08:00
|
|
|
|
$build_args += $command_build
|
2024-02-13 23:27:21 -08:00
|
|
|
|
$build_args += '.'
|
|
|
|
|
$build_args += $flag_build_mode_dll
|
|
|
|
|
$build_args += $flag_output_path + $module_dll
|
2024-03-19 15:52:33 -07:00
|
|
|
|
$build_args += ($flag_collection + $pkg_collection_thirdparty)
|
2024-03-19 21:44:43 -07:00
|
|
|
|
# $build_args += $flag_micro_architecture_native
|
2024-03-19 09:18:39 -07:00
|
|
|
|
# $build_args += $flag_use_separate_modules
|
2024-03-19 21:44:43 -07:00
|
|
|
|
# $build_args += $flag_thread_count + $CoreCount_Physical
|
2024-03-11 23:32:46 -07:00
|
|
|
|
$build_args += $flag_optimize_none
|
2024-03-10 07:31:21 -07:00
|
|
|
|
# $build_args += $flag_optimize_minimal
|
2024-03-10 23:05:18 -07:00
|
|
|
|
# $build_args += $flag_optimize_speed
|
2024-03-11 23:32:46 -07:00
|
|
|
|
# $build_args += $falg_optimize_aggressive
|
2024-02-13 23:27:21 -08:00
|
|
|
|
$build_args += $flag_debug
|
|
|
|
|
$build_args += $flag_pdb_name + $pdb
|
2024-02-27 04:50:57 -08:00
|
|
|
|
$build_args += $flag_subsystem + 'windows'
|
|
|
|
|
# $build_args += $flag_show_system_calls
|
2024-03-02 07:24:09 -08:00
|
|
|
|
$build_args += $flag_show_timings
|
2024-03-13 21:00:29 -07:00
|
|
|
|
$build_args += ($flag_extra_linker_flags + $linker_args )
|
2024-03-11 23:32:46 -07:00
|
|
|
|
# $build_args += $flag_no_thread_checker
|
|
|
|
|
# $build_args += $flag_dynamic_map_calls
|
2024-03-19 17:20:34 -07:00
|
|
|
|
# $build_args += $flag_default_allocator_nil
|
2024-03-11 23:32:46 -07:00
|
|
|
|
$build_args += ($flag_max_error_count + '10')
|
|
|
|
|
# $build_args += $flag_sanitize_address
|
|
|
|
|
# $build_args += $flag_sanitize_memory
|
2024-03-10 07:31:21 -07:00
|
|
|
|
|
|
|
|
|
$raddbg_args = @()
|
|
|
|
|
$raddbg_args += $odin_compiler
|
|
|
|
|
$raddbg_args += $build_args
|
2024-02-13 23:27:21 -08:00
|
|
|
|
|
2024-02-27 06:32:26 -08:00
|
|
|
|
if ( Test-Path $module_dll) {
|
|
|
|
|
$module_dll_pre_build_hash = get-filehash -path $module_dll -Algorithm MD5
|
|
|
|
|
}
|
2024-03-01 12:23:32 -08:00
|
|
|
|
|
2024-03-19 17:20:34 -07:00
|
|
|
|
# write-host $build_args
|
2024-03-10 07:31:21 -07:00
|
|
|
|
|
2024-03-02 07:24:09 -08:00
|
|
|
|
Invoke-WithColorCodedOutput -command { & $odin_compiler $build_args }
|
2024-03-10 07:31:21 -07:00
|
|
|
|
# Invoke-WithColorCodedOutput -command { & $raddbg "$odin_compiler" "$build_args" }
|
2024-03-01 12:23:32 -08:00
|
|
|
|
|
|
|
|
|
if ( Test-Path $module_dll ) {
|
|
|
|
|
$module_dll_post_build_hash = get-filehash -path $module_dll -Algorithm MD5
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$built = ($module_dll_pre_build_hash -eq $null) -or ($module_dll_pre_build_hash.Hash -ne $module_dll_post_build_hash.Hash)
|
|
|
|
|
if ( -not $built ) {
|
|
|
|
|
write-host 'Failed to build, marking module dirty'
|
|
|
|
|
mark-ModuleDirty $module_sectr
|
|
|
|
|
}
|
|
|
|
|
return $built
|
2024-02-13 23:27:21 -08:00
|
|
|
|
}
|
2024-03-19 13:57:28 -07:00
|
|
|
|
$script:sectr_build_code = build-sectr
|
2024-02-13 23:27:21 -08:00
|
|
|
|
|
2024-01-25 07:49:57 -08:00
|
|
|
|
function build-host
|
|
|
|
|
{
|
|
|
|
|
$executable = join-path $path_build ($project_name + '_host.exe')
|
|
|
|
|
$pdb = join-path $path_build ($project_name + '_host.pdb')
|
|
|
|
|
|
|
|
|
|
if ( $host_process_active ) {
|
|
|
|
|
write-host 'Skipping sectr_host build, process is active'
|
|
|
|
|
return
|
|
|
|
|
}
|
2024-01-25 08:24:52 -08:00
|
|
|
|
|
2024-03-19 13:57:28 -07:00
|
|
|
|
$dependencies_built = $script:sectr_build_code -ne $module_build_failed
|
|
|
|
|
if ( -not $dependencies_built ) {
|
|
|
|
|
write-host 'Skipping sectr_host build, dependencies failed to build'
|
|
|
|
|
return
|
|
|
|
|
}
|
2024-03-01 12:23:32 -08:00
|
|
|
|
|
2024-03-19 13:57:28 -07:00
|
|
|
|
$should_build = (check-ModuleForChanges $module_host) -or ( $script:sectr_build_code -eq $module_built )
|
2024-01-25 07:49:57 -08:00
|
|
|
|
if ( -not( $should_build)) {
|
|
|
|
|
write-host 'Skipping sectr_host build, module up to date'
|
|
|
|
|
return
|
|
|
|
|
}
|
2024-01-22 18:38:09 -08:00
|
|
|
|
|
2024-03-20 17:50:46 -07:00
|
|
|
|
if (test-path $pdb) {
|
|
|
|
|
remove-item $pdb
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-02 07:24:09 -08:00
|
|
|
|
write-host 'Building Host Module'
|
2024-02-27 04:50:57 -08:00
|
|
|
|
$linker_args = ""
|
2024-03-19 05:36:58 -07:00
|
|
|
|
# $linker_args += ( $flag_msvc_link_disable_dynamic_base + ' ' )
|
|
|
|
|
# $linker_args += ( $flag_msvc_link_stack_size + ' ')
|
2024-02-27 04:50:57 -08:00
|
|
|
|
|
2024-01-22 00:47:53 -08:00
|
|
|
|
$build_args = @()
|
2024-02-27 04:50:57 -08:00
|
|
|
|
$build_args += $command_build
|
2024-01-22 00:47:53 -08:00
|
|
|
|
$build_args += './host'
|
|
|
|
|
$build_args += $flag_output_path + $executable
|
2024-03-19 15:52:33 -07:00
|
|
|
|
$build_args += ($flag_collection + $pkg_collection_thirdparty)
|
2024-03-19 21:44:43 -07:00
|
|
|
|
# $build_args += $flag_micro_architecture_native
|
|
|
|
|
# $build_args += $flag_use_separate_modules
|
|
|
|
|
# $build_args += $flag_thread_count + $CoreCount_Physical
|
2024-03-19 09:18:39 -07:00
|
|
|
|
$build_args += $flag_optimize_none
|
2024-03-10 23:05:18 -07:00
|
|
|
|
# $build_args += $flag_optimize_minimal
|
2024-03-10 23:05:30 -07:00
|
|
|
|
# $build_args += $flag_optimize_speed
|
2024-03-19 09:18:39 -07:00
|
|
|
|
# $build_args += $falg_optimize_aggressive
|
2024-01-22 00:47:53 -08:00
|
|
|
|
$build_args += $flag_debug
|
|
|
|
|
$build_args += $flag_pdb_name + $pdb
|
|
|
|
|
$build_args += $flag_subsystem + 'windows'
|
2024-03-10 07:31:21 -07:00
|
|
|
|
# $build_args += ($flag_extra_linker_flags + $linker_args )
|
2024-03-02 07:24:09 -08:00
|
|
|
|
$build_args += $flag_show_timings
|
2024-02-27 04:50:57 -08:00
|
|
|
|
# $build_args += $flag_show_system_call
|
2024-03-19 21:44:43 -07:00
|
|
|
|
# $build_args += $flag_no_bounds_check
|
|
|
|
|
# $build_args += $flag_no_thread_checker
|
2024-03-19 17:20:34 -07:00
|
|
|
|
# $build_args += $flag_default_allocator_nil
|
2024-03-11 23:32:46 -07:00
|
|
|
|
$build_args += ($flag_max_error_count + '10')
|
|
|
|
|
# $build_args += $flag_sanitize_address
|
|
|
|
|
# $build_args += $flag_sanitize_memory
|
2024-01-21 08:16:12 -08:00
|
|
|
|
|
2024-03-02 07:24:09 -08:00
|
|
|
|
Invoke-WithColorCodedOutput { & $odin_compiler $build_args }
|
2024-01-22 00:47:53 -08:00
|
|
|
|
}
|
2024-01-25 07:49:57 -08:00
|
|
|
|
build-host
|
|
|
|
|
|
2024-02-27 04:50:57 -08:00
|
|
|
|
Pop-Location # path_code
|
2024-01-21 08:16:12 -08:00
|
|
|
|
}
|
|
|
|
|
build-prototype
|
2024-02-27 04:50:57 -08:00
|
|
|
|
pop-location # path_root
|
2024-03-02 07:24:09 -08:00
|
|
|
|
|
|
|
|
|
exit 0
|